Skip to content

Commit 8afffff

Browse files
committed
[uss_qualifier/reports] Typing fixes
1 parent bac22cb commit 8afffff

File tree

8 files changed

+73
-807
lines changed

8 files changed

+73
-807
lines changed

.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 & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def generate_globally_expanded_report(
110110
111111
"""
112112

113+
assert report.configuration.v1 and report.configuration.v1.test_run
113114
resource_pool = make_resources_config(report.configuration.v1.test_run)
114115

115116
def indented_ul(value) -> list[str]:
@@ -184,6 +185,7 @@ def describe_pool_resource(k: str, v: dict) -> str:
184185

185186
def _generate_sections(node: ActionNode) -> Iterator[_Section]:
186187
if node.node_type == ActionNodeType.Scenario:
188+
assert node.scenario
187189
yield _generate_scenario_section(node.scenario)
188190
elif node.node_type == ActionNodeType.SkippedAction:
189191
yield _generate_skipped_scenario_section(node)
@@ -195,7 +197,7 @@ def _generate_sections(node: ActionNode) -> Iterator[_Section]:
195197
def _generate_skipped_scenario_section(node: ActionNode) -> _Section:
196198
return _Section(
197199
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}",
200+
body=f"This instance of this test scenario was skipped in this test run because: {node.skipped_action.reason if node.skipped_action else '?'}",
199201
)
200202

201203

@@ -237,15 +239,15 @@ def _indent_headings(elements: Sequence[marko.element.Element], levels: int) ->
237239
for element in elements:
238240
if isinstance(element, marko.block.Heading):
239241
element.level = min(element.level + levels, 6)
240-
if hasattr(element, "children") and element.children:
241-
_indent_headings(element.children, levels)
242+
if children := getattr(element, "children", None):
243+
_indent_headings(children, levels)
242244

243245

244246
def _inflate_fragments(parent: marko.element.Element, origin_filename: str) -> None:
245-
if hasattr(parent, "children") and parent.children:
247+
if hasattr(parent, "children") and parent.children: # pyright: ignore[reportAttributeAccessIssue]
246248
c = 0
247-
while c < len(parent.children):
248-
child = parent.children[c]
249+
while c < len(parent.children): # pyright: ignore[reportAttributeAccessIssue]
250+
child = parent.children[c] # pyright: ignore[reportAttributeAccessIssue]
249251
if (
250252
isinstance(child, marko.block.Heading)
251253
and hasattr(child, "children")
@@ -260,12 +262,12 @@ def _inflate_fragments(parent: marko.element.Element, origin_filename: str) -> N
260262
doc = _get_test_step_fragment(absolute_path, child.level)
261263
_update_links(doc, absolute_path)
262264
_strip_link(child)
263-
parent.children = (
264-
parent.children[0 : c + 1] + doc.children + parent.children[c + 1 :]
265+
parent.children = ( # pyright: ignore[reportAttributeAccessIssue]
266+
parent.children[0 : c + 1] + doc.children + parent.children[c + 1 :] # pyright: ignore[reportAttributeAccessIssue]
265267
)
266268
c += len(doc.children)
267269
elif isinstance(child, marko.element.Element):
268-
_inflate_fragments(parent.children[c], origin_filename)
270+
_inflate_fragments(parent.children[c], origin_filename) # pyright: ignore[reportAttributeAccessIssue]
269271
c += 1
270272
else:
271273
c += 1
@@ -286,14 +288,14 @@ def add_resource_origin():
286288
note = marko.parse(
287289
"""&empty; _This resource was not applicable to this test run and was therefore not provided._\n\n"""
288290
)
289-
doc.children = doc.children[0:c] + note.children + doc.children[c:]
291+
doc.children = doc.children[0:c] + note.children + doc.children[c:] # pyright: ignore[reportAttributeAccessIssue,reportOperatorIssue]
290292
c += len(note.children)
291293
return
292294
# Insert resource origin information
293295
origin = marko.parse(
294296
f"\n\n&#x2705; Provided by {scenario.resource_origins[current_resource]}.\n"
295297
)
296-
doc.children = doc.children[0:c] + origin.children + doc.children[c:]
298+
doc.children = doc.children[0:c] + origin.children + doc.children[c:] # pyright: ignore[reportOperatorIssue]
297299
c += len(origin.children)
298300

299301
while c < len(doc.children):
@@ -327,11 +329,11 @@ def add_resource_origin():
327329

328330

329331
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]
332+
if hasattr(element, "children") and element.children: # pyright: ignore[reportAttributeAccessIssue]
333+
for c in range(len(element.children)): # pyright: ignore[reportAttributeAccessIssue]
334+
child = element.children[c] # pyright: ignore[reportAttributeAccessIssue]
333335
if isinstance(child, marko.block.inline.Link):
334-
element.children[c] = child.children[0]
336+
element.children[c] = child.children[0] # pyright: ignore[reportAttributeAccessIssue]
335337
elif isinstance(child, marko.element.Element):
336338
_strip_link(child)
337339

@@ -372,7 +374,7 @@ def add_context_to_case():
372374
"""&empty; _This test case was not applicable to this test run and is therefore not statused._\n\n"""
373375
)
374376
doc.children = (
375-
doc.children[0 : test_case_i0 + 1]
377+
doc.children[0 : test_case_i0 + 1] # pyright: ignore[reportAttributeAccessIssue,reportOperatorIssue]
376378
+ note.children
377379
+ doc.children[test_case_i0 + 1 :]
378380
)
@@ -396,6 +398,7 @@ def add_context_to_case():
396398
for epoch in scenario.epochs:
397399
if epoch.type != EpochType.Case:
398400
continue
401+
assert epoch.case
399402
if case_name == epoch.case.name:
400403
test_case = epoch.case
401404
break
@@ -409,6 +412,7 @@ def add_context_to_case():
409412
for epoch in scenario.epochs:
410413
if epoch.type != EpochType.Case:
411414
continue
415+
assert epoch.case
412416
if len(epoch.case.steps) == 1 and epoch.case.steps[0].name == "Cleanup":
413417
test_case = epoch.case
414418
break
@@ -444,7 +448,7 @@ def add_context_to_step():
444448
)
445449
dc = len(note.children)
446450
doc.children = (
447-
doc.children[0 : test_step_i0 + 1]
451+
doc.children[0 : test_step_i0 + 1] # pyright: ignore[reportOperatorIssue]
448452
+ note.children
449453
+ doc.children[test_step_i0 + 1 :]
450454
)
@@ -494,6 +498,7 @@ def _add_context_to_step(
494498
def add_context_to_check():
495499
nonlocal c, i1, added, test_check_name, test_check_i0, test_check_level
496500
if test_check_name is not None:
501+
assert test_check_i0 is not None
497502
dc = _add_context_to_check(doc, step, test_check_name, test_check_i0, c)
498503
c += dc
499504
i1 += dc
@@ -534,13 +539,15 @@ def _add_context_to_check(
534539
for event in step.events:
535540
if (
536541
event.type == EventType.PassedCheck
542+
and event.passed_check is not None
537543
and event.passed_check.name == test_check_name
538544
):
539545
check_text.append(
540546
f"&#x2705; {', '.join(event.passed_check.participants)} ({event.passed_check.timestamp})"
541547
)
542548
elif (
543549
event.type == EventType.FailedCheck
550+
and event.failed_check
544551
and event.failed_check.name == test_check_name
545552
):
546553
check_text.append(
@@ -552,7 +559,7 @@ def _add_context_to_check(
552559
additions = marko.parse(
553560
"""&empty; _This check was not applicable to this test run and is therefore not statused._\n\n"""
554561
)
555-
doc.children = doc.children[0:i1] + additions.children + doc.children[i1:]
562+
doc.children = doc.children[0:i1] + additions.children + doc.children[i1:] # pyright: ignore[reportOperatorIssue]
556563
return len(additions.children)
557564

558565

@@ -571,16 +578,16 @@ def _update_links(element: marko.element.Element, origin_filename: str) -> None:
571578
url = url.replace("/github.com/", "/raw.githubusercontent.com/")
572579
url = url.replace("/blob/", "/")
573580
element.dest = url
574-
if hasattr(element, "children") and element.children:
575-
for child in element.children:
581+
if hasattr(element, "children") and element.children: # pyright: ignore[reportAttributeAccessIssue]
582+
for child in element.children: # pyright: ignore[reportAttributeAccessIssue]
576583
if isinstance(child, marko.element.Element):
577584
_update_links(child, origin_filename)
578585

579586

580587
def _add_section_numbers(elements: Sequence[marko.element.Element]) -> None:
581588
heading_level = 2
582589
levels = [0]
583-
headings = [None]
590+
headings: list[str | None] = [None]
584591
prev_heading = None
585592
for i, element in enumerate(elements):
586593
if isinstance(element, marko.block.Heading):
@@ -599,7 +606,7 @@ def _add_section_numbers(elements: Sequence[marko.element.Element]) -> None:
599606
heading_level += 1
600607
else:
601608
headings.append(text_of(element))
602-
heading_trace = " -> ".join(headings)
609+
heading_trace = " -> ".join([str(heading) for heading in headings])
603610
raise ValueError(
604611
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}"
605612
)
@@ -612,4 +619,4 @@ def _add_section_numbers(elements: Sequence[marko.element.Element]) -> None:
612619
else:
613620
element.children = [
614621
marko.block.inline.RawText(section_number)
615-
] + element.children
622+
] + 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _step_events(
6767
scenario_participants: dict[ParticipantID, TestedParticipant],
6868
all_events: list[Event],
6969
after: datetime | None,
70-
) -> tuple[TestedStep, datetime]:
70+
) -> tuple[TestedStep, datetime | None]:
7171
events = []
7272

7373
# Create events for this step's passed checks
@@ -117,6 +117,7 @@ def _step_events(
117117
for e in all_events:
118118
if (
119119
e.type == EventType.Query
120+
and e.query is not None
120121
and e.query.request.initiated_at == query_timestamp
121122
):
122123
query_events.append(e)

monitoring/uss_qualifier/reports/sequence_view/generate.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
def _skipped_action_of(report: SkippedActionReport) -> ActionNode:
5353
if report.declaration.get_action_type() == ActionType.TestSuite:
54+
assert report.declaration.test_suite
5455
if (
5556
"suite_type" in report.declaration.test_suite
5657
and report.declaration.test_suite.suite_type
@@ -76,6 +77,7 @@ def _skipped_action_of(report: SkippedActionReport) -> ActionNode:
7677
)
7778
name = "All actions in test suite"
7879
elif report.declaration.get_action_type() == ActionType.TestScenario:
80+
assert report.declaration.test_scenario
7981
docs = get_documentation_by_name(report.declaration.test_scenario.scenario_type)
8082
return ActionNode(
8183
name=docs.name,
@@ -84,6 +86,7 @@ def _skipped_action_of(report: SkippedActionReport) -> ActionNode:
8486
skipped_action=SkippedAction(reason=report.reason),
8587
)
8688
elif report.declaration.get_action_type() == ActionType.ActionGenerator:
89+
assert report.declaration.action_generator
8790
generator_type = action_generator_type_from_name(
8891
report.declaration.action_generator.generator_type
8992
)
@@ -123,20 +126,23 @@ def compute_action_node(report: TestSuiteActionReport, indexer: Indexer) -> Acti
123126
is_action_generator,
124127
) = report.get_applicable_report()
125128
if is_test_scenario:
129+
assert report.test_scenario
126130
return ActionNode(
127131
name=report.test_scenario.name,
128132
node_type=ActionNodeType.Scenario,
129133
children=[],
130134
scenario=compute_tested_scenario(report.test_scenario, indexer),
131135
)
132136
elif is_test_suite:
137+
assert report.test_suite
133138
children = [compute_action_node(a, indexer) for a in report.test_suite.actions]
134139
return ActionNode(
135140
name=report.test_suite.name,
136141
node_type=ActionNodeType.Suite,
137142
children=children,
138143
)
139144
elif is_action_generator:
145+
assert report.action_generator
140146
generator_type = action_generator_type_from_name(
141147
report.action_generator.generator_type
142148
)
@@ -148,6 +154,7 @@ def compute_action_node(report: TestSuiteActionReport, indexer: Indexer) -> Acti
148154
],
149155
)
150156
else:
157+
assert report.skipped_action
151158
return _skipped_action_of(report.skipped_action)
152159

153160

@@ -177,9 +184,13 @@ def _align_overview_rows(rows: list[OverviewRow]) -> None:
177184
row.filled = True
178185
to_fill -= 1
179186
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
187+
if (
188+
row.suite_cells[-1].first_row
189+
and row.suite_cells[-1].node is not None
190+
and all(
191+
c.node_type == ActionNodeType.Scenario
192+
for c in row.suite_cells[-1].node.children
193+
)
183194
):
184195
row.suite_cells[-1].colspan += max_suite_cols - len(row.suite_cells)
185196
row.filled = True
@@ -212,6 +223,7 @@ def _align_overview_rows(rows: list[OverviewRow]) -> None:
212223

213224
def _enumerate_all_participants(node: ActionNode) -> list[ParticipantID]:
214225
if node.node_type == ActionNodeType.Scenario:
226+
assert node.scenario
215227
return list(node.scenario.participants)
216228
else:
217229
result = set()
@@ -225,6 +237,7 @@ def _generate_scenario_pages(
225237
node: ActionNode, config: SequenceViewConfiguration, output_path: str
226238
) -> None:
227239
if node.node_type == ActionNodeType.Scenario:
240+
assert node.scenario
228241
all_participants = list(node.scenario.participants)
229242
all_participants.sort()
230243
if UNATTRIBUTED_PARTICIPANT in all_participants:
@@ -308,6 +321,7 @@ def generate_sequence_view(
308321
) -> None:
309322
node = compute_action_node(report.report, Indexer())
310323

324+
assert report.configuration.v1 and report.configuration.v1.test_run
311325
resources_config = make_resources_config(report.configuration.v1.test_run)
312326

313327
os.makedirs(output_path, exist_ok=True)

0 commit comments

Comments
 (0)