Update tests/test_utils_pv.py
Run CI Tests / test (push) Successful in 55s

This commit is contained in:
2025-08-04 12:37:24 +02:00
parent ae9aff7c81
commit acfbf24db3
+20 -22
View File
@@ -5,41 +5,39 @@ from slic.utils.pv import PV
@pytest.fixture @pytest.fixture
def fake_epics_pv(monkeypatch): def fake_epics_pv(monkeypatch):
"""Fixture with proper initialization and value control"""
class FakeEPICS: class FakeEPICS:
def __init__(self, pvname): def __init__(self, pvname):
self.pvname = pvname self.pvname = pvname
self.value = 0.0 self._value = None
self.units = "units" self.units = "units"
self._callbacks = {} self._callbacks = {}
def get(self): def get(self):
return self.value return self._value
def put(self, value, **kwargs): def put(self, value, **kwargs):
old = self.value old = self._value
self.value = value self._value = value
for cb in self._callbacks.values(): for cb in self._callbacks.values():
cb(value, old=old, **kwargs) cb(value, old=old, **kwargs)
def add_callback(self, callback): # Add setter for testing
cb_id = id(callback) def set_value(self, value):
self._callbacks[cb_id] = callback self._value = value
return cb_id
# Store instances for access
def remove_callback(self, cb_id): instances = {}
self._callbacks.pop(cb_id, None)
def create_pv(pvname, **kwargs):
# Store the created fake PVs to access them later instances[pvname] = FakeEPICS(pvname)
fake_pvs = {} return instances[pvname]
def create_fake_pv(pvname, **kwargs): monkeypatch.setattr('epics.PV', create_pv)
fake_pvs[pvname] = FakeEPICS(pvname)
return fake_pvs[pvname]
monkeypatch.setattr('epics.PV', create_fake_pv)
# Create and initialize
pv = PV("TEST:PV") pv = PV("TEST:PV")
instances["TEST:PV"]._value = 0.0
return pv return pv
@pytest.fixture @pytest.fixture