@@ -82,6 +82,10 @@ def notify_change(self, change):
8282 self ._notify_type = change ["type" ]
8383
8484
85+ class CrossValidationStub (HasTraits ):
86+ _cross_validation_lock = False
87+
88+
8589# -----------------------------------------------------------------------------
8690# Test classes
8791# -----------------------------------------------------------------------------
@@ -2924,7 +2928,7 @@ def _from_string_test(traittype, s, expected):
29242928 if type (expected ) is type and issubclass (expected , Exception ):
29252929 with pytest .raises (expected ):
29262930 value = cast (s )
2927- trait .validate (None , value )
2931+ trait .validate (CrossValidationStub () , value )
29282932 else :
29292933 value = cast (s )
29302934 assert value == expected
@@ -3144,6 +3148,22 @@ def test_union_of_list_and_unicode_from_string(s, expected):
31443148 _from_string_test (Union ([List (), Unicode ()]), s , expected )
31453149
31463150
3151+ @pytest .mark .parametrize (
3152+ "s, expected" ,
3153+ [("1" , 1 ), ("1.5" , 1.5 )],
3154+ )
3155+ def test_union_of_int_and_float_from_string (s , expected ):
3156+ _from_string_test (Union ([Int (), Float ()]), s , expected )
3157+
3158+
3159+ @pytest .mark .parametrize (
3160+ "s, expected, allow_none" ,
3161+ [("[]" , [], False ), ("{}" , {}, False ), ("None" , TraitError , False ), ("None" , None , True )],
3162+ )
3163+ def test_union_of_list_and_dict_from_string (s , expected , allow_none ):
3164+ _from_string_test (Union ([List (), Dict ()], allow_none = allow_none ), s , expected )
3165+
3166+
31473167def test_all_attribute ():
31483168 """Verify all trait types are added to `traitlets.__all__`"""
31493169 names = dir (traitlets )
0 commit comments