From c39af3cb2ac136e2af75379f56a80455cb45d772 Mon Sep 17 00:00:00 2001 From: tligui_y Date: Fri, 8 Aug 2025 01:19:15 +0200 Subject: [PATCH] Update tests/test_utils_pv.py --- tests/test_utils_pv.py | 70 ++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/tests/test_utils_pv.py b/tests/test_utils_pv.py index d9762033a..a20a3b9c5 100644 --- a/tests/test_utils_pv.py +++ b/tests/test_utils_pv.py @@ -55,16 +55,16 @@ def strip_ansi(text): return ansi_escape.sub('', text) # === Tests === -@pytest.mark.parametrize("value_new, value_before, expected_color", [ - (25, 0, colorama.Fore.GREEN), - (50, 25, colorama.Fore.GREEN), - (75, 50, colorama.Fore.GREEN), - (100, 75, colorama.Fore.GREEN), - (150, 100, colorama.Fore.GREEN), - (-50, 150, colorama.Fore.GREEN) +@pytest.mark.parametrize("value_new, value_before, show_bar, expected_color", [ + (25, 0, True, colorama.Fore.GREEN), + (50, 25, True, colorama.Fore.GREEN), + (75, 50, False, colorama.Fore.GREEN), + (100, 75, True, colorama.Fore.GREEN), + (150, 100, False, colorama.Fore.GREEN), + (-50, 150, True, colorama.Fore.GREEN) ]) -def test_put_with_progress_and_repr(value_new, value_before, expected_color): +def test_put_with_progress_and_repr(value_new, value_before, show_bar, expected_color): pv = PV("TEST:VAL", connection_timeout=2.0) assert pv.wait_for_connection(timeout=2.0), "PV not connected" @@ -82,7 +82,7 @@ def test_put_with_progress_and_repr(value_new, value_before, expected_color): original_print = builtins.print builtins.print = fake_print try: - pv.put(value_new, show_progress=True) + pv.put(value_new, show_progress=show_bar) finally: builtins.print = original_print @@ -90,19 +90,24 @@ def test_put_with_progress_and_repr(value_new, value_before, expected_color): cleaned_lines = [strip_ansi(line) for line in printed_lines] # Initialisation bar - matches = [line for line in cleaned_lines if f"| |" in line] - assert matches, f"Expected bar not found in:\n" + "\n".join(printed_lines) - - # Vérifie que la bonne barre a été affichée au moins une fois - matches = [line for line in cleaned_lines if f"|██████████████████████████████|" in line] - assert matches, f"Expected bar not found in:\n" + "\n".join(printed_lines) + if show_bar==True: + matches = [line for line in cleaned_lines if f"| |" in line] + assert matches, f"Expected bar not found in:\n" + "\n".join(printed_lines) + + # Vérifie que la bonne barre a été affichée au moins une fois + matches = [line for line in cleaned_lines if f"|██████████████████████████████|" in line] + assert matches, f"Expected bar not found in:\n" + "\n".join(printed_lines) - # Vérifie que la couleur est bien utilisée (au moins une fois dans les lignes printées) - color_matches = [line for line in printed_lines if expected_color in line] - assert color_matches, "Expected color code not found" + # Vérifie que la couleur est bien utilisée (au moins une fois dans les lignes printées) + color_matches = [line for line in printed_lines if expected_color in line] + assert color_matches, "Expected color code not found" - assert all(f"{value_new}" in line for line in printed_lines), "new value not in all lines" - assert all(f"{value_before}" in line for line in printed_lines), "old value not in all lines" + assert all(f"{value_new}" in line for line in printed_lines), "new value not in all lines" + assert all(f"{value_before}" in line for line in printed_lines), "old value not in all lines" + + else : + + assert len(printed_lines) == 0 # Vérifie que la valeur finale est correcte assert pv.get() == value_new @@ -149,27 +154,4 @@ def test_orig_repr_is_not_custom_repr(): assert original.startswith("