Skip to content

Commit 02e49a3

Browse files
committed
use get_data instead of __file__
1 parent 0db3b18 commit 02e49a3

File tree

7 files changed

+95
-104
lines changed

7 files changed

+95
-104
lines changed

tests/test_cite_extract.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# SPDX-License-Identifier: Apache-2.0
22
"""Tests for cwl-cite-extract."""
3-
from pathlib import Path
4-
53
import cwl_utils.parser.cwl_v1_0 as parser
64
from cwl_utils.cite_extract import traverse_workflow
75

8-
HERE = Path(__file__).resolve().parent
9-
TEST_CWL = HERE / "../testdata/md5sum.cwl"
6+
from .util import get_data
107

118

129
def test_traverse_workflow() -> None:
1310
"""Test the citation extraction, simply."""
14-
loaded = parser.load_document(str(TEST_CWL.resolve()))
11+
loaded = parser.load_document(get_data("testdata/md5sum.cwl"))
1512
traverse_workflow(loaded)

tests/test_docker_extract.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
from cwl_utils.docker_extract import traverse
1111
from cwl_utils.image_puller import DockerImagePuller, SingularityImagePuller
1212

13-
HERE = Path(__file__).resolve().parent
14-
TEST_CWL = HERE / "../testdata/md5sum.cwl"
13+
from .util import get_data
14+
15+
TEST_CWL = get_data("testdata/md5sum.cwl")
1516

1617

1718
@mark.skipif(which("docker") is None, reason="docker is not available")
1819
def test_traverse_workflow() -> None:
1920
"""Test container extraction tool using Docker."""
20-
loaded = parser.load_document(str(TEST_CWL.resolve()))
21+
loaded = parser.load_document(TEST_CWL)
2122

2223
with TemporaryDirectory() as tmpdir:
2324
reqs = set(traverse(loaded))
@@ -32,7 +33,7 @@ def test_traverse_workflow() -> None:
3233
@mark.skipif(which("singularity") is None, reason="singularity is not available")
3334
def test_traverse_workflow_singularity() -> None:
3435
"""Test container extraction tool using Singularity."""
35-
loaded = parser.load_document(str(TEST_CWL.resolve()))
36+
loaded = parser.load_document(TEST_CWL)
3637

3738
with TemporaryDirectory() as tmpdir:
3839
reqs = set(traverse(loaded))

tests/test_etools_to_clt.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@
2020
from cwl_utils.errors import WorkflowException
2121
from cwl_utils.expression_refactor import run as expression_refactor
2222

23-
HERE = Path(__file__).resolve().parent
23+
from .util import get_data
2424

2525

