<s> from traits . api import HasStrictTraits , Int , TraitError <EOL> from traits . testing . unittest_tools import unittest <EOL> from traits . tests . tuple_test_mixin import TupleTestMixin <EOL> from traits . trait_types import ValidatedTuple <EOL> class Simple ( HasStrictTraits ) : <EOL> scalar_range = ValidatedTuple ( <EOL> Int ( <NUM_LIT:0> ) , Int ( <NUM_LIT:1> ) , fvalidate = lambda x : x [ <NUM_LIT:0> ] < x [ <NUM_LIT:1> ] ) <EOL> class ValidatedTupleTestCase ( TupleTestMixin , unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . trait = ValidatedTuple <EOL> def test_initialization ( self ) : <EOL> simple = Simple ( ) <EOL> self . assertEqual ( simple . scalar_range , ( <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> def test_custom_validation ( self ) : <EOL> simple = Simple ( ) <EOL> simple . scalar_range = ( <NUM_LIT:2> , <NUM_LIT:5> ) <EOL> self . assertEqual ( simple . scalar_range , ( <NUM_LIT:2> , <NUM_LIT:5> ) ) <EOL> with self . assertRaises ( TraitError ) : <EOL> simple . scalar_range = ( <NUM_LIT:5> , <NUM_LIT:2> ) <EOL> def test_error_during_custom_validation ( self ) : <EOL> def fvalidate ( x ) : <EOL> if x == ( <NUM_LIT:5> , <NUM_LIT:2> ) : <EOL> raise RuntimeError ( ) <EOL> return True <EOL> class Simple ( HasStrictTraits ) : <EOL> scalar_range = ValidatedTuple ( Int ( <NUM_LIT:0> ) , Int ( <NUM_LIT:1> ) , fvalidate = fvalidate ) <EOL> simple = Simple ( ) <EOL> with self . assertRaises ( RuntimeError ) : <EOL> simple . scalar_range = ( <NUM_LIT:5> , <NUM_LIT:2> ) </s>
