11"""Tests of helpful error messages."""
22
33import importlib
4+ import os
5+ import shutil
46from collections .abc import MutableSequence
57from pathlib import Path
68from typing import Any , Optional , cast
1618from .util import cwl_file_uri , get_path
1719
1820
19- def test_error_message1 (tmp_path : Path ) -> None :
21+ def test_error_message1 (cwl_v1_0 : Any ) -> None :
2022 t = "test_schema/test1.cwl"
2123 match = r"""^.*test1\.cwl:2:1:\s+Object\s+`.*test1\.cwl`\s+is\s+not\s+valid\s+because:
2224\s+\*\s+missing\s+required\s+field\s+`inputs`
@@ -25,19 +27,19 @@ def test_error_message1(tmp_path: Path) -> None:
2527 path = get_path ("tests/" + t )
2628 assert path .exists ()
2729 with pytest .raises (ValidationException , match = match ):
28- load_document_by_uri (tmp_path , path )
30+ load_document_by_uri (cwl_v1_0 , path )
2931
3032
31- def test_error_message2 (tmp_path : Path ) -> None :
33+ def test_error_message2 (cwl_v1_0 : Any ) -> None :
3234 t = "test_schema/test2.cwl"
3335 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`$"""
3436 path = get_path ("tests/" + t )
3537 assert path .exists ()
3638 with pytest .raises (ValidationException , match = match ):
37- load_document_by_uri (tmp_path , path )
39+ load_document_by_uri (cwl_v1_0 , path )
3840
3941
40- def test_error_message4 (tmp_path : Path ) -> None :
42+ def test_error_message4 (cwl_v1_0 : Any ) -> None :
4143 t = "test_schema/test4.cwl"
4244 match = r"""^.*test4.cwl:2:1:\s+Object\s+`.*test4.cwl`\s+is\s+not\s+valid\s+because:
4345.*test4\.cwl:6:1:\s+the\s+`outputs`\s+field\s+is\s+not\s+valid\s+because:
@@ -48,10 +50,10 @@ def test_error_message4(tmp_path: Path) -> None:
4850 path = get_path ("tests/" + t )
4951 assert path .exists ()
5052 with pytest .raises (ValidationException , match = match ):
51- load_document_by_uri (tmp_path , path )
53+ load_document_by_uri (cwl_v1_0 , path )
5254
5355
54- def test_error_message5 (tmp_path : Path ) -> None :
56+ def test_error_message5 (cwl_v1_0 : Any ) -> None :
5557 t = "test_schema/test5.cwl"
5658 match = r"""^.*test5\.cwl:2:1:\s+Object\s+`.*test5\.cwl`\s+is\s+not\s+valid\s+because:
5759.+test5\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -60,10 +62,10 @@ def test_error_message5(tmp_path: Path) -> None:
6062 path = get_path ("tests/" + t )
6163 assert path .exists ()
6264 with pytest .raises (ValidationException , match = match ):
63- load_document_by_uri (tmp_path , path )
65+ load_document_by_uri (cwl_v1_0 , path )
6466
6567
66- def test_error_message6 (tmp_path : Path ) -> None :
68+ def test_error_message6 (cwl_v1_0 : Any ) -> None :
6769 t = "test_schema/test6.cwl"
6870 match = r"""\*\s+tried\s+`CommandLineTool`\s+but
6971\s+missing\s+required\s+field\s+`class`
@@ -74,10 +76,10 @@ def test_error_message6(tmp_path: Path) -> None:
7476 path = get_path ("tests/" + t )
7577 assert path .exists ()
7678 with pytest .raises (ValidationException , match = match ):
77- load_document_by_uri (tmp_path , path )
79+ load_document_by_uri (cwl_v1_0 , path )
7880
7981
80- def test_error_message7 (tmp_path : Path ) -> None :
82+ def test_error_message7 (cwl_v1_0 : Any ) -> None :
8183 t = "test_schema/test7.cwl"
8284 match = r"""^.*test7\.cwl:2:1:\s+Object\s+`.*test7\.cwl`\s+is\s+not\s+valid\s+because:
8385.*test7\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -88,10 +90,10 @@ def test_error_message7(tmp_path: Path) -> None:
8890 path = get_path ("tests/" + t )
8991 assert path .exists ()
9092 with pytest .raises (ValidationException , match = match ):
91- load_document_by_uri (tmp_path , path )
93+ load_document_by_uri (cwl_v1_0 , path )
9294
9395
94- def test_error_message8 (tmp_path : Path ) -> None :
96+ def test_error_message8 (cwl_v1_0 : Any ) -> None :
9597 t = "test_schema/test8.cwl"
9698 match = r"""^.*test8.cwl:2:1:\s+Object\s+`.*test8.cwl`\s+is\s+not\s+valid\s+because:
9799.*test8\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -103,10 +105,10 @@ def test_error_message8(tmp_path: Path) -> None:
103105 path = get_path ("tests/" + t )
104106 assert path .exists ()
105107 with pytest .raises (ValidationException , match = match ):
106- load_document_by_uri (tmp_path , path )
108+ load_document_by_uri (cwl_v1_0 , path )
107109
108110
109- def test_error_message9 (tmp_path : Path ) -> None :
111+ def test_error_message9 (cwl_v1_0 : Any ) -> None :
110112 t = "test_schema/test9.cwl"
111113 match = r"""^.*test9.cwl:2:1:\s+Object\s+`.*test9.cwl`\s+is\s+not\s+valid\s+because:
112114.*test9\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -118,10 +120,10 @@ def test_error_message9(tmp_path: Path) -> None:
118120 path = get_path ("tests/" + t )
119121 assert path .exists ()
120122 with pytest .raises (ValidationException , match = match ):
121- load_document_by_uri (tmp_path , path )
123+ load_document_by_uri (cwl_v1_0 , path )
122124
123125
124- def test_error_message10 (tmp_path : Path ) -> None :
126+ def test_error_message10 (cwl_v1_0 : Any ) -> None :
125127 t = "test_schema/test10.cwl"
126128 match = r"""^.*test10\.cwl:2:1:\s+Object\s+`.*test10\.cwl`\s+is\s+not\s+valid\s+because:
127129.*test10\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -133,10 +135,10 @@ def test_error_message10(tmp_path: Path) -> None:
133135 path = get_path ("tests/" + t )
134136 assert path .exists ()
135137 with pytest .raises (ValidationException , match = match ):
136- load_document_by_uri (tmp_path , path )
138+ load_document_by_uri (cwl_v1_0 , path )
137139
138140
139- def test_error_message11 (tmp_path : Path ) -> None :
141+ def test_error_message11 (cwl_v1_0 : Any ) -> None :
140142 t = "test_schema/test11.cwl"
141143 match = r"""^.*test11\.cwl:2:1:\s+Object\s+`.*test11.cwl`\s+is\s+not\s+valid\s+because:
142144.*test11\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -146,11 +148,10 @@ def test_error_message11(tmp_path: Path) -> None:
146148 path = get_path ("tests/" + t )
147149 assert path .exists ()
148150 with pytest .raises (ValidationException , match = match ):
149- load_document_by_uri (tmp_path , path )
151+ load_document_by_uri (cwl_v1_0 , path )
150152
151153
152- # `loadContents`,\s+`position`,\s+`prefix`,\s+`separate`,\s+`itemSeparator`,\s+`valueFrom`,\s+`shellQuote`
153- def test_error_message15 (tmp_path : Path ) -> None :
154+ def test_error_message15 (cwl_v1_0 : Any ) -> None :
154155 t = "test_schema/test15.cwl"
155156 match = r"""^.*test15\.cwl:3:1:\s+Object\s+`.*test15\.cwl`\s+is\s+not\s+valid\s+because:
156157.*test15\.cwl:6:1:\s+the\s+`inputs`\s+field\s+is\s+not\s+valid\s+because:
@@ -163,10 +164,12 @@ def test_error_message15(tmp_path: Path) -> None:
163164 path = get_path ("tests/" + t )
164165 assert path .exists ()
165166 with pytest .raises (ValidationException , match = match ):
166- load_document_by_uri (tmp_path , path )
167+ load_document_by_uri (cwl_v1_0 , path )
167168
168169
169- def load_document_by_uri (tmp_path : Path , path : Path ) -> Any :
170+ @pytest .fixture (scope = "session" )
171+ def cwl_v1_0 (tmp_path_factory : pytest .TempPathFactory ) -> Any :
172+ tmp_path = tmp_path_factory .mktemp ("cwl_v1_0_pycode" )
170173 src_target = tmp_path / "cwl_v1_0.py"
171174 python_codegen (cwl_file_uri , src_target )
172175 spec = importlib .util .spec_from_file_location ("cwl_v1_0" , src_target )
@@ -175,11 +178,13 @@ def load_document_by_uri(tmp_path: Path, path: Path) -> Any:
175178 temp_cwl_v1_0 = importlib .util .module_from_spec (spec )
176179 spec .loader .exec_module (temp_cwl_v1_0 )
177180 cwl_v1_0 : Any = temp_cwl_v1_0
181+ yield cwl_v1_0
182+ shutil .rmtree (os .path .join (tmp_path ))
178183
179- path_uri = path .resolve ().as_uri ()
180184
185+ def load_document_by_uri (cwl_v1_0 : Any , path : Path ) -> Any :
186+ path_uri = path .resolve ().as_uri ()
181187 baseuri = path_uri
182-
183188 loadingOptions = cwl_v1_0 .LoadingOptions (fileuri = baseuri )
184189
185190 with open (path ) as file :
0 commit comments