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

This commit is contained in:
2025-08-04 12:33:51 +02:00
parent f18608f465
commit ae9aff7c81
+14 -10
View File
@@ -5,10 +5,11 @@ from slic.utils.pv import PV
@pytest.fixture
def fake_epics_pv(monkeypatch):
# Simule a minimal PV EPICS for testing
class FakeEPICS:
def __init__(self):
self.value = None
def __init__(self, pvname):
self.pvname = pvname
self.value = 0.0
self.units = "units"
self._callbacks = {}
@@ -29,12 +30,16 @@ def fake_epics_pv(monkeypatch):
def remove_callback(self, cb_id):
self._callbacks.pop(cb_id, None)
# Injecte our fake pv in the PV class
monkeypatch.setattr('epics.PV', FakeEPICS)
# Create PV
# Store the created fake PVs to access them later
fake_pvs = {}
def create_fake_pv(pvname, **kwargs):
fake_pvs[pvname] = FakeEPICS(pvname)
return fake_pvs[pvname]
monkeypatch.setattr('epics.PV', create_fake_pv)
pv = PV("TEST:PV")
pv._pv.value = 0.0 # Set initial value
return pv
@pytest.fixture
@@ -45,7 +50,6 @@ def capture_stdout(monkeypatch):
@pytest.mark.parametrize("value, expected_bar, expected_color, expected_repr", [
# value | bar | color | expected representation
(25.0, "██▌ ", colorama.Fore.GREEN, 'PV "TEST:PV" at 25.0 units'),
(50.0, "█████ ", colorama.Fore.GREEN, 'PV "TEST:PV" at 50.0 units'),
(75.0, "███████▌ ", colorama.Fore.GREEN, 'PV "TEST:PV" at 75.0 units'),
@@ -55,7 +59,7 @@ def capture_stdout(monkeypatch):
])
def test_progress_and_repr(fake_epics_pv, capture_stdout, value, expected_bar, expected_color, expected_repr):
"""Test PV put operations with progress bar and representation"""
pv = fake_epics_pv
# Test put() and progress bar