diff --git a/tests/test_utils_pv.py b/tests/test_utils_pv.py index 03fc45e5a..8d1558ff1 100644 --- a/tests/test_utils_pv.py +++ b/tests/test_utils_pv.py @@ -44,6 +44,12 @@ def use_callback(pv, callback): finally: pv.remove_callback(cbid) +import re + +def strip_ansi(text): + ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]') + return ansi_escape.sub('', text) + # === Tests === @pytest.mark.parametrize("value, expected_bar, expected_color", [ (25.0, "██████████", colorama.Fore.GREEN), @@ -76,9 +82,13 @@ def test_put_with_progress_and_repr(value, expected_bar, expected_color): finally: builtins.print = original_print + # Initialisation bar + matches = [line for line in cleaned_lines if f"| |" in line] + assert matches, f"Expected bar '{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 printed_lines if f"|{expected_bar}|" in line] + cleaned_lines = [strip_ansi(line) for line in printed_lines] + matches = [line for line in cleaned_lines if f"|{expected_bar}|" in line] assert matches, f"Expected bar '{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)