diff --git a/tests/test_utils_pv.py b/tests/test_utils_pv.py index 5ef74704..96a8e441 100644 --- a/tests/test_utils_pv.py +++ b/tests/test_utils_pv.py @@ -1,18 +1,19 @@ import pytest from io import StringIO import colorama -from slic.utils.pv import PV +from unittest.mock import MagicMock +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): + def __init__(self, pvname, **kwargs): self.pvname = pvname - self._value = None + self._value = 0.0 # Initialize with default value self.units = "units" self._callbacks = {} - + self.auto_monitor = kwargs.get('auto_monitor', False) + def get(self): return self._value @@ -21,23 +22,29 @@ def fake_epics_pv(monkeypatch): self._value = value for cb in self._callbacks.values(): cb(value, old=old, **kwargs) - - # Add setter for testing - def set_value(self, value): - self._value = value + + def add_callback(self, callback): + cb_id = len(self._callbacks) + 1 + self._callbacks[cb_id] = callback + return cb_id + + def remove_callback(self, cb_id): + self._callbacks.pop(cb_id, None) + + def __repr__(self): + return f"" - # Store instances for access - instances = {} - - def create_pv(pvname, **kwargs): - instances[pvname] = FakeEPICS(pvname) - return instances[pvname] - - monkeypatch.setattr('epics.PV', create_pv) + # Create mock instance we can control + mock_pv = FakeEPICS("TEST:PV") - # Create and initialize + # Monkey patch EPICS PV creation + def mock_pv_creator(pvname, **kwargs): + return mock_pv + + monkeypatch.setattr('epics.PV', mock_pv_creator) + + # Create our test PV pv = PV("TEST:PV") - instances["TEST:PV"]._value = 0.0 return pv @pytest.fixture