Skip to content

Commit 5c72297

Browse files
nsoranzomr-c
authored andcommitted
Fix new type annotation errors from mypy 1.16.0
1 parent a1c3ee1 commit 5c72297

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

tests/test_categories.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from os import linesep as n
44
from os import sep as p
55
from pathlib import Path
6-
from typing import cast
7-
from xml.etree.ElementTree import Element
86

97
import defusedxml.ElementTree as ET
108
import schema_salad.ref_resolver
@@ -88,10 +86,10 @@ def test_category_in_junit_xml(tmp_path: Path) -> None:
8886
]
8987
run_with_mock_cwl_runner(args)
9088
tree = ET.parse(junit_xml_report)
91-
root = tree.getroot()
92-
category = cast(
93-
Element, cast(Element, root.find("testsuite")).find("testcase")
94-
).attrib["class"]
89+
assert (root := tree.getroot()) is not None
90+
assert (testsuite_el := root.find("testsuite")) is not None
91+
assert (testcase_el := testsuite_el.find("testcase")) is not None
92+
category = testcase_el.attrib["class"]
9593
assert category == "js, init_work_dir"
9694

9795

tests/test_short_names.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from os import linesep as n
22
from pathlib import Path
3-
from typing import cast
4-
from xml.etree.ElementTree import Element
53

64
import defusedxml.ElementTree as ET
75

@@ -49,8 +47,8 @@ def test_short_name_in_junit_xml(tmp_path: Path) -> None:
4947
]
5048
run_with_mock_cwl_runner(args)
5149
tree = ET.parse(junit_xml_report)
52-
root = tree.getroot()
53-
category = cast(
54-
Element, cast(Element, root.find("testsuite")).find("testcase")
55-
).attrib["file"]
50+
assert (root := tree.getroot()) is not None
51+
assert (testsuite_el := root.find("testsuite")) is not None
52+
assert (testcase_el := testsuite_el.find("testcase")) is not None
53+
category = testcase_el.attrib["file"]
5654
assert category == "opt-error"

tests/test_timeout.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os
22
from pathlib import Path
3-
from typing import cast
4-
from xml.etree.ElementTree import Element
53

64
import defusedxml.ElementTree as ET
75
import schema_salad.ref_resolver
@@ -31,20 +29,14 @@ def test_timeout_stderr_stdout(tmp_path: Path) -> None:
3129
assert "Test 1 timed out" in stderr
3230
tree = ET.parse(junit_xml_report)
3331
try:
34-
root = tree.getroot()
35-
timeout_text = cast(
36-
Element,
37-
cast(Element, cast(Element, root.find("testsuite")).find("testcase")).find(
38-
"failure"
39-
),
40-
).text
41-
timeout_stderr = cast(
42-
Element,
43-
cast(Element, cast(Element, root.find("testsuite")).find("testcase")).find(
44-
"system-err"
45-
),
46-
).text
32+
assert (root := tree.getroot()) is not None
33+
assert (testsuite_el := root.find("testsuite")) is not None
34+
assert (testcase_el := testsuite_el.find("testcase")) is not None
35+
assert (failure_el := testcase_el.find("failure")) is not None
36+
timeout_text = failure_el.text
4737
assert timeout_text is not None and "Test timed out" in timeout_text
38+
assert (system_err_el := testcase_el.find("system-err")) is not None
39+
timeout_stderr = system_err_el.text
4840
assert timeout_stderr is not None and "timeout stderr" in timeout_stderr
4941
except AttributeError as e:
5042
print(junit_xml_report.read_text())

0 commit comments

Comments
 (0)