MCPcopy Create free account
hub / github.com/ipython/traitlets / test_multiple_validate

Method test_multiple_validate

tests/test_traitlets.py:1985–2006  ·  view source on GitHub ↗

Verify that we can register the same validator to multiple names

(self)

Source from the content-addressed store, hash-verified

1983 u.value = 2 # OK
1984
1985 def test_multiple_validate(self):
1986 """Verify that we can register the same validator to multiple names"""
1987
1988 class OddEven(HasTraits):
1989 odd = Int(1)
1990 even = Int(0)
1991
1992 @validate("odd", "even")
1993 def check_valid(self, proposal):
1994 if proposal["trait"].name == "odd" and not proposal["value"] % 2:
1995 raise TraitError("odd should be odd")
1996 if proposal["trait"].name == "even" and proposal["value"] % 2:
1997 raise TraitError("even should be even")
1998
1999 u = OddEven()
2000 u.odd = 3 # OK
2001 with self.assertRaises(TraitError):
2002 u.odd = 2 # Trait Error
2003
2004 u.even = 2 # OK
2005 with self.assertRaises(TraitError):
2006 u.even = 3 # Trait Error
2007
2008 def test_validate_used(self):
2009 """Verify that the validate value is being used"""

Callers

nothing calls this directly

Calls 1

OddEvenClass · 0.85

Tested by

no test coverage detected