Skip to content

Commit

Permalink
Merge pull request #1068 from bluesky/fix-synaxisnoposition
Browse files Browse the repository at this point in the history
Fix SynAxisNoPosition
  • Loading branch information
tacaswell authored Sep 6, 2022
2 parents 8eb539e + 2db432f commit 75a35fd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ophyd/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ def readback_func(x):
self._events_per_move = events_per_move
self.egu = egu

def _make_status(self, target: float):
return MoveStatus(positioner=self, target=target)

def set(self, value: float) -> MoveStatus:
old_setpoint = self.sim_state["setpoint"]
distance = value - old_setpoint
Expand Down Expand Up @@ -499,7 +502,7 @@ def update_state(position: float) -> None:
timestamp=self.sim_state["readback_ts"],
)

st = MoveStatus(positioner=self, target=value)
st = self._make_status(target=value)

def sleep_and_finish():
event_delay = self.delay / self._events_per_move
Expand Down Expand Up @@ -1143,6 +1146,9 @@ def inverse(self, real_pos):


class SynAxisNoPosition(SynAxis):
def _make_status(self, target: float):
return DeviceStatus(device=self)

@property
def position(self):
raise AttributeError
Expand Down
32 changes: 32 additions & 0 deletions ophyd/tests/test_sim.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import shutil
import tempfile
from typing import Callable

import numpy as np
import pytest
Expand All @@ -18,6 +19,9 @@
FakeEpicsSignalWithRBV,
Syn2DGauss,
SynAxis,
SynAxisEmptyHints,
SynAxisNoHints,
SynAxisNoPosition,
SynGauss,
SynSignalWithRegistry,
clear_fake_device,
Expand Down Expand Up @@ -104,6 +108,34 @@ def test_synaxis_requires_at_least_1_event_per_move(events_per_move):
SynAxis(name="motor1", events_per_move=0)


@pytest.mark.parametrize(
"motor_factory",
[
lambda: SynAxis(name="motor", value=0.0),
lambda: SynAxisEmptyHints(name="motor", value=0.0),
lambda: SynAxisNoHints(name="motor", value=0.0),
lambda: SynAxisNoPosition(name="motor", value=0.0),
],
)
def test_move_synaxis(motor_factory: Callable[[], SynAxis]):
# Test is run twice, once for caproto and once for pyepics, so we need a
# factory rather than a global object to preserve state management
motor = motor_factory()

initial_value = motor.readback.get()
motor.set(1.0).wait()
final_value = motor.readback.get()

assert initial_value == 0.0
assert final_value == 1.0


def test_synaxisnoposition_has_no_position():
motor = SynAxisNoPosition(name="motor", labels={"motors"})
with pytest.raises(AttributeError):
motor.position


@pytest.mark.parametrize("events_per_move", [1, 2, 6, 20])
def test_synaxis_subcribe(events_per_move: int):
hits = dict.fromkeys(["r", "s", "a"], 0)
Expand Down

0 comments on commit 75a35fd

Please sign in to comment.