Update tests/test_utils_pv.py
Run CI Tests / test (push) Successful in 1m5s

This commit is contained in:
2025-08-08 01:19:15 +02:00
parent 39d001aacc
commit c39af3cb2a
+26 -44
View File
@@ -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("<PV ")
assert "TEST:VAL" in original
assert f'PV "TEST:VAL" at' in custom
def test_put_without_progress(capture_stdout):
pv = PV("TEST:VAL", connection_timeout=2.0)
assert pv.wait_for_connection(timeout=2.0), "PV not connected"
# Test de base
test_value = 50.0
pv.put(test_value, wait=True)
assert pv.get() == pytest.approx(test_value)
# Now proceed with the actual test
initial_value = pv.get()
new_value = initial_value + 10
# Capture stdout
stdout_before = capture_stdout.getvalue()
pv.put(new_value, show_progress=False, wait=True)
stdout_after = capture_stdout.getvalue()
# Verify no output was produced
assert stdout_before == stdout_after, "Expected no output when show_progress=False"
assert pv.get() == pytest.approx(new_value)
assert f'PV "TEST:VAL" at' in custom