This commit is contained in:
+26
-7
@@ -6,7 +6,7 @@ import colorama
|
||||
from contextlib import contextmanager
|
||||
|
||||
from slic.utils.pv import PV
|
||||
from morbidissimo import MorIOC # alias 'cs' dans votre repo
|
||||
from morbidissimo import MorIOC
|
||||
|
||||
# === IOC simulé avec MorIOC ===
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
@@ -52,21 +52,40 @@ def use_callback(pv, callback):
|
||||
(150.0, ">>>>>>>>>>", colorama.Fore.RED),
|
||||
(-50.0, "<<<<<<<<<<", colorama.Fore.RED)
|
||||
])
|
||||
def test_put_with_progress_and_repr(capture_stdout, value, expected_bar, expected_color):
|
||||
def test_put_with_progress_and_repr(value, expected_bar, expected_color):
|
||||
pv = PV("TEST:VAL", connection_timeout=2.0)
|
||||
assert pv.wait_for_connection(timeout=2.0), "PV not connected"
|
||||
|
||||
pv.put(0.0, wait=True)
|
||||
assert pv.get() == pytest.approx(0.0)
|
||||
|
||||
pv.put(value, show_progress=True)
|
||||
output = capture_stdout.getvalue()
|
||||
# Capture tous les prints dans une liste
|
||||
printed_lines = []
|
||||
|
||||
assert f"|{expected_bar}|" in output
|
||||
assert expected_color in output
|
||||
assert str(value) in output
|
||||
def fake_print(*args, **kwargs):
|
||||
line = " ".join(str(a) for a in args)
|
||||
printed_lines.append(line)
|
||||
|
||||
# Monkeypatch print uniquement dans ce contexte
|
||||
original_print = builtins.print
|
||||
builtins.print = fake_print
|
||||
try:
|
||||
pv.put(value, show_progress=True)
|
||||
finally:
|
||||
builtins.print = original_print
|
||||
|
||||
# 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]
|
||||
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)
|
||||
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 valeur finale est correcte
|
||||
assert pv.get() == pytest.approx(value)
|
||||
|
||||
# Représentation
|
||||
expected_repr = f'PV "TEST:VAL" at {value} units'
|
||||
assert repr(pv) == expected_repr
|
||||
assert pv.orig_repr().startswith('<epics.pv.PV')
|
||||
|
||||
Reference in New Issue
Block a user