This commit is contained in:
+16
-18
@@ -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
|
|
||||||
|
|
||||||
def remove_callback(self, cb_id):
|
# Store instances for access
|
||||||
self._callbacks.pop(cb_id, None)
|
instances = {}
|
||||||
|
|
||||||
# Store the created fake PVs to access them later
|
def create_pv(pvname, **kwargs):
|
||||||
fake_pvs = {}
|
instances[pvname] = FakeEPICS(pvname)
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user