diff --git a/MANIFEST.in b/MANIFEST.in index 1641225..6c6bdd6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,6 @@ -include Makefile +include Makefile gittaggers.py +include tests/* +include tests/test-data/* global-exclude *~ global-exclude *.pyc + diff --git a/Makefile b/Makefile index f377b2f..044b2e6 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ MODULE=cwltest # `SHELL=bash` doesn't work for some, so don't use BASH-isms like # `[[` conditional expressions. PYSOURCES=$(wildcard ${MODULE}/**.py tests/*.py) setup.py -DEVPKGS=pep8 diff_cover autopep8 pylint coverage pep257 flake8 +DEVPKGS=pep8 diff_cover autopep8 pylint coverage pep257 flake8 pytest DEBDEVPKGS=pep8 python-autopep8 pylint python-coverage pep257 sloccount python-flake8 VERSION=1.0.$(shell date +%Y%m%d%H%M%S --date=`git log --first-parent \ --max-count=1 --format=format:%cI`) @@ -34,7 +34,7 @@ mkfile_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) ## all : default task all: - ./setup.py develop + pip install -e . ## help : print this help message and exit help: Makefile @@ -109,10 +109,7 @@ diff_pylint_report: pylint_report.txt diff-quality --violations=pylint pylint_report.txt .coverage: $(PYSOURCES) all - export COVERAGE_PROCESS_START=${mkfile_dir}.coveragerc; \ - cd ${CWL}; ./run_test.sh RUNNER=cwltool - coverage run setup.py test - coverage combine ${CWL} ${CWL}/draft-3/ ./ + coverage run ./setup.py test coverage.xml: .coverage python-coverage xml @@ -135,6 +132,7 @@ diff-cover.html: coverage-gcovr.xml coverage.xml ## test : run the ${MODULE} test suite test: FORCE + ./setup.py test sloccount.sc: ${PYSOURCES} Makefile sloccount --duplicates --wide --details $^ > sloccount.sc diff --git a/release-test.sh b/release-test.sh index c0c4ff2..124a2ea 100755 --- a/release-test.sh +++ b/release-test.sh @@ -6,7 +6,7 @@ set -x package=cwltest module=cwltest repo=https://github.com/common-workflow-language/cwltest.git -run_tests="cwltest --help" +run_tests="py.test --pyarg ${module}" pipver=8.0.1 # minimum required version of pip setupver=20.10.1 # minimum required version of setuptools diff --git a/setup.cfg b/setup.cfg index 87c34d2..903a610 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,3 +5,9 @@ ignore = E124,E128,E129,E201,E202,E225,E226,E231,E265,E271,E302,E303,F401,E402,E [bdist_wheel] universal = 1 + +[tool:pytest] +testpaths = tests + +[aliases] +test=pytest diff --git a/setup.py b/setup.py index 9127eb0..0c05388 100755 --- a/setup.py +++ b/setup.py @@ -22,6 +22,9 @@ 'six>=1.10.0' ] +needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv) +pytest_runner = ['pytest-runner'] if needs_pytest else [] + if sys.version_info.major == 2: install_requires.extend(['futures >= 3.0.5', 'subprocess32']) @@ -37,10 +40,13 @@ url="https://github.com/common-workflow-language/cwltest", download_url="https://github.com/common-workflow-language/cwltest", license='Apache 2.0', - packages=["cwltest"], + packages=["cwltest", "cwltest.tests"], + package_dir={'cwltest.tests': 'tests'}, + include_package_data=True, install_requires=install_requires, test_suite='tests', - tests_require=[], + setup_requires=[] + pytest_runner, + tests_require=['pytest'], entry_points={ 'console_scripts': ["cwltest=cwltest:main"] }, diff --git a/tests/test_compare.py b/tests/test_compare.py index ddaeeea..d748430 100644 --- a/tests/test_compare.py +++ b/tests/test_compare.py @@ -1,18 +1,10 @@ import unittest +from .util import get_data from cwltest import CompareFail from cwltest.utils import compare_file, compare -class TestCompare(unittest.TestCase): - - def compare_success(self, expected, actual): - try: - compare(expected, actual) - except CompareFail: - self.fail("Comparison failed unexpectedly") - - -class TestCompareFile(TestCompare): +class TestCompareFile(unittest.TestCase): def test_compare_file(self): expected = { @@ -20,7 +12,7 @@ def test_compare_file(self): "size": 2, "class": "File", "checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a" - } + } actual = { "basename": "cores.txt", @@ -48,10 +40,10 @@ def test_compare_contents_success(self): "checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a", "class": "File", "location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt", - "path": "tests/test-data/cores.txt", + "path": get_data("tests/test-data/cores.txt"), "size": 2 } - self.compare_success(expected, actual) + compare(expected, actual) def test_compare_contents_failure(self): expected = { @@ -66,7 +58,7 @@ def test_compare_contents_failure(self): "checksum": "sha1$7448d8798a4380162d4b56f9b452e2f6f9e24e7a", "class": "File", "location": "file:///var/folders/8x/2df05_7j20j6r8y81w4qf43r0000gn/T/tmpG0EkrS/cores.txt", - "path": "tests/test-data/cores.txt", + "path": get_data("tests/test-data/cores.txt"), "size": 2 } with self.assertRaises(CompareFail): diff --git a/tests/util.py b/tests/util.py new file mode 100644 index 0000000..c131cd3 --- /dev/null +++ b/tests/util.py @@ -0,0 +1,19 @@ +from __future__ import absolute_import +import os + +from pkg_resources import (Requirement, ResolutionError, # type: ignore + resource_filename) + + +def get_data(filename): + filename = os.path.normpath( + filename) # normalizing path depending on OS or else it will cause problem when joining path + filepath = None + try: + filepath = resource_filename( + Requirement.parse("cwltest"), filename) + except ResolutionError: + pass + if not filepath or not os.path.isfile(filepath): + filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename) + return filepath diff --git a/tox.ini b/tox.ini index 348a5f3..7af39d7 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] #envlist = py35-lint,py34-lint,py33-lint,py27-lint,py35-unit,py34-unit,py33-unit,py27-unit -envlist = py27-lint, py27-unit, py35-mypy{2,3} +envlist = py27-lint, py{27,33,34,35}-unit, py35-mypy{2,3} skipsdist = True [travis] @@ -12,7 +12,9 @@ python = 3.5: py35-mypy{2,3} [testenv] -deps = -rrequirements.txt +deps = + pytest + -rrequirements.txt [testenv:py35-mypy2] commands = make mypy2 @@ -49,13 +51,14 @@ whitelist_externals = flake8 deps = flake8 [testenv:py35-unit] -commands = python setup.py test +commands = pytest {posargs} # substitute with tox' positional arguments [testenv:py34-unit] -commands = python setup.py test +commands = pytest {posargs} # substitute with tox' positional arguments [testenv:py33-unit] -commands = python setup.py test +commands = pytest {posargs} # substitute with tox' positional arguments [testenv:py27-unit] -commands = python setup.py test +commands = pytest {posargs} # substitute with tox' positional arguments +