3
3
import importlib
4
4
from collections .abc import MutableSequence
5
5
from pathlib import Path
6
- from typing import Any , Optional , Union , cast
7
- from urllib .parse import urlparse
6
+ from typing import Any , Optional , cast
8
7
9
8
import pytest
10
9
14
13
from schema_salad .schema import load_schema
15
14
from schema_salad .utils import yaml_no_ts
16
15
17
- from .util import cwl_file_uri , get_data
16
+ from .util import cwl_file_uri , get_path
18
17
19
18
20
19
def test_error_message1 (tmp_path : Path ) -> None :
@@ -23,17 +22,17 @@ def test_error_message1(tmp_path: Path) -> None:
23
22
\s+\*\s+missing\s+required\s+field\s+`inputs`
24
23
\s+\*\s+missing\s+required\s+field\s+`outputs`
25
24
\s+\*\s+missing\s+required\s+field\s+`steps`"""
26
- path = get_data ("tests/" + t )
27
- assert path
25
+ path = get_path ("tests/" + t )
26
+ assert path . exists ()
28
27
with pytest .raises (ValidationException , match = match ):
29
28
load_document_by_uri (tmp_path , path )
30
29
31
30
32
31
def test_error_message2 (tmp_path : Path ) -> None :
33
32
t = "test_schema/test2.cwl"
34
33
match = r"""^.*test2\.cwl:2:1:\s+Field\s+`class`\s+contains\s+undefined\s+reference\s+to\s+`file://.+/schema_salad/tests/test_schema/xWorkflow`$"""
35
- path = get_data ("tests/" + t )
36
- assert path
34
+ path = get_path ("tests/" + t )
35
+ assert path . exists ()
37
36
with pytest .raises (ValidationException , match = match ):
38
37
load_document_by_uri (tmp_path , path )
39
38
@@ -46,8 +45,8 @@ def test_error_message4(tmp_path: Path) -> None:
46
45
.*test4\.cwl:7:3:\s+checking\s+object\s+`.*test4\.cwl#bar`\s+using\s+`WorkflowOutputParameter`
47
46
\s+the\s+`type`\s+field\s+is\s+not\s+valid\s+because:
48
47
\s+Value\s+`12`\s+is\s+a\s+int,\s+but\s+valid\s+types\s+for\s+this\s+field\s+are\s+\((str|object),\s+(str|object)\)"""
49
- path = get_data ("tests/" + t )
50
- assert path
48
+ path = get_path ("tests/" + t )
49
+ assert path . exists ()
51
50
with pytest .raises (ValidationException , match = match ):
52
51
load_document_by_uri (tmp_path , path )
53
52
@@ -58,8 +57,8 @@ def test_error_message5(tmp_path: Path) -> None:
58
57
.+test5\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
59
58
.+test5\.cwl:8:9:\s+array\s+item\s+is\s+invalid\s+because
60
59
\s+Value\s+is\s+a\s+int,\s+but\s+valid\s+type\s+for\s+this\s+field\s+is\s+an\s+object"""
61
- path = get_data ("tests/" + t )
62
- assert path
60
+ path = get_path ("tests/" + t )
61
+ assert path . exists ()
63
62
with pytest .raises (ValidationException , match = match ):
64
63
load_document_by_uri (tmp_path , path )
65
64
@@ -72,8 +71,8 @@ def test_error_message6(tmp_path: Path) -> None:
72
71
\s+missing\s+required\s+field\s+`class`
73
72
+\*\s+tried\s+`Workflow`\s+but
74
73
\s+missing\s+required\s+field\s+`class`"""
75
- path = get_data ("tests/" + t )
76
- assert path
74
+ path = get_path ("tests/" + t )
75
+ assert path . exists ()
77
76
with pytest .raises (ValidationException , match = match ):
78
77
load_document_by_uri (tmp_path , path )
79
78
@@ -86,8 +85,8 @@ def test_error_message7(tmp_path: Path) -> None:
86
85
.*test7\.cwl:9:3:\s+checking\s+object\s+`.*test7.cwl#step1`\s+using\s+`WorkflowStep`
87
86
\s+\*\s+missing\s+required\s+field\s+`run`
88
87
.*test7\.cwl:10:5:\s+\*\s+invalid\s+field\s+`scatter_method`,\s+expected\s+one\s+of:\s+.*\s+.*\s+.*\s+.*\s+.*\s+.*\s+.*\s+.*\s+.*\s+.*$"""
89
- path = get_data ("tests/" + t )
90
- assert path
88
+ path = get_path ("tests/" + t )
89
+ assert path . exists ()
91
90
with pytest .raises (ValidationException , match = match ):
92
91
load_document_by_uri (tmp_path , path )
93
92
@@ -101,8 +100,8 @@ def test_error_message8(tmp_path: Path) -> None:
101
100
\s+\*\s+missing\s+required\s+field\s+`run`
102
101
.*test8\.cwl:10:5:\s+\*\s+the\s+`scatterMethod`\s+field\s+is\s+not\s+valid\s+because:
103
102
\s+contains\s+undefined\s+reference\s+to\s+`file:///.*/tests/test_schema/abc`$"""
104
- path = get_data ("tests/" + t )
105
- assert path
103
+ path = get_path ("tests/" + t )
104
+ assert path . exists ()
106
105
with pytest .raises (ValidationException , match = match ):
107
106
load_document_by_uri (tmp_path , path )
108
107
@@ -116,8 +115,8 @@ def test_error_message9(tmp_path: Path) -> None:
116
115
\s+\*\s+missing\s+required\s+field\s+`run`
117
116
.*test9\.cwl:10:5:\s+\*\s+the\s+`scatterMethod`\s+field\s+is\s+not\s+valid\s+because:
118
117
\s+Value\s+`12`\s+is\s+a\s+int,\s+but\s+valid\s+values\s+for\s+this\s+field\s+are\s+\("(dotproduct|nested_crossproduct|flat_crossproduct)",\s+"(dotproduct|nested_crossproduct|flat_crossproduct)",\s+"(dotproduct|nested_crossproduct|flat_crossproduct)"\)"""
119
- path = get_data ("tests/" + t )
120
- assert path
118
+ path = get_path ("tests/" + t )
119
+ assert path . exists ()
121
120
with pytest .raises (ValidationException , match = match ):
122
121
load_document_by_uri (tmp_path , path )
123
122
@@ -131,8 +130,8 @@ def test_error_message10(tmp_path: Path) -> None:
131
130
\s+\*\s+missing\s+required\s+field\s+`run`
132
131
.*test10\.cwl:10:5:\s+\*\s+the\s+`scatterMethod`\s+field\s+is\s+not\s+valid\s+because:
133
132
\s+Value\s+is\s+a\s+array,\s+but\s+valid\s+types\s+for\s+this\s+field\s+are\s+\("dotproduct|nested_crossproduct|flat_crossproduct",\s+"dotproduct|nested_crossproduct|flat_crossproduct",\s+"dotproduct|nested_crossproduct|flat_crossproduct"\)"""
134
- path = get_data ("tests/" + t )
135
- assert path
133
+ path = get_path ("tests/" + t )
134
+ assert path . exists ()
136
135
with pytest .raises (ValidationException , match = match ):
137
136
load_document_by_uri (tmp_path , path )
138
137
@@ -144,8 +143,8 @@ def test_error_message11(tmp_path: Path) -> None:
144
143
\s+array\s+item\s+is\s+invalid\s+because
145
144
.*test11\.cwl:9:3:\s+checking\s+object\s+`.*test11\.cwl#step1`\s+using\s+`WorkflowStep`
146
145
.*test11\.cwl:10:5:\s+the\s+`run`\s+field\s+is\s+not\s+valid\s+because:\s+contains\s+undefined\s+reference\s+to\s+`file:///.*/tests/test_schema/blub\.cwl`$"""
147
- path = get_data ("tests/" + t )
148
- assert path
146
+ path = get_path ("tests/" + t )
147
+ assert path . exists ()
149
148
with pytest .raises (ValidationException , match = match ):
150
149
load_document_by_uri (tmp_path , path )
151
150
@@ -161,13 +160,13 @@ def test_error_message15(tmp_path: Path) -> None:
161
160
\s+tried\s+`CommandLineBinding`\s+but
162
161
.*test15\.cwl:11:7:\s+\*\s+invalid\s+field\s+`invalid_field`,\s+expected\s+one\s+of:\s+`loadContents`,\s+`position`,\s+`prefix`,\s+`separate`,\s+`itemSeparator`,\s+`valueFrom`,\s+`shellQuote`
163
162
.*test15\.cwl:12:7:\s+\*\s+invalid\s+field\s+`another_invalid_field`,\s+expected one\s+of:\s+`loadContents`,\s+`position`,\s+`prefix`,\s+`separate`,\s+`itemSeparator`,\s+`valueFrom`,\s+`shellQuote`$"""
164
- path = get_data ("tests/" + t )
165
- assert path
163
+ path = get_path ("tests/" + t )
164
+ assert path . exists ()
166
165
with pytest .raises (ValidationException , match = match ):
167
166
load_document_by_uri (tmp_path , path )
168
167
169
168
170
- def load_document_by_uri (tmp_path : Path , path : Union [ str , Path ] ) -> Any :
169
+ def load_document_by_uri (tmp_path : Path , path : Path ) -> Any :
171
170
src_target = tmp_path / "cwl_v1_0.py"
172
171
python_codegen (cwl_file_uri , src_target )
173
172
spec = importlib .util .spec_from_file_location ("cwl_v1_0" , src_target )
@@ -177,22 +176,15 @@ def load_document_by_uri(tmp_path: Path, path: Union[str, Path]) -> Any:
177
176
spec .loader .exec_module (temp_cwl_v1_0 )
178
177
cwl_v1_0 : Any = temp_cwl_v1_0
179
178
180
- if isinstance (path , str ):
181
- uri = urlparse (path )
182
- if not uri .scheme or uri .scheme == "file" :
183
- real_path = Path (uri .path ).resolve ().as_uri ()
184
- else :
185
- real_path = path
186
- else :
187
- real_path = path .resolve ().as_uri ()
179
+ path_uri = path .resolve ().as_uri ()
188
180
189
- baseuri = str ( real_path )
181
+ baseuri = path_uri
190
182
191
183
loadingOptions = cwl_v1_0 .LoadingOptions (fileuri = baseuri )
192
184
193
185
with open (path ) as file :
194
186
doc = file .read ()
195
- # doc = loadingOptions.fetcher.fetch_text(urllib.parse.unquote(str(real_path) ))
187
+ # doc = loadingOptions.fetcher.fetch_text(urllib.parse.unquote(path_uri ))
196
188
yaml = yaml_no_ts ()
197
189
doc = yaml .load (doc )
198
190
0 commit comments