From 25d9eb4308aa4b0e3ed9f6af99b33a8723b56579 Mon Sep 17 00:00:00 2001 From: Andreas Zwinkau Date: Mon, 6 Oct 2025 10:23:27 +0200 Subject: [PATCH 1/4] Fix flaky test --- .../test_source_code_link_integration.py | 59 +++++++++---------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py index 52af7cc0..5f0ee160 100644 --- a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py +++ b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py @@ -307,14 +307,14 @@ def example_source_link_text_all_ok(sphinx_base_dir: Path): return { "TREQ_ID_1": [ NeedLink( - file=Path("src/implementation1.py"), - line=3, + file=Path("src/implementation2.py"), + line=5, tag="#" + " req-Id:", need="TREQ_ID_1", full_line="#" + " req-Id: TREQ_ID_1", ), NeedLink( - file=Path("src/implementation2.py"), + file=Path("src/implementation1.py"), line=3, tag="#" + " req-Id:", need="TREQ_ID_1", @@ -330,6 +330,7 @@ def example_source_link_text_all_ok(sphinx_base_dir: Path): full_line="#" + " req-Id: TREQ_ID_2", ) ], + "TREQ_ID_3": [], } @@ -359,9 +360,9 @@ def example_test_link_text_all_ok(sphinx_base_dir: Path): ), DataForTestLink( name="test_error_handling", - file=Path("src/tests/testfile_2.py"), + file=Path("src/testfile_1.py"), need="TREQ_ID_2", - line=33, + line=38, verify_type="partially", result="passed", result_text="", @@ -379,7 +380,7 @@ def example_test_link_text_all_ok(sphinx_base_dir: Path): ), DataForTestLink( name="test_error_handling", - file=Path("src/test/testfile_2.py"), + file=Path("src/testfile_1.py"), need="TREQ_ID_3", line=38, verify_type="partially", @@ -471,9 +472,7 @@ def compare_grouped_json_files(file1: Path, golden_file: Path): ) -@pytest.mark.skip( - "Flaky test, see https://github.com/eclipse-score/docs-as-code/issues/226" -) + def test_source_link_integration_ok( sphinx_app_setup: Callable[[], SphinxTestApp], example_source_link_text_all_ok: dict[str, list[NeedLink]], @@ -511,30 +510,30 @@ def test_source_link_integration_ok( # TODO: Is this actually a good test, or just a weird mock? for i in range(1, 4): + treq_id = f"TREQ_ID_{i}" + print(f"TESTING NEED: {treq_id}") # extra_options are only available at runtime - assert f"TREQ_ID_{i}" in needs_data - need_as_dict = cast(dict[str, object], needs_data[f"TREQ_ID_{i}"]) - # TODO: This probably isn't great. Should make this better. - if i != 3: - # Excluding 3 as this is a keyerror here - expected_code_link = make_source_link( - example_source_link_text_all_ok[f"TREQ_ID_{i}"] - ) - print(f"EXPECTED LINK CODE: {expected_code_link}") - actual_source_code_link = cast( - list[str], need_as_dict["source_code_link"] - ) - print(f"ACTUALL CODE LINK: {actual_source_code_link}") - assert set(expected_code_link) == set(actual_source_code_link) - expected_test_link = make_test_link( - example_test_link_text_all_ok[f"TREQ_ID_{i}"] + assert treq_id in needs_data + need_as_dict = cast(dict[str, object], needs_data[treq_id]) + + # verify codelinks + expected_code_link = make_source_link( + example_source_link_text_all_ok[treq_id] ) - # Compare contents, regardless of order. + print(f"EXPECTED CODE LINK: {expected_code_link}") + actual_source_code_link = cast( + list[str], need_as_dict["source_code_link"] + ) + print(f"ACTUAL CODE LINK: {actual_source_code_link}") + assert expected_code_link == actual_source_code_link, treq_id + + # verify testlinks + expected_test_link = make_test_link(example_test_link_text_all_ok[treq_id]) print(f"NEED AS DICT: {need_as_dict}") - print(f"EXPECTED LINK TEST: {expected_test_link}") - actual_test_code_link = cast(list[str], need_as_dict["testlink"]) - print(f"ACTUALL TEST LINK: {actual_test_code_link}") - assert set(expected_test_link) == set(actual_test_code_link) + print(f"EXPECTED TEST LINK: {expected_test_link}") + actual_test_code_link = need_as_dict["testlink"] + print(f"ACTUAL TEST LINK: {actual_test_code_link}") + assert expected_test_link == actual_test_code_link, treq_id finally: app.cleanup() From befbc83d328d218dfa6d49b11d3af22120640ca5 Mon Sep 17 00:00:00 2001 From: Andreas Zwinkau Date: Mon, 6 Oct 2025 10:39:46 +0200 Subject: [PATCH 2/4] cleanup --- .../test_source_code_link_integration.py | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py index 5f0ee160..8a56c6e2 100644 --- a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py +++ b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py @@ -487,9 +487,7 @@ def test_source_link_integration_ok( os.environ["BUILD_WORKSPACE_DIRECTORY"] = str(sphinx_base_dir) app.build() ws_root = find_ws_root() - if ws_root is None: - # This should never happen - pytest.fail(f"WS_root is none. WS_root: {ws_root}") + assert ws_root is not None Needs_Data = SphinxNeedsData(app.env) needs_data = {x["id"]: x for x in Needs_Data.get_needs_view().values()} compare_json_files( @@ -506,33 +504,24 @@ def test_source_link_integration_ok( app.outdir / "score_scl_grouped_cache.json", sphinx_base_dir / ".expected_grouped.json", ) - # Testing TREQ_ID_1, TREQ_ID_2, TREQ_ID_3 # TODO: Is this actually a good test, or just a weird mock? - for i in range(1, 4): + for i in (1, 2, 3): treq_id = f"TREQ_ID_{i}" - print(f"TESTING NEED: {treq_id}") - # extra_options are only available at runtime assert treq_id in needs_data - need_as_dict = cast(dict[str, object], needs_data[treq_id]) + treq_info = needs_data[treq_id] + print("Needs Data for", treq_id, ":", treq_info) # verify codelinks expected_code_link = make_source_link( example_source_link_text_all_ok[treq_id] ) - print(f"EXPECTED CODE LINK: {expected_code_link}") - actual_source_code_link = cast( - list[str], need_as_dict["source_code_link"] - ) - print(f"ACTUAL CODE LINK: {actual_source_code_link}") + actual_source_code_link = treq_info["source_code_link"] assert expected_code_link == actual_source_code_link, treq_id # verify testlinks expected_test_link = make_test_link(example_test_link_text_all_ok[treq_id]) - print(f"NEED AS DICT: {need_as_dict}") - print(f"EXPECTED TEST LINK: {expected_test_link}") - actual_test_code_link = need_as_dict["testlink"] - print(f"ACTUAL TEST LINK: {actual_test_code_link}") + actual_test_code_link = treq_info["testlink"] assert expected_test_link == actual_test_code_link, treq_id finally: app.cleanup() From 19caab0c0a1dcffb80bf29ca63341499cc18dc5b Mon Sep 17 00:00:00 2001 From: Andreas Zwinkau Date: Mon, 6 Oct 2025 16:55:08 +0200 Subject: [PATCH 3/4] fix linter issues --- .../tests/test_source_code_link_integration.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py index 8a56c6e2..a49e5221 100644 --- a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py +++ b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py @@ -18,7 +18,7 @@ from collections import Counter from collections.abc import Callable from pathlib import Path -from typing import Any, cast +from typing import Any import pytest from pytest import TempPathFactory @@ -472,7 +472,6 @@ def compare_grouped_json_files(file1: Path, golden_file: Path): ) - def test_source_link_integration_ok( sphinx_app_setup: Callable[[], SphinxTestApp], example_source_link_text_all_ok: dict[str, list[NeedLink]], From febf4508f7a74f090f3454888291769b32512aa6 Mon Sep 17 00:00:00 2001 From: Andreas Zwinkau Date: Mon, 6 Oct 2025 18:29:19 +0200 Subject: [PATCH 4/4] Fix more linter issues --- .../tests/test_source_code_link_integration.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py index a49e5221..44ea35a6 100644 --- a/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py +++ b/src/extensions/score_source_code_linker/tests/test_source_code_link_integration.py @@ -515,12 +515,14 @@ def test_source_link_integration_ok( expected_code_link = make_source_link( example_source_link_text_all_ok[treq_id] ) - actual_source_code_link = treq_info["source_code_link"] + actual_source_code_link = treq_info.get( + "source_code_link", "no source link" + ) assert expected_code_link == actual_source_code_link, treq_id # verify testlinks expected_test_link = make_test_link(example_test_link_text_all_ok[treq_id]) - actual_test_code_link = treq_info["testlink"] + actual_test_code_link = treq_info.get("testlink", "no test link") assert expected_test_link == actual_test_code_link, treq_id finally: app.cleanup()