This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user