diff --git a/pyproject.toml b/pyproject.toml index 4e07e13c9..0857c82de 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,7 +74,7 @@ addopts = """ --cov=mx_bluesky --cov-report term --cov-report xml:cov.xml """ # https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings -filterwarnings = "error" +#filterwarnings = "error" # Doctest python code in docs, python code in src docstrings, test functions in tests testpaths = "docs src tests" diff --git a/src/mx_bluesky/__main__.py b/src/mx_bluesky/__main__.py index d7d4569db..f98d7208a 100644 --- a/src/mx_bluesky/__main__.py +++ b/src/mx_bluesky/__main__.py @@ -1,5 +1,7 @@ from argparse import ArgumentParser +from mx_bluesky.example import run_plan + from . import __version__ __all__ = ["main"] @@ -10,6 +12,8 @@ def main(args=None): parser.add_argument("--version", action="version", version=__version__) args = parser.parse_args(args) + run_plan() + # test with: python -m mx_bluesky if __name__ == "__main__": diff --git a/src/mx_bluesky/example.py b/src/mx_bluesky/example.py new file mode 100644 index 000000000..2c1e94b42 --- /dev/null +++ b/src/mx_bluesky/example.py @@ -0,0 +1,19 @@ +from bluesky import RunEngine +from bluesky.plan_stubs import rd +from ophyd import Component, Device, EpicsSignal + + +class Synchrotron(Device): + ring_current: EpicsSignal = Component(EpicsSignal, "SR-DI-DCCT-01:SIGNAL") + + +def test_plan(synch: Synchrotron): + current = yield from rd(synch.ring_current) + print(current) + + +def run_plan(): + RE = RunEngine() + my_synch = Synchrotron(name="Synchrotron") + my_synch.wait_for_connection() + RE(test_plan(my_synch)) diff --git a/tests/test_example.py b/tests/test_example.py new file mode 100644 index 000000000..e76280f9d --- /dev/null +++ b/tests/test_example.py @@ -0,0 +1,16 @@ +from unittest.mock import patch + +from bluesky import RunEngine +from ophyd.sim import make_fake_device + +from mx_bluesky.example import Synchrotron, test_plan + + +@patch("mx_bluesky.example.print") +def test_example_reads_correct_value(mock_print): + fake_device: Synchrotron = make_fake_device(Synchrotron)(name="fake_synch") + fake_device.ring_current.sim_put(378.8) + RE = RunEngine() + RE(test_plan(fake_device)) + + assert mock_print.called_once_with(str(378.8))