-
Notifications
You must be signed in to change notification settings - Fork 31
Add tests for derived signal #850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
e28f018
718ac5e
8f31ccd
4c3c50e
4385dbb
8b2e302
963d3b7
6f6d46f
0b0a7ab
153ef0e
38adf73
4f1eedc
3c85fe6
552fbd7
72c4148
258e6a6
fb18898
f4170cf
35b0cb3
36bc916
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,6 +10,13 @@ | |||||
DerivedSignalFactory, | ||||||
soft_signal_rw, | ||||||
) | ||||||
from ophyd_async.core._derived_signal_backend import ( | ||||||
DerivedSignalBackend, # noqa: PLC2701 | ||||||
SignalTransformer, # noqa: PLC2701 | ||||||
Transform, # noqa: PLC2701 | ||||||
) | ||||||
from ophyd_async.core._signal import SignalRW # noqa: PLC2701 | ||||||
from ophyd_async.core._table import Table # noqa: PLC2701 | ||||||
from ophyd_async.sim import ( | ||||||
HorizontalMirror, | ||||||
HorizontalMirrorDerived, | ||||||
|
@@ -128,3 +135,47 @@ def test_mismatching_args(): | |||||
jack22=soft_signal_rw(float), | ||||||
distance=soft_signal_rw(float), | ||||||
) | ||||||
|
||||||
|
||||||
@pytest.fixture | ||||||
def derived_signal_backend() -> DerivedSignalBackend: | ||||||
return DerivedSignalBackend(Table, "derived_backend", | ||||||
SignalTransformer(Transform, None, None)) | ||||||
|
||||||
|
||||||
async def test_derived_signal_backend_connect_pass( | ||||||
derived_signal_backend: DerivedSignalBackend | ||||||
) -> None: | ||||||
result = await derived_signal_backend.connect(0.0) | ||||||
assert result is None | ||||||
|
||||||
|
||||||
def test_derived_signal_backend_set_value( | ||||||
derived_signal_backend: DerivedSignalBackend | ||||||
) -> None: | ||||||
with pytest.raises(RuntimeError): | ||||||
derived_signal_backend.set_value(0.0) | ||||||
|
||||||
|
||||||
async def test_derived_signal_backend_put_fails( | ||||||
derived_signal_backend: DerivedSignalBackend | ||||||
) -> None: | ||||||
with pytest.raises(RuntimeError): | ||||||
await derived_signal_backend.put(value=None, wait=False) | ||||||
with pytest.raises(RuntimeError): | ||||||
await derived_signal_backend.put(value=None, wait=True) | ||||||
|
||||||
|
||||||
def test_make_rw_signal_type_mismatch(): | ||||||
factory = DerivedSignalFactory( | ||||||
TwoJackTransform, | ||||||
set_derived=None, | ||||||
distance=soft_signal_rw(float), | ||||||
jack1=soft_signal_rw(float), | ||||||
jack2=soft_signal_rw(float), | ||||||
) | ||||||
with pytest.raises( | ||||||
ValueError, | ||||||
match=re.escape("Must define a set_derived method to support derived") | ||||||
): | ||||||
factory._make_signal(signal_cls=SignalRW, datatype=Table, name="") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Public interface is
Suggested change
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all of these are possible without using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have to say am really struggling trying to find the way around using public interface without mock for e.g. ?
any ideas on that one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I don't think you can test that one with the public interface. Best I can do is: async def test_set_derived_not_initialized():
def _get(ts: int) -> float:
return ts
sig = derived_signal_r(_get, ts=soft_signal_rw(int, initial_value=4))
with pytest.raises(
RuntimeError,
match="Cannot put as no set_derived method given",
):
await sig._connector.backend.put(1.0, True) If you've tried using the public interface and it's not possible then I'm happy with patches or private member variables |
Uh oh!
There was an error while loading. Please reload this page.