@@ -119,20 +119,6 @@ def record_values_names(fixture_value):
119119 ("strOut_empty" , builder .stringOut , "" , "" , str ),
120120 ("strin_utf8" , builder .stringIn , "%a€b" , "%a€b" , str ), # Valid UTF-8
121121 ("strOut_utf8" , builder .stringOut , "%a€b" , "%a€b" , str ), # Valid UTF-8
122- (
123- "strIn_longstr" ,
124- builder .stringIn ,
125- "this string is much longer than 40 characters" ,
126- "this string is much longer than 40 char" ,
127- str ,
128- ),
129- (
130- "strOut_longstr" ,
131- builder .stringOut ,
132- "this string is much longer than 40 characters" ,
133- "this string is much longer than 40 char" ,
134- str ,
135- ),
136122 (
137123 "wIn_list" ,
138124 builder .WaveformIn ,
@@ -148,17 +134,31 @@ def record_values_names(fixture_value):
148134 numpy .ndarray ,
149135 ),
150136 (
151- "wIn_str " ,
137+ "wIn_int " ,
152138 builder .WaveformIn ,
153- "ABC" ,
154- numpy .array ([65 , 66 , 67 , 0 ], dtype = numpy .uint8 ),
139+ 567 ,
140+ numpy .array ([567 ], dtype = numpy .int32 ),
155141 numpy .ndarray ,
156142 ),
157143 (
158- "wOut_str " ,
144+ "wOut_int " ,
159145 builder .WaveformOut ,
160- "ABC" ,
161- numpy .array ([65 , 66 , 67 , 0 ], dtype = numpy .uint8 ),
146+ 567 ,
147+ numpy .array ([567 ], dtype = numpy .int32 ),
148+ numpy .ndarray ,
149+ ),
150+ (
151+ "wIn_float" ,
152+ builder .WaveformIn ,
153+ 12.345 ,
154+ numpy .array ([12.345 ], dtype = numpy .float32 ),
155+ numpy .ndarray ,
156+ ),
157+ (
158+ "wOut_float" ,
159+ builder .WaveformOut ,
160+ 12.345 ,
161+ numpy .array ([12.345 ], dtype = numpy .float32 ),
162162 numpy .ndarray ,
163163 ),
164164 (
@@ -179,20 +179,6 @@ def record_values_names(fixture_value):
179179 ),
180180 numpy .ndarray ,
181181 ),
182- (
183- "wIn_unicode" ,
184- builder .WaveformIn ,
185- "%a€b" ,
186- numpy .array ([37 , 97 , 226 , 130 , 172 , 98 , 0 ], dtype = numpy .uint8 ),
187- numpy .ndarray ,
188- ),
189- (
190- "wOut_unicode" ,
191- builder .WaveformOut ,
192- "%a€b" ,
193- numpy .array ([37 , 97 , 226 , 130 , 172 , 98 , 0 ], dtype = numpy .uint8 ),
194- numpy .ndarray ,
195- ),
196182 (
197183 "longStringIn_str" ,
198184 builder .longStringIn ,
@@ -221,20 +207,6 @@ def record_values_names(fixture_value):
221207 VERY_LONG_STRING ,
222208 str ,
223209 ),
224- (
225- "longStringIn_bytes" ,
226- builder .longStringIn ,
227- b"HELLO\0 WORLD" ,
228- "HELLO" ,
229- str ,
230- ),
231- (
232- "longStringOut_bytes" ,
233- builder .longStringOut ,
234- b"HELLO\0 WORLD" ,
235- "HELLO" ,
236- str ,
237- ),
238210 (
239211 "longStringIn_unicode" ,
240212 builder .longStringIn ,
@@ -507,14 +479,10 @@ def run_test_function(
507479 ) = configuration
508480
509481 # Infer some required keywords from parameters
510- put_kwargs = {}
511- get_kwargs = {}
512- if creation_func in [builder .WaveformOut , builder .WaveformIn ]:
482+ kwargs = {}
483+ if creation_func in [builder .longStringIn , builder .longStringOut ]:
513484 from cothread .dbr import DBR_CHAR_STR
514-
515- if type (initial_value ) in [str , bytes ]:
516- put_kwargs .update ({"datatype" : DBR_CHAR_STR })
517- get_kwargs .update ({"count" : len (initial_value ) + 1 })
485+ kwargs .update ({"datatype" : DBR_CHAR_STR })
518486
519487 if set_enum == SetValueEnum .CAPUT :
520488 if get_enum == GetValueEnum .GET :
@@ -526,7 +494,7 @@ def run_test_function(
526494 DEVICE_NAME + ":" + record_name ,
527495 initial_value ,
528496 wait = True ,
529- ** put_kwargs
497+ ** kwargs
530498 )
531499
532500 if get_enum == GetValueEnum .GET :
@@ -546,7 +514,7 @@ def run_test_function(
546514 rec_val = caget (
547515 DEVICE_NAME + ":" + record_name ,
548516 timeout = TIMEOUT ,
549- ** get_kwargs
517+ ** kwargs ,
550518 )
551519 # '+' operator used to convert cothread's types into Python
552520 # native types e.g. "+ca_int" -> int
@@ -830,32 +798,41 @@ class TestNoneValue:
830798 # We expect using None as a value will trigger one of these exceptions
831799 expected_exceptions = (ValueError , TypeError , AttributeError )
832800
801+
802+ @pytest .fixture
803+ def record_func_reject_none (self , record_func ):
804+ """Parameterized fixture for all records that reject None"""
805+ if record_func in [builder .WaveformIn , builder .WaveformOut ]:
806+ pytest .skip ("None is accepted by Waveform records, as numpy "
807+ "treats it as NaN" )
808+ return record_func
809+
833810 def test_value_none_rejected_initial_value (
834- self , clear_records , record_func
811+ self , clear_records , record_func_reject_none
835812 ):
836813 """Test setting \" None\" as the initial_value raises an exception"""
837814
838815 kwarg = {}
839- if record_func in [
816+ if record_func_reject_none in [
840817 builder .WaveformIn ,
841818 builder .WaveformOut ,
842819 ]:
843820 kwarg = {"length" : 50 } # Required when no value on creation
844821
845822 with pytest .raises (self .expected_exceptions ):
846- record_func ("SOME-NAME" , initial_value = None , ** kwarg )
823+ record_func_reject_none ("SOME-NAME" , initial_value = None , ** kwarg )
847824
848825 def test_value_none_rejected_set_before_init (
849- self , clear_records , record_func
826+ self , clear_records , record_func_reject_none
850827 ):
851828 """Test that setting \" None\" using .set() raises an exception"""
852829
853830 kwarg = {}
854- if record_func in [builder .WaveformIn , builder .WaveformOut ]:
831+ if record_func_reject_none in [builder .WaveformIn , builder .WaveformOut ]:
855832 kwarg = {"length" : 50 } # Required when no value on creation
856833
857834 with pytest .raises (self .expected_exceptions ):
858- record = record_func ("SOME-NAME" , ** kwarg )
835+ record = record_func_reject_none ("SOME-NAME" , ** kwarg )
859836 record .set (None )
860837
861838 def none_value_test_func (self , record_func , queue ):
@@ -877,13 +854,13 @@ def none_value_test_func(self, record_func, queue):
877854 queue .put (Exception ("FAIL:Test did not raise exception during .set()" ))
878855
879856 @requires_cothread
880- def test_value_none_rejected_set_after_init (self , record_func ):
857+ def test_value_none_rejected_set_after_init (self , record_func_reject_none ):
881858 """Test that setting \" None\" using .set() after IOC init raises an
882859 exception"""
883860 queue = multiprocessing .Queue ()
884861 process = multiprocessing .Process (
885862 target = self .none_value_test_func ,
886- args = (record_func , queue ),
863+ args = (record_func_reject_none , queue ),
887864 )
888865
889866 process .start ()
@@ -974,23 +951,30 @@ def validate_test_runner(
974951 process .start ()
975952
976953 try :
977- queue .get (timeout = 5 ) # Get the expected IOc initialised message
954+ queue .get (timeout = 5 ) # Get the expected IOC initialised message
978955
979956 from cothread .catools import caget , caput , _channel_cache
980957
981958 # See other places in this file for why we call it
982959 _channel_cache .purge ()
983960
961+ kwargs = {}
962+ if creation_func in [builder .longStringIn , builder .longStringOut ]:
963+ from cothread .dbr import DBR_CHAR_STR
964+ kwargs .update ({"datatype" : DBR_CHAR_STR })
965+
984966 put_ret = caput (
985967 DEVICE_NAME + ":" + "VALIDATE-RECORD" ,
986968 new_value ,
987969 wait = True ,
970+ ** kwargs ,
988971 )
989972 assert put_ret .ok , "caput did not succeed"
990973
991974 ret_val = caget (
992975 DEVICE_NAME + ":" + "VALIDATE-RECORD" ,
993- timeout = 3
976+ timeout = 3 ,
977+ ** kwargs
994978 )
995979
996980 if creation_func in [builder .WaveformOut , builder .WaveformIn ]:
0 commit comments