@@ -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
185186def _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]:
195197def _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
244246def _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 """∅ _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 ✅ 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
329331def _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 """∅ _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"✅ { ', ' .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 """∅ _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
580587def _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]
0 commit comments