-
Notifications
You must be signed in to change notification settings - Fork 10
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 #333 from DiamondLightSource/331_fix_tests
331 fix and improve tests
- Loading branch information
Showing
17 changed files
with
270 additions
and
36 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
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
Empty file.
Empty file.
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,36 +1,61 @@ | ||
import importlib | ||
import os | ||
from typing import Any | ||
from unittest.mock import patch | ||
|
||
from dodal.beamlines import beamline_utils, i03, i04, i04_1, i23, i24, p38, p45 | ||
import pytest | ||
|
||
from dodal.beamlines import beamline_utils | ||
from dodal.utils import BLUESKY_PROTOCOLS, make_all_devices | ||
|
||
ALL_BEAMLINES = {i03, i04, i04_1, i23, i24, p38, p45} | ||
from ...conftest import mock_beamline_module_filepaths | ||
|
||
ALL_BEAMLINES = {"i03", "i04", "i04_1", "i23", "i24", "p38", "p45"} | ||
|
||
|
||
def follows_bluesky_protocols(obj: Any) -> bool: | ||
return any((isinstance(obj, protocol) for protocol in BLUESKY_PROTOCOLS)) | ||
|
||
|
||
def test_device_creation(RE): | ||
def mock_bl(beamline): | ||
bl_mod = importlib.import_module("dodal.beamlines." + beamline) | ||
mock_beamline_module_filepaths(beamline, bl_mod) | ||
return bl_mod | ||
|
||
|
||
@pytest.mark.parametrize("beamline", ALL_BEAMLINES) | ||
def test_device_creation(RE, beamline): | ||
""" | ||
Ensures that for every beamline all device factories are using valid args | ||
and creating types that conform to Bluesky protocols. | ||
""" | ||
for beamline in ALL_BEAMLINES: | ||
devices = make_all_devices(beamline, fake_with_ophyd_sim=True) | ||
with patch.dict(os.environ, {"BEAMLINE": beamline}, clear=True): | ||
bl_mod = mock_bl(beamline) | ||
devices = make_all_devices( | ||
bl_mod, include_skipped=True, fake_with_ophyd_sim=True | ||
) | ||
for device_name, device in devices.items(): | ||
assert device_name in beamline_utils.ACTIVE_DEVICES | ||
assert follows_bluesky_protocols(device) | ||
assert len(beamline_utils.ACTIVE_DEVICES) == len(devices) | ||
beamline_utils.clear_devices() | ||
del bl_mod | ||
|
||
|
||
def test_devices_are_identical(RE): | ||
@pytest.mark.parametrize("beamline", ALL_BEAMLINES) | ||
def test_devices_are_identical(RE, beamline): | ||
""" | ||
Ensures that for every beamline all device functions prevent duplicate instantiation. | ||
""" | ||
for beamline in ALL_BEAMLINES: | ||
devices_a = make_all_devices(beamline, fake_with_ophyd_sim=True) | ||
devices_b = make_all_devices(beamline, fake_with_ophyd_sim=True) | ||
with patch.dict(os.environ, {"BEAMLINE": beamline}, clear=True): | ||
bl_mod = mock_bl(beamline) | ||
devices_a = make_all_devices( | ||
bl_mod, include_skipped=True, fake_with_ophyd_sim=True | ||
) | ||
devices_b = make_all_devices( | ||
bl_mod, include_skipped=True, fake_with_ophyd_sim=True | ||
) | ||
for device_name in devices_a.keys(): | ||
assert devices_a[device_name] is devices_b[device_name] | ||
beamline_utils.clear_devices() | ||
del bl_mod |
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
Empty file.
Empty file.
Oops, something went wrong.