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

This commit is contained in:
2025-08-08 00:08:21 +02:00
parent 15e38e07aa
commit 95c7d072e4
+24
View File
@@ -229,3 +229,27 @@ def test_offload(tmp_path, caplog):
assert "PV offload start" in logs
assert "PV offload done" in logs
def test_offload_exception(tmp_path, caplog):
configure_logzero_for_pytest(caplog)
# Fichier invalide : un répertoire à la place d'un fichier
fake_file = tmp_path / "invalid_dir"
fake_file.mkdir() # <-- on crée un répertoire avec ce nom, pas un fichier
pvname = "TEST:PV1"
# Créer et connecter un PV pour qu'il soit dans le cache
pv = get_pv(pvname, connect=True)
assert pv.wait_for_connection(timeout=2), "PV non connecté"
assert is_pv_in_cache(pvname)
# Patch la variable fn pour qu'elle pointe vers le mauvais "fichier"
with pytest.MonkeyPatch().context() as mp:
mp.setattr("slic.utils.pvpreload.fn", fake_file)
mp.setattr("slic.utils.pvpreload.delay", 0.01)
with caplog.at_level("WARNING"):
offload()
logs = "\n".join(caplog.messages)
assert "PV preload file not saved due to: IsADirectoryError:" in logs