Skip to content

Commit 9a768f3

Browse files
committed
add workflow test
1 parent 44108ce commit 9a768f3

File tree

9 files changed

+118
-12
lines changed

9 files changed

+118
-12
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include MANIFEST.in
2+
include tests/*.cwl

cwlupgrader/main.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
from collections import Mapping, MutableMapping, Sequence
66
import sys
77
import copy
8-
from typing import Any, Dict, List, Text, Union # pylint:disable=unused-import
8+
from typing import (Any, Dict, List, Optional, # pylint:disable=unused-import
9+
Text, Union)
910
import ruamel.yaml
1011

11-
def main(): # type: () -> int
12+
13+
def main(args=None): # type: (Optional[List[str]]) -> int
1214
"""Main function."""
13-
for path in sys.argv[1:]:
15+
if not args:
16+
args = sys.argv[1:]
17+
assert args is not None
18+
for path in args:
1419
with open(path) as entry:
1520
document = ruamel.yaml.safe_load(entry)
1621
if ('cwlVersion' in document
@@ -36,6 +41,7 @@ def draft3_to_v1_0(document): # type: (Dict[Text, Any]) -> None
3641
value[index] = _draft3_to_v1_0(entry)
3742
document['cwlVersion'] = 'v1.0'
3843

44+
3945
def _draft3_to_v1_0(document):
4046
# type: (MutableMapping[Text, Any]) -> MutableMapping[Text, Any]
4147
"""Inner loop for transforming draft-3 to v1.0."""
@@ -144,7 +150,7 @@ def shorten_type(type_obj): # type: (List[Any]) -> Union[Text, List[Any]]
144150
if 'null' in new_type:
145151
type_copy = copy.deepcopy(new_type)
146152
type_copy.remove('null')
147-
if isinstance(type_copy[0], Text):
153+
if isinstance(type_copy[0], (str, Text)):
148154
return type_copy[0] + '?'
149155
return new_type
150156

@@ -160,4 +166,4 @@ def clean_secondary_files(document):
160166

161167

162168
if __name__ == "__main__":
163-
sys.exit(main())
169+
sys.exit(main(sys.argv[:1]))

setup.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import os
44
import sys
55

6-
from setuptools import setup, find_packages
6+
from setuptools import setup
77

88
SETUP_DIR = os.path.dirname(__file__)
99
README = os.path.join(SETUP_DIR, 'README.rst')
1010

11-
needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
12-
pytest_runner = ['pytest-runner', 'pytest-cov'] if needs_pytest else []
11+
NEEDS_PYTEST = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
12+
PYTEST_RUNNER = ['pytest-runner', 'pytest-cov'] if NEEDS_PYTEST else []
1313

1414
setup(name='cwl-upgrader',
1515
version='0.4.0',
@@ -20,8 +20,10 @@
2020
url="https://github.com/common-workflow-language/cwl-upgrader",
2121
download_url="https://github.com/common-workflow-language/cwl-upgrader",
2222
license='Apache 2.0',
23-
packages=["cwlupgrader"],
23+
packages=["cwlupgrader", "cwlupgrader.tests"],
24+
package_dir={'cwlupgrader.tests': 'tests'},
2425
install_requires=[
26+
'setuptools',
2527
'ruamel.yaml >= 0.14.12, < 0.15',
2628
'typing'],
2729
entry_points={
@@ -44,5 +46,6 @@
4446
'Topic :: Scientific/Engineering',
4547
'Topic :: Scientific/Engineering :: Bio-Informatics'],
4648
zip_safe=True,
47-
setup_requires=[] + pytest_runner,
48-
tests_require=['pytest'])
49+
setup_requires=[] + PYTEST_RUNNER,
50+
tests_require=['pytest'],
51+
test_suite='tests')

tests/__init__.py

Whitespace-only changes.

tests/draft-3-wf-v1.0.cwl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class: Workflow
2+
cwlVersion: v1.0
3+
inputs:
4+
input_file: File?
5+
outputs:
6+
md5_report:
7+
outputSource: md5/report
8+
type: File?
9+
validatefiles_report:
10+
outputSource: validatefiles/report
11+
type: File?
12+
requirements:
13+
InlineJavascriptRequirement: {}
14+
steps:
15+
md5:
16+
in:
17+
input_file: input_file
18+
out:
19+
- report
20+
run: md5.cwl
21+
validatefiles:
22+
in:
23+
input_file: input_file
24+
type: {}
25+
out:
26+
- report
27+
run: validate.cwl
28+

tests/draft-3-wf.cwl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class: Workflow
2+
cwlVersion: draft-3
3+
inputs:
4+
- id: '#input_file'
5+
type: ['null', File]
6+
outputs:
7+
- id: '#validatefiles_report'
8+
source: '#validatefiles.report'
9+
type: ['null', File]
10+
- id: '#md5_report'
11+
source: '#md5.report'
12+
type: ['null', File]
13+
requirements:
14+
- {class: InlineJavascriptRequirement}
15+
steps:
16+
- id: '#md5'
17+
inputs:
18+
- {id: '#md5.input_file', source: '#input_file'}
19+
outputs:
20+
- {id: '#md5.report'}
21+
run: md5.cwl
22+
- id: '#validatefiles'
23+
inputs:
24+
- {id: '#validatefiles.input_file', source: '#input_file'}
25+
- {id: '#validatefiles.type'}
26+
outputs:
27+
- {id: '#validatefiles.report'}
28+
run: validate.cwl

tests/test_complete.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import filecmp
2+
import os
3+
from cwlupgrader.main import main
4+
from .util import get_data
5+
6+
7+
def test_draft3_workflow(tmpdir, capsys):
8+
main([get_data('tests/draft-3-wf.cwl')])
9+
test_path = tmpdir.join("test.cwl")
10+
with test_path.open('w') as outfile:
11+
outfile.write(capsys.readouterr().out)
12+
outfile.flush()
13+
outfile.close()
14+
result = filecmp.cmp('tests/draft-3-wf-v1.0.cwl', str(test_path),
15+
shallow=False)
16+
assert result

tests/util.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from __future__ import absolute_import
2+
import os
3+
4+
from pkg_resources import (Requirement, ResolutionError, # type: ignore
5+
resource_filename)
6+
7+
8+
def get_data(filename):
9+
filename = os.path.normpath(filename)
10+
# normalizing path depending on OS or else it will cause problem when
11+
# joining path
12+
filepath = None
13+
try:
14+
filepath = resource_filename(Requirement.parse("cwlupgrader"),
15+
filename)
16+
except ResolutionError:
17+
pass
18+
if not filepath or not os.path.isfile(filepath):
19+
filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
20+
# warning, __file__ is all lowercase on Windows systems, this can
21+
# sometimes conflict with docker toolkit. Workaround: pip install .
22+
# and run the tests elsewhere via python -m pytest --pyarg cwltool
23+
return filepath

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ skipsdist = True
1717
deps =
1818
-rrequirements.txt
1919
lint: flake8
20-
unit: pytest-xdist
20+
# unit: pytest
2121
pydoc: pydocstyle
2222
tyle: diff-cover
2323
pycode: pycodestyle

0 commit comments

Comments
 (0)