1919from ruamel .yaml .scanner import ScannerError
2020
2121# https://raw.githubusercontent.com/common-workflow-language/cwl-v1.2/1.2.1_proposed/conformance_tests.yaml
22- CONFORMANCE_TESTS_FILE = os .path .join (os .path .dirname (__file__ ), "../../conformance_tests.yaml" )
22+ CONFORMANCE_TESTS_FILE = os .path .join (
23+ os .path .dirname (__file__ ), "../../conformance_tests.yaml"
24+ )
2325# https://raw.githubusercontent.com/common-workflow-language/cwl-v1.2/1.2.1_proposed/json-schema/cwl.yaml
24- CWL_JSON_SCHEMA_FILE = os .path .join (os .path .dirname (__file__ ), "../../json-schema/cwl.yaml" )
26+ CWL_JSON_SCHEMA_FILE = os .path .join (
27+ os .path .dirname (__file__ ), "../../json-schema/cwl.yaml"
28+ )
2529CWL_JSON_SCHEMA_REF = f"{ CWL_JSON_SCHEMA_FILE } #/$defs/CWL"
2630
2731LOGGER = logging .getLogger (__name__ )
3539_JSON : TypeAlias = "JSON"
3640_JsonObjectItemAlias : TypeAlias = "_JsonObjectItem"
3741_JsonListItemAlias : TypeAlias = "_JsonListItem"
38- _JsonObjectItem = Dict [str , Union [AnyValueType , _JSON , _JsonObjectItemAlias , _JsonListItemAlias ]]
42+ _JsonObjectItem = Dict [
43+ str , Union [AnyValueType , _JSON , _JsonObjectItemAlias , _JsonListItemAlias ]
44+ ]
3945_JsonListItem = List [Union [AnyValueType , _JSON , _JsonObjectItem , _JsonListItemAlias ]]
4046_JsonItem = Union [AnyValueType , _JSON , _JsonObjectItem , _JsonListItem ]
41- JSON = Union [Dict [str , Union [_JSON , _JsonItem ]], List [Union [_JSON , _JsonItem ]], AnyValueType ]
47+ JSON = Union [
48+ Dict [str , Union [_JSON , _JsonItem ]], List [Union [_JSON , _JsonItem ]], AnyValueType
49+ ]
4250
4351ConformanceTestDef = TypedDict (
4452 "ConformanceTestDef" ,
4553 {
4654 "id" : str ,
4755 "doc" : str ,
48- "tags" : List [str ], # should contain 'json_schema_invalid' to XFAIL schema validation tests
56+ "tags" : List [
57+ str
58+ ], # should contain 'json_schema_invalid' to XFAIL schema validation tests
4959 "tool" : str ,
5060 "job" : NotRequired [str ], # not used, for running the actual CWL
5161 "output" : JSON , # not used, output of CWL execution
52- "should_fail" : NotRequired [bool ], # indicates failure as "execute failing", but potentially still valid CWL
53- }
62+ "should_fail" : NotRequired [
63+ bool
64+ ], # indicates failure as "execute failing", but potentially still valid CWL
65+ },
5466)
5567
5668
@@ -76,7 +88,7 @@ def load_file(file_path: str, text: bool = False) -> Union[JSON, str]:
7688 :returns: loaded contents either parsed and converted to Python objects or as plain text.
7789 :raises ValueError: if YAML or JSON cannot be parsed or loaded from location.
7890 """
79- yaml = YAML (typ = ' safe' , pure = True )
91+ yaml = YAML (typ = " safe" , pure = True )
8092 try :
8193 if is_remote_file (file_path ):
8294 headers = {"Accept" : "text/plain" }
@@ -131,10 +143,11 @@ def load_conformance_tests(test_file: str) -> List[ConformanceTestDef]:
131143
132144
133145@pytest .mark .parametrize (
134- "conformance_test" ,
135- load_conformance_tests (CONFORMANCE_TESTS_FILE )
146+ "conformance_test" , load_conformance_tests (CONFORMANCE_TESTS_FILE )
136147)
137- def test_conformance (conformance_test : ConformanceTestDef , request : pytest .FixtureRequest ) -> None :
148+ def test_conformance (
149+ conformance_test : ConformanceTestDef , request : pytest .FixtureRequest
150+ ) -> None :
138151 LOGGER .debug (
139152 "Testing [%s] (%s) with [%s]" ,
140153 conformance_test ["id" ],
@@ -149,11 +162,17 @@ def test_conformance(conformance_test: ConformanceTestDef, request: pytest.Fixtu
149162 instance_file = conformance_test ["tool" ].rsplit ("#" )[0 ]
150163 instance = load_file (instance_file )
151164 instance_xfail = "json_schema_invalid" in conformance_test .get ("tags" , [])
152- request .applymarker (pytest .mark .xfail (reason = "Test tagged with 'json_schema_invalid'." , condition = instance_xfail ))
165+ request .applymarker (
166+ pytest .mark .xfail (
167+ reason = "Test tagged with 'json_schema_invalid'." , condition = instance_xfail
168+ )
169+ )
153170
154171 schema_uri , schema_base , schema_test = resolve_ref (CWL_JSON_SCHEMA_REF )
155172 validator : Type [Validator ] = jsonschema .validators .validator_for (schema_base )
156- validator .resolver = jsonschema .RefResolver (base_uri = schema_uri , referrer = schema_base )
173+ validator .resolver = jsonschema .RefResolver (
174+ base_uri = schema_uri , referrer = schema_base
175+ )
157176
158177 try :
159178 # similar to 'validate()' call that raises directly, but obtain the error for more context
@@ -164,15 +183,21 @@ def test_conformance(conformance_test: ConformanceTestDef, request: pytest.Fixtu
164183 if len (errors ) == 1 and "oneOf" in errors [0 ].schema :
165184 error = errors [0 ]
166185 error .message += "\n \n For each case under oneOf:\n " + "\n " .join (
167- f"- { err .message } "
168- if not err .message .endswith ("is not valid under any of the given schemas" )
169- else f"- all invalid under oneOf { err .validator_value } "
186+ (
187+ f"- { err .message } "
188+ if not err .message .endswith (
189+ "is not valid under any of the given schemas"
190+ )
191+ else f"- all invalid under oneOf { err .validator_value } "
192+ )
170193 for err in error .context
171194 )
172195 raise error
173196 main_error = cast (
174197 ValidationError ,
175- best_match (errors ), # what 'validate()' normally does using 'iter_errors()'
198+ best_match (
199+ errors
200+ ), # what 'validate()' normally does using 'iter_errors()'
176201 )
177202 raise main_error
178203 except Exception as exc :
0 commit comments