-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from DiamondLightSource/testRigFixes
Tidy up util module(s) and tests
- Loading branch information
Showing
9 changed files
with
157 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
import socket | ||
|
||
from pydantic import BaseSettings | ||
import os | ||
|
||
from dodal.devices.adsim import SimStage | ||
from dodal.devices.areadetector import AdSimDetector | ||
|
||
from .utils import get_hostname | ||
|
||
# Settings can be customized via environment variables | ||
class Settings(BaseSettings): | ||
pv_prefix: str = socket.gethostname().split(".")[0] | ||
|
||
|
||
_settings = Settings() | ||
# Default prefix to hostname unless overriden with export PREFIX=<prefix> | ||
PREFIX: str = os.environ.get("PREFIX", get_hostname()) | ||
|
||
|
||
def stage(name: str = "sim_motors") -> SimStage: | ||
return SimStage(name=name, prefix=f"{_settings.pv_prefix}-MO-SIM-01:") | ||
return SimStage(name=name, prefix=f"{PREFIX}-MO-SIM-01:") | ||
|
||
|
||
def det(name: str = "adsim") -> AdSimDetector: | ||
return AdSimDetector(name=name, prefix=f"{_settings.pv_prefix}-AD-SIM-01:") | ||
return AdSimDetector(name=name, prefix=f"{PREFIX}-AD-SIM-01:") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,22 @@ | ||
from pydantic import BaseSettings | ||
|
||
from dodal.devices.areadetector import AdAravisDetector | ||
from dodal.devices.p45 import Choppers, TomoStageWithStretchAndSkew | ||
|
||
from .utils import BeamlinePrefix | ||
|
||
# Settings can be customized via environment variables | ||
class Settings(BaseSettings): | ||
pv_prefix: str = "BL45P" | ||
|
||
|
||
_settings = Settings() | ||
PREFIX: str = BeamlinePrefix("p45").beamline_prefix | ||
|
||
|
||
def sample_sample(name: str = "sample_stage") -> TomoStageWithStretchAndSkew: | ||
return TomoStageWithStretchAndSkew( | ||
name=name, prefix=f"{_settings.pv_prefix}-MO-STAGE-01:" | ||
) | ||
def sample(name: str = "sample_stage") -> TomoStageWithStretchAndSkew: | ||
return TomoStageWithStretchAndSkew(name=name, prefix=f"{PREFIX}-MO-STAGE-01:") | ||
|
||
|
||
def choppers(name: str = "chopper") -> Choppers: | ||
return Choppers(name=name, prefix=f"{_settings.pv_prefix}-MO-CHOP-01:") | ||
return Choppers(name=name, prefix=f"{PREFIX}-MO-CHOP-01:") | ||
|
||
|
||
def det(name: str = "det") -> AdAravisDetector: | ||
return AdAravisDetector(name=name, prefix=f"{_settings.pv_prefix}-EA-MAP-01:") | ||
return AdAravisDetector(name=name, prefix=f"{PREFIX}-EA-MAP-01:") | ||
|
||
|
||
def diff(name: str = "diff") -> AdAravisDetector: | ||
return AdAravisDetector(name=name, prefix=f"{_settings.pv_prefix}-EA-DIFF-01:") | ||
return AdAravisDetector(name=name, prefix=f"{PREFIX}-EA-DIFF-01:") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
2 changes: 2 additions & 0 deletions
2
tests/devices/system_tests/test_aperturescatterguard_system.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from unittest.mock import MagicMock, patch | ||
|
||
from bluesky.protocols import Readable | ||
from ophyd import EpicsMotor | ||
|
||
from dodal.utils import collect_factories, get_hostname, make_all_devices | ||
|
||
|
||
def test_finds_device_factories() -> None: | ||
import tests.fake_beamline as fake_beamline | ||
|
||
factories = set(collect_factories(fake_beamline)) | ||
|
||
from tests.fake_beamline import device_a, device_b, device_c | ||
|
||
assert {device_a, device_b, device_c} == factories | ||
|
||
|
||
def test_makes_devices() -> None: | ||
import tests.fake_beamline as fake_beamline | ||
|
||
devices = make_all_devices(fake_beamline) | ||
assert {"readable", "motor", "cryo"} == devices.keys() | ||
|
||
|
||
def test_makes_devices_with_module_name() -> None: | ||
devices = make_all_devices("tests.fake_beamline") | ||
assert {"readable", "motor", "cryo"} == devices.keys() | ||
|
||
|
||
def test_get_hostname() -> None: | ||
with patch("dodal.utils.socket.gethostname") as mock: | ||
mock.return_value = "a.b.c" | ||
assert get_hostname() == "a" | ||
|
||
|
||
def device_a() -> Readable: | ||
return MagicMock() | ||
|
||
|
||
def device_b() -> EpicsMotor: | ||
return MagicMock() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from bluesky.protocols import Readable | ||
from ophyd import EpicsMotor | ||
|
||
from dodal.devices.cryostream import Cryo | ||
|
||
|
||
def device_a() -> Readable: | ||
return _mock_with_name("readable") | ||
|
||
|
||
def device_b() -> EpicsMotor: | ||
return _mock_with_name("motor") | ||
|
||
|
||
def device_c() -> Cryo: | ||
return _mock_with_name("cryo") | ||
|
||
|
||
def not_device() -> int: | ||
return 5 | ||
|
||
|
||
def _mock_with_name(name: str) -> MagicMock: | ||
mock = MagicMock() | ||
mock.name = name | ||
return mock |