-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
443 additions
and
44 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
Empty file.
90 changes: 90 additions & 0 deletions
90
tests/unit_tests/beamlines/i24/jungfrau_commissioning/tests/conftest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import time | ||
from collections.abc import Callable | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from dodal.devices.i24.i24_vgonio import VGonio | ||
from ophyd.device import Device | ||
from ophyd.status import Status | ||
|
||
from mx_bluesky.beamlines.i24.jungfrau_commissioning.plans.rotation_scan_plans import ( | ||
JfDevices, | ||
) | ||
from mx_bluesky.beamlines.i24.jungfrau_commissioning.utils import i24 | ||
from mx_bluesky.beamlines.i24.jungfrau_commissioning.utils.jf_commissioning_devices import ( | ||
JungfrauM1, | ||
ReadOnlyEnergyAndAttenuator, | ||
SetAttenuator, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def completed_status(): | ||
result = Status() | ||
result.set_finished() | ||
return result | ||
|
||
|
||
@pytest.fixture | ||
def fake_vgonio(completed_status) -> VGonio: | ||
gon: VGonio = i24.vgonio(fake_with_ophyd_sim=True) | ||
|
||
def set_omega_side_effect(val): | ||
gon.omega.user_readback.sim_put(val) # type: ignore | ||
return completed_status | ||
|
||
gon.omega.set = MagicMock(side_effect=set_omega_side_effect) | ||
|
||
gon.x.user_setpoint._use_limits = False | ||
gon.yh.user_setpoint._use_limits = False | ||
gon.z.user_setpoint._use_limits = False | ||
gon.omega.user_setpoint._use_limits = False | ||
return gon | ||
|
||
|
||
@pytest.fixture | ||
def fake_jungfrau() -> JungfrauM1: | ||
JF: JungfrauM1 = i24.jungfrau(fake_with_ophyd_sim=True) | ||
|
||
def set_acquire_side_effect(val): | ||
JF.acquire_rbv.sim_put(1) # type: ignore | ||
time.sleep(1) | ||
JF.acquire_rbv.sim_put(0) # type: ignore | ||
return completed_status | ||
|
||
JF.acquire_start.set = MagicMock(side_effect=set_acquire_side_effect) | ||
|
||
return JF | ||
|
||
|
||
@pytest.fixture | ||
def fake_beam_params() -> ReadOnlyEnergyAndAttenuator: | ||
BP: ReadOnlyEnergyAndAttenuator = i24.beam_params(fake_with_ophyd_sim=True) | ||
BP.transmission.sim_put(0.1) # type: ignore | ||
BP.energy.sim_put(20000) # type: ignore | ||
BP.wavelength.sim_put(0.65) # type: ignore | ||
BP.intensity.sim_put(9999999) # type: ignore | ||
return BP | ||
|
||
|
||
@pytest.fixture | ||
def attenuator() -> SetAttenuator: | ||
return i24.attenuator(fake_with_ophyd_sim=True) | ||
|
||
|
||
@pytest.fixture | ||
def fake_devices( | ||
fake_vgonio, fake_jungfrau, zebra, fake_beam_params, attenuator | ||
) -> JfDevices: | ||
return { | ||
"jungfrau": fake_jungfrau, | ||
"gonio": fake_vgonio, | ||
"zebra": zebra, | ||
"beam_params": fake_beam_params, | ||
"attenuator": attenuator, | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def fake_create_devices_function(fake_devices) -> Callable[..., dict[str, Device]]: | ||
return lambda: fake_devices |
44 changes: 44 additions & 0 deletions
44
tests/unit_tests/beamlines/i24/jungfrau_commissioning/tests/test_dark_plans.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from unittest.mock import MagicMock, patch | ||
|
||
from bluesky.run_engine import RunEngine | ||
from dodal.devices.i24.jungfrau import JungfrauM1 | ||
|
||
from mx_bluesky.beamlines.i24.jungfrau_commissioning.plans.gain_mode_darks_plans import ( | ||
GainMode, | ||
do_manual_acquisition, | ||
set_gain_mode, | ||
) | ||
|
||
|
||
@patch( | ||
"bluesky.plan_stubs.wait", | ||
) | ||
def test_set_gain_mode( | ||
bps_wait: MagicMock, | ||
fake_devices, | ||
RE: RunEngine, | ||
): | ||
jungfrau: JungfrauM1 = fake_devices["jungfrau"] | ||
|
||
RE(set_gain_mode(jungfrau, GainMode.dynamic)) | ||
assert jungfrau.gain_mode.get() == "dynamic" | ||
RE(set_gain_mode(jungfrau, GainMode.forceswitchg1)) | ||
assert jungfrau.gain_mode.get() == "forceswitchg1" | ||
RE(set_gain_mode(jungfrau, GainMode.forceswitchg2)) | ||
assert jungfrau.gain_mode.get() == "forceswitchg2" | ||
|
||
|
||
@patch( | ||
"bluesky.plan_stubs.wait", | ||
) | ||
def test_do_dark_acq( | ||
bps_wait: MagicMock, | ||
fake_devices, | ||
RE: RunEngine, | ||
): | ||
# gonio: VGonio = fake_devices["gonio"] | ||
# zebra: Zebra = fake_devices["zebra"] | ||
jungfrau: JungfrauM1 = fake_devices["jungfrau"] | ||
|
||
RE(do_manual_acquisition(jungfrau, 0.001, 0.001, 1000)) | ||
jungfrau.acquire_start.set.assert_called() |
13 changes: 13 additions & 0 deletions
13
...s/beamlines/i24/jungfrau_commissioning/tests/test_data/bad_params_acq_time_too_short.json
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,13 @@ | ||
{ | ||
"rotation_axis": "omega", | ||
"scan_width_deg": 360.0, | ||
"image_width_deg": 0.1, | ||
"omega_start_deg": 0.0, | ||
"exposure_time_s": 0.01, | ||
"acquire_time_s": 0.001, | ||
"rotation_direction": "POSITIVE", | ||
"offset_deg": 1.0, | ||
"shutter_opening_time_s": 0.6, | ||
"storage_directory": "/tmp/jungfrau_data/", | ||
"nexus_filename": "scan" | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/unit_tests/beamlines/i24/jungfrau_commissioning/tests/test_main.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from unittest.mock import MagicMock, patch | ||
|
||
from mx_bluesky.beamlines.i24.jungfrau_commissioning.__main__ import hlp | ||
|
||
|
||
@patch("builtins.print") | ||
def test_hlp(mock_print: MagicMock): | ||
hlp() | ||
assert "There are a bunch of available functions." in mock_print.call_args.args[0] | ||
hlp(hlp) | ||
assert ( | ||
"When called with no arguments, displays a welcome message." | ||
in mock_print.call_args.args[0] | ||
) |
Oops, something went wrong.