Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[uss_qualifier/reports] Update GER to include all original content and have section numbers #849

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 75 additions & 17 deletions monitoring/uss_qualifier/reports/globally_expanded/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ def generate_globally_expanded_report(

### Setup

* Test run information
* Resource pool
2. Test run information
3. Resource pool
Comment on lines +62 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is starting at 2 instead of 1 intended here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -- section 1 is the table of contents


### Test scenarios
"""
)
+ "\n".join(f"* {section.title}" for section in sections)
+ "\n".join(
f"{str(s)}. {section.title}"
for s, section in enumerate(sections, start=4)
)
)
+ "\n\n"
)
Expand Down Expand Up @@ -165,6 +168,9 @@ def describe_pool_resource(k: str, v: dict) -> str:

ger += "\n\n".join(f"## {section.title}\n\n{section.body}" for section in sections)

gerdoc = gfm.parse(ger)
_add_section_numbers(gerdoc.children[1:])

os.makedirs(output_path, exist_ok=True)
with open(os.path.join(output_path, "report.html"), "w") as f:
f.write("<html>\n")
Expand All @@ -176,7 +182,7 @@ def describe_pool_resource(k: str, v: dict) -> str:
) as style:
f.write(style.read())
f.write("<body>\n")
f.write(gfm.render(gfm.parse(ger)))
f.write(gfm.render(gerdoc))
f.write("</body>\n")
f.write("</html>\n")

Expand Down Expand Up @@ -210,7 +216,7 @@ def _generate_scenario_section(scenario: TestedScenario) -> _Section:

renderer = MarkdownRenderer()
return _Section(
title=f"[{scenario.scenario_index}] {scenario.name}",
title=f"[S{scenario.scenario_index}] {scenario.name}",
body=renderer.render_children(doc),
)

Expand Down Expand Up @@ -282,13 +288,16 @@ def add_resource_origin():
if current_resource is None:
return
if current_resource not in scenario.resource_origins:
# This resource wasn't provided for this scenario instance; remove resource definition
doc.children = doc.children[0:current_resource_i0] + doc.children[c:]
c = current_resource_i0
# This resource wasn't provided for this scenario instance
note = marko.parse(
"""&empty; _This resource was not applicable to this test run and was therefore not provided._\n\n"""
)
doc.children = doc.children[0:c] + note.children + doc.children[c:]
c += len(note.children)
return
# Insert resource origin information
origin = marko.parse(
f"\n\nProvided by {scenario.resource_origins[current_resource]}.\n"
f"\n\n&#x2705; Provided by {scenario.resource_origins[current_resource]}.\n"
)
doc.children = doc.children[0:c] + origin.children + doc.children[c:]
c += len(origin.children)
Expand Down Expand Up @@ -364,9 +373,16 @@ def add_context_to_case():
else:
c += _add_context_to_case(doc, test_case, test_case_i0, c)
else:
# This test case wasn't executed this test run; remove it
doc.children = doc.children[0:test_case_i0] + doc.children[c:]
c = test_case_i0
# This test case wasn't executed this test run
note = marko.parse(
"""&empty; _This test case was not applicable to this test run and is therefore not statused._\n\n"""
)
doc.children = (
doc.children[0 : test_case_i0 + 1]
+ note.children
+ doc.children[test_case_i0 + 1 :]
)
c += len(note.children)
test_case = None
test_case_i0 = None
test_case_level = None
Expand Down Expand Up @@ -428,9 +444,16 @@ def add_context_to_step():
if test_step is not None:
dc = _add_context_to_step(doc, test_step, test_step_i0, c)
else:
# This test step wasn't executed this test run; remove it
dc = test_step_i0 - c
doc.children = doc.children[0:test_step_i0] + doc.children[c:]
# This test step wasn't executed this test run
note = marko.parse(
"""&empty; _This test step was not applicable to this test run and is therefore not statused._\n\n"""
)
dc = len(note.children)
doc.children = (
doc.children[0 : test_step_i0 + 1]
+ note.children
+ doc.children[test_step_i0 + 1 :]
)
c += dc
i1 += dc
added += dc
Expand Down Expand Up @@ -476,7 +499,6 @@ def _add_context_to_step(

def add_context_to_check():
nonlocal c, i1, added, test_check_name, test_check_i0, test_check_level
# TODO: Remove checks which were not actually performed in this test run
if test_check_name is not None:
dc = _add_context_to_check(doc, step, test_check_name, test_check_i0, c)
c += dc
Expand Down Expand Up @@ -530,7 +552,12 @@ def _add_context_to_check(
check_text.append(
f"&#x274C; {', '.join(event.failed_check.participants)} ({event.failed_check.timestamp})"
)
additions = marko.parse("\n\n".join(check_text))
if len(check_text) > 1:
additions = marko.parse("\n\n".join(check_text))
else:
additions = marko.parse(
"""&empty; _This check was not applicable to this test run and is therefore not statused._\n\n"""
)
doc.children = doc.children[0:i1] + additions.children + doc.children[i1:]
return len(additions.children)

Expand All @@ -554,3 +581,34 @@ def _update_links(element: marko.element.Element, origin_filename: str) -> None:
for child in element.children:
if isinstance(child, marko.element.Element):
_update_links(child, origin_filename)


def _add_section_numbers(elements: Sequence[marko.element.Element]) -> None:
heading_level = 2
levels = [0]
prev_heading = None
for i, element in enumerate(elements):
if isinstance(element, marko.block.Heading):
if element.level < heading_level:
levels = levels[0 : element.level - heading_level]
heading_level = element.level
levels[-1] += 1
elif element.level == heading_level:
levels[-1] += 1
elif element.level == heading_level + 1:
levels.append(1)
heading_level += 1
else:
raise ValueError(
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"
)
prev_heading = text_of(element)
section_number = ".".join(str(level) for level in levels) + ". "
if isinstance(element.children[0], marko.block.inline.RawText):
element.children[0].children = (
section_number + element.children[0].children
)
else:
element.children = [
marko.block.inline.RawText(section_number)
] + element.children
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ it is in violation of the OpenAPI spec referenced by **[astm.f3548.v21.DSS0100,1

## Cleanup

#### ⚠️ USS Availability can be requested check
### ⚠️ USS Availability can be requested check

If, when queried for the availability of a USS using valid credentials, the DSS does not return a valid 200 response,
it is in violation of the OpenAPI spec referenced by **[astm.f3548.v21.DSS0100,1](../../../../../requirements/astm/f3548/v21.md)**.

#### ⚠️ USS Availability can be set to Unknown check
### ⚠️ USS Availability can be set to Unknown check

A valid request to set the availability of a USS to `Unknown` should be accepted by the DSS,
otherwise it is failing to implement the OpenAPI spec referenced by **[astm.f3548.v21.DSS0100,1](../../../../../requirements/astm/f3548/v21.md)**.
Loading