Skip to content

Commit

Permalink
Cleaned up some flake8 complaints, and moved simulated ioc pytest fix…
Browse files Browse the repository at this point in the history
…tures to a separate conftest.py file.
  • Loading branch information
canismarko committed Dec 2, 2022
1 parent b8a8159 commit a5d9350
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 253 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 88
49 changes: 49 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from pathlib import Path
import pytest

from haven.simulated_ioc import simulated_ioc


ioc_dir = Path(__file__).parent.resolve() / "iocs"


@pytest.fixture
def ioc_undulator():
with simulated_ioc(fp=ioc_dir / "undulator.py") as pvdb:
yield pvdb


@pytest.fixture
def ioc_mono():
with simulated_ioc(fp=ioc_dir / "mono.py") as pvdb:
yield pvdb


@pytest.fixture
def ioc_scaler():
with simulated_ioc(fp=ioc_dir / "scaler.py") as pvdb:
yield pvdb


@pytest.fixture
def ioc_motor():
with simulated_ioc(fp=ioc_dir / "motor.py") as pvdb:
yield pvdb


@pytest.fixture
def ioc_preamp():
with simulated_ioc(fp=ioc_dir / "preamp.py") as pvdb:
yield pvdb


@pytest.fixture
def ioc_simple():
with simulated_ioc(fp=ioc_dir / "simple.py") as pvdb:
yield pvdb


@pytest.fixture
def ioc_vortex():
with simulated_ioc(fp=ioc_dir / "vortex.py") as pvdb:
yield pvdb
8 changes: 3 additions & 5 deletions tests/iocs/mono.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python3
from textwrap import dedent

from caproto.server import (
pvproperty,
run,
PvpropertyDouble,
)

from haven.simulated_ioc import ResponsiveMotorFields, ioc_arg_parser, IOC as IOC_
from haven.simulated_ioc import ResponsiveMotorFields, IOC as IOC_


class IOC(IOC_):
Expand All @@ -25,10 +23,10 @@ class IOC(IOC_):
m7 = pvproperty(value=0, doc="roll-int", record=ResponsiveMotorFields)
m8 = pvproperty(value=0, doc="pi-int", record=ResponsiveMotorFields)
Energy = pvproperty(value=10000.0, doc="Energy", record=ResponsiveMotorFields)

default_prefix = "mono_ioc:"


if __name__ == '__main__':
if __name__ == "__main__":
pvdb, run_options = IOC.parse_args()
run(pvdb, **run_options)
6 changes: 2 additions & 4 deletions tests/iocs/motor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python3
from textwrap import dedent

from caproto.server import (
pvproperty,
run,
PvpropertyDouble,
)

from haven.simulated_ioc import ResponsiveMotorFields, ioc_arg_parser, IOC as IOC_
from haven.simulated_ioc import ResponsiveMotorFields, IOC as IOC_


class IOC(IOC_):
Expand All @@ -25,6 +23,6 @@ class IOC(IOC_):
default_prefix = "vme_crate_ioc:"


if __name__ == '__main__':
if __name__ == "__main__":
pvdb, run_options = IOC.parse_args()
run(pvdb, **run_options)
6 changes: 2 additions & 4 deletions tests/iocs/preamp.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env python3
from textwrap import dedent

from caproto import ChannelType
from caproto.server import (
pvproperty,
run,
PvpropertyDouble,
)

from haven.simulated_ioc import ResponsiveMotorFields, ioc_arg_parser, IOC as IOC_
from haven.simulated_ioc import IOC as IOC_


class IOC(IOC_):
Expand Down Expand Up @@ -37,6 +35,6 @@ class IOC(IOC_):
default_prefix = "preamp_ioc:"


if __name__ == '__main__':
if __name__ == "__main__":
pvdb, run_options = IOC.parse_args()
run(pvdb, **run_options)
8 changes: 3 additions & 5 deletions tests/iocs/scaler.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
#!/usr/bin/env python3
from textwrap import dedent

from caproto.server import (
pvproperty,
run,
PvpropertyDouble,
)

from haven.simulated_ioc import ResponsiveMotorFields, ioc_arg_parser, IOC as IOC_
from haven.simulated_ioc import IOC as IOC_


class IOC(IOC_):
"""An IOC mimicing a scaler connected to a VME crate."""

S2 = pvproperty(name=".S2", value=21000000, doc="It")
CNT = pvproperty(name=".CNT", value=1)
TP = pvproperty(name=".TP", value=1.)
TP = pvproperty(name=".TP", value=1.0)
calc2 = pvproperty(name="_calc2.VAL", value=2.35)

default_prefix = "vme_crate_ioc"


if __name__ == '__main__':
if __name__ == "__main__":
pvdb, run_options = IOC.parse_args()
run(pvdb, **run_options)
6 changes: 2 additions & 4 deletions tests/iocs/simple.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python3
from textwrap import dedent

from caproto.server import (
pvproperty,
run,
PvpropertyDouble,
)

from haven.simulated_ioc import ResponsiveMotorFields, ioc_arg_parser, IOC as IOC_
from haven.simulated_ioc import IOC as IOC_


class IOC(IOC_):
Expand All @@ -31,6 +29,6 @@ class IOC(IOC_):
default_prefix = "simple:"


