Skip to content

Commit c949878

Browse files
authored
Merge pull request #294 from common-workflow-language/ship-tests
ship tests, add release tester
2 parents c2ff713 + ff9bef1 commit c949878

9 files changed

+135
-20
lines changed

MANIFEST.in

+18
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
11
include gittaggers.py ez_setup.py Makefile cwltool.py
2+
include tests/*
3+
include tests/wf/*
4+
include cwltool/schemas/v1.0/*.yml
5+
include cwltool/schemas/draft-2/*.yml
6+
include cwltool/schemas/draft-3/*.yml
7+
include cwltool/schemas/draft-3/*.md
8+
include cwltool/schemas/draft-3/salad/schema_salad/metaschema/*.yml
9+
include cwltool/schemas/draft-3/salad/schema_salad/metaschema/*.md
10+
include cwltool/schemas/v1.0/*.yml
11+
include cwltool/schemas/v1.0/*.md
12+
include cwltool/schemas/v1.0/salad/schema_salad/metaschema/*.yml
13+
include cwltool/schemas/v1.0/salad/schema_salad/metaschema/*.md
14+
include cwltool/schemas/v1.1.0-dev1/*.yml
15+
include cwltool/schemas/v1.1.0-dev1/*.md
16+
include cwltool/schemas/v1.1.0-dev1/salad/schema_salad/metaschema/*.yml
17+
include cwltool/schemas/v1.1.0-dev1/salad/schema_salad/metaschema/*.md
18+
include cwltool/cwlNodeEngine.js
19+
global-exclude *.pyc

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ MODULE=cwltool
2626
# `SHELL=bash` doesn't work for some, so don't use BASH-isms like
2727
# `[[` conditional expressions.
2828
PYSOURCES=$(wildcard ${MODULE}/**.py tests/*.py) setup.py
29-
DEVPKGS=pep8 diff_cover autopep8 pylint coverage pep257 flake8
29+
DEVPKGS=pep8 diff_cover autopep8 pylint coverage pep257 flake8 pytest
3030
DEBDEVPKGS=pep8 python-autopep8 pylint python-coverage pep257 sloccount python-flake8
3131
VERSION=1.0.$(shell date +%Y%m%d%H%M%S --date=`git log --first-parent \
3232
--max-count=1 --format=format:%cI`)
@@ -50,7 +50,7 @@ install-deb-dep:
5050

5151
## install : install the ${MODULE} module and schema-salad-tool
5252
install: FORCE
53-
./setup.py build install
53+
pip install .
5454

5555
## dist : create a module package for distribution
5656
dist: dist/${MODULE}-$(VERSION).tar.gz

release-test.sh

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
package=cwltool
7+
module=cwltool
8+
repo=https://github.com/common-workflow-language/cwltool.git
9+
run_tests="py.test --ignore ${module}/schemas/ --pyarg cwltool"
10+
pipver=7.0.2 # minimum required version of pip
11+
12+
rm -Rf testenv? || /bin/true
13+
14+
export HEAD=`git rev-parse HEAD`
15+
virtualenv testenv1
16+
virtualenv testenv2
17+
virtualenv testenv3
18+
virtualenv testenv4
19+
20+
# First we test the head
21+
source testenv1/bin/activate
22+
rm testenv1/lib/python-wheels/setuptools* \
23+
&& pip install --force-reinstall -U pip==${pipver} \
24+
&& pip install setuptools==20.10.1 wheel
25+
make install-dep
26+
make test
27+
pip uninstall -y ${package} || true; pip uninstall -y ${package} || true; make install
28+
mkdir testenv1/not-${module}
29+
# if there is a subdir named '${module}' py.test will execute tests
30+
# there instead of the installed module's tests
31+
pushd testenv1/not-${module}; ../bin/${run_tests}; popd
32+
33+
34+
# Secondly we test via pip
35+
36+
cd testenv2
37+
source bin/activate
38+
rm lib/python-wheels/setuptools* \
39+
&& pip install --force-reinstall -U pip==${pipver} \
40+
&& pip install setuptools==20.10.1 wheel
41+
pip install -e git+${repo}@${HEAD}#egg=${package}
42+
cd src/${package}
43+
make install-dep
44+
make dist
45+
make test
46+
cp dist/${package}*tar.gz ../../../testenv3/
47+
pip uninstall -y ${package} || true; pip uninstall -y ${package} || true; make install
48+
cd ../.. # no subdir named ${proj} here, safe for py.testing the installed module
49+
bin/${run_tests}
50+
51+
# Is the distribution in testenv2 complete enough to build another
52+
# functional distribution?
53+
54+
cd ../testenv3/
55+
source bin/activate
56+
rm lib/python-wheels/setuptools* \
57+
&& pip install --force-reinstall -U pip==${pipver} \
58+
&& pip install setuptools==20.10.1 wheel
59+
pip install ${package}*tar.gz
60+
pip install pytest
61+
mkdir out
62+
tar --extract --directory=out -z -f ${package}*.tar.gz
63+
cd out/${package}*
64+
make dist
65+
make test
66+
pip uninstall -y ${package} || true; pip uninstall -y ${package} || true; make install
67+
mkdir ../not-${module}
68+
pushd ../not-${module} ; ../../bin/${run_tests}; popd

setup.cfg

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
ignore = E124,E128,E129,E201,E202,E225,E226,E231,E265,E271,E302,E303,F401,E402,E501,W503,E731,F811,F821,F841
33
exclude = cwltool/schemas
44

5-
[easy_install]
5+
[aliases]
6+
test=pytest
67

8+
[tool:pytest]
9+
addopts=--ignore cwltool/schemas
10+
testpaths = tests

setup.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
import os
3+
import sys
34

45
import setuptools.command.egg_info as egg_info_cmd
56
from setuptools import setup
@@ -14,6 +15,9 @@
1415
except ImportError:
1516
tagger = egg_info_cmd.egg_info
1617

18+
needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
19+
pytest_runner = ['pytest-runner'] if needs_pytest else []
20+
1721
setup(name='cwltool',
1822
version='1.0',
1923
description='Common workflow language reference implementation',
@@ -23,7 +27,8 @@
2327
url="https://github.com/common-workflow-language/cwltool",
2428
download_url="https://github.com/common-workflow-language/cwltool",
2529
license='Apache 2.0',
26-
packages=["cwltool"],
30+
packages=["cwltool", 'cwltool.tests'],
31+
package_dir={'cwltool.tests': 'tests'},
2732
package_data={'cwltool': ['schemas/draft-2/*.yml',
2833
'schemas/draft-3/*.yml',
2934
'schemas/draft-3/*.md',
@@ -38,6 +43,7 @@
3843
'schemas/v1.1.0-dev1/salad/schema_salad/metaschema/*.yml',
3944
'schemas/v1.1.0-dev1/salad/schema_salad/metaschema/*.md',
4045
'cwlNodeEngine.js']},
46+
include_package_data=True,
4147
install_requires=[
4248
'setuptools',
4349
'requests >= 1.0',
@@ -47,8 +53,9 @@
4753
'schema-salad >= 2.2.20170216125639, < 3',
4854
'typing >= 3.5.2, < 3.6'
4955
],
56+
setup_requires=[] + pytest_runner,
5057
test_suite='tests',
51-
tests_require=[],
58+
tests_require=['pytest'],
5259
entry_points={
5360
'console_scripts': ["cwltool=cwltool.main:main"]
5461
},

tests/test_examples.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import cwltool.pathmapper
66
import cwltool.process
77
import cwltool.workflow
8-
8+
from .util import get_data
99

1010
class TestParamMatching(unittest.TestCase):
1111
def test_params(self):
@@ -112,12 +112,12 @@ def test_params(self):
112112
class TestFactory(unittest.TestCase):
113113
def test_factory(self):
114114
f = cwltool.factory.Factory()
115-
echo = f.make("tests/echo.cwl")
115+
echo = f.make(get_data("tests/echo.cwl"))
116116
self.assertEqual(echo(inp="foo"), {"out": "foo\n"})
117117

118118
def test_partial_scatter(self):
119119
f = cwltool.factory.Factory(on_error="continue")
120-
fail = f.make("tests/wf/scatterfail.cwl")
120+
fail = f.make(get_data("tests/wf/scatterfail.cwl"))
121121
try:
122122
fail()
123123
except cwltool.factory.WorkflowStatus as e:
@@ -129,7 +129,7 @@ def test_partial_scatter(self):
129129

130130
def test_partial_output(self):
131131
f = cwltool.factory.Factory(on_error="continue")
132-
fail = f.make("tests/wf/wffail.cwl")
132+
fail = f.make(get_data("tests/wf/wffail.cwl"))
133133
try:
134134
fail()
135135
except cwltool.factory.WorkflowStatus as e:
@@ -333,7 +333,7 @@ def test_lifting(self):
333333
# fails if the step 'out' doesn't match.
334334
with self.assertRaises(cwltool.workflow.WorkflowException):
335335
f = cwltool.factory.Factory()
336-
echo = f.make("tests/test_bad_outputs_wf.cwl")
336+
echo = f.make(get_data("tests/test_bad_outputs_wf.cwl"))
337337
self.assertEqual(echo(inp="foo"), {"out": "foo\n"})
338338

339339

tests/test_pack.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88
from cwltool.load_tool import fetch_document, validate_document
99
from cwltool.main import makeRelative
1010
from cwltool.process import adjustFileObjs, adjustDirObjs
11-
11+
from .util import get_data
1212

1313
class TestPack(unittest.TestCase):
1414
def test_pack(self):
1515
self.maxDiff = None
1616

17-
document_loader, workflowobj, uri = fetch_document("tests/wf/revsort.cwl")
17+
document_loader, workflowobj, uri = fetch_document(
18+
get_data("tests/wf/revsort.cwl"))
1819
document_loader, avsc_names, processobj, metadata, uri = validate_document(
1920
document_loader, workflowobj, uri)
2021
packed = cwltool.pack.pack(document_loader, processobj, uri, metadata)
21-
with open("tests/wf/expect_packed.cwl") as f:
22+
with open(get_data("tests/wf/expect_packed.cwl")) as f:
2223
expect_packed = json.load(f)
23-
adjustFileObjs(packed, partial(makeRelative, os.path.abspath("tests/wf")))
24-
adjustDirObjs(packed, partial(makeRelative, os.path.abspath("tests/wf")))
24+
adjustFileObjs(packed, partial(makeRelative,
25+
os.path.abspath(get_data("tests/wf"))))
26+
adjustDirObjs(packed, partial(makeRelative,
27+
os.path.abspath(get_data("tests/wf"))))
2528
self.assertIn("$schemas", packed)
2629
del packed["$schemas"]
2730
del expect_packed["$schemas"]

tests/test_toolargparse.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from tempfile import NamedTemporaryFile
33

44
from cwltool.main import main
5-
5+
from .util import get_data
66

77
class ToolArgparse(unittest.TestCase):
88
script = '''
@@ -66,8 +66,10 @@ def test_help(self):
6666
with NamedTemporaryFile() as f:
6767
f.write(self.script)
6868
f.flush()
69-
self.assertEquals(main(["--debug", f.name, '--input', 'README.rst']), 0)
70-
self.assertEquals(main(["--debug", f.name, '--input', 'README.rst']), 0)
69+
self.assertEquals(main(["--debug", f.name, '--input',
70+
get_data('tests/echo.cwl')]), 0)
71+
self.assertEquals(main(["--debug", f.name, '--input',
72+
get_data('tests/echo.cwl')]), 0)
7173

7274
def test_bool(self):
7375
with NamedTemporaryFile() as f:
@@ -92,8 +94,8 @@ def test_record(self):
9294
f.write(self.script3)
9395
f.flush()
9496
try:
95-
self.assertEquals(main([f.name, '--foo.one', 'README.rst',
96-
'--foo.two', 'test']), 0)
97+
self.assertEquals(main([f.name, '--foo.one',
98+
get_data('tests/echo.cwl'), '--foo.two', 'test']), 0)
9799
except SystemExit as e:
98100
self.assertEquals(e.code, 0)
99101

tests/util.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pkg_resources import Requirement, resource_filename, ResolutionError # type: ignore
2+
import os
3+
4+
def get_data(filename):
5+
filepath = None
6+
try:
7+
filepath = resource_filename(
8+
Requirement.parse("cwltool"), filename)
9+
except ResolutionError:
10+
pass
11+
if not filepath or not os.path.isfile(filepath):
12+
filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
13+
return filepath

0 commit comments

Comments
 (0)