Skip to content

Commit

Permalink
Merge pull request #33 from hhslepicka/ref_lazy_load
Browse files Browse the repository at this point in the history
REF: Move no_device_lazy_load from lucid to typhos.
  • Loading branch information
klauer authored Feb 25, 2020
2 parents 841e8a3 + 2db020c commit b8dcaa9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 42 deletions.
2 changes: 1 addition & 1 deletion lucid/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 1 addition & 16 deletions lucid/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import re
import time
import contextlib

import fuzzywuzzy.fuzz

Expand All @@ -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__)

Expand Down Expand Up @@ -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
26 changes: 1 addition & 25 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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

0 comments on commit b8dcaa9

Please sign in to comment.