Skip to content

Commit

Permalink
(DiamondLightSource/hyperion#996) Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Nov 27, 2023
1 parent aa356dd commit 23ac20f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/dodal/devices/areadetector/plugins/MXSC.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def set_to_default_and_finish(timeout_status: Status):
self._timeout_status = Status(self, timeout=self.validity_timeout.get())
self._timeout_status.add_callback(set_to_default_and_finish)
subscription_status.add_callback(lambda _: self._timeout_status.set_finished())
subscription_status.add_callback(self.log_tips_and_standard_deviation)
subscription_status.add_callback(self.log_tips_and_statistics)

return subscription_status

Expand Down
33 changes: 29 additions & 4 deletions tests/devices/unit_tests/test_pin_tip_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ def test_given_multiple_tips_found_then_running_median_calculated(
assert fake_pin_tip_detect.triggered_tip.get() == (100, 200)


def trigger_and_read_twice(
fake_pin_tip_detect: PinTipDetect, first_values: List[Tuple], second_value: Tuple
):
yield from trigger_and_read(fake_pin_tip_detect, first_values)
fake_pin_tip_detect.tip_y.sim_put(second_value[1])
fake_pin_tip_detect.tip_x.sim_put(second_value[0])
return (yield from trigger_and_read(fake_pin_tip_detect, []))


def test_given_median_previously_calculated_when_triggered_again_then_only_calculated_on_new_values(
fake_pin_tip_detect: PinTipDetect,
):
Expand All @@ -99,10 +108,26 @@ def test_given_median_previously_calculated_when_triggered_again_then_only_calcu
RE = RunEngine(call_returns_result=True)

def my_plan():
yield from trigger_and_read(fake_pin_tip_detect, [(10, 20), (1, 3), (4, 8)])
fake_pin_tip_detect.tip_y.sim_put(200)
fake_pin_tip_detect.tip_x.sim_put(100)
tip_pos = yield from trigger_and_read(fake_pin_tip_detect, [(100, 200)])
tip_pos = yield from trigger_and_read_twice(
fake_pin_tip_detect, [(10, 20), (1, 3), (4, 8)], (100, 200)
)
assert tip_pos == (100, 200)

RE(my_plan())


def test_given_previous_tip_found_when_this_tip_not_found_then_returns_invalid(
fake_pin_tip_detect: PinTipDetect,
):
fake_pin_tip_detect.settle_time_s.set(0.1).wait()
fake_pin_tip_detect.validity_timeout.set(0.5).wait()

RE = RunEngine(call_returns_result=True)

def my_plan():
tip_pos = yield from trigger_and_read_twice(
fake_pin_tip_detect, [(10, 20), (1, 3), (4, 8)], (-1, -1)
)
assert tip_pos == (-1, -1)

RE(my_plan())

0 comments on commit 23ac20f

Please sign in to comment.