Update tests/test_utils_pv.py
Run CI Tests / test (push) Successful in 59s

This commit is contained in:
2025-08-07 14:14:20 +02:00
parent b0a157645a
commit 89a30ebc5a
+11 -1
View File
@@ -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)