@@ -224,6 +224,7 @@ def test_DISP_can_be_overridden():
224224 record = builder .longIn ("DISP-OFF" , DISP = 0 )
225225 # Note: DISP attribute won't exist if field not specified
226226 assert record .DISP .Value () == 0
227+
227228def record_value_asserts (
228229 creation_func ,
229230 actual_value ,
@@ -234,7 +235,17 @@ def record_value_asserts(
234235 if type (expected_value ) == float and isnan (expected_value ):
235236 assert isnan (actual_value ) # NaN != Nan, so needs special case
236237 elif creation_func in [builder .WaveformOut , builder .WaveformIn ]:
237- assert numpy .array_equal (actual_value , expected_value ), \
238+
239+ # Special case for lack of default value on Out records before init
240+ if actual_value is None and expected_value is None :
241+ assert type (actual_value ) == expected_type
242+ return
243+
244+ # Using .get() on the array returns entire length, not just filled part.
245+ # Confirm this by ensuring sliced part of array is all zeros
246+ assert not numpy .any (actual_value [expected_value .size :])
247+ truncated_value = actual_value [:expected_value .size ]
248+ assert numpy .array_equal (truncated_value , expected_value ), \
238249 "Arrays not equal: {} {}" .format (actual_value , expected_value )
239250 assert type (actual_value ) == expected_type
240251 else :
@@ -433,33 +444,6 @@ def run_test_function(
433444 if ioc_process .exitcode is None :
434445 pytest .fail ("Process did not terminate" )
435446
436- def record_value_asserts (
437- creation_func ,
438- actual_value ,
439- expected_value ,
440- expected_type ):
441- """Asserts that the expected value and expected type are matched with
442- the actual value. Handles both scalar and waveform data"""
443- if type (expected_value ) == float and isnan (expected_value ):
444- assert isnan (actual_value ) # NaN != Nan, so needs special case
445- elif creation_func in [builder .WaveformOut , builder .WaveformIn ]:
446-
447- # Special case for lack of default value on Out records before init
448- if actual_value is None and expected_value is None :
449- assert type (actual_value ) == expected_type
450- return
451-
452- # Using .get() on the array returns entire length, not just filled part.
453- # Confirm this by ensuring sliced part of array is all zeros
454- assert not numpy .any (actual_value [expected_value .size :])
455- truncated_value = actual_value [:expected_value .size ]
456- assert numpy .array_equal (truncated_value , expected_value ), \
457- "Arrays not equal: {} {}" .format (actual_value , expected_value )
458- assert type (actual_value ) == expected_type
459- else :
460- assert actual_value == expected_value
461- assert type (actual_value ) == expected_type
462-
463447
464448def skip_long_strings (record_values ):
465449 if (
@@ -468,20 +452,6 @@ def skip_long_strings(record_values):
468452 ):
469453 pytest .skip ("CAPut blocks strings > 40 characters." )
470454
471- def test_records (tmp_path ):
472- import sim_records
473-
474- path = str (tmp_path / "records.db" )
475- builder .WriteRecords (path )
476- expected = os .path .join (os .path .dirname (__file__ ), "expected_records.db" )
477- assert open (path ).readlines ()[5 :] == open (expected ).readlines ()
478-
479- def test_enum_length_restriction ():
480- with pytest .raises (AssertionError ):
481- builder .mbbIn (
482- "ManyLabels" , "one" , "two" , "three" , "four" , "five" , "six" ,
483- "seven" , "eight" , "nine" , "ten" , "eleven" , "twelve" , "thirteen" ,
484- "fourteen" , "fifteen" , "sixteen" , "seventeen" )
485455
486456class TestGetValue :
487457 """Tests that use .get() to check whether values applied with .set()
0 commit comments