From 921de12c092ca7110ccd665dee1865dfa8902a56 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 15 Aug 2022 11:44:52 +0200 Subject: snippets_translate: Fix the tests Change c4a266e38fe5bdce707ad6b123fa88bb4f10dff3 broke the test by changing the function values and signature. Task-number: PYSIDE-1984 Task-number: PYSIDE-2030 Change-Id: I88412f3f4398aa7fd0748d9ad3b7ba2a75cf9ff0 Reviewed-by: Adrian Herrmann Reviewed-by: Christian Tismer (cherry picked from commit 780c7a9314672da4c917650f0a9548a537515fd8) Reviewed-by: Qt Cherry-pick Bot --- .../snippets_translate.pyproject | 3 +- tools/snippets_translate/tests/test_snippets.py | 87 ++++++++++++++-------- 2 files changed, 57 insertions(+), 33 deletions(-) diff --git a/tools/snippets_translate/snippets_translate.pyproject b/tools/snippets_translate/snippets_translate.pyproject index 6073e9b89..f660033c1 100644 --- a/tools/snippets_translate/snippets_translate.pyproject +++ b/tools/snippets_translate/snippets_translate.pyproject @@ -1,3 +1,4 @@ { - "files": ["main.py", "converter.py", "handlers.py", "override.py", "tests/test_converter.py"] + "files": ["main.py", "converter.py", "handlers.py", "override.py", + "tests/test_converter.py", "tests/test_snippets.py"] } diff --git a/tools/snippets_translate/tests/test_snippets.py b/tools/snippets_translate/tests/test_snippets.py index 802bbc662..3c04a14b1 100644 --- a/tools/snippets_translate/tests/test_snippets.py +++ b/tools/snippets_translate/tests/test_snippets.py @@ -37,7 +37,7 @@ ## ############################################################################# -from main import get_snippets, get_snippet_ids +from main import _get_snippets, get_snippet_ids, CPP_SNIPPET_PATTERN def test_stacking(): @@ -48,13 +48,23 @@ def test_stacking(): "//! [C] //! [A] ", "//! [B] //! [D] //! [E]", ] - snippets = get_snippets(lines) + snippets = _get_snippets(lines, CPP_SNIPPET_PATTERN) assert len(snippets) == 5 - assert len(snippets[0]) == 4 # A starts at line 0 and ends at line 3 - assert len(snippets[1]) == 5 # B starts at line 0 and ends at line 4 - assert len(snippets[2]) == 3 # C starts at line 1 and ends at line 3 - assert len(snippets[3]) == 4 # D starts at line 1 and ends at line 4 - assert len(snippets[4]) == 4 # E starts at line 1 and ends at line 4 + + snippet_a = snippets["A"] + assert len(snippet_a) == 4 # A starts at line 0 and ends at line 3 + + snippet_b = snippets["B"] + assert len(snippet_b) == 5 # B starts at line 0 and ends at line 4 + + snippet_c = snippets["C"] + assert len(snippet_c) == 3 # C starts at line 1 and ends at line 3 + + snippet_d = snippets["D"] + assert len(snippet_d) == 4 # D starts at line 1 and ends at line 4 + + snippet_e = snippets["E"] + assert len(snippet_e) == 4 # E starts at line 1 and ends at line 4 def test_nesting(): @@ -67,17 +77,20 @@ def test_nesting(): "//! [C]", "//! [B]", ] - snippets = get_snippets(lines) + snippets = _get_snippets(lines, CPP_SNIPPET_PATTERN) assert len(snippets) == 3 - assert len(snippets[0]) == 5 - assert snippets[0] == lines[:5] + snippet_a = snippets["A"] + assert len(snippet_a) == 5 + assert snippet_a == lines[:5] - assert len(snippets[1]) == 6 - assert snippets[1] == lines[1:] + snippet_b = snippets["B"] + assert len(snippet_b) == 6 + assert snippet_b == lines[1:] - assert len(snippets[2]) == 4 - assert snippets[2] == lines[2:6] + snippet_c = snippets["C"] + assert len(snippet_c) == 4 + assert snippet_c == lines[2:6] def test_overlapping(): @@ -93,17 +106,20 @@ def test_overlapping(): "posttext", "//! [C]", ] - snippets = get_snippets(lines) + snippets = _get_snippets(lines, CPP_SNIPPET_PATTERN) assert len(snippets) == 3 - assert len(snippets[0]) == 4 - assert snippets[0] == lines[1:5] + snippet_a = snippets["A"] + assert len(snippet_a) == 4 + assert snippet_a == lines[1:5] - assert len(snippets[1]) == 7 - assert snippets[1] == lines[3:] + snippet_c = snippets["C"] + assert len(snippet_c) == 7 + assert snippet_c == lines[3:] - assert len(snippets[2]) == 4 - assert snippets[2] == lines[4:8] + snippet_b = snippets["B"] + assert len(snippet_b) == 4 + assert snippet_b == lines[4:8] def test_snippets(): @@ -118,20 +134,27 @@ def test_snippets(): "posttext" ] - snippets = get_snippets(lines) + snippets = _get_snippets(lines, CPP_SNIPPET_PATTERN) assert len(snippets) == 2 - assert len(snippets[0]) == 3 - assert snippets[0] == lines[1:4] + snippet_a = snippets["A"] + assert len(snippet_a) == 3 + assert snippet_a == lines[1:4] - assert len(snippets[1]) == 4 - assert snippets[1] == lines[3:7] + snippet_b = snippets["B"] + assert len(snippet_b) == 4 + assert snippet_b == lines[3:7] def test_snippet_ids(): - assert get_snippet_ids("") == [] - assert get_snippet_ids("//! ") == [] # Invalid id - assert get_snippet_ids("//! [some name]") == ["some name"] - assert get_snippet_ids("//! [some name] [some other name]") == ["some name"] - assert get_snippet_ids("//! [some name] //! ") == ["some name"] # Invalid id - assert get_snippet_ids("//! [some name] //! [some other name]") == ["some name", "some other name"] + assert get_snippet_ids("", CPP_SNIPPET_PATTERN) == [] + assert get_snippet_ids("//! ", + CPP_SNIPPET_PATTERN) == [] # Invalid id + assert get_snippet_ids("//! [some name]", + CPP_SNIPPET_PATTERN) == ["some name"] + assert get_snippet_ids("//! [some name] [some other name]", + CPP_SNIPPET_PATTERN) == ["some name"] + assert get_snippet_ids("//! [some name] //! ", + CPP_SNIPPET_PATTERN) == ["some name"] # Invalid id + assert get_snippet_ids("//! [some name] //! [some other name]", + CPP_SNIPPET_PATTERN) == ["some name", "some other name"] -- cgit v1.2.3