Skip to content

Commit 0bcd86f

Browse files
Add CAGet tests to the Default tests
1 parent 20cf010 commit 0bcd86f

File tree

1 file changed

+49
-30
lines changed

1 file changed

+49
-30
lines changed

tests/test_records.py

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ def record_values(request):
174174
175175
Fields are:
176176
- Record builder function
177-
- Input value passed to .set() or used in initial_value on record creation
178-
- Expected output value after doing .get()
179-
- Expected type of the output value from .get()"""
177+
- Input value passed to .set()/initial_value/caput
178+
- Expected output value after doing .get()/caget
179+
- Expected type of the output value from .get()/caget"""
180180
return request.param # One item from the params list
181181

182182
def test_records(tmp_path):
@@ -624,6 +624,9 @@ def test_value_post_init_caput(self, record_values):
624624
SetValueEnum.CAPUT,
625625
GetValueEnum.CAGET)
626626

627+
def default_values_names(fixture_value):
628+
"""Provide nice name for default_values fixture"""
629+
return fixture_value[0].__name__
627630

628631
class TestDefaultValue:
629632
"""Tests related to default values"""
@@ -663,34 +666,50 @@ def test_value_default_pre_init(
663666
expected_value,
664667
expected_type)
665668

669+
670+
671+
@pytest.fixture(params= [
672+
(builder.aOut, None, 0.0, float),
673+
(builder.aIn, None, 0.0, float),
674+
(builder.longOut, None, 0, int),
675+
(builder.longIn, None, 0, int),
676+
(builder.boolOut, None, 0, int),
677+
(builder.boolIn, None, 0, int),
678+
(builder.stringOut, None, "", str),
679+
(builder.stringIn, None, "", str),
680+
(builder.mbbOut, None, 0, int),
681+
(builder.mbbIn, None, 0, int),
682+
(builder.WaveformOut, None, numpy.empty(0), numpy.ndarray),
683+
(builder.WaveformIn, None, numpy.empty(0), numpy.ndarray),
684+
], ids=default_values_names)
685+
def default_values(self, request):
686+
"""Fixture for default values for initialised records.
687+
688+
Fields are:
689+
- Record builder function
690+
- (UNUSED) fake initial value, so parameters are same as other fixtures
691+
- Input value passed to .set()/initial_value/caput
692+
- Expected output value after doing .get()/caget
693+
- Expected type of the output value from .get()/caget"""
694+
return request.param
695+
696+
666697
@requires_cothread
667-
@pytest.mark.parametrize("creation_func,expected_value,expected_type", [
668-
(builder.aOut, 0.0, float),
669-
(builder.aIn, 0.0, float),
670-
(builder.longOut, 0, int),
671-
(builder.longIn, 0, int),
672-
(builder.boolOut, 0, int),
673-
(builder.boolIn, 0, int),
674-
(builder.stringOut, "", str),
675-
(builder.stringIn, "", str),
676-
(builder.mbbOut, 0, int),
677-
(builder.mbbIn, 0, int),
678-
(builder.WaveformOut, numpy.empty(0), numpy.ndarray),
679-
(builder.WaveformIn, numpy.empty(0), numpy.ndarray),
680-
])
681-
def test_value_default_post_init(
682-
self,
683-
creation_func,
684-
expected_value,
685-
expected_type):
686-
"""Test that records provide the expected default value after they are
687-
initialised, having never had a value set"""
698+
def test_value_default_post_init(self, default_values):
699+
"""Test that records return the expected default value from .get after
700+
they are initialised, having never had a value set"""
688701

689-
# Add a dummy initial_value to the tuple, so we can use the same
690-
# framework as the other tests
691-
tmp = list((creation_func, expected_value, expected_type))
692-
tmp.insert(1, None)
693-
run_test_function(tuple(tmp), SetValueEnum.NO_SET, GetValueEnum.GET)
702+
run_test_function(default_values, SetValueEnum.NO_SET, GetValueEnum.GET)
703+
704+
@requires_cothread
705+
def test_value_default_post_init_caget(self, default_values):
706+
"""Test that records return the expected default value from CAGet after
707+
they are initialised, having never had a value set"""
708+
709+
run_test_function(
710+
default_values,
711+
SetValueEnum.NO_SET,
712+
GetValueEnum.CAGET)
694713

695714
class TestNoneValue:
696715
"""Various tests regarding record value of None"""
@@ -743,7 +762,7 @@ def none_value_test_func(self, record_func, queue):
743762

744763
@requires_cothread
745764
def test_value_none_rejected_set_after_init(self, record_funcs_reject_none):
746-
"""Test that setting \"None\" using .set() after IOc init raises an
765+
"""Test that setting \"None\" using .set() after IOC init raises an
747766
exception"""
748767
queue = multiprocessing.Queue()
749768
process = multiprocessing.Process(

0 commit comments

Comments
 (0)