Skip to content

Commit

Permalink
Merge pull request #147 from spc-group/fix_tests
Browse files Browse the repository at this point in the history
Fixed tests.

Thought using ubutnu 20.04 on CI had fixed seg-faults. But I did still see one intermittent segfault in the CI. Might still have to come back to this.
  • Loading branch information
canismarko authored Nov 16, 2023
2 parents 5dccc2e + fc3c319 commit 0690bf7
Show file tree
Hide file tree
Showing 146 changed files with 1,201 additions and 1,817 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
defaults:
run:
shell: bash -l {0}
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
max-parallel: 5
steps:
Expand All @@ -29,20 +29,22 @@ jobs:
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
- name: Setup X virtual frame buffer
run: Xvfb $DISPLAY &
- name: Install haven
run: pip install -e .
- name: Environment info
run: |
env
micromamba info
micromamba list
- name: Lint with flake8
- name: Lint
run: |
# stop the build if there are Python syntax errors or undefined names
# Check for syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# Make sure black code formatting is applied
black --check --preview src/
# Make sure import orders are correct
isort --check src/
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: pytest --timeout=120
- name: Test with pytest in Xvfb
run: xvfb-run python -m pytest -vv --timeout=120
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies:
- numba>=0.56 # Ensures 0.53 (broken) isn't installed

# --- testing and quality assurance
- black
- black >=22.1
- flake8
- pre-commit
- pylint
Expand Down Expand Up @@ -90,6 +90,7 @@ dependencies:
- ophyd >=1.6.3
- pcdsdevices # For extra signal types
- pydm >=1.18.0
- typhos
- p4p
- tiled-server
- tiled-client >= 0.1.0a106 # 2023-10-02 to get new Cache() behavior
Expand Down
12 changes: 6 additions & 6 deletions ipython_startup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from bluesky import plans as bp, plan_stubs as bps, RunEngine, suspenders
from bluesky.simulators import summarize_plan
from bluesky.callbacks.best_effort import BestEffortCallback
import databroker
import matplotlib.pyplot as plt
from bluesky import plans as bp, plan_stubs as bps, RunEngine, suspenders # noqa: F401
from bluesky.simulators import summarize_plan # noqa: F401
from bluesky.callbacks.best_effort import BestEffortCallback # noqa: F401
import databroker # noqa: F401
import matplotlib.pyplot as plt # noqa: F401

import haven
import haven # noqa: F401

# Prepare the haven instrument
config = haven.load_config()
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ firefly_cameras = "firefly.launcher:cameras"
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.isort]
profile = "black"
53 changes: 29 additions & 24 deletions src/conftest.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
from unittest import mock
import os
import subprocess
import psutil
from pathlib import Path
import os
from unittest import mock

from bluesky import RunEngine
import psutil

# from pydm.data_plugins import plugin_modules, add_plugin
import pydm
import pytest
from ophyd import DynamicDeviceComponent as DDC, Kind
from bluesky import RunEngine
from ophyd import DynamicDeviceComponent as DDC
from ophyd import Kind
from ophyd.sim import (
FakeEpicsSignal,
fake_device_cache,
instantiate_fake_device,
make_fake_device,
fake_device_cache,
FakeEpicsSignal,
)
from pydm.data_plugins import add_plugin
from pytestqt.qt_compat import qt_api

import haven
from firefly.application import FireflyApplication
from firefly.main_window import FireflyMainWindow
from haven._iconfig import beamline_connected as _beamline_connected
from haven.instrument.aerotech import AerotechStage
from haven.instrument.aps import ApsMachine
from haven.instrument.shutter import Shutter
from haven.instrument.camera import AravisDetector
from haven.instrument.delay import EpicsSignalWithIO
from haven.instrument.dxp import DxpDetector, add_mcas as add_dxp_mcas
from haven.instrument.dxp import DxpDetector
from haven.instrument.dxp import add_mcas as add_dxp_mcas
from haven.instrument.ion_chamber import IonChamber
from haven.instrument.xspress import Xspress3Detector, add_mcas as add_xspress_mcas
from firefly.application import FireflyApplication
from firefly.main_window import FireflyMainWindow
from firefly.ophyd_plugin import OphydPlugin

