33import importlib
44from collections .abc import MutableSequence
55from pathlib import Path
6- from typing import Any , Optional , Union , cast
7- from urllib .parse import urlparse
6+ from typing import Any , Optional , cast
87
98import pytest
109
1413from schema_salad .schema import load_schema
1514from schema_salad .utils import yaml_no_ts
1615
17- from .util import cwl_file_uri , get_data
16+ from .util import cwl_file_uri , get_path
1817
1918
2019def test_error_message1 (tmp_path : Path ) -> None :
@@ -23,17 +22,17 @@ def test_error_message1(tmp_path: Path) -> None:
2322\s+\*\s+missing\s+required\s+field\s+`inputs`
2423\s+\*\s+missing\s+required\s+field\s+`outputs`
2524\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 ()
2827 with pytest .raises (ValidationException , match = match ):
2928 load_document_by_uri (tmp_path , path )
3029
3130
3231def test_error_message2 (tmp_path : Path ) -> None :
3332 t = "test_schema/test2.cwl"
3433 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 ()
3736 with pytest .raises (ValidationException , match = match ):
3837 load_document_by_uri (tmp_path , path )
3938
@@ -46,8 +45,8 @@ def test_error_message4(tmp_path: Path) -> None:
4645.*test4\.cwl:7:3:\s+checking\s+object\s+`.*test4\.cwl#bar`\s+using\s+`WorkflowOutputParameter`
4746\s+the\s+`type`\s+field\s+is\s+not\s+valid\s+because:
4847\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 ()
5150 with pytest .raises (ValidationException , match = match ):
5251 load_document_by_uri (tmp_path , path )
5352
@@ -58,8 +57,8 @@ def test_error_message5(tmp_path: Path) -> None:
5857.+test5\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
5958.+test5\.cwl:8:9:\s+array\s+item\s+is\s+invalid\s+because
6059\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 ()
6362 with pytest .raises (ValidationException , match = match ):
6463 load_document_by_uri (tmp_path , path )
6564
@@ -72,8 +71,8 @@ def test_error_message6(tmp_path: Path) -> None:
7271\s+missing\s+required\s+field\s+`class`
7372+\*\s+tried\s+`Workflow`\s+but
7473\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 ()
7776 with pytest .raises (ValidationException , match = match ):
7877 load_document_by_uri (tmp_path , path )
7978
@@ -86,8 +85,8 @@ def test_error_message7(tmp_path: Path) -> None:
8685.*test7\.cwl:9:3:\s+checking\s+object\s+`.*test7.cwl#step1`\s+using\s+`WorkflowStep`
8786\s+\*\s+missing\s+required\s+field\s+`run`
8887.*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 ()
9190 with pytest .raises (ValidationException , match = match ):
9291 load_document_by_uri (tmp_path , path )
9392
@@ -101,8 +100,8 @@ def test_error_message8(tmp_path: Path) -> None:
101100\s+\*\s+missing\s+required\s+field\s+`run`
102101.*test8\.cwl:10:5:\s+\*\s+the\s+`scatterMethod`\s+field\s+is\s+not\s+valid\s+because:
103102\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 ()
106105 with pytest .raises (ValidationException , match = match ):
107106 load_document_by_uri (tmp_path , path )
108107
@@ -116,8 +115,8 @@ def test_error_message9(tmp_path: Path) -> None:
116115\s+\*\s+missing\s+required\s+field\s+`run`
117116.*test9\.cwl:10:5:\s+\*\s+the\s+`scatterMethod`\s+field\s+is\s+not\s+valid\s+because:
118117\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 ()
121120 with pytest .raises (ValidationException , match = match ):
122121 load_document_by_uri (tmp_path , path )
123122
@@ -131,8 +130,8 @@ def test_error_message10(tmp_path: Path) -> None:
131130\s+\*\s+missing\s+required\s+field\s+`run`
132131.*test10\.cwl:10:5:\s+\*\s+the\s+`scatterMethod`\s+field\s+is\s+not\s+valid\s+because:
133132\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 ()
136135 with pytest .raises (ValidationException , match = match ):
137136 load_document_by_uri (tmp_path , path )
138137
@@ -144,8 +143,8 @@ def test_error_message11(tmp_path: Path) -> None:
144143\s+array\s+item\s+is\s+invalid\s+because
145144.*test11\.cwl:9:3:\s+checking\s+object\s+`.*test11\.cwl#step1`\s+using\s+`WorkflowStep`
146145.*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 ()
149148 with pytest .raises (ValidationException , match = match ):
150149 load_document_by_uri (tmp_path , path )
151150
@@ -161,13 +160,13 @@ def test_error_message15(tmp_path: Path) -> None:
161160\s+tried\s+`CommandLineBinding`\s+but
162161.*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`
163162.*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 ()
166165 with pytest .raises (ValidationException , match = match ):
167166 load_document_by_uri (tmp_path , path )
168167
169168
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 :
171170 src_target = tmp_path / "cwl_v1_0.py"
172171 python_codegen (cwl_file_uri , src_target )
173172 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:
177176 spec .loader .exec_module (temp_cwl_v1_0 )
178177 cwl_v1_0 : Any = temp_cwl_v1_0
179178
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 ()
188180
189- baseuri = str ( real_path )
181+ baseuri = path_uri
190182
191183 loadingOptions = cwl_v1_0 .LoadingOptions (fileuri = baseuri )
192184
193185 with open (path ) as file :
194186 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 ))
196188 yaml = yaml_no_ts ()
197189 doc = yaml .load (doc )
198190
0 commit comments