Standardise config client and fix tests dependent on order they are ran#2099
Standardise config client and fix tests dependent on order they are ran#2099oliwenmandiamond wants to merge 36 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2099 +/- ##
=======================================
Coverage 99.15% 99.15%
=======================================
Files 346 346
Lines 13536 13541 +5
=======================================
+ Hits 13422 13427 +5
Misses 114 114 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…est_device_creation pass
DominicOram
left a comment
There was a problem hiding this comment.
Thanks, I couldn't reproduce the flaky tests issue but I think this cleans things up a bit anyway. Couple of spelling mistakes, I would suggest installing https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker
|
|
||
| @devices.fixture | ||
| def iconfig_client() -> ConfigClient: | ||
| return ConfigClient() |
There was a problem hiding this comment.
Could: In other beamlines this fixture then calls set_config_client. I know it's not strictly required as you're not relying on get_config_client() but I would consider doing it here (and the other beamlines you've changed) anyway as you may later expect it there
|
|
||
| @devices.fixture | ||
| def jconfig_client() -> ConfigClient: | ||
| return ConfigClient(url="https://daq-config.diamond.ac.uk") |
There was a problem hiding this comment.
Could: This is the default URL, why are we specifying it?
| @pytest.fixture | ||
| async def oav() -> OAV: | ||
| oav_config = OAVConfig(TEST_OAV_ZOOM_LEVELS, ConfigClient("")) | ||
| async def oav(mock_config_client: ConfigClient) -> OAV: |
There was a problem hiding this comment.
Should: This fixture isn't actually used anywhere, just remove it.
| # We need to find a better way of integrating this, see https://github.com/DiamondLightSource/mx-bluesky/issues/183 | ||
| @pytest.mark.skip(reason="Don't want to actually take snapshots during testing.") | ||
| def test_grid_overlay(run_engine: RunEngine): | ||
| def test_grid_overlay(run_engine: RunEngine, mock_config_client: ConfigClient): |
There was a problem hiding this comment.
This test is failing on main anyway - I've made #2108.
|
|
||
| def fake_config_server_get_file_contents( | ||
| filepath: str | Path, | ||
| # Tests can register a specific file path with an assoicated file contents to model |
There was a problem hiding this comment.
| # Tests can register a specific file path with an assoicated file contents to model | |
| # Tests can register a specific file path with an associated file contents to model |
| Beamlines and devices may depend on the daq-config-server `ConfigClient` to retrieve configuration files. These files are often stored on the DLS filesystem and contain configuration data that determines device behaviour. | ||
|
|
||
| For example, an insertion device may use a calibration file containing polynomial coefficients that convert photon energy into insertion device gap for different polarisation modes. A device may retrieve this information using a `ConfigClient`: | ||
|
|
||
| ```python | ||
| from pathlib import Path | ||
|
|
||
| from daq_config_server import ConfigClient | ||
|
|
||
| from dodal.device_manager import DeviceManager | ||
| from dodal.devices.my_device import MyDevice | ||
|
|
||
| LOOKUPTABLE_DIR = ( | ||
| "/dls_sw/iXX/software/gda/workspace_git/" | ||
| "gda-diamond.git/configurations/iXX/lookupTables" | ||
| ) | ||
| LOOKUP_FILE_NAME = "JIDEnergy2GapCalibrations.csv" | ||
|
|
||
| devices = DeviceManager() | ||
|
|
||
|
|
||
| @devices.fixture | ||
| def config_client() -> ConfigClient: | ||
| return ConfigClient() | ||
|
|
||
|
|
||
| @devices.factory() | ||
| def my_device(config_client: ConfigClient) -> MyDevice: | ||
| return MyDevice( | ||
| config_client=config_client, | ||
| path=Path(LOOKUPTABLE_DIR, LOOKUP_FILE_NAME), | ||
| ) | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Should: I like this bit of documentation but it doesn't belong in the "how to write tests" document. It's more about how to use the config server
|
|
||
| ### Registering a custom parser | ||
|
|
||
| Some configuration file formats are not JSON-based and require custom parsing logic. For these cases, tests can register a parser using `MOCK_CONFIG_CLIENT_PATH_TO_MODEL_CONVERSION`. |
There was a problem hiding this comment.
Should: If you accept my suggestion this documentation needs changing a bit
| set(all_beamline_modules()), | ||
| indirect=True, | ||
| ) | ||
| # Increase timeout for this specific test as running inividually can take over a second |
There was a problem hiding this comment.
| # Increase timeout for this specific test as running inividually can take over a second | |
| # Increase timeout for this specific test as running individually can take over a second |
| set(all_beamline_modules()), | ||
| indirect=True, | ||
| ) | ||
| # Increase timeout for this specific test as running inividually can take over a second |
There was a problem hiding this comment.
| # Increase timeout for this specific test as running inividually can take over a second | |
| # Increase timeout for this specific test as running individually can take over a second |
| 1. Replaces `ConfigClient.get_file_contents()` with the `mock_config_client` implementation. | ||
| 2. Replaces known module-level file path constants with paths to test data files. | ||
|
|
||
| ### Mocking `ConfigClient` |
There was a problem hiding this comment.
Could: I'm not sure why we need to document this? Why does someone writing new tests need to know about it?
Fixes #2098
Instructions to reviewer on how to test:
dodal/tests/common/beamlines/test_device_instantiation.py::test_device_creation[iXX]in main branch and this branch. Confirm they now pass and doesn't depend on order.Checks for reviewer
dodal connect ${BEAMLINE}