from haven.instrument.shutter import Shutter
from haven.instrument.xspress import Xspress3Detector
from haven.instrument.xspress import add_mcas as add_xspress_mcas

top_dir = Path(__file__).parent.resolve()
haven_dir = top_dir / "haven"
Expand Down Expand Up @@ -113,27 +116,29 @@ def kill_process(process_name):
def sim_registry(monkeypatch):
# mock out Ophyd connections so devices can be created
modules = [
haven.instrument.fluorescence_detector,
haven.instrument.monochromator,
haven.instrument.ion_chamber,
haven.instrument.motor,
haven.instrument.device,
]
for mod in modules:
monkeypatch.setattr(mod, "await_for_connection", mock.AsyncMock())
monkeypatch.setattr(
haven.instrument.ion_chamber, "caget", mock.AsyncMock(return_value="I0")
)
# Clean the registry so we can restore it later
# Save the registry so we can restore it later
registry = haven.registry
use_typhos = registry.use_typhos
objects_by_name = registry._objects_by_name
objects_by_label = registry._objects_by_label
registry.clear()
# Run the test
yield registry
# Restore the previous registry components
registry._objects_by_name = objects_by_name
registry._objects_by_label = objects_by_label
try:
yield registry
finally:
# Restore the previous registry components
registry.clear(clear_typhos=True)
registry._objects_by_name = objects_by_name
registry._objects_by_label = objects_by_label
registry.use_typhos = use_typhos


@pytest.fixture()
Expand Down Expand Up @@ -265,7 +270,7 @@ def shutters(sim_registry):

@pytest.fixture(scope="session")
def pydm_ophyd_plugin():
return add_plugin(OphydPlugin)
return pydm.data_plugins.plugin_for_address("sig://")


