-
Notifications
You must be signed in to change notification settings - Fork 12
331 fix and improve tests #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f611b7
#331 fix device tests
d-perl ae2690c
#331 add test data
d-perl 5456513
#331 fix mocking of config gile paths
d-perl b6ea322
#331 add inits for pytest
d-perl b2c71b3
#331 only run tests once for each BL and include skipped
d-perl 0029972
#331 delete some unused bulk from test params file
d-perl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.