From fa2f32c94df1565bfe799e7ce4e62ce49cde8852 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Thu, 10 Oct 2024 11:02:33 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX=20`need=5Fcount`=20infinite?= =?UTF-8?q?=20ratio=20(#1324)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sphinx_needs/roles/need_count.py | 2 +- tests/doc_test/doc_need_count/index.rst | 4 ++++ tests/test_need_count.py | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sphinx_needs/roles/need_count.py b/sphinx_needs/roles/need_count.py index 2bb861f74..06ee0d472 100644 --- a/sphinx_needs/roles/need_count.py +++ b/sphinx_needs/roles/need_count.py @@ -59,7 +59,7 @@ def process_need_count( need_list, needs_config, filters[1], location=node_need_count ) ) - amount = f"{amount_1 / amount_2 * 100:2.1f}" + amount = "inf" if amount_2 == 0 else f"{amount_1 / amount_2 * 100:2.1f}" elif len(filters) > 2: raise NeedsInvalidFilter( "Filter not valid. Got too many filter elements. Allowed are 1 or 2. " diff --git a/tests/doc_test/doc_need_count/index.rst b/tests/doc_test/doc_need_count/index.rst index eb5d2bfcc..9cc624f94 100644 --- a/tests/doc_test/doc_need_count/index.rst +++ b/tests/doc_test/doc_need_count/index.rst @@ -23,3 +23,7 @@ result_1-:need_count:`"A" in tags` result_2-:need_count:`"B" in tags` result_3-:need_count:`True` + +result_4-:need_count:`"A" in tags ? "B" in tags` + +result_5-:need_count:`"A" in tags ? "X" in tags` diff --git a/tests/test_need_count.py b/tests/test_need_count.py index 7d0883d4f..3d03839b6 100644 --- a/tests/test_need_count.py +++ b/tests/test_need_count.py @@ -15,3 +15,5 @@ def test_doc_need_count(test_app): assert "result_1-3" in html assert "result_2-2" in html assert "result_3-4" in html + assert "result_4-1" in html + assert "result_5-inf" in html