1111from collections .abc import Iterable , MutableMapping , MutableSequence
1212from importlib .metadata import EntryPoint , entry_points
1313from importlib .resources import files
14- from typing import Any , Optional , Union , cast
14+ from typing import Any , cast
1515from urllib .parse import urljoin
1616
1717import junit_xml
@@ -36,31 +36,31 @@ def __init__(
3636 self ,
3737 entry : str ,
3838 entry_line : str ,
39- basedir : Optional [ str ] = None ,
40- test_baseuri : Optional [ str ] = None ,
41- test_basedir : Optional [ str ] = None ,
42- outdir : Optional [ str ] = None ,
43- classname : Optional [ str ] = None ,
44- tool : Optional [ str ] = None ,
45- args : Optional [ list [str ]] = None ,
46- testargs : Optional [ list [str ]] = None ,
47- timeout : Optional [ int ] = None ,
48- verbose : Optional [ bool ] = None ,
49- runner_quiet : Optional [ bool ] = None ,
39+ basedir : str | None = None ,
40+ test_baseuri : str | None = None ,
41+ test_basedir : str | None = None ,
42+ outdir : str | None = None ,
43+ classname : str | None = None ,
44+ tool : str | None = None ,
45+ args : list [str ] | None = None ,
46+ testargs : list [str ] | None = None ,
47+ timeout : int | None = None ,
48+ verbose : bool | None = None ,
49+ runner_quiet : bool | None = None ,
5050 ) -> None :
5151 """Initialize test configuration."""
5252 self .basedir : str = basedir or os .getcwd ()
5353 self .test_baseuri : str = test_baseuri or "file://" + self .basedir
5454 self .test_basedir : str = test_basedir or self .basedir
55- self .outdir : Optional [ str ] = outdir
55+ self .outdir : str | None = outdir
5656 self .classname : str = classname or ""
5757 self .entry = urljoin (
5858 self .test_baseuri , os .path .basename (entry ) + f"#L{ entry_line } "
5959 )
6060 self .tool : str = tool or "cwl-runner"
6161 self .args : list [str ] = args or []
6262 self .testargs : list [str ] = testargs or []
63- self .timeout : Optional [ int ] = timeout
63+ self .timeout : int | None = timeout
6464 self .verbose : bool = verbose or False
6565 self .runner_quiet : bool = runner_quiet or True
6666
@@ -70,11 +70,11 @@ class CWLTestReport:
7070
7171 def __init__ (
7272 self ,
73- id : Union [ int , str ] ,
73+ id : int | str ,
7474 category : list [str ],
7575 entry : str ,
7676 tool : str ,
77- job : Optional [ str ] ,
77+ job : str | None ,
7878 ) -> None :
7979 """Initialize a CWLTestReport object."""
8080 self .id = id
@@ -96,7 +96,7 @@ def __init__(
9696 classname : str ,
9797 entry : str ,
9898 tool : str ,
99- job : Optional [ str ] ,
99+ job : str | None ,
100100 message : str = "" ,
101101 ) -> None :
102102 """Initialize a TestResult object."""
@@ -240,7 +240,7 @@ def generate_badges(
240240
241241def get_test_number_by_key (
242242 tests : list [dict [str , str ]], key : str , value : str
243- ) -> Optional [ int ] :
243+ ) -> int | None :
244244 """Retrieve the test index from its name."""
245245 for i , test in enumerate (tests ):
246246 if key in test and test [key ] == value :
@@ -256,7 +256,7 @@ def load_and_validate_tests(path: str) -> tuple[Any, dict[str, Any]]:
256256 """
257257 schema_resource = files ("cwltest" ).joinpath ("cwltest-schema.yml" )
258258 with schema_resource .open ("r" , encoding = "utf-8" ) as fp :
259- cache : Optional [ dict [str , Union [ str , Graph , bool ]]] = {
259+ cache : dict [str , str | Graph | bool ] | None = {
260260 "https://w3id.org/cwl/cwltest/cwltest-schema.yml" : fp .read ()
261261 }
262262 (
@@ -283,8 +283,8 @@ def load_and_validate_tests(path: str) -> tuple[Any, dict[str, Any]]:
283283def parse_results (
284284 results : Iterable [TestResult ],
285285 tests : list [dict [str , Any ]],
286- suite_name : Optional [ str ] = None ,
287- report : Optional [ junit_xml .TestSuite ] = None ,
286+ suite_name : str | None = None ,
287+ report : junit_xml .TestSuite | None = None ,
288288) -> tuple [
289289 int , # total
290290 int , # passed
@@ -294,7 +294,7 @@ def parse_results(
294294 dict [str , list [CWLTestReport ]], # passed for each tag
295295 dict [str , list [CWLTestReport ]], # failures for each tag
296296 dict [str , list [CWLTestReport ]], # unsupported for each tag
297- Optional [ junit_xml .TestSuite ] ,
297+ junit_xml .TestSuite | None ,
298298]:
299299 """
300300 Parse the results and return statistics and an optional report.
@@ -366,10 +366,10 @@ def parse_results(
366366def prepare_test_command (
367367 tool : str ,
368368 args : list [str ],
369- testargs : Optional [ list [str ]] ,
369+ testargs : list [str ] | None ,
370370 test : dict [str , Any ],
371371 cwd : str ,
372- quiet : Optional [ bool ] = True ,
372+ quiet : bool | None = True ,
373373) -> list [str ]:
374374 """Turn the test into a command line."""
375375 test_command = [tool ]
@@ -407,7 +407,7 @@ def prepare_test_command(
407407def prepare_test_paths (
408408 test : dict [str , str ],
409409 cwd : str ,
410- ) -> tuple [str , Optional [ str ] ]:
410+ ) -> tuple [str , str | None ]:
411411 """Determine the test path and the tool path."""
412412 cwd = schema_salad .ref_resolver .file_uri (cwd )
413413 processfile = test ["tool" ]
@@ -424,7 +424,7 @@ def prepare_test_paths(
424424def run_test_plain (
425425 config : CWLTestConfig ,
426426 test : dict [str , str ],
427- test_number : Optional [ int ] = None ,
427+ test_number : int | None = None ,
428428) -> TestResult :
429429 """Plain test runner."""
430430 out : dict [str , Any ] = {}
@@ -443,7 +443,7 @@ def run_test_plain(
443443
444444 if test_number is not None :
445445 number = str (test_number )
446- process : Optional [ subprocess .Popen [str ]] = None
446+ process : subprocess .Popen [str ] | None = None
447447 try :
448448 cwd = os .getcwd ()
449449 test_command = prepare_test_command (
0 commit comments