From aea3de755ba1a1315bba9a69b54d94d9021aeea6 Mon Sep 17 00:00:00 2001 From: Aymen-Soussi-01 Date: Wed, 18 Dec 2024 12:18:00 +0100 Subject: [PATCH 1/4] Correct the import of filter-func in needpie if the path is composed from multiple dot --- sphinx_needs/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_needs/utils.py b/sphinx_needs/utils.py index ab5d9ab07..3a606ce31 100644 --- a/sphinx_needs/utils.py +++ b/sphinx_needs/utils.py @@ -326,7 +326,7 @@ def check_and_get_external_filter_func( return None try: - filter_module, filter_function = filter_func_ref.rsplit(".") + filter_module, filter_function = filter_func_ref.rsplit(".",1) except ValueError: raise NeedsInvalidFilter("does not contain a dot") From 20d66e281a904ff8b3dbc3a7a0632f9cfd876a77 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 15:47:51 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sphinx_needs/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_needs/utils.py b/sphinx_needs/utils.py index 3a606ce31..5ee09f651 100644 --- a/sphinx_needs/utils.py +++ b/sphinx_needs/utils.py @@ -326,7 +326,7 @@ def check_and_get_external_filter_func( return None try: - filter_module, filter_function = filter_func_ref.rsplit(".",1) + filter_module, filter_function = filter_func_ref.rsplit(".", 1) except ValueError: raise NeedsInvalidFilter("does not contain a dot") From 9dff714988cc23f1384855c0c7eb76d4d0771757 Mon Sep 17 00:00:00 2001 From: Aymen-Soussi-01 Date: Mon, 23 Dec 2024 15:11:34 +0100 Subject: [PATCH 3/4] Add test case for the fix --- .../doc_needs_filter_data/filter_code.rst | 17 ++++++++++ .../module/filter_code_func.py | 34 +++++++++++++++++++ tests/test_needs_filter_data.py | 13 ++++--- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 tests/doc_test/doc_needs_filter_data/module/filter_code_func.py diff --git a/tests/doc_test/doc_needs_filter_data/filter_code.rst b/tests/doc_test/doc_needs_filter_data/filter_code.rst index c3ba58272..644c4a50f 100644 --- a/tests/doc_test/doc_needs_filter_data/filter_code.rst +++ b/tests/doc_test/doc_needs_filter_data/filter_code.rst @@ -22,6 +22,14 @@ Filter code test cases :labels: project_x, project_y :filter-func: filter_code_func.my_pie_filter_code +.. needtable:: Filter code func table with multiple dots filter function path + :style: table + :filter-func: module.filter_code_func.own_filter_code + + +.. needpie:: Filter code func pie with multiple dots filter function path + :labels: project_x, project_y + :filter-func: module.filter_code_func.my_pie_filter_code .. needtable:: Malformed filter func table :style: table @@ -31,3 +39,12 @@ Filter code test cases .. needpie:: Malformed filter func pie :labels: project_x, project_y :filter-func: filter_code_func.my_pie_filter_code( + +.. needtable:: Malformed filter func table with multiple dots filter function path + :style: table + :filter-func: module.filter_code_func.own_filter_code( + + +.. needpie:: Malformed filter func pie with multiple dots filter function path + :labels: project_x, project_y + :filter-func: module.filter_code_func.my_pie_filter_code( \ No newline at end of file diff --git a/tests/doc_test/doc_needs_filter_data/module/filter_code_func.py b/tests/doc_test/doc_needs_filter_data/module/filter_code_func.py new file mode 100644 index 000000000..091423552 --- /dev/null +++ b/tests/doc_test/doc_needs_filter_data/module/filter_code_func.py @@ -0,0 +1,34 @@ +def own_filter_code(needs, results): + for need in needs: + if need["type"] == "test": + results.append(need) + + +def own_filter_code_args(needs, results, **kwargs): + for need in needs: + if need["status"] == kwargs["arg1"]: + results.append(need) + + +def my_pie_filter_code(needs, results): + cnt_x = 0 + cnt_y = 0 + for need in needs: + if need["variant"] == "project_x": + cnt_x += 1 + if need["variant"] == "project_y": + cnt_y += 1 + results.append(cnt_x) + results.append(cnt_y) + + +def my_pie_filter_code_args(needs, results, **kwargs): + cnt_x = 0 + cnt_y = 0 + for need in needs: + if need["status"] == kwargs["arg1"]: + cnt_x += 1 + if need["status"] == kwargs["arg2"]: + cnt_y += 1 + results.append(cnt_x) + results.append(cnt_y) diff --git a/tests/test_needs_filter_data.py b/tests/test_needs_filter_data.py index 53e45f3dd..eaa543815 100644 --- a/tests/test_needs_filter_data.py +++ b/tests/test_needs_filter_data.py @@ -20,14 +20,17 @@ def test_doc_needs_filter_data_html(test_app): ).splitlines() print(warnings) assert warnings == [ - "srcdir/filter_code.rst:26: WARNING: malformed function signature: 'own_filter_code(' [needs.filter_func]", - "srcdir/filter_code.rst:31: WARNING: malformed function signature: 'my_pie_filter_code(' [needs.filter_func]", + "srcdir/filter_code.rst:34: WARNING: malformed function signature: 'own_filter_code(' [needs.filter_func]", + "srcdir/filter_code.rst:43: WARNING: malformed function signature: 'own_filter_code(' [needs.filter_func]", + "srcdir/filter_code.rst:39: WARNING: malformed function signature: 'my_pie_filter_code(' [needs.filter_func]", + "srcdir/filter_code.rst:48: WARNING: malformed function signature: 'my_pie_filter_code(' [needs.filter_func]", "WARNING: variant_not_equal_current_variant: failed", "\t\tfailed needs: 1 (extern_filter_story_002)", "\t\tused filter: variant != current_variant [needs.warnings]", ] index_html = Path(app.outdir, "index.html").read_text() + filter_code = Path(app.outdir, "filter_code.html").read_text() # Check need_count works assert "The amount of needs that belong to current variants: 6" in index_html @@ -45,6 +48,7 @@ def test_doc_needs_filter_data_html(test_app): '

my_tag; current_variant

' in index_html ) + assert 'Filter code func table with multiple dots filter function path' in filter_code # check needflow works if int(doc_ver.split(".")[1]) >= 18: @@ -58,7 +62,8 @@ def test_doc_needs_filter_data_html(test_app): # check needpie works assert '_images/need_pie_dba00.svgtags: ' @@ -66,7 +71,7 @@ def test_doc_needs_filter_data_html(test_app): ', current_variant' in index_html ) - + @pytest.mark.parametrize( "test_app", From 1250bd07d3770f164218197c20c57879d60c5cd2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:13:33 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_needs_filter_data.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/test_needs_filter_data.py b/tests/test_needs_filter_data.py index eaa543815..5bf747d73 100644 --- a/tests/test_needs_filter_data.py +++ b/tests/test_needs_filter_data.py @@ -48,7 +48,10 @@ def test_doc_needs_filter_data_html(test_app): '

my_tag; current_variant

' in index_html ) - assert 'Filter code func table with multiple dots filter function path' in filter_code + assert ( + 'Filter code func table with multiple dots filter function path' + in filter_code + ) # check needflow works if int(doc_ver.split(".")[1]) >= 18: @@ -62,8 +65,14 @@ def test_doc_needs_filter_data_html(test_app): # check needpie works assert '_images/need_pie_dba00.svgtags: ' @@ -71,7 +80,7 @@ def test_doc_needs_filter_data_html(test_app): ', current_variant' in index_html ) - + @pytest.mark.parametrize( "test_app",