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

This commit is contained in:
2025-08-07 16:48:01 +02:00
parent 5f2f2719fa
commit 9e023db701
@@ -33,7 +33,10 @@ def epics_ioc():
thread = threading.Thread(target=ioc_thread, daemon=True)
thread.start()
time.sleep(1)
time.sleep(1)
def is_pv_in_cache(name):
return any(k[0] == name for k in epics.pv._PVcache_)
# Tests
@@ -68,8 +71,8 @@ def test_preload_fichier_valide(tmp_path, caplog):
pickle.dump([pvname_1, pvname_2], pkl)
# Vérifie que les PV ne sont pas encore dans le cache EPICS
assert pvname_1 not in _PVcache_
assert pvname_2 not in _PVcache_
assert !is_pv_in_cache(pvname_1)
assert !is_pv_in_cache(pvname_2)
# Patch le chemin utilisé dans preload()
with pytest.MonkeyPatch().context() as mp:
@@ -79,28 +82,20 @@ def test_preload_fichier_valide(tmp_path, caplog):
preload()
# Vérifie que les PV ont bien été créés et sont dans le cache
assert pvname_1 in _PVcache_
assert pvname_2 in _PVcache_
pv_1 = _PVcache_[pvname_1]
pv_2 = _PVcache_[pvname_2]
assert is_pv_in_cache(pvname_1)
assert is_pv_in_cache(pvname_2)
# Vérifie qu'ils sont bien connectés
assert pv_1.wait_for_connection(timeout=2)
assert pv_2.wait_for_connection(timeout=2)
assert pvname_1.wait_for_connection(timeout=2)
assert pvname_2.wait_for_connection(timeout=2)
# Vérifie le log final
logs = "\n".join(caplog.messages)
assert "PV preload done" in logs
import os
import pickle
from datetime import datetime, timedelta
import pytest
from slic.utils.pvpreload import preload, fn as original_fn, lifetime
def test_preload_fichier_trop_vieux(tmp_path, caplog):
f = tmp_path / "trop_vieux.pkl"
f = tmp_path / "too_old.pkl"
pvname = "TEST:PV_X"
# Crée un fichier pickle valide avec un nom de PV
@@ -123,7 +118,7 @@ def test_preload_fichier_trop_vieux(tmp_path, caplog):
assert "PV preload file too old" in logs
# Vérifie que le PV na pas été créé (pas dans le cache)
assert pvname not in _PVcache_
assert is_pv_in_cache(pvname)
# offload()
def test_offload(tmp_path, caplog):