Skip to content

Commit

Permalink
Couple more xfail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k2bd committed Apr 10, 2024
1 parent 7c988a8 commit eda60d4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion traits/tests/test_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class TestClass(HasTraits):
@unittest.expectedFailure
def test_constant_validator(self):
"""
XFAIL: `validate` on constant does not reject new values.
XFAIL: `validate` on Constant is permissive.
See enthought/traits#1784
"""
Expand Down
29 changes: 28 additions & 1 deletion traits/tests/test_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,22 @@ class TestClass(HasTraits):
with self.assertRaises(TraitError):
TestClass(attribute=1.23)

@unittest.expectedFailure
def test_optional_default_value_validation(self):
"""
XFAIL: Default value is not validated against allowed types
See discussion on enthought/traits#1784
"""
with self.assertRaises(Exception):
# Expectation: something in here ought to fail
class TestClass(HasTraits):
attribute = Optional(Str, default_value=3.5)

TestClass()

@unittest.expectedFailure # See enthought/traits#1784
def test_optional_constant(self):
def test_optional_constant_initialization(self):
class TestClass(HasTraits):
attribute = Optional(Constant(123))

Expand All @@ -301,3 +315,16 @@ class TestClass(HasTraits):
# Fails here - internal trait validation fails
with self.assertRaises(TraitError):
TestClass(attribute=124)

@unittest.expectedFailure # See enthought/traits#1784
def test_optional_constant_setting(self):
class TestClass(HasTraits):
attribute = Optional(Constant(123))

obj = TestClass(attribute=123)
obj.attribute = None
obj.attribute = 123

# Fails here - internal trait validation fails
with self.assertRaises(TraitError):
obj.attribute = 124
30 changes: 29 additions & 1 deletion traits/tests/test_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,22 @@ class HasUnionWithList(HasTraits):
(DefaultValue.constant, ""),
)

@unittest.expectedFailure
def test_union_default_value_validation(self):
"""
XFAIL: Default value is not validated against allowed types
See discussion on enthought/traits#1784
"""
with self.assertRaises(Exception):
# Expectation: something in here ought to fail
class TestClass(HasTraits):
attribute = Union(Int, Str, default_value=3.5)

TestClass()

@unittest.expectedFailure # See enthought/traits#1784
def test_union_constant(self):
def test_union_constant_initialization(self):
class TestClass(HasTraits):
attribute = Union(None, Constant(123))

Expand All @@ -240,3 +254,17 @@ class TestClass(HasTraits):
# Fails here - internal trait validation fails
with self.assertRaises(TraitError):
TestClass(attribute=124)

@unittest.expectedFailure # See enthought/traits#1784
def test_union_constant_setting(self):
class TestClass(HasTraits):
attribute = Union(None, Constant(123))

obj = TestClass(attribute=123)

obj.attribute = None
obj.attribute = 123

# Fails here - internal trait validation fails
with self.assertRaises(TraitError):
obj.attribute = 124

0 comments on commit eda60d4

Please sign in to comment.