qs_status = {
Expand Down
5 changes: 2 additions & 3 deletions src/firefly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import display

from .application import FireflyApplication
from . import display # noqa: F401
from .application import FireflyApplication # noqa: F401
56 changes: 33 additions & 23 deletions src/firefly/application.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import logging
import subprocess
from collections import OrderedDict
from pathlib import Path
from dataclasses import dataclass, field
from typing import Optional, Union, Mapping, Sequence
from functools import partial
import subprocess
from pathlib import Path
from typing import Mapping, Sequence

from qtpy import QtWidgets, QtCore
from qtpy.QtWidgets import QAction
from qtpy.QtCore import Slot, QThread, Signal, QObject
from PyQt5.QtWidgets import QStyleFactory
import qtawesome as qta
import pydm
import pyqtgraph as pg
import qtawesome as qta
from pydm.application import PyDMApplication
from pydm.display import load_file
from pydm.utilities.stylesheet import apply_stylesheet
from bluesky_queueserver_api import BPlan
from bluesky_queueserver_api.zmq import REManagerAPI
import pyqtgraph as pg
from PyQt5.QtWidgets import QStyleFactory
from qtpy import QtCore, QtWidgets
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QAction

from haven import HavenMotor, load_config, registry
from haven.exceptions import ComponentNotFound
from haven import HavenMotor, registry, load_config
import haven

from .main_window import FireflyMainWindow, PlanMainWindow
from .ophyd_plugin import OphydPlugin
from .queue_client import QueueClient, QueueClientThread, queueserver_api

generator = type((x for x in []))
Expand Down Expand Up @@ -51,6 +46,8 @@ class FireflyApplication(PyDMApplication):
show_runs_window_action: QtWidgets.QAction
show_energy_window_action: QtWidgets.QAction
show_bss_window_action: QtWidgets.QAction
show_voltmeters_window_action: QtWidgets.QAction
show_logs_window_action: QtWidgets.QAction
launch_queuemonitor_action: QtWidgets.QAction

# Keep track of motors
Expand Down Expand Up @@ -174,6 +171,18 @@ def setup_window_actions(self):
text="Scheduling (&BSS)",
slot=self.show_bss_window,
)
# Launch ion chamber voltmeters window
self._setup_window_action(
action_name="show_voltmeters_window_action",
text="&Voltmeters",
slot=self.show_voltmeters_window,
)
# Launch log window
self._setup_window_action(
action_name="show_logs_window_action",
text="Logs",
slot=self.show_logs_window,
)
# Launch energy window
self._setup_window_action(
action_name="show_energy_window_action",
Expand Down Expand Up @@ -266,14 +275,13 @@ def _prepare_device_windows(self, device_label: str, attr_name: str):
window_slots = []
setattr(self, f"{attr_name}_window_slots", window_slots)
setattr(self, f"{attr_name}_windows", {})
# if attr_name == "ion_chamber":
# breakpoint()
for device in devices:
# Create the window action
action = QtWidgets.QAction(self)
action.setObjectName(f"actionShow_{attr_name}_{device.name}")
action.setText(device.name)
actions[device.name] = action
# Create a slot for opening the motor window
# Create a slot for opening the device window
slot = getattr(self, f"show_{attr_name}_window")
slot = partial(slot, device=device)
action.triggered.connect(slot)
Expand Down Expand Up @@ -341,7 +349,11 @@ def prepare_queue_client(self, api=None):
thread = QueueClientThread()
self._queue_thread = thread
# Create the client object
client = QueueClient(api=api, autoplay_action=self.queue_autoplay_action, open_environment_action=self.queue_open_environment_action)
client = QueueClient(
api=api,
autoplay_action=self.queue_autoplay_action,
open_environment_action=self.queue_open_environment_action,
)
client.moveToThread(thread)
thread.timer.timeout.connect(client.update)
self._queue_client = client
Expand Down Expand Up @@ -429,9 +441,7 @@ def connect_menu_signals(self, window):
and setup code.
"""
window.actionShow_Log_Viewer.triggered.connect(self.show_log_viewer_window)
window.actionShow_Xafs_Scan.triggered.connect(self.show_xafs_scan_window)
window.actionShow_Voltmeters.triggered.connect(self.show_voltmeters_window)
window.actionShow_Sample_Viewer.triggered.connect(
self.show_sample_viewer_window
)
Expand Down Expand Up @@ -540,7 +550,7 @@ def show_run_browser(self):
)

@QtCore.Slot()
def show_log_viewer_window(self):
def show_logs_window(self):
self.show_window(FireflyMainWindow, ui_dir / "log_viewer.ui", name="log_viewer")

@QtCore.Slot()
Expand Down
12 changes: 6 additions & 6 deletions src/firefly/area_detector_overlay.ui
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<string/>
</property>
<property name="channel" stdset="0">
<string>oph://${AD}.overlays.overlay_${OV}.use</string>
<string>sig://${AD}.overlays.overlay_${OV}.use</string>
</property>
</widget>
</item>
Expand All @@ -61,7 +61,7 @@
<string/>
</property>
<property name="channel" stdset="0">
<string>oph://${AD}.overlays.overlay_${OV}.shape</string>
<string>sig://${AD}.overlays.overlay_${OV}.shape</string>
</property>
</widget>
</item>
Expand All @@ -75,7 +75,7 @@
<string/>
</property>
<property name="channel" stdset="0">
<string>oph://${AD}.overlays.overlay_${OV}.position_y</string>
<string>sig://${AD}.overlays.overlay_${OV}.position_y</string>
</property>
<property name="orientation" stdset="0">
<enum>Qt::Vertical</enum>
Expand All @@ -100,7 +100,7 @@
<string/>
</property>
<property name="channel" stdset="0">
<string>oph://${AD}.overlays.overlay_${OV}.position_x</string>
<string>sig://${AD}.overlays.overlay_${OV}.position_x</string>
</property>
<property name="step_size" stdset="0">
<number>0</number>
Expand Down Expand Up @@ -132,7 +132,7 @@
<string/>
</property>
<property name="channel" stdset="0">
<string>oph://${AD}.overlays.overlay_${OV}.size_y</string>
<string>sig://${AD}.overlays.overlay_${OV}.size_y</string>
</property>
<property name="orientation" stdset="0">
<enum>Qt::Vertical</enum>
Expand All @@ -157,7 +157,7 @@
<string/>
</property>
<property name="channel" stdset="0">
<string>oph://${AD}.overlays.overlay_${OV}.size_x</string>
<string>sig://${AD}.overlays.overlay_${OV}.size_x</string>
</property>
</widget>
</item>
Expand Down
Loading

0 comments on commit 0690bf7

Please sign in to comment.