@@ -312,5 +312,69 @@ def test_list_add(self, param_args: ParamArguments):
312312 ) # Adding a new overriding parameter should update the one in the list, too.
313313
314314
315+ @_pass_param_arguments (test_create_param )
316+ def test_valueproxy_operators (self , param_args : ParamArguments ):
317+
318+ param_args .normal_param .value = 2
319+ assert int (param_args .normal_param .value ) == 2
320+
321+
322+ with self .assertDoesNotRaise (TypeError ):
323+ param_args .normal_param .value + 2 # ValueProxy + int
324+
325+ with self .assertDoesNotRaise (TypeError ):
326+ 2 + param_args .normal_param .value # int + ValueProxy
327+
328+
329+ with self .assertDoesNotRaise (TypeError ):
330+ param_args .normal_param .value * 2 # ValueProxy * int
331+
332+ with self .assertDoesNotRaise (TypeError ):
333+ 2 * param_args .normal_param .value # int * ValueProxy
334+
335+
336+ with self .assertDoesNotRaise (TypeError ):
337+ param_args .normal_param .value % 2 # ValueProxy % int
338+
339+ with self .assertDoesNotRaise (TypeError ):
340+ 2 % param_args .normal_param .value # int % ValueProxy
341+
342+
343+ with self .assertDoesNotRaise (TypeError ):
344+ 2 / param_args .normal_param .value # int / ValueProxy
345+
346+ with self .assertDoesNotRaise (TypeError ):
347+ param_args .normal_param .value / 2 # ValueProxy / int
348+
349+
350+ with self .assertDoesNotRaise (TypeError ):
351+ param_args .normal_param .value // 2 # ValueProxy // int
352+
353+ with self .assertDoesNotRaise (TypeError ):
354+ 2 // param_args .normal_param .value # int // ValueProxy
355+
356+
357+ with self .assertDoesNotRaise (TypeError ):
358+ param_args .str_param .value + "123" # ValueProxy + str
359+
360+ with self .assertDoesNotRaise (TypeError ):
361+ "123" + param_args .str_param .value # str + ValueProxy
362+
363+
364+ try :
365+ param_args .str_param .value + 2
366+ except TypeError as e :
367+ # Assert that operator is correctly forwarded to the string value.
368+ # It's a bit tricky to check since both cases will raise a TypeError.
369+ self .assertTrue ('ValueProxy' not in e .args [0 ])
370+
371+ try :
372+ 2 + param_args .str_param .value
373+ except TypeError as e :
374+ # Assert that operator is correctly forwarded to the string value.
375+ # It's a bit tricky to check since both cases will raise a TypeError.
376+ self .assertTrue ('ValueProxy' not in e .args [0 ])
377+
378+
315379if __name__ == "__main__" :
316380 unittest .main ()
0 commit comments