Skip to content

Commit

Permalink
Removed beamline_connected pytest fixture, and restored
Browse files Browse the repository at this point in the history
``titleize`` function to haven.utils.
  • Loading branch information
canismarko committed Dec 5, 2024
1 parent 3e60f1b commit f8959a5
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 324 deletions.
7 changes: 0 additions & 7 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from tiled.server.app import build_app

import haven
from haven._iconfig import beamline_connected as _beamline_connected
from haven.catalog import Catalog
from haven.devices.aps import ApsMachine
from haven.devices.area_detector import AravisDetector
Expand Down Expand Up @@ -44,12 +43,6 @@
)


@pytest.fixture()
def beamline_connected():
with _beamline_connected(True):
yield


@pytest.fixture()
def sim_registry(monkeypatch):
# Save the registry so we can restore it later
Expand Down
4 changes: 2 additions & 2 deletions src/firefly/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from qtpy.QtWidgets import QAction, QErrorMessage

from haven import beamline, load_config
from haven.device import titelize
from haven.exceptions import ComponentNotFound, InvalidConfiguration
from haven.utils import titleize

from .action import Action, ActionsRegistry, WindowAction
from .kafka_client import KafkaClient
Expand Down Expand Up @@ -502,7 +502,7 @@ def device_actions(
actions = {
device.name: WindowAction(
name=f"show_{device.name}_action",
text=titelize(device.name),
text=titleize(device.name),
display_file=display_file,
icon=icon,
WindowClass=WindowClass,
Expand Down
17 changes: 0 additions & 17 deletions src/haven/_iconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import argparse
import logging
import os
from contextlib import contextmanager
from copy import deepcopy
from pathlib import Path
from pprint import pprint
from typing import Optional, Sequence
Expand Down Expand Up @@ -99,21 +97,6 @@ def print_config_value(args: Sequence[str] = None):
print(value)


@contextmanager
def beamline_connected(is_connected=True):
global _local_overrides
# Save old value
old_dict = deepcopy(_local_overrides)
# Set temporary value
if "beamline" not in _local_overrides.keys():
_local_overrides["beamline"] = {}
_local_overrides["beamline"]["hardware_is_present"] = is_connected
# Return to enclosing code
yield
# Restore old value
_local_overrides = old_dict


# -----------------------------------------------------------------------------
# :author: Mark Wolfman
# :email: [email protected]
Expand Down
8 changes: 4 additions & 4 deletions src/haven/devices/xspress.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import re
import logging
import re
import time
from collections import OrderedDict
from enum import IntEnum
from functools import partial
from typing import Dict, Optional, Sequence, Callable
from typing import Callable, Dict, Optional, Sequence

import numpy as np
import pandas as pd
from apstools.devices import CamMixin_V34, SingleTrigger_V34
from ophyd import ADComponent as ADCpt
from ophyd import Component
from ophyd import Component as Cpt
from ophyd import Device
from ophyd import DynamicDeviceComponent as DDC
from ophyd import EpicsSignal, EpicsSignalRO, Kind
from ophyd import Component, K
from ophyd import EpicsSignal, EpicsSignalRO, K, Kind
from ophyd.areadetector.base import EpicsSignalWithRBV as SignalWithRBV
from ophyd.signal import InternalSignal
from ophyd.sim import make_fake_device
Expand Down
2 changes: 1 addition & 1 deletion src/haven/tests/test_iconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path

from haven import _iconfig
from haven._iconfig import beamline_connected, load_config, print_config_value
from haven._iconfig import load_config, print_config_value


def test_default_values():
Expand Down
5 changes: 4 additions & 1 deletion src/haven/tests/test_xspress.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ def test_roi_size(xspress):


def test_make_xspress_device():
xspress = make_xspress_device(name="xspress", prefix="255id_xsp:", num_elements=3, mock=True)
xspress = make_xspress_device(
name="xspress", prefix="255id_xsp:", num_elements=3, mock=True
)
xspress.wait_for_connection()
assert xspress.name == "xspress"
assert xspress.prefix == "255id_xsp:"
assert hasattr(xspress.mcas, "mca2")
assert not hasattr(xspress.mcas, "mca3")


# -----------------------------------------------------------------------------
# :author: Mark Wolfman
# :email: [email protected]
Expand Down
10 changes: 10 additions & 0 deletions src/haven/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
bad_separators = re.compile("[-. ]+")


def titleize(name):
"""Convert a device name into a human-readable title."""
title = name.replace("_", " ").title()
# Replace select phrases that are known to be incorrect
replacements = {"Kb ": "KB "}
for orig, new in replacements.items():
title = title.replace(orig, new)
return title


def sanitize_name(name: str) -> str:
"""Convert *name* into something usable as a queueserver device."""
return bad_separators.sub("_", name)
Loading

0 comments on commit f8959a5

Please sign in to comment.