<s> """<STR_LIT>""" <EOL> import abc <EOL> import warnings <EOL> from traits . testing . unittest_tools import unittest <EOL> from . . api import ABCHasTraits , ABCMetaHasTraits , HasTraits , Int , Float <EOL> class TestNew ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . old_filters = warnings . filters [ : ] <EOL> warnings . simplefilter ( '<STR_LIT:error>' , DeprecationWarning ) <EOL> def tearDown ( self ) : <EOL> warnings . filters [ : ] = self . old_filters <EOL> def test_new ( self ) : <EOL> HasTraits ( x = <NUM_LIT:10> ) <EOL> class AbstractFoo ( ABCHasTraits ) : <EOL> x = Int ( <NUM_LIT:10> ) <EOL> y = Float ( <NUM_LIT> ) <EOL> @ abc . abstractmethod <EOL> def foo ( self ) : <EOL> raise NotImplementedError ( ) <EOL> @ abc . abstractproperty <EOL> def bar ( self ) : <EOL> raise NotImplementedError ( ) <EOL> class ConcreteFoo ( AbstractFoo ) : <EOL> def foo ( self ) : <EOL> return '<STR_LIT:foo>' <EOL> @ property <EOL> def bar ( self ) : <EOL> return '<STR_LIT:bar>' <EOL> class FooLike ( HasTraits ) : <EOL> x = Int ( <NUM_LIT:10> ) <EOL> y = Float ( <NUM_LIT> ) <EOL> def foo ( self ) : <EOL> return '<STR_LIT:foo>' <EOL> @ property <EOL> def bar ( self ) : <EOL> return '<STR_LIT:bar>' <EOL> AbstractFoo . register ( FooLike ) <EOL> class AbstractBar ( object ) : <EOL> __metaclass__ = abc . ABCMeta <EOL> @ abc . abstractmethod <EOL> def bar ( self ) : <EOL> raise NotImplementedError ( ) <EOL> class TestABC ( unittest . TestCase ) : <EOL> def test_basic_abc ( self ) : <EOL> self . assertRaises ( TypeError , AbstractFoo ) <EOL> concrete = ConcreteFoo ( ) <EOL> self . assertEqual ( concrete . foo ( ) , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( concrete . bar , '<STR_LIT:bar>' ) <EOL> self . assertEqual ( concrete . x , <NUM_LIT:10> ) <EOL> self . assertEqual ( concrete . y , <NUM_LIT> ) <EOL> self . assertTrue ( isinstance ( concrete , AbstractFoo ) ) <EOL> def test_registered ( self ) : <EOL> foolike = FooLike ( ) <EOL> self . assertTrue ( isinstance ( foolike , AbstractFoo ) ) <EOL> def test_post_hoc_mixing ( self ) : <EOL> class TraitedBar ( HasTraits , AbstractBar ) : <EOL> __metaclass__ = ABCMetaHasTraits <EOL> x = Int ( <NUM_LIT:10> ) <EOL> def bar ( self ) : <EOL> return '<STR_LIT:bar>' <EOL> traited = TraitedBar ( ) <EOL> self . assertTrue ( isinstance ( traited , AbstractBar ) ) <EOL> self . assertEqual ( traited . x , <NUM_LIT:10> ) </s>