if __name__ == '__main__':
if __name__ == "__main__":
pvdb, run_options = IOC.parse_args()
run(pvdb, **run_options)
12 changes: 5 additions & 7 deletions tests/iocs/undulator.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#!/usr/bin/env python3
from textwrap import dedent

from caproto.server import (
PVGroup,
template_arg_parser,
pvproperty,
run,
records,
PvpropertyDouble,
)

from haven.simulated_ioc import ResponsiveMotorFields, ioc_arg_parser, IOC as IOC_
from haven.simulated_ioc import ResponsiveMotorFields, IOC as IOC_


class IOC(IOC_):
Expand All @@ -22,13 +18,15 @@ class IOC(IOC_):
"""

ScanEnergy = pvproperty(value=0, doc="ID Energy Scan Input", dtype=PvpropertyDouble)
Energy = pvproperty(value=0, doc="", record=ResponsiveMotorFields, dtype=PvpropertyDouble)
Energy = pvproperty(
value=0, doc="", record=ResponsiveMotorFields, dtype=PvpropertyDouble
)
Busy = pvproperty(value=0, doc="")
Stop = pvproperty(value=0, doc="")

default_prefix = "id_ioc:"


if __name__ == '__main__':
if __name__ == "__main__":
pvdb, run_options = IOC.parse_args()
run(pvdb, **run_options)
6 changes: 2 additions & 4 deletions tests/iocs/vortex.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/env python3
from textwrap import dedent

from caproto.server import (
pvproperty,
run,
PvpropertyDouble,
)

from haven.simulated_ioc import ResponsiveMotorFields, ioc_arg_parser, IOC as IOC_
from haven.simulated_ioc import IOC as IOC_


class IOC(IOC_):
Expand All @@ -34,6 +32,6 @@ class IOC(IOC_):
default_prefix = "xspress:"


if __name__ == '__main__':
if __name__ == "__main__":
pvdb, run_options = IOC.parse_args()
run(pvdb, **run_options)
3 changes: 1 addition & 2 deletions tests/test_beam_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ def test_fit_step():


def test_knife_scan():
plan = knife_scan(motor1, -200, 200, 401, I0=det1, It=det2,
relative=True)
plan = knife_scan(motor1, -200, 200, 401, I0=det1, It=det2, relative=True)
# Check metadata
open_msg = [m for m in plan if m.command == "open_run"][0]
assert open_msg.kwargs["plan_name"] == "knife_scan"
Expand Down
2 changes: 0 additions & 2 deletions tests/test_energy_positioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from haven.instrument.energy_positioner import EnergyPositioner

from test_simulated_ioc import ioc_mono, ioc_undulator


def test_pseudo_to_real_positioner(ioc_mono, ioc_undulator):
positioner = EnergyPositioner(
Expand Down
1 change: 0 additions & 1 deletion tests/test_fluorescence.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from epics import caget
from haven.instrument.fluorescence_detector import XspressDetector
from test_simulated_ioc import ioc_vortex


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions tests/test_iconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_default_values():
config = load_config()
assert "beamline" in config.keys()


def test_loading_a_file():
test_file = Path(__file__).resolve().parent / "test_iconfig.toml"
config = load_config(file_paths=[test_file])
Expand All @@ -26,9 +26,9 @@ def test_config_files_from_env():
importlib.reload(_iconfig)
config = _iconfig.load_config()
# Check that the test file was loaded
assert config["beamline"]["pv_prefix"] == "spam"
assert config["beamline"]["pv_prefix"] == "spam"



def test_merging_dicts():
"""Do the entries from multiple dictioneries merge properly?"""
this_dir = Path(__file__).resolve().parent
Expand Down
2 changes: 2 additions & 0 deletions tests/test_instrument_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_find_missing_components():
with pytest.raises(exceptions.ComponentNotFound):
reg.findall(label="spam")


def test_find_allow_missing_components():
"""Test that registry tolerates missing components with the
*allow_none* argument.
Expand Down Expand Up @@ -187,6 +188,7 @@ def test_find_by_device():
result = reg.find(cptD)
assert result is cptD


def test_find_by_list_of_names():
"""Will the findall() method handle lists of things to look up."""
# Prepare registry
Expand Down
2 changes: 0 additions & 2 deletions tests/test_ion_chamber.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from haven import exceptions
import epics

from test_simulated_ioc import ioc_preamp, ioc_scaler


def test_gain_level(ioc_preamp, ioc_scaler):
positioner = SensitivityLevelPositioner("preamp_ioc", name="positioner")
Expand Down
5 changes: 1 addition & 4 deletions tests/test_monochromator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import epics

from haven import Monochromator
from test_simulated_ioc import ioc_mono


def test_mono_energy_signal(ioc_mono):
mono = Monochromator("mono_ioc",
energy_prefix="mono_ioc",
name="monochromator")
mono = Monochromator("mono_ioc", energy_prefix="mono_ioc", name="monochromator")
time.sleep(0.1)
# Change mono energy
mono.energy.set(5000)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_motor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import pytest

from haven.instrument.instrument_registry import registry
from haven.instrument import motor
from test_simulated_ioc import ioc_motor


def test_load_vme_motors(ioc_motor):
Expand Down
Loading

0 comments on commit a5d9350

Please sign in to comment.