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

This commit is contained in:
2025-08-08 01:13:00 +02:00
parent 856b54c0ad
commit 39d001aacc
+19 -19
View File
@@ -14,20 +14,24 @@ from morbidissimo import MorIOC
def morioc_server():
def run_ioc():
with MorIOC("TEST") as mor:
val = 0.0
# Initialisation explicite à 0.0
current_val = 0.0
mor.host(VAL=float)
while True:
mor.host(VAL=float)
# Vérifie les nouvelles valeurs
input_val = mor.get("VAL")
if input_val is not None:
val = input_val
mor.serve(VAL=val)
current_val = input_val
# Sert la valeur actuelle
mor.serve(VAL=current_val)
time.sleep(0.1)
thread = threading.Thread(target=run_ioc, daemon=True)
thread.start()
time.sleep(1) # attendre que le serveur soit prêt
yield # le thread tourne en fond
time.sleep(1) # Attend que le serveur soit prêt
yield
# === Utils ===
@pytest.fixture
@@ -100,12 +104,8 @@ def test_put_with_progress_and_repr(value_new, value_before, expected_color):
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"
# Vérifie que la valeur finale est correcte
assert pv.get() == pytest.approx(value_new)
# Représentation
expected_repr = f'PV "TEST:VAL" at {value_new} '
assert pv.get() == value_new
def test_use_callback_context_manager():
pv = PV("TEST:VAL", connection_timeout=2.0)
@@ -149,14 +149,17 @@ 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"
# First ensure we can write to the PV
# Test de base
test_value = 50.0
pv.put(test_value, wait=True)
assert pv.get() == pytest.approx(test_value), "Basic PV write test failed"
assert pv.get() == pytest.approx(test_value)
# Now proceed with the actual test
initial_value = pv.get()
@@ -169,7 +172,4 @@ def test_put_without_progress(capture_stdout):
# Verify no output was produced
assert stdout_before == stdout_after, "Expected no output when show_progress=False"
# See if update is done
time.sleep(0.1)
assert pv.get() == new_value
assert pv.get() == pytest.approx(new_value)