Skip to content

Commit 836d684

Browse files
committed
Test: Run cwltool.main in tmpdir
1 parent d256a1b commit 836d684

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

tests/test_provenance.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,27 @@
3636

3737

3838
@pytest.mark.skipif(onWindows(),
39-
reason="On Windows this would invoke a default docker container")
39+
reason="On Windows this would invoke a default docker container, some of the test workflows need unix commands")
4040
class TestProvenance(unittest.TestCase):
4141
folder = None
4242

43+
44+
def cwltool(self, *args):
45+
new_args = ['--no-container',
46+
'--provenance',
47+
self.folder]
48+
new_args.extend(args)
49+
# Run within a temporary directory to not pollute git checkout
50+
test_dir = os.path.abspath(os.curdir)
51+
tmp_dir = tempfile.mkdtemp("cwltool-run")
52+
os.chdir(tmp_dir)
53+
try:
54+
status = main(new_args)
55+
self.assertEquals(status, 0, "Failed: cwltool.main(%r)" % (args,))
56+
finally:
57+
# Change back
58+
os.chdir(test_dir)
59+
4360
def setUp(self):
4461
self.folder = tempfile.mkdtemp("ro")
4562
if os.environ.get("DEBUG"):
@@ -50,22 +67,22 @@ def tearDown(self):
5067
shutil.rmtree(self.folder)
5168

5269
def test_hello_workflow(self):
53-
self.assertEquals(main(['--provenance', self.folder, get_data('tests/wf/hello-workflow.cwl'),
54-
"--usermessage", "Hello workflow"]), 0)
70+
self.cwltool(get_data('tests/wf/hello-workflow.cwl'),
71+
"--usermessage", "Hello workflow")
5572
self.check_provenance()
5673

5774
def test_hello_single_tool(self):
58-
self.assertEquals(main(['--provenance', self.folder, get_data('tests/wf/hello_single_tool.cwl'),
59-
"--message", "Hello tool"]), 0)
75+
self.cwltool(get_data('tests/wf/hello_single_tool.cwl'),
76+
"--message", "Hello tool")
6077
self.check_provenance(single_tool=True)
6178

6279
def test_revsort_workflow(self):
63-
self.assertEquals(main(['--no-container', '--provenance', self.folder, get_data('tests/wf/revsort.cwl'),
64-
get_data('tests/wf/revsort-job.json')]), 0)
80+
self.cwltool(get_data('tests/wf/revsort.cwl'),
81+
get_data('tests/wf/revsort-job.json'))
6582
self.check_provenance()
6683

6784
def test_nested_workflow(self):
68-
self.assertEquals(main(['--no-container', '--provenance', self.folder, get_data('tests/wf/nested.cwl')]), 0)
85+
self.cwltool(get_data('tests/wf/nested.cwl'))
6986
self.check_provenance(nested=True)
7087

7188
def test_directory_workflow(self):
@@ -83,8 +100,8 @@ def test_directory_workflow(self):
83100
with open(os.path.join(dir2, x), "w", encoding="ascii") as f:
84101
f.write(x)
85102

86-
self.assertEquals(main(['--provenance', self.folder, get_data('tests/wf/directory.cwl'),
87-
"--dir", dir2]), 0)
103+
self.cwltool(get_data('tests/wf/directory.cwl'),
104+
"--dir", dir2)
88105
self.check_provenance(directory=True)
89106

90107
# Output should include ls stdout of filenames a b c on each line

0 commit comments

Comments
 (0)