Skip to content

Commit 59139ba

Browse files
committed
add tests
1 parent 1432031 commit 59139ba

File tree

5 files changed

+308
-0
lines changed

5 files changed

+308
-0
lines changed

testdata/v1.0/params_inc.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
- id: t1
2+
type: Any
3+
outputBinding:
4+
outputEval: $(inputs)
5+
- id: t2
6+
type: Any
7+
outputBinding:
8+
outputEval: $(inputs.bar)
9+
- id: t3
10+
type: Any
11+
outputBinding:
12+
outputEval: $(inputs['bar'])
13+
- id: t4
14+
type: Any
15+
outputBinding:
16+
outputEval: $(inputs["bar"])
17+
18+
- id: t5
19+
type: Any
20+
outputBinding:
21+
outputEval: $(inputs.bar.baz)
22+
- id: t6
23+
type: Any
24+
outputBinding:
25+
outputEval: $(inputs['bar'].baz)
26+
- id: t7
27+
type: Any
28+
outputBinding:
29+
outputEval: $(inputs['bar']["baz"])
30+
- id: t8
31+
type: Any
32+
outputBinding:
33+
outputEval: $(inputs.bar['baz'])
34+
35+
- id: t9
36+
type: Any
37+
outputBinding:
38+
outputEval: $(inputs.bar['b az'])
39+
- id: t10
40+
type: Any
41+
outputBinding:
42+
outputEval: $(inputs.bar['b\'az'])
43+
- id: t11
44+
type: Any
45+
outputBinding:
46+
outputEval: $(inputs.bar["b'az"])
47+
- id: t12
48+
type: "null"
49+
outputBinding:
50+
outputEval: $(inputs.bar['b"az'])
51+
52+
- id: t13
53+
type: Any
54+
outputBinding:
55+
outputEval: -$(inputs.bar.baz)
56+
- id: t14
57+
type: Any
58+
outputBinding:
59+
outputEval: -$(inputs['bar'].baz)
60+
- id: t15
61+
type: Any
62+
outputBinding:
63+
outputEval: -$(inputs['bar']["baz"])
64+
- id: t16
65+
type: Any
66+
outputBinding:
67+
outputEval: -$(inputs.bar['baz'])
68+
69+
- id: t17
70+
type: Any
71+
outputBinding:
72+
outputEval: $(inputs.bar.baz) $(inputs.bar.baz)
73+
- id: t18
74+
type: Any
75+
outputBinding:
76+
outputEval: $(inputs['bar'].baz) $(inputs['bar'].baz)
77+
- id: t19
78+
type: Any
79+
outputBinding:
80+
outputEval: $(inputs['bar']["baz"]) $(inputs['bar']["baz"])
81+
- id: t20
82+
type: Any
83+
outputBinding:
84+
outputEval: $(inputs.bar['baz']) $(inputs.bar['baz'])
85+
86+
- id: t21
87+
type: Any
88+
outputBinding:
89+
outputEval: $(inputs.bar['b az']) $(inputs.bar['b az'])
90+
- id: t22
91+
type: Any
92+
outputBinding:
93+
outputEval: $(inputs.bar['b\'az']) $(inputs.bar['b\'az'])
94+
- id: t23
95+
type: Any
96+
outputBinding:
97+
outputEval: $(inputs.bar["b'az"]) $(inputs.bar["b'az"])
98+
- id: t24
99+
type: Any
100+
outputBinding:
101+
outputEval: $(inputs.bar['b"az']) $(inputs.bar['b"az'])
102+
103+
- id: t25
104+
type: Any
105+
outputBinding:
106+
outputEval: $(inputs.bar.buz[1])
107+
- id: t26
108+
type: Any
109+
outputBinding:
110+
outputEval: $(inputs.bar.buz[1]) $(inputs.bar.buz[1])
111+
112+
- id: t27
113+
type: "null"
114+
outputBinding:
115+
outputEval: $(null)
116+
117+
- id: t28
118+
type: int
119+
outputBinding:
120+
outputEval: $(inputs.bar.buz.length)

testdata/v1.0/subdir/params.cwl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.0
3+
hints:
4+
ResourceRequirement:
5+
ramMin: 8
6+
inputs:
7+
bar:
8+
type: Any
9+
default: {
10+
"baz": "zab1",
11+
"b az": 2,
12+
"b'az": true,
13+
'b"az': null,
14+
"buz": ['a', 'b', 'c']
15+
}
16+
17+
outputs: {"$import": ../params_inc.yml}
18+
19+
baseCommand: "true"

