From 2db020cdcaabae8704c8ac109d161b8589dc6838 Mon Sep 17 00:00:00 2001 From: Hugo Slepicka Date: Mon, 24 Feb 2020 20:36:22 -0800 Subject: [PATCH] REF: Move no_device_lazy_load from lucid to typhos. TST: Add tests for typhos.utils.no_device_lazy_load. --- lucid/launcher.py | 2 +- lucid/utils.py | 17 +---------------- tests/test_utils.py | 26 +------------------------- 3 files changed, 3 insertions(+), 42 deletions(-) diff --git a/lucid/launcher.py b/lucid/launcher.py index 52b92a4..7098f60 100644 --- a/lucid/launcher.py +++ b/lucid/launcher.py @@ -95,7 +95,7 @@ def run(self): cli = lucid.utils.get_happi_client() devices = cli.search(beamline=self.beamline) or [] - with lucid.utils.no_device_lazy_load(): + with typhos.utils.no_device_lazy_load(): for dev in devices: try: stand = get_happi_entry_value(dev, row_group_key) diff --git a/lucid/utils.py b/lucid/utils.py index ff4569c..304fdf4 100644 --- a/lucid/utils.py +++ b/lucid/utils.py @@ -1,7 +1,6 @@ import logging import re import time -import contextlib import fuzzywuzzy.fuzz @@ -11,7 +10,7 @@ import happi from pydm.widgets import PyDMDrawingCircle from typhos import TyphosDeviceDisplay, TyphosSuite -from ophyd import Device +from typhos.utils import no_device_lazy_load logger = logging.getLogger(__name__) @@ -208,17 +207,3 @@ def check_stale_cache(): _HAPPI_CACHE = (time.monotonic(), list(client.search(as_dict=True))) return _HAPPI_CACHE[1] - - -@contextlib.contextmanager -def no_device_lazy_load(): - ''' - Context manager which disables the ophyd.device.Device - `lazy_wait_for_connection` behavior and later restore its value. - ''' - old_val = Device.lazy_wait_for_connection - try: - Device.lazy_wait_for_connection = False - yield - finally: - Device.lazy_wait_for_connection = old_val diff --git a/tests/test_utils.py b/tests/test_utils.py index 64f6f2d..b5a38c5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,7 +2,7 @@ from qtpy.QtCore import Qt from qtpy.QtWidgets import QWidget -from lucid.utils import SnakeLayout, no_device_lazy_load +from lucid.utils import SnakeLayout @pytest.mark.parametrize('direction,shape', @@ -18,27 +18,3 @@ def test_snake_layout_add(qtbot, direction, shape): qtbot.addWidget(widget) assert (layout.columnCount(), layout.rowCount()) == shape - - -def test_no_device_lazy_load(): - from ophyd import Device, Component as Cpt - - class TestDevice(Device): - c = Cpt(Device, suffix='Test') - - dev = TestDevice(name='foo') - - old_val = Device.lazy_wait_for_connection - assert dev.lazy_wait_for_connection is old_val - assert dev.c.lazy_wait_for_connection is old_val - - with no_device_lazy_load(): - dev2 = TestDevice(name='foo') - - assert Device.lazy_wait_for_connection is False - assert dev2.lazy_wait_for_connection is False - assert dev2.c.lazy_wait_for_connection is False - - assert Device.lazy_wait_for_connection is old_val - assert dev.lazy_wait_for_connection is old_val - assert dev.c.lazy_wait_for_connection is old_val