Skip to content

Commit c913cf2

Browse files
committed
[uss_qualifier/reports] Typing fixes
1 parent 31f047a commit c913cf2

9 files changed

Lines changed: 85 additions & 857 deletions

File tree

.basedpyright/baseline.json

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

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]

monitoring/uss_qualifier/reports/report.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,13 @@ def queries(self) -> list[fetch.Query]:
357357
for case in self.cases:
358358
for step in case.steps:
359359
if step.has_field_with_value("queries"):
360+
assert step.queries
360361
queries.extend(step.queries)
361362

362-
if self.has_field_with_value("cleanup") and self.cleanup.has_field_with_value(
363+
if self.has_field_with_value("cleanup") and self.cleanup.has_field_with_value( # pyright: ignore[reportOptionalMemberAccess]
363364
"queries"
364365
):
365-
queries.extend(self.cleanup.queries)
366+
queries.extend(self.cleanup.queries) # pyright: ignore[reportOptionalMemberAccess,reportArgumentType]
366367

367368
return queries
368369

monitoring/uss_qualifier/reports/sequence_view/events.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from monitoring.uss_qualifier.reports.sequence_view.summary_types import (
1616
Epoch,
1717
Event,
18-
EventType,
1918
Indexer,
2019
NoteEvent,
2120
TestedCase,
@@ -67,7 +66,7 @@ def _step_events(
6766
scenario_participants: dict[ParticipantID, TestedParticipant],
6867
all_events: list[Event],
6968
after: datetime | None,
70-
) -> tuple[TestedStep, datetime]:
69+
) -> tuple[TestedStep, datetime | None]:
7170
events = []
7271

7372
# Create events for this step's passed checks
@@ -116,7 +115,7 @@ def _step_events(
116115
found = False
117116
for e in all_events:
118117
if (
119-
e.type == EventType.Query
118+
e.query is not None
120119
and e.query.request.initiated_at == query_timestamp
121120
):
122121
query_events.append(e)

monitoring/uss_qualifier/reports/sequence_view/generate.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
from monitoring.uss_qualifier.reports.sequence_view.summary_types import (
3232
ActionNode,
3333
ActionNodeType,
34-
EpochType,
35-
EventType,
3634
Indexer,
3735
OverviewRow,
3836
SkippedAction,
@@ -51,6 +49,7 @@
5149

5250
def _skipped_action_of(report: SkippedActionReport) -> ActionNode:
5351
if report.declaration.get_action_type() == ActionType.TestSuite:
52+
assert report.declaration.test_suite
5453
if (
5554
"suite_type" in report.declaration.test_suite
5655
and report.declaration.test_suite.suite_type
@@ -76,6 +75,7 @@ def _skipped_action_of(report: SkippedActionReport) -> ActionNode:
7675
)
7776
name = "All actions in test suite"
7877
elif report.declaration.get_action_type() == ActionType.TestScenario:
78+
assert report.declaration.test_scenario
7979
docs = get_documentation_by_name(report.declaration.test_scenario.scenario_type)
8080
return ActionNode(
8181
name=docs.name,
@@ -84,6 +84,7 @@ def _skipped_action_of(report: SkippedActionReport) -> ActionNode:
8484
skipped_action=SkippedAction(reason=report.reason),
8585
)
8686
elif report.declaration.get_action_type() == ActionType.ActionGenerator:
87+
assert report.declaration.action_generator
8788
generator_type = action_generator_type_from_name(
8889
report.declaration.action_generator.generator_type
8990
)
@@ -123,20 +124,23 @@ def compute_action_node(report: TestSuiteActionReport, indexer: Indexer) -> Acti
123124
is_action_generator,
124125
) = report.get_applicable_report()
125126
if is_test_scenario:
127+
assert report.test_scenario
126128
return ActionNode(
127129
name=report.test_scenario.name,
128130
node_type=ActionNodeType.Scenario,
129131
children=[],
130132
scenario=compute_tested_scenario(report.test_scenario, indexer),
131133
)
132134
elif is_test_suite:
135+
assert report.test_suite
133136
children = [compute_action_node(a, indexer) for a in report.test_suite.actions]
134137
return ActionNode(
135138
name=report.test_suite.name,
136139
node_type=ActionNodeType.Suite,
137140
children=children,
138141
)
139142
elif is_action_generator:
143+
assert report.action_generator
140144
generator_type = action_generator_type_from_name(
141145
report.action_generator.generator_type
142146
)
@@ -148,6 +152,7 @@ def compute_action_node(report: TestSuiteActionReport, indexer: Indexer) -> Acti
148152
],
149153
)
150154
else:
155+
assert report.skipped_action
151156
return _skipped_action_of(report.skipped_action)
152157

153158

@@ -177,9 +182,13 @@ def _align_overview_rows(rows: list[OverviewRow]) -> None:
177182
row.filled = True
178183
to_fill -= 1
179184
elif len(row.suite_cells) < max_suite_cols:
180-
if row.suite_cells[-1].first_row and all(
181-
c.node_type == ActionNodeType.Scenario
182-
for c in row.suite_cells[-1].node.children
185+
if (
186+
row.suite_cells[-1].first_row
187+
and row.suite_cells[-1].node is not None
188+
and all(
189+
c.node_type == ActionNodeType.Scenario
190+
for c in row.suite_cells[-1].node.children
191+
)
183192
):
184193
row.suite_cells[-1].colspan += max_suite_cols - len(row.suite_cells)
185194
row.filled = True
@@ -212,6 +221,7 @@ def _align_overview_rows(rows: list[OverviewRow]) -> None:
212221

213222
def _enumerate_all_participants(node: ActionNode) -> list[ParticipantID]:
214223
if node.node_type == ActionNodeType.Scenario:
224+
assert node.scenario
215225
return list(node.scenario.participants)
216226
else:
217227
result = set()
@@ -225,6 +235,7 @@ def _generate_scenario_pages(
225235
node: ActionNode, config: SequenceViewConfiguration, output_path: str
226236
) -> None:
227237
if node.node_type == ActionNodeType.Scenario:
238+
assert node.scenario
228239
all_participants = list(node.scenario.participants)
229240
all_participants.sort()
230241
if UNATTRIBUTED_PARTICIPANT in all_participants:
@@ -241,8 +252,6 @@ def _generate_scenario_pages(
241252
test_scenario=node.scenario,
242253
all_participants=all_participants,
243254
kml_file=kml_file if config.render_kml else None,
244-
EpochType=EpochType,
245-
EventType=EventType,
246255
UNATTRIBUTED_PARTICIPANT=UNATTRIBUTED_PARTICIPANT,
247256
len=len,
248257
str=str,
@@ -308,6 +317,7 @@ def generate_sequence_view(
308317
) -> None:
309318
node = compute_action_node(report.report, Indexer())
310319

320+
assert report.configuration.v1 and report.configuration.v1.test_run
311321
resources_config = make_resources_config(report.configuration.v1.test_run)
312322

313323
os.makedirs(output_path, exist_ok=True)

0 commit comments

Comments
 (0)