Skip to content

Commit

Permalink
Merge pull request #2 from ggrossetie/pytest
Browse files Browse the repository at this point in the history
Switch to pytest (nose is unmaintained and does not work on Python3.10)
  • Loading branch information
ggrossetie authored Aug 13, 2023
2 parents dc1d35e + 4f4f726 commit a1dbac4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_version():
'docutils'
],
'testing': [
'nose',
'pytest',
'flake8',
'flake8-coding',
'flake8-copyright',
Expand All @@ -74,7 +74,6 @@ def get_version():
'docutils',
],
},
test_suite='nose.collector',
entry_points="""
[console_scripts]
blockdiag = blockdiag.command:main
Expand Down
95 changes: 47 additions & 48 deletions src/blockdiag/tests/test_generate_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import unittest
from xml.etree import ElementTree

from nose.tools import nottest
import pytest

import blockdiag
import blockdiag.command
Expand All @@ -46,66 +46,65 @@ def get_diagram_files(testdir):
yield os.path.join(diagramsdir, file)


def test_generate():
mainfunc = blockdiag.command.main
basepath = os.path.dirname(__file__)
files = get_diagram_files(basepath)
options = []
base_path = os.path.dirname(__file__)
files = get_diagram_files(base_path)
generate_testdata = []
generate_with_separate_testdata = []
for file_source in files:
generate_testdata.append((file_source, 'svg', []))
generate_testdata.append((file_source, 'png', []))
generate_testdata.append((file_source, 'png', ['--antialias']))
generate_testdata.append((file_source, 'pdf', []))
if re.search('separate', file_source):
generate_with_separate_testdata.append((file_source, 'svg', ['--separate']))
generate_with_separate_testdata.append((file_source, 'png', ['--separate']))
generate_with_separate_testdata.append((file_source, 'png', ['--separate', '--antialias']))
generate_with_separate_testdata.append((file_source, 'pdf', ['--separate']))

for testcase in testcase_generator(basepath, mainfunc, files, options):
yield testcase

@pytest.mark.parametrize("source,file_type,options", generate_with_separate_testdata)
def test_generate_with_separate_option(source, file_type, options):
generate(source, file_type, options)

def test_generate_with_separate():
mainfunc = blockdiag.command.main
basepath = os.path.dirname(__file__)
files = get_diagram_files(basepath)
filtered = (f for f in files if re.search('separate', f))
options = ['--separate']

for testcase in testcase_generator(basepath, mainfunc, filtered, options):
yield testcase
@pytest.mark.parametrize("source,file_type,options", generate_testdata)
def test_generate_with_separate(source, file_type, options):
generate(source, file_type, options)


@nottest
def testcase_generator(basepath, mainfunc, files, options):
fontpath = get_fontpath(basepath)
options = options + ['-f', fontpath]

for source in files:
yield generate, mainfunc, 'svg', source, options

@capture_stderr
def generate(source, file_type, options):
if file_type == 'png':
if not supported_pil():
yield unittest.skip("Pillow is not available")(generate)
yield unittest.skip("Pillow is not available")(generate)
elif os.environ.get('ALL_TESTS') is None:
message = "Skipped by default. To enable it, specify $ALL_TESTS=1"
yield unittest.skip(message)(generate)
yield unittest.skip(message)(generate)
else:
yield generate, mainfunc, 'png', source, options
yield generate, mainfunc, 'png', source, options + ['--antialias']

unittest.skip('Pillow is not available')
return
if os.environ.get('ALL_TESTS') is None:
unittest.skip('Skipped by default. To enable it, specify $ALL_TESTS=1')
return
elif file_type == 'pdf':
if not supported_pdf():
yield unittest.skip("reportlab is not available")(generate)
elif os.environ.get('ALL_TESTS') is None:
message = "Skipped by default. To enable it, specify $ALL_TESTS=1"
yield unittest.skip(message)(generate)
else:
yield generate, mainfunc, 'pdf', source, options
unittest.skip('reportlab is not available')
return
if os.environ.get('ALL_TESTS') is None:
unittest.skip('Skipped by default. To enable it, specify $ALL_TESTS=1')
return


@capture_stderr
def generate(mainfunc, filetype, source, options):
tmpdir = None
try:
tmpdir = TemporaryDirectory()
fd, tmpfile = tmpdir.mkstemp()
fd, tmp_file = tmpdir.mkstemp()
os.close(fd)

mainfunc(['--debug', '-T', filetype, '-o', tmpfile, source] +
list(options))
blockdiag.command.main(
[
'--debug',
'-T',
file_type,
'-o', tmp_file, source
] + list(options)
)
finally:
tmpdir.clean()
if tmpdir is not None:
tmpdir.clean()


def not_exist_font_config_option_test():
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ deps =
passenv =
ALL_TESTS
commands =
nosetests
pytest

[testenv:flake8]
description =
Expand Down

0 comments on commit a1dbac4

Please sign in to comment.