Skip to content

Commit d62835d

Browse files
authored
[uss_qualifier/reports] Typing fixes (#1385)
1 parent 6eb67a1 commit d62835d

File tree

17 files changed

+177
-1065
lines changed

17 files changed

+177
-1065
lines changed

.basedpyright/baseline.json

Lines changed: 0 additions & 814 deletions
Large diffs are not rendered by default.

monitoring/uss_qualifier/action_generators/documentation/definitions.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from monitoring.uss_qualifier.action_generators.definitions import GeneratorTypeName
44
from monitoring.uss_qualifier.scenarios.definitions import TestScenarioTypeName
55
from monitoring.uss_qualifier.suites.definitions import (
6-
ActionType,
76
TestSuiteDefinition,
87
TestSuiteTypeName,
98
)
@@ -34,9 +33,3 @@ class PotentialGeneratedAction(ImplicitDict):
3433
test_scenario: Optional[PotentialTestScenarioAction]
3534
test_suite: Optional[PotentialTestSuiteAction]
3635
action_generator: Optional[PotentialActionGeneratorAction]
37-
38-
def get_action_type(self) -> ActionType:
39-
matches = [v for v in ActionType if v in self and self[v]]
40-
if len(matches) != 1:
41-
raise ActionType.build_invalid_action_declaration()
42-
return ActionType(matches[0])

monitoring/uss_qualifier/action_generators/documentation/documentation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
PotentialTestSuiteAction,
1515
)
1616
from monitoring.uss_qualifier.suites.definitions import (
17-
ActionType,
1817
TestSuiteActionDeclaration,
1918
)
2019

