Skip to content

Commit

Permalink
Added basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Nov 28, 2022
1 parent 3d90edd commit 193a3df
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions src/mx_bluesky/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from argparse import ArgumentParser

from mx_bluesky.example import run_plan

from . import __version__

__all__ = ["main"]
Expand All @@ -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__":
Expand Down
19 changes: 19 additions & 0 deletions src/mx_bluesky/example.py
Original file line number Diff line number Diff line change
@@ -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))
16 changes: 16 additions & 0 deletions tests/test_example.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 193a3df

Please sign in to comment.