Skip to content

Commit 83bacad

Browse files
Add tests for Action, longStringIn, longStringOut
Also neaten names for Validate tests, and tweak None tests to add extra exception
1 parent 2b76593 commit 83bacad

File tree

1 file changed

+68
-6
lines changed

1 file changed

+68
-6
lines changed

tests/test_records.py

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ def record_funcs_names(fixture_value):
5858
builder.longOut,
5959
builder.boolIn,
6060
builder.boolOut,
61+
builder.Action,
6162
builder.stringIn,
6263
builder.stringOut,
6364
builder.mbbIn,
6465
builder.mbbOut,
6566
builder.WaveformIn,
6667
builder.WaveformOut,
68+
builder.longStringIn,
69+
builder.longStringOut,
6770
],
6871
ids=record_funcs_names,
6972
)
@@ -112,6 +115,9 @@ def record_values_names(fixture_value):
112115
("boolOut_true", builder.boolOut, True, 1, int),
113116
("boolIn_false", builder.boolIn, False, 0, int),
114117
("boolOut_false", builder.boolOut, False, 0, int),
118+
("Action_int", builder.Action, 1, 1, int),
119+
("Action_true", builder.Action, True, 1, int),
120+
("Action_false", builder.Action, False, 0, int),
115121
("mbbIn_int", builder.mbbIn, 1, 1, int),
116122
("mbbOut_int", builder.mbbOut, 1, 1, int),
117123
("strIn_abc", builder.stringIn, "abc", "abc", str),
@@ -218,6 +224,48 @@ def record_values_names(fixture_value):
218224
numpy.array([37, 97, 226, 130, 172, 98, 0], dtype=numpy.uint8),
219225
numpy.ndarray,
220226
),
227+
(
228+
"longStringIn_str",
229+
builder.longStringIn,
230+
"ABC",
231+
"ABC",
232+
str,
233+
),
234+
(
235+
"longStringOut_str",
236+
builder.longStringOut,
237+
"ABC",
238+
"ABC",
239+
str,
240+
),
241+
(
242+
"longStringIn_bytes",
243+
builder.longStringIn,
244+
b"HELLO\0WORLD",
245+
"HELLO",
246+
str,
247+
),
248+
(
249+
"longStringOut_bytes",
250+
builder.longStringOut,
251+
b"HELLO\0WORLD",
252+
"HELLO",
253+
str,
254+
),
255+
(
256+
"longStringIn_unicode",
257+
builder.longStringIn,
258+
"%a€b",
259+
"%a€b",
260+
str
261+
),
262+
(
263+
"longStringOut_unicode",
264+
builder.longStringOut,
265+
"%a€b",
266+
"%a€b",
267+
str
268+
),
221269
]
222270

223271

@@ -719,12 +767,15 @@ def test_value_post_init_caput(self):
719767
("default_longIn", builder.longIn, None, 0, int),
720768
("default_boolOut", builder.boolOut, None, 0, int),
721769
("default_boolIn", builder.boolIn, None, 0, int),
770+
("default_Action", builder.Action, None, 0, int),
722771
("default_stringOut", builder.stringOut, None, "", str),
723772
("default_stringIn", builder.stringIn, None, "", str),
724773
("default_mbbOut", builder.mbbOut, None, 0, int),
725774
("default_mbbIn", builder.mbbIn, None, 0, int),
726775
("default_wOut", builder.WaveformOut, None, numpy.empty(0), numpy.ndarray),
727776
("default_wIn", builder.WaveformIn, None, numpy.empty(0), numpy.ndarray),
777+
("default_longStringOut", builder.longStringOut, None, "", str),
778+
("default_longStringIn", builder.longStringIn, None, "", str),
728779
]
729780

730781

@@ -740,12 +791,15 @@ class TestDefaultValue:
740791
(builder.longIn, 0, int),
741792
(builder.boolOut, None, type(None)),
742793
(builder.boolIn, 0, int),
794+
(builder.Action, None, type(None)),
743795
(builder.stringOut, None, type(None)),
744796
(builder.stringIn, "", str),
745797
(builder.mbbOut, None, type(None)),
746798
(builder.mbbIn, 0, int),
747799
(builder.WaveformOut, None, type(None)),
748800
(builder.WaveformIn, numpy.empty(0), numpy.ndarray),
801+
(builder.longStringOut, "", str),
802+
(builder.longStringIn, "", str),
749803
],
750804
)
751805
def test_value_default_pre_init(
@@ -786,6 +840,9 @@ def test_value_default_post_init_caget(self):
786840
class TestNoneValue:
787841
"""Various tests regarding record value of None"""
788842

843+
# We expect using None as a value will trigger one of these exceptions
844+
expected_exceptions = (ValueError, TypeError, AttributeError)
845+
789846
def test_value_none_rejected_initial_value(
790847
self, clear_records, record_funcs_reject_none
791848
):
@@ -798,7 +855,7 @@ def test_value_none_rejected_initial_value(
798855
]:
799856
kwarg = {"length": 50} # Required when no value on creation
800857

801-
with pytest.raises((ValueError, TypeError)):
858+
with pytest.raises(self.expected_exceptions):
802859
record_funcs_reject_none("SOME-NAME", initial_value=None, **kwarg)
803860

804861
def test_value_none_rejected_set_before_init(
@@ -813,7 +870,7 @@ def test_value_none_rejected_set_before_init(
813870
]:
814871
kwarg = {"length": 50} # Required when no value on creation
815872

816-
with pytest.raises((ValueError, TypeError)):
873+
with pytest.raises(self.expected_exceptions):
817874
record = record_funcs_reject_none("SOME-NAME", **kwarg)
818875
record.set(None)
819876

@@ -850,24 +907,29 @@ def test_value_none_rejected_set_after_init(self, record_funcs_reject_none):
850907
try:
851908
exception = queue.get(timeout=5)
852909

853-
assert isinstance(exception, (ValueError, TypeError))
910+
assert isinstance(exception, self.expected_exceptions)
854911
finally:
855912
process.terminate()
856913
process.join(timeout=3)
857914

858-
915+
def fixture_names(params):
916+
"""Provide nice names for the out_records fixture in TestValidate class"""
917+
return params[0].__name__
859918
class TestValidate:
860919
"""Tests related to the validate callback"""
861920

862921
@pytest.fixture(
863922
params=[
864923
(builder.aOut, 7.89, 0),
865924
(builder.boolOut, 1, 0),
925+
(builder.Action, 1, 0),
866926
(builder.longOut, 7, 0),
867927
(builder.stringOut, "HI", ""),
868928
(builder.mbbOut, 2, 0),
869929
(builder.WaveformOut, [10, 11, 12], []),
870-
]
930+
(builder.longStringOut, "A LONGER HELLO", ""),
931+
],
932+
ids=fixture_names
871933
)
872934
def out_records(self, request):
873935
"""The list of Out records and an associated value to set """
@@ -973,7 +1035,7 @@ def test_validate_blocks_updates(self, out_records):
9731035
process.start()
9741036

9751037
try:
976-
queue.get(timeout=5) # Get the expected IOc initialised message
1038+
queue.get(timeout=5) # Get the expected IOC initialised message
9771039

9781040
from cothread.catools import caget, caput, _channel_cache
9791041

0 commit comments

Comments
 (0)