From 0970b29e40fa6df7fe60fcac7e882d684ea63102 Mon Sep 17 00:00:00 2001 From: Stanislav Pankevich Date: Tue, 19 Sep 2023 21:32:24 +0200 Subject: [PATCH] source coverage: fix case when source file last line is not empty Closes #1307 --- strictdoc/__init__.py | 2 +- .../html/generators/source_file_view_generator.py | 8 +++++--- .../01_basic_req_to_file_link_full_path/test.itest | 1 + .../19_no_newline_at_end_of_file/file.py | 3 +++ .../19_no_newline_at_end_of_file/input.sdoc | 10 ++++++++++ .../19_no_newline_at_end_of_file/test.itest | 11 +++++++++++ 6 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/file.py create mode 100644 tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/input.sdoc create mode 100644 tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/test.itest diff --git a/strictdoc/__init__.py b/strictdoc/__init__.py index d40de17b7..55a445cfe 100644 --- a/strictdoc/__init__.py +++ b/strictdoc/__init__.py @@ -1,6 +1,6 @@ from strictdoc.core.environment import SDocRuntimeEnvironment -__version__ = "0.0.44a10" +__version__ = "0.0.44a11" environment = SDocRuntimeEnvironment(__file__) diff --git a/strictdoc/export/html/generators/source_file_view_generator.py b/strictdoc/export/html/generators/source_file_view_generator.py index 7b999131a..8aee02b3a 100644 --- a/strictdoc/export/html/generators/source_file_view_generator.py +++ b/strictdoc/export/html/generators/source_file_view_generator.py @@ -107,7 +107,7 @@ def get_pygmented_source_lines( # HACK: # Otherwise, Pygments will skip the first line as if it does not exist. - # This behavior surprisingly affects on the first line if its empty. + # This behavior surprisingly has an effect on the first line if its empty. hack_first_line: bool = False if source_file_lines[0] == "\n": source_file_lines[0] = " \n" @@ -152,12 +152,14 @@ def get_pygmented_source_lines( ), "Expected marker to be in place." # Pop ###, pop "\n" pygmented_source_file_lines.pop() - pygmented_source_file_lines.pop() + if pygmented_source_file_lines[-1] == "": + pygmented_source_file_lines.pop() assert len(pygmented_source_file_lines) == len(source_file_lines), ( f"Something went wrong when running Pygments against " f"the source file: " - f"{len(pygmented_source_file_lines)} == {len(source_file_lines)}" + f"{len(pygmented_source_file_lines)} == {len(source_file_lines)}, " + f"{pygmented_source_file_lines} == {source_file_lines}." ) for pragma in coverage_info.pragmas: diff --git a/tests/integration/commands/export/html/file_traceability/01_basic_req_to_file_link_full_path/test.itest b/tests/integration/commands/export/html/file_traceability/01_basic_req_to_file_link_full_path/test.itest index 34ec21f9f..f7b65ec9e 100644 --- a/tests/integration/commands/export/html/file_traceability/01_basic_req_to_file_link_full_path/test.itest +++ b/tests/integration/commands/export/html/file_traceability/01_basic_req_to_file_link_full_path/test.itest @@ -8,3 +8,4 @@ CHECK-HTML: RUN: %cat %S/Output/html/_source_files/file.py.html | filecheck %s --dump-input=fail --check-prefix CHECK-SOURCE-FILE CHECK-SOURCE-FILE: +CHECK-SOURCE-FILE: # noqa: T201 diff --git a/tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/file.py b/tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/file.py new file mode 100644 index 000000000..a9e31d2a8 --- /dev/null +++ b/tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/file.py @@ -0,0 +1,3 @@ +def hello_world(): + print("hello world") # noqa: T201 +123123 # noqa: W292, B018 \ No newline at end of file diff --git a/tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/input.sdoc b/tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/input.sdoc new file mode 100644 index 000000000..ce4dcbb0e --- /dev/null +++ b/tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/input.sdoc @@ -0,0 +1,10 @@ +[DOCUMENT] +TITLE: Hello world doc + +[REQUIREMENT] +UID: REQ-001 +REFS: +- TYPE: File + VALUE: file.py +TITLE: Requirement Title +STATEMENT: Requirement Statement diff --git a/tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/test.itest b/tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/test.itest new file mode 100644 index 000000000..cf19edf1c --- /dev/null +++ b/tests/integration/commands/export/html/file_traceability/19_no_newline_at_end_of_file/test.itest @@ -0,0 +1,11 @@ +RUN: %strictdoc export %S --experimental-enable-file-traceability --output-dir Output | filecheck %s --dump-input=fail +CHECK: Published: Hello world doc + +RUN: %check_exists --file "%S/Output/html/_source_files/file.py.html" + +RUN: %cat %S/Output/html/19_no_newline_at_end_of_file/input.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML +CHECK-HTML: + +RUN: %cat %S/Output/html/_source_files/file.py.html | filecheck %s --dump-input=fail --check-prefix CHECK-SOURCE-FILE +CHECK-SOURCE-FILE: +CHECK-SOURCE-FILE:
123123  # noqa: W292, B018