Skip to content

Commit

Permalink
TST #1218 refactor and reduce number of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Oct 29, 2024
1 parent 66d3df8 commit ada8229
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions ophyd/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,6 @@ def read_configuration(self):
return {self.name + "_conf": {"value": 0}}


class FakeBoolTriggerableDevice(Device):
"""Common trigger signals expect value=1"""

strigger = Component(Signal, value=False, trigger_value=True)


class FakeIntTriggerableDevice(Device):
"""Common trigger signals expect value=1"""

strigger = Component(Signal, value=0, trigger_value=1)


class FakeStrTriggerableDevice(Device):
"""Some FPGA triggers on a custom string value."""

strigger = Component(Signal, value="", trigger_value="1!")


def test_device_state():
d = Device("test", name="test")

Expand Down Expand Up @@ -965,26 +947,26 @@ class MyDevice(Device):


@pytest.mark.parametrize(
"klass, before, after, expected",
"before, after, expected",
[
[FakeBoolTriggerableDevice, False, True, True],
[FakeBoolTriggerableDevice, False, False, False],
[FakeBoolTriggerableDevice, False, 1, True], # odd, but True
[FakeBoolTriggerableDevice, False, "1", False],
[FakeIntTriggerableDevice, 0, 1, True],
[FakeIntTriggerableDevice, 0, "1", False],
[FakeIntTriggerableDevice, 0, "1!", False],
[FakeStrTriggerableDevice, "", "1!", True],
[FakeStrTriggerableDevice, "", 1, False],
[FakeStrTriggerableDevice, "", "1", False],
[False, True, True],
[0, 1, True],
[0, 0, False],
["", "1!", True],
],
)
def test_trigger_value(klass, before, after, expected):
def test_trigger_value(before, after, expected):
"""Ensure the configured trigger_value is used."""
d = klass("", name="test")

class FakeTriggerableDevice(Device):
"""Common trigger signals expect value=1"""

strigger = Component(Signal, value=before, trigger_value=after)

d = FakeTriggerableDevice("", name="test")
assert len(d.trigger_signals) == 1
assert [d.strigger] == d.trigger_signals
assert d.strigger.get() == before

d.trigger()
assert (d.strigger.get() == after) == expected
assert d.strigger.get() == after

0 comments on commit ada8229

Please sign in to comment.