From 9e023db7014aac2053db288e5240cdef8a6f6384 Mon Sep 17 00:00:00 2001 From: tligui_y Date: Thu, 7 Aug 2025 16:48:01 +0200 Subject: [PATCH] Update tests/test_utils_pvpreload.py --- ...ils_preload.py => test_utils_pvpreload.py} | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) rename tests/{test_utils_preload.py => test_utils_pvpreload.py} (87%) diff --git a/tests/test_utils_preload.py b/tests/test_utils_pvpreload.py similarity index 87% rename from tests/test_utils_preload.py rename to tests/test_utils_pvpreload.py index da9dd8ef8..654580d47 100644 --- a/tests/test_utils_preload.py +++ b/tests/test_utils_pvpreload.py @@ -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 n’a 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):