Skip to content

Commit a3d13a5

Browse files
committed
Enhancement: revamp testing for extension
Change image for workflow needing python to make it compatible with Windows. Changed style to pytest, as part of common-workflow-language#885 Uncomment all code, but still skip those tests
1 parent 9234194 commit a3d13a5

File tree

2 files changed

+184
-151
lines changed

2 files changed

+184
-151
lines changed

tests/test_ext.py

Lines changed: 180 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import shutil
55
import tempfile
6-
import unittest
76

87
import pytest
98

@@ -18,152 +17,183 @@
1817

1918

2019
@needs_docker
21-
class TestListing(unittest.TestCase):
22-
def test_missing_enable_ext(self):
23-
# Require that --enable-ext is provided.
24-
self.assertEquals(main([get_data('tests/wf/listing_deep.cwl'), get_data('tests/listing-job.yml')]), 1)
25-
26-
def test_listing_deep(self):
27-
# Should succeed.
28-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/listing_deep.cwl'), get_data('tests/listing-job.yml')]), 0)
29-
30-
def test_listing_shallow(self):
31-
# This fails on purpose, because it tries to access listing in a subdirectory the same way that listing_deep does,
32-
# but it shouldn't be expanded.
33-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/listing_shallow.cwl'), get_data('tests/listing-job.yml')]), 1)
34-
35-
def test_listing_none(self):
36-
# This fails on purpose, because it tries to access listing but it shouldn't be there.
37-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/listing_none.cwl'), get_data('tests/listing-job.yml')]), 1)
38-
39-
def test_listing_v1_0(self):
40-
# Default behavior in 1.0 is deep expansion.
41-
self.assertEquals(main([get_data('tests/wf/listing_v1_0.cwl'), get_data('tests/listing-job.yml')]), 0)
42-
43-
# def test_listing_v1_1(self):
44-
# # Default behavior in 1.1 will be no expansion
45-
# self.assertEquals(main([get_data('tests/wf/listing_v1_1.cwl'), get_data('tests/listing-job.yml')]), 1)
46-
47-
@pytest.mark.skipif(onWindows(),
48-
reason="InplaceUpdate uses symlinks,does not run on windows without admin privileges")
49-
class TestInplaceUpdate(unittest.TestCase):
50-
51-
def test_updateval(self):
52-
try:
53-
tmp = tempfile.mkdtemp()
54-
with open(os.path.join(tmp, "value"), "w") as f:
55-
f.write("1")
56-
out = tempfile.mkdtemp()
57-
self.assertEquals(main(["--outdir", out, get_data('tests/wf/updateval.cwl'), "-r", os.path.join(tmp, "value")]), 0)
58-
59-
with open(os.path.join(tmp, "value"), "r") as f:
60-
self.assertEquals("1", f.read())
61-
with open(os.path.join(out, "value"), "r") as f:
62-
self.assertEquals("2", f.read())
63-
finally:
64-
shutil.rmtree(tmp)
65-
shutil.rmtree(out)
66-
67-
def test_updateval_inplace(self):
68-
try:
69-
tmp = tempfile.mkdtemp()
70-
with open(os.path.join(tmp, "value"), "w") as f:
71-
f.write("1")
72-
out = tempfile.mkdtemp()
73-
self.assertEquals(main(["--enable-ext", "--leave-outputs", "--outdir", out, get_data('tests/wf/updateval_inplace.cwl'), "-r", os.path.join(tmp, "value")]), 0)
74-
75-
with open(os.path.join(tmp, "value"), "r") as f:
76-
self.assertEquals("2", f.read())
77-
self.assertFalse(os.path.exists(os.path.join(out, "value")))
78-
finally:
79-
shutil.rmtree(tmp)
80-
shutil.rmtree(out)
81-
82-
def test_write_write_conflict(self):
83-
try:
84-
tmp = tempfile.mkdtemp()
85-
with open(os.path.join(tmp, "value"), "w") as f:
86-
f.write("1")
87-
88-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/mut.cwl'), "-a", os.path.join(tmp, "value")]), 1)
89-
with open(os.path.join(tmp, "value"), "r") as f:
90-
self.assertEquals("2", f.read())
91-
finally:
92-
shutil.rmtree(tmp)
93-
94-
def test_sequencing(self):
95-
try:
96-
tmp = tempfile.mkdtemp()
97-
with open(os.path.join(tmp, "value"), "w") as f:
98-
f.write("1")
99-
100-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/mut2.cwl'), "-a", os.path.join(tmp, "value")]), 0)
101-
with open(os.path.join(tmp, "value"), "r") as f:
102-
self.assertEquals("3", f.read())
103-
finally:
104-
shutil.rmtree(tmp)
105-
106-
# def test_read_write_conflict(self):
107-
# try:
108-
# tmp = tempfile.mkdtemp()
109-
# with open(os.path.join(tmp, "value"), "w") as f:
110-
# f.write("1")
111-
112-
# self.assertEquals(main(["--enable-ext", get_data('tests/wf/mut3.cwl'), "-a", os.path.join(tmp, "value")]), 0)
113-
# finally:
114-
# shutil.rmtree(tmp)
115-
116-
def test_updatedir(self):
117-
try:
118-
tmp = tempfile.mkdtemp()
119-
with open(os.path.join(tmp, "value"), "w") as f:
120-
f.write("1")
121-
out = tempfile.mkdtemp()
122-
123-
self.assertFalse(os.path.exists(os.path.join(tmp, "blurb")))
124-
self.assertFalse(os.path.exists(os.path.join(out, "blurb")))
125-
126-
self.assertEquals(main(["--outdir", out, get_data('tests/wf/updatedir.cwl'), "-r", tmp]), 0)
127-
128-
self.assertFalse(os.path.exists(os.path.join(tmp, "blurb")))
129-
self.assertTrue(os.path.exists(os.path.join(out, "inp/blurb")))
130-
finally:
131-
shutil.rmtree(tmp)
132-
shutil.rmtree(out)
133-
134-
def test_updatedir_inplace(self):
135-
try:
136-
tmp = tempfile.mkdtemp()
137-
with open(os.path.join(tmp, "value"), "w") as f:
138-
f.write("1")
139-
out = tempfile.mkdtemp()
140-
141-
self.assertFalse(os.path.exists(os.path.join(tmp, "blurb")))
142-
self.assertFalse(os.path.exists(os.path.join(out, "blurb")))
143-
144-
self.assertEquals(main(["--enable-ext", "--leave-outputs", "--outdir", out, get_data('tests/wf/updatedir_inplace.cwl'), "-r", tmp]), 0)
145-
146-
self.assertTrue(os.path.exists(os.path.join(tmp, "blurb")))
147-
self.assertFalse(os.path.exists(os.path.join(out, "inp/blurb")))
148-
finally:
149-
shutil.rmtree(tmp)
150-
shutil.rmtree(out)
151-
152-
class TestV1_1backports(unittest.TestCase):
153-
@needs_docker
154-
def test_require_prefix_networkaccess(self):
155-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/networkaccess.cwl')]), 0)
156-
self.assertEquals(main([get_data('tests/wf/networkaccess.cwl')]), 1)
157-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/networkaccess-fail.cwl')]), 1)
158-
159-
@needs_docker
160-
def test_require_prefix_workreuse(self):
161-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/workreuse.cwl')]), 0)
162-
self.assertEquals(main([get_data('tests/wf/workreuse.cwl')]), 1)
163-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/workreuse-fail.cwl')]), 1)
164-
165-
@windows_needs_docker
166-
def test_require_prefix_timelimit(self):
167-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/timelimit.cwl')]), 0)
168-
self.assertEquals(main([get_data('tests/wf/timelimit.cwl')]), 1)
169-
self.assertEquals(main(["--enable-ext", get_data('tests/wf/timelimit-fail.cwl')]), 1)
20+
def test_missing_enable_ext():
21+
# Require that --enable-ext is provided.
22+
assert main([get_data('tests/wf/listing_deep.cwl'), get_data('tests/listing-job.yml')]) != 0
23+
24+
@needs_docker
25+
def test_listing_deep():
26+
assert main(["--enable-ext", get_data('tests/wf/listing_deep.cwl'), get_data('tests/listing-job.yml')]) == 0
27+
28+
@needs_docker
29+
def test_listing_shallow():
30+
# This fails on purpose, because it tries to access listing in a subdirectory the same way that listing_deep does,
31+
# but it shouldn't be expanded.
32+
assert main(["--enable-ext", get_data('tests/wf/listing_shallow.cwl'), get_data('tests/listing-job.yml')]) != 0
33+
34+
@needs_docker
35+
def test_listing_none():
36+
# This fails on purpose, because it tries to access listing but it shouldn't be there.
37+
assert main(["--enable-ext", get_data('tests/wf/listing_none.cwl'), get_data('tests/listing-job.yml')]) != 0
38+
39+
@needs_docker
40+
def test_listing_v1_0():
41+
# Default behavior in 1.0 is deep expansion.
42+
assert main([get_data('tests/wf/listing_v1_0.cwl'), get_data('tests/listing-job.yml')]) == 0
43+
44+
@pytest.mark.skip(reason="This is not the default behaviour yet")
45+
@needs_docker
46+
def test_listing_v1_1():
47+
# Default behavior in 1.1 will be no expansion
48+
assert main([get_data('tests/wf/listing_v1_1.cwl'), get_data('tests/listing-job.yml')]) != 0
49+
50+
@needs_docker
51+
def test_double_overwrite():
52+
try:
53+
tmp = tempfile.mkdtemp()
54+
tmp_name = os.path.join(tmp, "value")
55+
56+
before_value, expected_value = "1", "3"
57+
58+
with open(tmp_name, "w") as f:
59+
f.write(before_value)
60+
61+
assert main(["--enable-ext", get_data('tests/wf/mut2.cwl'), "-a", tmp_name]) == 0
62+
63+
with open(tmp_name, "r") as f:
64+
actual_value = f.read()
65+
66+
assert actual_value == expected_value
67+
finally:
68+
shutil.rmtree(tmp)
69+
70+
@needs_docker
71+
def test_disable_file_overwrite_without_ext():
72+
try:
73+
tmp = tempfile.mkdtemp()
74+
out = tempfile.mkdtemp()
75+
76+
tmp_name = os.path.join(tmp, "value")
77+
out_name = os.path.join(out, "value")
78+
79+
before_value, expected_value = "1", "2"
80+
81+
with open(tmp_name, "w") as f:
82+
f.write(before_value)
83+
84+
assert main(["--outdir", out, get_data('tests/wf/updateval.cwl'), "-r", tmp_name]) == 0
85+
86+
with open(tmp_name, "r") as f:
87+
tmp_value = f.read()
88+
with open(out_name, "r") as f:
89+
out_value = f.read()
90+
91+
assert tmp_value == before_value
92+
assert out_value == expected_value
93+
finally:
94+
shutil.rmtree(tmp)
95+
shutil.rmtree(out)
96+
97+
@needs_docker
98+
def test_disable_dir_overwrite_without_ext():
99+
try:
100+
tmp = tempfile.mkdtemp()
101+
out = tempfile.mkdtemp()
102+
103+
assert main(["--outdir", out, get_data('tests/wf/updatedir.cwl'), "-r", tmp]) == 0
104+
105+
assert not os.listdir(tmp)
106+
assert os.listdir(out)
107+
finally:
108+
shutil.rmtree(tmp)
109+
shutil.rmtree(out)
110+
111+
@needs_docker
112+
def test_disable_file_creation_in_outdir_with_ext():
113+
try:
114+
tmp = tempfile.mkdtemp()
115+
out = tempfile.mkdtemp()
116+
117+
tmp_name = os.path.join(tmp, "value")
118+
out_name = os.path.join(out, "value")
119+
120+
before_value, expected_value = "1", "2"
121+
122+
with open(tmp_name, "w") as f:
123+
f.write(before_value)
124+
125+
assert main(["--enable-ext", "--leave-outputs", "--outdir", out, get_data('tests/wf/updateval_inplace.cwl'), "-r", tmp_name]) == 0
126+
127+
with open(tmp_name, "r") as f:
128+
tmp_value = f.read()
129+
130+
assert tmp_value == expected_value
131+
assert not os.path.exists(out_name)
132+
finally:
133+
shutil.rmtree(tmp)
134+
shutil.rmtree(out)
135+
136+
@needs_docker
137+
def test_disable_dir_creation_in_outdir_with_ext():
138+
try:
139+
tmp = tempfile.mkdtemp()
140+
out = tempfile.mkdtemp()
141+
142+
assert main(["--enable-ext", "--leave-outputs", "--outdir", out, get_data('tests/wf/updatedir_inplace.cwl'), "-r", tmp]) == 0
143+
144+
assert os.listdir(tmp)
145+
assert not os.listdir(out)
146+
finally:
147+
shutil.rmtree(tmp)
148+
shutil.rmtree(out)
149+
150+
@needs_docker
151+
def test_write_write_conflict():
152+
try:
153+
tmp = tempfile.mkdtemp()
154+
tmp_name = os.path.join(tmp, "value")
155+
156+
before_value, expected_value = "1", "2"
157+
158+
with open(tmp_name, "w") as f:
159+
f.write(before_value)
160+
161+
assert main(["--enable-ext", get_data('tests/wf/mut.cwl'), "-a", tmp_name]) != 0
162+
163+
with open(tmp_name, "r") as f:
164+
tmp_value = f.read()
165+
166+
assert tmp_value == expected_value
167+
finally:
168+
shutil.rmtree(tmp)
169+
170+
@pytest.mark.skip(reason="This test is non-deterministic")
171+
def test_read_write_conflict():
172+
try:
173+
tmp = tempfile.mkdtemp()
174+
tmp_name = os.path.join(tmp, "value")
175+
176+
with open(tmp_name, "w") as f:
177+
f.write("1")
178+
179+
assert main(["--enable-ext", get_data('tests/wf/mut3.cwl'), "-a", tmp_name]) != 0
180+
finally:
181+
shutil.rmtree(tmp)
182+
183+
@needs_docker
184+
def test_require_prefix_networkaccess():
185+
assert main(["--enable-ext", get_data('tests/wf/networkaccess.cwl')]) == 0
186+
assert main([get_data('tests/wf/networkaccess.cwl')]) != 0
187+
assert main(["--enable-ext", get_data('tests/wf/networkaccess-fail.cwl')]) != 0
188+
189+
@needs_docker
190+
def test_require_prefix_workreuse():
191+
assert main(["--enable-ext", get_data('tests/wf/workreuse.cwl')]) == 0
192+
assert main([get_data('tests/wf/workreuse.cwl')]) != 0
193+
assert main(["--enable-ext", get_data('tests/wf/workreuse-fail.cwl')]) != 0
194+
195+
@windows_needs_docker
196+
def test_require_prefix_timelimit():
197+
assert main(["--enable-ext", get_data('tests/wf/timelimit.cwl')]) == 0
198+
assert main([get_data('tests/wf/timelimit.cwl')]) != 0
199+
assert main(["--enable-ext", get_data('tests/wf/timelimit-fail.cwl')]) != 0

tests/wf/updateval_inplace.cwl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ requirements:
1010
writable: true
1111
cwltool:InplaceUpdateRequirement:
1212
inplaceUpdate: true
13+
hints:
14+
DockerRequirement:
15+
dockerPull: "python:2.7.15-alpine3.7"
1316
inputs:
1417
r: File
1518
script:
@@ -22,4 +25,4 @@ outputs:
2225
type: File
2326
outputBinding:
2427
glob: $(inputs.r.basename)
25-
arguments: [python, $(inputs.script), $(inputs.r.basename)]
28+
arguments: [python, $(inputs.script), $(inputs.r.basename)]

0 commit comments

Comments
 (0)