Skip to content

Commit f8b67f8

Browse files
Fix more tests
Default record values updated Removed unnecessary special-case logic for Waveforms Add special handling for bytestrings in Waveforms
1 parent 3cdbfdd commit f8b67f8

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

tests/test_records.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,7 @@ def record_value_asserts(
313313
if type(expected_value) == float and isnan(expected_value):
314314
assert isnan(actual_value) # NaN != Nan, so needs special case
315315
elif creation_func in [builder.WaveformOut, builder.WaveformIn]:
316-
317-
# Special case for lack of default value on Out records before init
318-
if actual_value is None and expected_value is None:
319-
assert type(actual_value) == expected_type
320-
return
321-
322-
# Using .get() on the array returns entire length, not just filled
323-
# part. Confirm this by ensuring sliced part of array is all zeros
324-
assert not numpy.any(actual_value[expected_value.size:])
325-
truncated_value = actual_value[: expected_value.size]
326-
assert numpy.array_equal(
327-
truncated_value, expected_value
328-
), f"Arrays not equal: {actual_value} {expected_value}"
316+
assert numpy.array_equal(actual_value, expected_value)
329317
assert type(actual_value) == expected_type
330318
else:
331319
assert actual_value == expected_value
@@ -489,9 +477,12 @@ def run_test_function(
489477

490478
if (creation_func in [builder.WaveformIn, builder.WaveformOut]
491479
and type(initial_value) is bytes):
492-
# Want to put bytestrings using this, but then retrieve the
493-
# value as an array so NOT specify datatype there
494-
put_kwarg.update({"datatype": DBR_CHAR_STR})
480+
# There's a bug in caput that means DBR_CHAR_STR doesn't
481+
# truncate the array of the target record, meaning .get()
482+
# returns all NELM rather than just NORD elements. Instead we
483+
# encode the data ourselves
484+
initial_value = numpy.frombuffer(
485+
initial_value, dtype = numpy.uint8)
495486

496487
if set_enum == SetValueEnum.CAPUT:
497488
if get_enum == GetValueEnum.GET:
@@ -744,16 +735,16 @@ class TestDefaultValue:
744735
@pytest.mark.parametrize(
745736
"creation_func,expected_value,expected_type",
746737
[
747-
(builder.aOut, None, type(None)),
738+
(builder.aOut, 0.0, float),
748739
(builder.aIn, 0.0, float),
749-
(builder.longOut, None, type(None)),
740+
(builder.longOut, 0, int),
750741
(builder.longIn, 0, int),
751-
(builder.boolOut, None, type(None)),
742+
(builder.boolOut, 0, int),
752743
(builder.boolIn, 0, int),
753-
(builder.Action, None, type(None)),
754-
(builder.stringOut, None, type(None)),
744+
(builder.Action, 0, int),
745+
(builder.stringOut, "", str),
755746
(builder.stringIn, "", str),
756-
(builder.mbbOut, None, type(None)),
747+
(builder.mbbOut, 0, int),
757748
(builder.mbbIn, 0, int),
758749
(builder.WaveformOut, numpy.empty(0), numpy.ndarray),
759750
(builder.WaveformIn, numpy.empty(0), numpy.ndarray),

0 commit comments

Comments
 (0)