This commit is contained in:
+20
-22
@@ -5,41 +5,39 @@ from slic.utils.pv import PV
|
||||
|
||||
@pytest.fixture
|
||||
def fake_epics_pv(monkeypatch):
|
||||
|
||||
"""Fixture with proper initialization and value control"""
|
||||
class FakeEPICS:
|
||||
def __init__(self, pvname):
|
||||
self.pvname = pvname
|
||||
self.value = 0.0
|
||||
self._value = None
|
||||
self.units = "units"
|
||||
self._callbacks = {}
|
||||
|
||||
def get(self):
|
||||
return self.value
|
||||
return self._value
|
||||
|
||||
def put(self, value, **kwargs):
|
||||
old = self.value
|
||||
self.value = value
|
||||
old = self._value
|
||||
self._value = value
|
||||
for cb in self._callbacks.values():
|
||||
cb(value, old=old, **kwargs)
|
||||
|
||||
def add_callback(self, callback):
|
||||
cb_id = id(callback)
|
||||
self._callbacks[cb_id] = callback
|
||||
return cb_id
|
||||
|
||||
def remove_callback(self, cb_id):
|
||||
self._callbacks.pop(cb_id, None)
|
||||
|
||||
# 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)
|
||||
|
||||
# Add setter for testing
|
||||
def set_value(self, value):
|
||||
self._value = value
|
||||
|
||||
# Store instances for access
|
||||
instances = {}
|
||||
|
||||
def create_pv(pvname, **kwargs):
|
||||
instances[pvname] = FakeEPICS(pvname)
|
||||
return instances[pvname]
|
||||
|
||||
monkeypatch.setattr('epics.PV', create_pv)
|
||||
|
||||
# Create and initialize
|
||||
pv = PV("TEST:PV")
|
||||
instances["TEST:PV"]._value = 0.0
|
||||
return pv
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user