testdata/v1.1/params_inc.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
- id: t1
2+
type: Any
3+
outputBinding:
4+
outputEval: $(inputs)
5+
- id: t2
6+
type: Any
7+
outputBinding:
8+
outputEval: $(inputs.bar)
9+
- id: t3
10+
type: Any
11+
outputBinding:
12+
outputEval: $(inputs['bar'])
13+
- id: t4
14+
type: Any
15+
outputBinding:
16+
outputEval: $(inputs["bar"])
17+
18+
- id: t5
19+
type: Any
20+
outputBinding:
21+
outputEval: $(inputs.bar.baz)
22+
- id: t6
23+
type: Any
24+
outputBinding:
25+
outputEval: $(inputs['bar'].baz)
26+
- id: t7
27+
type: Any
28+
outputBinding:
29+
outputEval: $(inputs['bar']["baz"])
30+
- id: t8
31+
type: Any
32+
outputBinding:
33+
outputEval: $(inputs.bar['baz'])
34+
35+
- id: t9
36+
type: Any
37+
outputBinding:
38+
outputEval: $(inputs.bar['b az'])
39+
- id: t10
40+
type: Any
41+
outputBinding:
42+
outputEval: $(inputs.bar['b\'az'])
43+
- id: t11
44+
type: Any
45+
outputBinding:
46+
outputEval: $(inputs.bar["b'az"])
47+
- id: t12
48+
type: "null"
49+
outputBinding:
50+
outputEval: $(inputs.bar['b"az'])
51+
52+
- id: t13
53+
type: Any
54+
outputBinding:
55+
outputEval: -$(inputs.bar.baz)
56+
- id: t14
57+
type: Any
58+
outputBinding:
59+
outputEval: -$(inputs['bar'].baz)
60+
- id: t15
61+
type: Any
62+
outputBinding:
63+
outputEval: -$(inputs['bar']["baz"])
64+
- id: t16
65+
type: Any
66+
outputBinding:
67+
outputEval: -$(inputs.bar['baz'])
68+
69+
- id: t17
70+
type: Any
71+
outputBinding:
72+
outputEval: $(inputs.bar.baz) $(inputs.bar.baz)
73+
- id: t18
74+
type: Any
75+
outputBinding:
76+
outputEval: $(inputs['bar'].baz) $(inputs['bar'].baz)
77+
- id: t19
78+
type: Any
79+
outputBinding:
80+
outputEval: $(inputs['bar']["baz"]) $(inputs['bar']["baz"])
81+
- id: t20
82+
type: Any
83+
outputBinding:
84+
outputEval: $(inputs.bar['baz']) $(inputs.bar['baz'])
85+
86+
- id: t21
87+
type: Any
88+
outputBinding:
89+
outputEval: $(inputs.bar['b az']) $(inputs.bar['b az'])
90+
- id: t22
91+
type: Any
92+
outputBinding:
93+
outputEval: $(inputs.bar['b\'az']) $(inputs.bar['b\'az'])
94+
- id: t23
95+
type: Any
96+
outputBinding:
97+
outputEval: $(inputs.bar["b'az"]) $(inputs.bar["b'az"])
98+
- id: t24
99+
type: Any
100+
outputBinding:
101+
outputEval: $(inputs.bar['b"az']) $(inputs.bar['b"az'])
102+
103+
- id: t25
104+
type: Any
105+
outputBinding:
106+
outputEval: $(inputs.bar.buz[1])
107+
- id: t26
108+
type: Any
109+
outputBinding:
110+
outputEval: $(inputs.bar.buz[1]) $(inputs.bar.buz[1])
111+
112+
- id: t27
113+
type: "null"
114+
outputBinding:
115+
outputEval: $(null)
116+
117+
- id: t28
118+
type: int
119+
outputBinding:
120+
outputEval: $(inputs.bar.buz.length)

testdata/v1.1/subdir/params.cwl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.1
3+
class: CommandLineTool
4+
requirements:
5+
NetworkAccess:
6+
networkAccess: true
7+
LoadListingRequirement:
8+
loadListing: deep_listing
9+
hints:
10+
ResourceRequirement:
11+
ramMin: 8
12+
inputs:
13+
bar:
14+
type: Any
15+
default: {"baz": "zab1", "b az": 2, "b'az": true, 'b"az': null, "buz": ['a', 'b',
16+
'c']}
17+
baseCommand: "true"
18+
outputs: {"$import": ../params_inc.yml}

tests/test_import.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import filecmp
2+
from pathlib import Path
3+
4+
from cwlupgrader.main import load_cwl_document, main, upgrade_document
5+
import pytest
6+
import logging
7+
from .util import get_data
8+
import re
9+
10+
def test_import_parent_directory(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
11+
"""Confirm that $import to a superior directory still preserves the directory structure."""
12+
caplog.set_level(logging.WARN)
13+
out_dir = tmp_path/"out"
14+
out_dir.mkdir()
15+
doc = load_cwl_document(get_data("testdata/v1.0/subdir/params.cwl"))
16+
upgraded = upgrade_document(doc, out_dir, out_dir, "v1.1")
17+
expected = load_cwl_document(get_data("testdata/v1.1/subdir/params.cwl"))
18+
assert upgraded == expected
19+
assert len(caplog.records) == 1
20+
assert re.search(re.escape(f"Writing file, '{tmp_path}/params_inc.yml', outside of the output directory, '{out_dir}'."), caplog.records[0].getMessage())
21+
22+
def test_import_parent_directory_safe(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
23+
"""Confirm no warning when $import to a superior directory (but still in the current working directory) still preserves the directory structure."""
24+
caplog.set_level(logging.WARN)
25+
out_dir = tmp_path/"out"
26+
out_dir.mkdir()
27+
doc = load_cwl_document(get_data("testdata/v1.0/subdir/params.cwl"))
28+
upgraded = upgrade_document(doc, out_dir, tmp_path, "v1.1")
29+
expected = load_cwl_document(get_data("testdata/v1.1/subdir/params.cwl"))
30+
assert upgraded == expected
31+
assert len(caplog.records) == 0

0 commit comments

Comments
 (0)