Skip to content

Commit eda60d4

Browse files
committed
Couple more xfail tests
1 parent 7c988a8 commit eda60d4

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

traits/tests/test_constant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class TestClass(HasTraits):
7676
@unittest.expectedFailure
7777
def test_constant_validator(self):
7878
"""
79-
XFAIL: `validate` on constant does not reject new values.
79+
XFAIL: `validate` on Constant is permissive.
8080
8181
See enthought/traits#1784
8282
"""

traits/tests/test_optional.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,22 @@ class TestClass(HasTraits):
290290
with self.assertRaises(TraitError):
291291
TestClass(attribute=1.23)
292292

293+
@unittest.expectedFailure
294+
def test_optional_default_value_validation(self):
295+
"""
296+
XFAIL: Default value is not validated against allowed types
297+
298+
See discussion on enthought/traits#1784
299+
"""
300+
with self.assertRaises(Exception):
301+
# Expectation: something in here ought to fail
302+
class TestClass(HasTraits):
303+
attribute = Optional(Str, default_value=3.5)
304+
305+
TestClass()
306+
293307
@unittest.expectedFailure # See enthought/traits#1784
294-
def test_optional_constant(self):
308+
def test_optional_constant_initialization(self):
295309
class TestClass(HasTraits):
296310
attribute = Optional(Constant(123))
297311

@@ -301,3 +315,16 @@ class TestClass(HasTraits):
301315
# Fails here - internal trait validation fails
302316
with self.assertRaises(TraitError):
303317
TestClass(attribute=124)
318+
319+
@unittest.expectedFailure # See enthought/traits#1784
320+
def test_optional_constant_setting(self):
321+
class TestClass(HasTraits):
322+
attribute = Optional(Constant(123))
323+
324+
obj = TestClass(attribute=123)
325+
obj.attribute = None
326+
obj.attribute = 123
327+
328+
# Fails here - internal trait validation fails
329+
with self.assertRaises(TraitError):
330+
obj.attribute = 124

traits/tests/test_union.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)