@@ -36,16 +35,15 @@ def list_potential_actions_for_action_generator_definition(
3635
def list_potential_actions_for_action_declaration(
3736
declaration: TestSuiteActionDeclaration,
3837
) -> list[PotentialGeneratedAction]:
39-
action_type = declaration.get_action_type()
40-
if action_type == ActionType.TestScenario:
38+
if "test_scenario" in declaration and declaration.test_scenario:
4139
return [
4240
PotentialGeneratedAction(
4341
test_scenario=PotentialTestScenarioAction(
4442
scenario_type=declaration.test_scenario.scenario_type
4543
)
4644
)
4745
]
48-
elif action_type == ActionType.TestSuite:
46+
elif "test_suite" in declaration and declaration.test_suite:
4947
if "suite_type" in declaration.test_suite and declaration.test_suite.suite_type:
5048
return [
5149
PotentialGeneratedAction(
@@ -65,7 +63,7 @@ def list_potential_actions_for_action_declaration(
6563
)
6664
)
6765
]
68-
elif action_type == ActionType.ActionGenerator:
66+
elif "action_generator" in declaration and declaration.action_generator:
6967
return [
7068
PotentialGeneratedAction(
7169
action_generator=PotentialActionGeneratorAction(
@@ -74,4 +72,4 @@ def list_potential_actions_for_action_declaration(
7472
)
7573
]
7674
else:
77-
raise NotImplementedError(f"Action type {action_type} is not supported")
75+
raise declaration.invalid_type_error

monitoring/uss_qualifier/reports/globally_expanded/generate.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
from monitoring.uss_qualifier.reports.sequence_view.summary_types import (
2222
ActionNode,
2323
ActionNodeType,
24-
EpochType,
25-
EventType,
2624
Indexer,
2725
TestedCase,
2826
TestedScenario,
@@ -110,6 +108,7 @@ def generate_globally_expanded_report(
110108
111109
"""
112110

111+
assert report.configuration.v1 and report.configuration.v1.test_run
113112
resource_pool = make_resources_config(report.configuration.v1.test_run)
114113

115114
def indented_ul(value) -> list[str]:
@@ -184,6 +183,7 @@ def describe_pool_resource(k: str, v: dict) -> str:
184183

185184
def _generate_sections(node: ActionNode) -> Iterator[_Section]:
186185
if node.node_type == ActionNodeType.Scenario:
186+
assert node.scenario
187187
yield _generate_scenario_section(node.scenario)
188188
elif node.node_type == ActionNodeType.SkippedAction:
189189
yield _generate_skipped_scenario_section(node)
@@ -195,7 +195,7 @@ def _generate_sections(node: ActionNode) -> Iterator[_Section]:
195195
def _generate_skipped_scenario_section(node: ActionNode) -> _Section:
196196
return _Section(
197197
title=f"[skipped] {node.name}",
198-
body=f"This instance of this test scenario was skipped in this test run because: {node.skipped_action.reason}",
198+
body=f"This instance of this test scenario was skipped in this test run because: {node.skipped_action.reason if node.skipped_action else '?'}",
199199
)
200200

201201

@@ -237,15 +237,15 @@ def _indent_headings(elements: Sequence[marko.element.Element], levels: int) ->
237237
for element in elements:
238238
if isinstance(element, marko.block.Heading):
239239
element.level = min(element.level + levels, 6)
240-
if hasattr(element, "children") and element.children:
241-
_indent_headings(element.children, levels)
240+
if hasattr(element, "children") and element.children: # pyright: ignore[reportAttributeAccessIssue]
241+
_indent_headings(element.children, levels) # pyright: ignore[reportAttributeAccessIssue]
242242

243243

244244
def _inflate_fragments(parent: marko.element.Element, origin_filename: str) -> None:
245-
if hasattr(parent, "children") and parent.children:
245+
if hasattr(parent, "children") and parent.children: # pyright: ignore[reportAttributeAccessIssue]
246246
c = 0
247-
while c < len(parent.children):
248-
child = parent.children[c]
247+
while c < len(parent.children): # pyright: ignore[reportAttributeAccessIssue]
248+
child = parent.children[c] # pyright: ignore[reportAttributeAccessIssue]
249249
if (
250250
isinstance(child, marko.block.Heading)
251251
and hasattr(child, "children")
@@ -260,12 +260,12 @@ def _inflate_fragments(parent: marko.element.Element, origin_filename: str) -> N
260260
doc = _get_test_step_fragment(absolute_path, child.level)
261261
_update_links(doc, absolute_path)
262262
_strip_link(child)
263-
parent.children = (
264-
parent.children[0 : c + 1] + doc.children + parent.children[c + 1 :]
263+
parent.children = ( # pyright: ignore[reportAttributeAccessIssue]
264+
parent.children[0 : c + 1] + doc.children + parent.children[c + 1 :] # pyright: ignore[reportAttributeAccessIssue]
265265
)
266266
c += len(doc.children)
267267
elif isinstance(child, marko.element.Element):
268-
_inflate_fragments(parent.children[c], origin_filename)
268+
_inflate_fragments(parent.children[c], origin_filename) # pyright: ignore[reportAttributeAccessIssue]
269269
c += 1
270270
else:
271271
c += 1
@@ -286,14 +286,14 @@ def add_resource_origin():
286286
note = marko.parse(
287287
"""&empty; _This resource was not applicable to this test run and was therefore not provided._\n\n"""
288288
)
289-
doc.children = doc.children[0:c] + note.children + doc.children[c:]
289+
doc.children = doc.children[0:c] + note.children + doc.children[c:] # pyright: ignore[reportAttributeAccessIssue,reportOperatorIssue]
290290
c += len(note.children)
291291
return
292292
# Insert resource origin information
293293
origin = marko.parse(
294294
f"\n\n&#x2705; Provided by {scenario.resource_origins[current_resource]}.\n"
295295
)
296-
doc.children = doc.children[0:c] + origin.children + doc.children[c:]
296+
doc.children = doc.children[0:c] + origin.children + doc.children[c:] # pyright: ignore[reportOperatorIssue]
297297
c += len(origin.children)
298298

299299
while c < len(doc.children):
@@ -327,11 +327,11 @@ def add_resource_origin():
327327

328328

329329
def _strip_link(element: marko.element.Element) -> None:
330-
if hasattr(element, "children") and element.children:
331-
for c in range(len(element.children)):
332-
child = element.children[c]
330+
if hasattr(element, "children") and element.children: # pyright: ignore[reportAttributeAccessIssue]
331+
for c in range(len(element.children)): # pyright: ignore[reportAttributeAccessIssue]
332+
child = element.children[c] # pyright: ignore[reportAttributeAccessIssue]
333333
if isinstance(child, marko.block.inline.Link):
334-
element.children[c] = child.children[0]
334+
element.children[c] = child.children[0] # pyright: ignore[reportAttributeAccessIssue]
335335
elif isinstance(child, marko.element.Element):
336336
_strip_link(child)
337337

@@ -372,7 +372,7 @@ def add_context_to_case():
372372
"""&empty; _This test case was not applicable to this test run and is therefore not statused._\n\n"""
373373
)
374374
doc.children = (
375-
doc.children[0 : test_case_i0 + 1]
375+
doc.children[0 : test_case_i0 + 1] # pyright: ignore[reportAttributeAccessIssue,reportOperatorIssue]
376376
+ note.children
377377
+ doc.children[test_case_i0 + 1 :]
378378
)
@@ -394,7 +394,7 @@ def add_context_to_case():
394394
test_case_i0 = c
395395
test_case_level = child.level
396396
for epoch in scenario.epochs:
397-
if epoch.type != EpochType.Case:
397+
if epoch.case is None:
398398
continue
399399
if case_name == epoch.case.name:
400400
test_case = epoch.case
@@ -407,7 +407,7 @@ def add_context_to_case():
407407
test_case_level = child.level
408408
cleanup = True
409409
for epoch in scenario.epochs:
410-
if epoch.type != EpochType.Case:
410+
if epoch.case is None:
411411
continue
412412
if len(epoch.case.steps) == 1 and epoch.case.steps[0].name == "Cleanup":
413413
test_case = epoch.case
@@ -444,7 +444,7 @@ def add_context_to_step():
444444
)
445445
dc = len(note.children)
446446
doc.children = (
447-
doc.children[0 : test_step_i0 + 1]
447+
doc.children[0 : test_step_i0 + 1] # pyright: ignore[reportOperatorIssue]
448448
+ note.children
449449
+ doc.children[test_step_i0 + 1 :]
450450
)
@@ -494,6 +494,7 @@ def _add_context_to_step(
494494
def add_context_to_check():
495495
nonlocal c, i1, added, test_check_name, test_check_i0, test_check_level
496496
if test_check_name is not None:
497+
assert test_check_i0 is not None
497498
dc = _add_context_to_check(doc, step, test_check_name, test_check_i0, c)
498499
c += dc
499500
i1 += dc
@@ -533,14 +534,14 @@ def _add_context_to_check(
533534
check_text = [""]
534535
for event in step.events:
535536
if (
536-
event.type == EventType.PassedCheck
537+
event.passed_check is not None
537538
and event.passed_check.name == test_check_name
538539
):
539540
check_text.append(
540541
f"&#x2705; {', '.join(event.passed_check.participants)} ({event.passed_check.timestamp})"
541542
)
542543
elif (
543-
event.type == EventType.FailedCheck
544+
event.failed_check is not None
544545
and event.failed_check.name == test_check_name
545546
):
546547
check_text.append(
@@ -552,7 +553,7 @@ def _add_context_to_check(
552553
additions = marko.parse(
553554
"""&empty; _This check was not applicable to this test run and is therefore not statused._\n\n"""
554555
)
555-
doc.children = doc.children[0:i1] + additions.children + doc.children[i1:]
556+
doc.children = doc.children[0:i1] + additions.children + doc.children[i1:] # pyright: ignore[reportOperatorIssue]
556557
return len(additions.children)
557558

558559

@@ -571,16 +572,16 @@ def _update_links(element: marko.element.Element, origin_filename: str) -> None:
571572
url = url.replace("/github.com/", "/raw.githubusercontent.com/")
572573
url = url.replace("/blob/", "/")
573574
element.dest = url
574-
if hasattr(element, "children") and element.children:
575-
for child in element.children:
575+
if hasattr(element, "children") and element.children: # pyright: ignore[reportAttributeAccessIssue]
576+
for child in element.children: # pyright: ignore[reportAttributeAccessIssue]
576577
if isinstance(child, marko.element.Element):
577578
_update_links(child, origin_filename)
578579

579580

580581
def _add_section_numbers(elements: Sequence[marko.element.Element]) -> None:
581582
heading_level = 2
582583
levels = [0]
583-
headings = [None]
584+
headings: list[str | None] = [None]
584585
prev_heading = None
585586
for i, element in enumerate(elements):
586587
if isinstance(element, marko.block.Heading):
@@ -599,7 +600,7 @@ def _add_section_numbers(elements: Sequence[marko.element.Element]) -> None:
599600
heading_level += 1
600601
else:
601602
headings.append(text_of(element))
602-
heading_trace = " -> ".join(headings)
603+
heading_trace = " -> ".join([str(heading) for heading in headings])
603604
raise ValueError(
604605
f"Encountered a level {element.level} heading ({text_of(element)}) at element {i} following a level {heading_level} heading ({prev_heading}); expected heading levels to increase by 1 level at a time. Trace: {heading_trace}"
605606
)
@@ -612,4 +613,4 @@ def _add_section_numbers(elements: Sequence[marko.element.Element]) -> None:
612613
else:
613614
element.children = [
614615
marko.block.inline.RawText(section_number)
615-
] + element.children
616+
] + element.children # pyright: ignore[reportOperatorIssue]

0 commit comments

Comments
 (0)