Skip to content

Commit 544e2ef

Browse files
authored
Merge pull request #123 from ISISComputingGroup/ibc93_standard_callbacks
add system test for standard callbacks
2 parents 59a1712 + c1d72ae commit 544e2ef

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ six
99
unittest-xml-reporting
1010
ibex_bluesky_core
1111
genie_python
12-
configobj
12+
matplotlib
13+
pyqt6

test_bluesky.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
import os
33
import unittest
44
import uuid
5+
from pathlib import Path
56

67
import bluesky.plan_stubs as bps
78
import bluesky.plans as bp
9+
import matplotlib
810
from bluesky.callbacks import LiveTable
911
from bluesky.preprocessors import subs_decorator
1012
from bluesky.run_engine import RunEngine, RunEngineResult
1113
from genie_python import genie as g # type: ignore
14+
from ibex_bluesky_core.callbacks import ISISCallbacks
15+
from ibex_bluesky_core.callbacks.fitting.fitting_utils import Linear
1216
from ibex_bluesky_core.devices import get_pv_prefix
1317
from ibex_bluesky_core.devices.block import block_r, block_rw_rbv
1418
from ibex_bluesky_core.devices.simpledae import SimpleDae
@@ -20,7 +24,10 @@
2024
GoodFramesNormalizer,
2125
PeriodGoodFramesNormalizer,
2226
)
23-
from ibex_bluesky_core.devices.simpledae.waiters import GoodFramesWaiter, PeriodGoodFramesWaiter
27+
from ibex_bluesky_core.devices.simpledae.waiters import (
28+
GoodFramesWaiter,
29+
PeriodGoodFramesWaiter,
30+
)
2431
from ibex_bluesky_core.log import set_bluesky_log_levels
2532
from ibex_bluesky_core.run_engine import get_run_engine
2633
from ophyd_async.plan_stubs import ensure_connected
@@ -30,6 +37,7 @@
3037
set_genie_python_raises_exceptions,
3138
)
3239

40+
matplotlib.use("qtagg")
3341
RE: RunEngine = get_run_engine()
3442

3543
P3_INIT_VALUE: float = 123.456
@@ -147,6 +155,29 @@ def _plan():
147155
self.assertTrue(any("| 123.456 | -10.00000 |" in line for line in livetable_lines))
148156
self.assertTrue(any("| 123.456 | 10.00000 |" in line for line in livetable_lines))
149157

158+
def test_scan_with_standard_callbacks(self) -> None:
159+
icc = ISISCallbacks(
160+
x="p5",
161+
y="p3",
162+
fit=Linear().fit(),
163+
human_readable_file_output_dir=Path(LOG_FOLDER) / "output_files",
164+
live_fit_logger_output_dir=Path(LOG_FOLDER) / "fitting",
165+
)
166+
167+
@icc
168+
def _plan():
169+
p3 = block_r(float, "p3")
170+
p5 = block_rw_rbv(float, "p5")
171+
yield from ensure_connected(p3, p5)
172+
yield from bp.scan([p3], p5, -10, 10, num=10)
173+
174+
RE(_plan())
175+
176+
self.assertAlmostEqual(icc.peak_stats["com"], 0)
177+
print(icc.live_fit.result.params["c0"])
178+
print(icc.live_fit.result.fit_report())
179+
self.assertAlmostEqual(icc.live_fit.result.params["c0"], P3_INIT_VALUE)
180+
150181
def test_count_simple_dae(self) -> None:
151182
start_run_number = int(g.get_runnumber())
152183

@@ -211,7 +242,9 @@ def test_GIVEN_logging_is_requested_THEN_the_log_file_exists(self) -> None:
211242
)
212243
self.assertTrue(os.path.exists(self.qualified_log_filename))
213244

214-
def test_GIVEN_logging_is_requested_THEN_the_log_file_contains_the_message(self) -> None:
245+
def test_GIVEN_logging_is_requested_THEN_the_log_file_contains_the_message(
246+
self,
247+
) -> None:
215248
# Log invocation.
216249
bluesky_message = LOG_MESSAGE + str(uuid.uuid4())
217250
other_message = LOG_MESSAGE + str(uuid.uuid4())
@@ -240,7 +273,9 @@ def test_GIVEN_logging_is_configured_at_info_level_THEN_debug_messages_do_not_go
240273
self.assertNotIn(debug_msg, content)
241274
self.assertIn(info_msg, content)
242275

243-
def test_GIVEN_logging_is_configured_at_debug_level_THEN_debug_messages_do_go_to_log_file(self):
276+
def test_GIVEN_logging_is_configured_at_debug_level_THEN_debug_messages_do_go_to_log_file(
277+
self,
278+
):
244279
debug_msg = LOG_MESSAGE + str(uuid.uuid4())
245280
info_msg = LOG_MESSAGE + str(uuid.uuid4())
246281

0 commit comments

Comments
 (0)