From eda60d4baf68ec7ce1f2be5f5ec6079d39b627dc Mon Sep 17 00:00:00 2001 From: Kevin Duff Date: Wed, 10 Apr 2024 19:10:56 +0100 Subject: [PATCH] Couple more xfail tests --- traits/tests/test_constant.py | 2 +- traits/tests/test_optional.py | 29 ++++++++++++++++++++++++++++- traits/tests/test_union.py | 30 +++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/traits/tests/test_constant.py b/traits/tests/test_constant.py index 81ac1794c..2a0c3e700 100644 --- a/traits/tests/test_constant.py +++ b/traits/tests/test_constant.py @@ -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 """ diff --git a/traits/tests/test_optional.py b/traits/tests/test_optional.py index f11b4ac1f..9e2f9a3ba 100644 --- a/traits/tests/test_optional.py +++ b/traits/tests/test_optional.py @@ -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)) @@ -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 diff --git a/traits/tests/test_union.py b/traits/tests/test_union.py index 9f694aef0..c72acc9e8 100644 --- a/traits/tests/test_union.py +++ b/traits/tests/test_union.py @@ -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)) @@ -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