@@ -229,8 +229,22 @@ class HasUnionWithList(HasTraits):
229229 (DefaultValue .constant , "" ),
230230 )
231231
232+ @unittest .expectedFailure
233+ def test_union_default_value_validation (self ):
234+ """
235+ XFAIL: Default value is not validated against allowed types
236+
237+ See discussion on enthought/traits#1784
238+ """
239+ with self .assertRaises (Exception ):
240+ # Expectation: something in here ought to fail
241+ class TestClass (HasTraits ):
242+ attribute = Union (Int , Str , default_value = 3.5 )
243+
244+ TestClass ()
245+
232246 @unittest .expectedFailure # See enthought/traits#1784
233- def test_union_constant (self ):
247+ def test_union_constant_initialization (self ):
234248 class TestClass (HasTraits ):
235249 attribute = Union (None , Constant (123 ))
236250
@@ -240,3 +254,17 @@ class TestClass(HasTraits):
240254 # Fails here - internal trait validation fails
241255 with self .assertRaises (TraitError ):
242256 TestClass (attribute = 124 )
257+
258+ @unittest .expectedFailure # See enthought/traits#1784
259+ def test_union_constant_setting (self ):
260+ class TestClass (HasTraits ):
261+ attribute = Union (None , Constant (123 ))
262+
263+ obj = TestClass (attribute = 123 )
264+
265+ obj .attribute = None
266+ obj .attribute = 123
267+
268+ # Fails here - internal trait validation fails
269+ with self .assertRaises (TraitError ):
270+ obj .attribute = 124
0 commit comments