2626
def test_v1_0_workflow_top_level_format_expr() -> None:
2727
"""Test for the correct error when converting a format expression in a workflow level input."""
2828
with raises(WorkflowException, match=r".*format specification.*"):
2929
result, modified = traverse0(
30-
parser.load_document(
31-
str(HERE / "../testdata/workflow_input_format_expr.cwl")
32-
),
30+
parser.load_document(get_data("testdata/workflow_input_format_expr.cwl")),
3331
False,
3432
False,
3533
False,
@@ -41,7 +39,7 @@ def test_v1_0_workflow_top_level_sf_expr() -> None:
4139
"""Test for the correct error when converting a secondaryFiles expression in a workflow level input."""
4240
with raises(WorkflowException, match=r".*secondaryFiles.*"):
4341
result, modified = traverse0(
44-
parser.load_document(str(HERE / "../testdata/workflow_input_sf_expr.cwl")),
42+
parser.load_document(get_data("testdata/workflow_input_sf_expr.cwl")),
4543
False,
4644
False,
4745
False,
@@ -53,9 +51,7 @@ def test_v1_0_workflow_top_level_sf_expr_array() -> None:
5351
"""Test for the correct error when converting a secondaryFiles expression (array form) in a workflow level input."""
5452
with raises(WorkflowException, match=r".*secondaryFiles.*"):
5553
result, modified = traverse0(
56-
parser.load_document(
57-
str(HERE / "../testdata/workflow_input_sf_expr_array.cwl")
58-
),
54+
parser.load_document(get_data("testdata/workflow_input_sf_expr_array.cwl")),
5955
False,
6056
False,
6157
False,
@@ -65,11 +61,10 @@ def test_v1_0_workflow_top_level_sf_expr_array() -> None:
6561

6662
def test_v1_1_workflow_top_level_format_expr() -> None:
6763
"""Test for the correct error when converting a format expression in a workflow level input."""
68-
# import ipdb; ipdb.set_trace()
6964
with raises(WorkflowException, match=r".*format specification.*"):
7065
result, modified = traverse1(
7166
parser1.load_document(
72-
str(HERE / "../testdata/workflow_input_format_expr_v1_1.cwl")
67+
get_data("testdata/workflow_input_format_expr_v1_1.cwl")
7368
),
7469
False,
7570
False,
@@ -82,9 +77,7 @@ def test_v1_1_workflow_top_level_sf_expr() -> None:
8277
"""Test for the correct error when converting a secondaryFiles expression in a workflow level input."""
8378
with raises(WorkflowException, match=r".*secondaryFiles.*"):
8479
result, modified = traverse1(
85-
parser1.load_document(
86-
str(HERE / "../testdata/workflow_input_sf_expr_v1_1.cwl")
87-
),
80+
parser1.load_document(get_data("testdata/workflow_input_sf_expr_v1_1.cwl")),
8881
False,
8982
False,
9083
False,
@@ -97,7 +90,7 @@ def test_v1_1_workflow_top_level_sf_expr_array() -> None:
9790
with raises(WorkflowException, match=r".*secondaryFiles.*"):
9891
result, modified = traverse1(
9992
parser1.load_document(
100-
str(HERE / "../testdata/workflow_input_sf_expr_array_v1_1.cwl")
93+
get_data("testdata/workflow_input_sf_expr_array_v1_1.cwl")
10194
),
10295
False,
10396
False,
@@ -111,7 +104,7 @@ def test_v1_2_workflow_top_level_format_expr() -> None:
111104
with raises(WorkflowException, match=r".*format specification.*"):
112105
result, modified = traverse2(
113106
parser2.load_document(
114-
str(HERE / "../testdata/workflow_input_format_expr_v1_2.cwl")
107+
get_data("testdata/workflow_input_format_expr_v1_2.cwl")
115108
),
116109
False,
117110
False,
@@ -124,9 +117,7 @@ def test_v1_2_workflow_top_level_sf_expr() -> None:
124117
"""Test for the correct error when converting a secondaryFiles expression in a workflow level input."""
125118
with raises(WorkflowException, match=r".*secondaryFiles.*"):
126119
result, modified = traverse2(
127-
parser2.load_document(
128-
str(HERE / "../testdata/workflow_input_sf_expr_v1_2.cwl")
129-
),
120+
parser2.load_document(get_data("testdata/workflow_input_sf_expr_v1_2.cwl")),
130121
False,
131122
False,
132123
False,
@@ -139,7 +130,7 @@ def test_v1_2_workflow_top_level_sf_expr_array() -> None:
139130
with raises(WorkflowException, match=r".*secondaryFiles.*"):
140131
result, modified = traverse2(
141132
parser2.load_document(
142-
str(HERE / "../testdata/workflow_input_sf_expr_array_v1_2.cwl")
133+
get_data("testdata/workflow_input_sf_expr_array_v1_2.cwl")
143134
),
144135
False,
145136
False,
@@ -151,7 +142,7 @@ def test_v1_2_workflow_top_level_sf_expr_array() -> None:
151142
def test_v1_0_step_valuefrom_expr_multisource() -> None:
152143
"""Convert a valueFrom expression that has multiple sources."""
153144
result, modified = traverse0(
154-
parser.load_document(str(HERE / "../testdata/step-valuefrom2-wf_v1_0.cwl")),
145+
parser.load_document(get_data("testdata/step-valuefrom2-wf_v1_0.cwl")),
155146
False,
156147
False,
157148
False,
@@ -162,7 +153,7 @@ def test_v1_0_step_valuefrom_expr_multisource() -> None:
162153
def test_v1_1_step_valuefrom_expr_multisource() -> None:
163154
"""Convert a valueFrom expression that has multiple sources."""
164155
result, modified = traverse1(
165-
parser1.load_document(str(HERE / "../testdata/step-valuefrom2-wf_v1_1.cwl")),
156+
parser1.load_document(get_data("testdata/step-valuefrom2-wf_v1_1.cwl")),
166157
False,
167158
False,
168159
False,
@@ -173,7 +164,7 @@ def test_v1_1_step_valuefrom_expr_multisource() -> None:
173164
def test_v1_2_step_valuefrom_expr_multisource() -> None:
174165
"""Convert a valueFrom expression that has multiple sources."""
175166
result, modified = traverse2(
176-
parser2.load_document(str(HERE / "../testdata/step-valuefrom2-wf_v1_2.cwl")),
167+
parser2.load_document(get_data("testdata/step-valuefrom2-wf_v1_2.cwl")),
177168
False,
178169
False,
179170
False,
@@ -184,7 +175,7 @@ def test_v1_2_step_valuefrom_expr_multisource() -> None:
184175
def test_v1_0_step_valuefrom_expr_sibling_inputs() -> None:
185176
"""Convert a valueFrom expression from a step input that has uninvolved sibling inputs."""
186177
result, modified = traverse0(
187-
parser.load_document(str(HERE / "../testdata/step-valuefrom3-wf_v1_0.cwl")),
178+
parser.load_document(get_data("testdata/step-valuefrom3-wf_v1_0.cwl")),
188179
False,
189180
False,
190181
False,
@@ -195,7 +186,7 @@ def test_v1_0_step_valuefrom_expr_sibling_inputs() -> None:
195186
def test_v1_1_step_valuefrom_expr_sibling_inputs() -> None:
196187
"""Convert a valueFrom expression from a step input that has uninvolved sibling inputs."""
197188
result, modified = traverse1(
198-
parser1.load_document(str(HERE / "../testdata/step-valuefrom3-wf_v1_1.cwl")),
189+
parser1.load_document(get_data("testdata/step-valuefrom3-wf_v1_1.cwl")),
199190
False,
200191
False,
201192
False,
@@ -206,7 +197,7 @@ def test_v1_1_step_valuefrom_expr_sibling_inputs() -> None:
206197
def test_v1_2_step_valuefrom_expr_sibling_inputs() -> None:
207198
"""Convert a valueFrom expression from a step input that has uninvolved sibling inputs."""
208199
result, modified = traverse2(
209-
parser2.load_document(str(HERE / "../testdata/step-valuefrom3-wf_v1_2.cwl")),
200+
parser2.load_document(get_data("testdata/step-valuefrom3-wf_v1_2.cwl")),
210201
False,
211202
False,
212203
False,
@@ -217,7 +208,7 @@ def test_v1_2_step_valuefrom_expr_sibling_inputs() -> None:
217208
def test_v1_2_workflow_output_pickvalue_expr() -> None:
218209
"""Convert a workflow output pickValue expression."""
219210
result, modified = traverse2(
220-
parser2.load_document(str(HERE / "../testdata/cond-wf-003.1.cwl")),
211+
parser2.load_document(get_data("testdata/cond-wf-003.1.cwl")),
221212
False,
222213
False,
223214
False,
@@ -227,22 +218,22 @@ def test_v1_2_workflow_output_pickvalue_expr() -> None:
227218

228219
def test_expression_refactor(tmp_path: Path) -> None:
229220
"""Functional test."""
230-
input_path = str(HERE / "../testdata/cond-wf-003.1.cwl")
221+
input_path = get_data("testdata/cond-wf-003.1.cwl")
231222
result = expression_refactor([str(tmp_path), input_path])
232223
assert result == 0
233224

234225

235226
def test_expression_refactor_noop_solo(tmp_path: Path) -> None:
236227
"""Functional test."""
237-
input_path = str(HERE / "../testdata/dockstore-tool-md5sum.cwl")
228+
input_path = get_data("testdata/dockstore-tool-md5sum.cwl")
238229
result = expression_refactor([str(tmp_path), input_path])
239230
assert result == 7
240231

241232

242233
def test_expression_refactor_noop(tmp_path: Path) -> None:
243234
"""Functional test."""
244-
input_path1 = str(HERE / "../testdata/dockstore-tool-md5sum.cwl")
245-
input_path2 = str(HERE / "../testdata/echo-tool-packed.cwl")
235+
input_path1 = get_data("testdata/dockstore-tool-md5sum.cwl")
236+
input_path2 = get_data("testdata/echo-tool-packed.cwl")
246237
result = expression_refactor([str(tmp_path), input_path1, input_path2])
247238
assert result == 0
248239

tests/test_format.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from cwl_utils.parser import load_document_by_uri
1818
from cwl_utils.types import CWLObjectType
1919

20+
from .util import get_data
21+
2022

2123
def _create_file(format_: Optional[str] = None) -> CWLObjectType:
2224
obj: CWLObjectType = {
@@ -45,9 +47,8 @@ def _load_format(fetchurl: str) -> Graph:
4547
return graph
4648

4749

48-
HERE = Path(__file__).resolve().parent
49-
EDAM = _load_format((HERE / "../testdata/EDAM_subset.owl").absolute().as_uri())
50-
GX = _load_format((HERE / "../testdata/gx_edam.ttl").absolute().as_uri())
50+
EDAM = _load_format(Path(get_data("testdata/EDAM_subset.owl")).as_uri())
51+
GX = _load_format(Path(get_data("testdata/gx_edam.ttl")).as_uri())
5152

5253

5354
def test_check_format() -> None:
@@ -136,36 +137,36 @@ def test_check_format_no_ontology() -> None:
136137

137138
def test_loading_options_graph_property_v1_0() -> None:
138139
"""Test that RDFLib Graph representations of $schema properties are correctly loaded, CWL v1.0."""
139-
uri = Path(HERE / "../testdata/formattest2_v1_0.cwl").resolve().as_uri()
140+
uri = Path(get_data("testdata/formattest2_v1_0.cwl")).resolve().as_uri()
140141
cwl_obj = load_document_by_uri(uri)
141142
assert to_isomorphic(cwl_obj.loadingOptions.graph) == to_isomorphic(EDAM)
142143

143144

144145
def test_loading_options_graph_property_v1_1() -> None:
145146
"""Test that RDFLib Graph representations of $schema properties are correctly loaded, CWL v1.1."""
146-
uri = Path(HERE / "../testdata/formattest2_v1_1.cwl").resolve().as_uri()
147+
uri = Path(get_data("testdata/formattest2_v1_1.cwl")).resolve().as_uri()
147148
cwl_obj = load_document_by_uri(uri)
148149
assert to_isomorphic(cwl_obj.loadingOptions.graph) == to_isomorphic(EDAM)
149150

150151

151152
def test_loading_options_graph_property_v1_2() -> None:
152153
"""Test that RDFLib Graph representations of $schema properties are correctly loaded, CWL v1.2."""
153-
uri = Path(HERE / "../testdata/formattest2.cwl").resolve().as_uri()
154+
uri = Path(get_data("testdata/formattest2.cwl")).resolve().as_uri()
154155
cwl_obj = load_document_by_uri(uri)
155156
assert to_isomorphic(cwl_obj.loadingOptions.graph) == to_isomorphic(EDAM)
156157

157158

158159
def test_loading_options_missing_graph_v1_0() -> None:
159160
"""Affirm that v1.0 documents without $schema still produce an empty graph property."""
160-
uri = Path(HERE / "../testdata/workflow_input_format_expr.cwl").resolve().as_uri()
161+
uri = Path(get_data("testdata/workflow_input_format_expr.cwl")).resolve().as_uri()
161162
cwl_obj = load_document_by_uri(uri)
162163
assert to_isomorphic(cwl_obj.loadingOptions.graph) == to_isomorphic(Graph())
163164

164165

165166
def test_loading_options_missing_graph_v1_1() -> None:
166167
"""Affirm that v1.1 documents without $schema still produce an empty graph property."""
167168
uri = (
168-
Path(HERE / "../testdata/workflow_input_format_expr_v1_1.cwl")
169+
Path(get_data("testdata/workflow_input_format_expr_v1_1.cwl"))
169170
.resolve()
170171
.as_uri()
171172
)
@@ -176,7 +177,7 @@ def test_loading_options_missing_graph_v1_1() -> None:
176177
def test_loading_options_missing_graph_v1_2() -> None:
177178
"""Affirm that v1.2 documents without $schema still produce an empty graph property."""
178179
uri = (
179-
Path(HERE / "../testdata/workflow_input_format_expr_v1_2.cwl")
180+
Path(get_data("testdata/workflow_input_format_expr_v1_2.cwl"))
180181
.resolve()
181182
.as_uri()
182183
)

tests/test_parser.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
save,
1616
)
1717

18-
HERE = Path(__file__).resolve().parent
19-
TEST_v1_0_CWL = HERE / "../testdata/md5sum.cwl"
18+
from .util import get_data
19+
20+
TEST_v1_0_CWL = get_data("testdata/md5sum.cwl")
2021
TEST_v1_0_CWL_REMOTE = "https://raw.githubusercontent.com/common-workflow-language/cwl-utils/main/testdata/md5sum.cwl"
21-
TEST_v1_2_CWL = HERE / "../testdata/workflow_input_format_expr_v1_2.cwl"
22+
TEST_v1_2_CWL = get_data("testdata/workflow_input_format_expr_v1_2.cwl")
2223
yaml = YAML(typ="rt")
2324
yaml.preserve_quotes = True # type: ignore[assignment]
2425

@@ -93,20 +94,20 @@ def test_shortname() -> None:
9394

9495
def test_get_id_from_graph() -> None:
9596
"""Test loading an explicit id of a CWL document with $graph property."""
96-
uri = Path(HERE / "../testdata/echo-tool-packed.cwl").resolve().as_uri()
97+
uri = Path(get_data("testdata/echo-tool-packed.cwl")).resolve().as_uri()
9798
cwl_obj = load_document_by_uri(uri + "#main")
9899
assert cwl_obj.id == uri + "#main"
99100

100101

101102
def test_get_default_id_from_graph() -> None:
102103
"""Test that loading the default id of a CWL document with $graph property returns the `#main` id."""
103-
uri = Path(HERE / "../testdata/echo-tool-packed.cwl").resolve().as_uri()
104+
uri = Path(get_data("testdata/echo-tool-packed.cwl")).resolve().as_uri()
104105
cwl_obj = load_document_by_uri(uri)
105106
assert cwl_obj.id == uri + "#main"
106107

107108

108109
def test_get_default_id_from_graph_without_main() -> None:
109110
"""Test that loading the default id of a CWL document with $graph property and no `#main` id throws an error."""
110111
with raises(GraphTargetMissingException):
111-
uri = Path(HERE / "../testdata/js-expr-req-wf.cwl").resolve().as_uri()
112+
uri = Path(get_data("testdata/js-expr-req-wf.cwl")).resolve().as_uri()
112113
load_document_by_uri(uri)

0 commit comments

Comments
 (0)