<s> from __future__ import absolute_import <EOL> from traits . testing . unittest_tools import unittest <EOL> from . . api import HasTraits , Instance , Str , Any , Property <EOL> class Foo ( HasTraits ) : <EOL> s = Str <EOL> class ClassWithAny ( HasTraits ) : <EOL> x = Property <EOL> _x = Any <EOL> def _get_x ( self ) : <EOL> return self . _x <EOL> def _set_x ( self , x ) : <EOL> self . _x = x <EOL> class ClassWithInstance ( HasTraits ) : <EOL> x = Property <EOL> _x = Instance ( Foo ) <EOL> def _get_x ( self ) : <EOL> return self . _x <EOL> def _set_x ( self , x ) : <EOL> self . _x = x <EOL> class ClassWithClassAttribute ( HasTraits ) : <EOL> name = '<STR_LIT>' <EOL> foo = Str <EOL> class BazAny ( HasTraits ) : <EOL> other = Any <EOL> class BarAny ( HasTraits ) : <EOL> other = Any <EOL> class BazInstance ( HasTraits ) : <EOL> other = Instance ( '<STR_LIT>' ) <EOL> unique = Instance ( Foo ) <EOL> shared = Instance ( Foo ) <EOL> ref = Instance ( Foo , copy = '<STR_LIT>' ) <EOL> class BarInstance ( HasTraits ) : <EOL> other = Instance ( '<STR_LIT>' , copy = '<STR_LIT>' ) <EOL> unique = Instance ( Foo ) <EOL> shared = Instance ( Foo ) <EOL> ref = Instance ( Foo , copy = '<STR_LIT>' ) <EOL> class CloneTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_any ( self ) : <EOL> b = ClassWithAny ( ) <EOL> f = Foo ( ) <EOL> f . s = '<STR_LIT>' <EOL> b . x = f <EOL> bc = b . clone_traits ( traits = '<STR_LIT:all>' , copy = '<STR_LIT>' ) <EOL> self . assertNotEqual ( id ( bc . x ) , id ( f ) , '<STR_LIT>' ) <EOL> return <EOL> def test_instance ( self ) : <EOL> b = ClassWithInstance ( ) <EOL> f = Foo ( ) <EOL> f . s = '<STR_LIT>' <EOL> b . x = f <EOL> bc = b . clone_traits ( traits = '<STR_LIT:all>' , copy = '<STR_LIT>' ) <EOL> self . assertNotEqual ( id ( bc . x ) , id ( f ) , '<STR_LIT>' ) <EOL> return <EOL> def test_class_attribute_missing ( self ) : <EOL> """<STR_LIT>""" <EOL> s = '<STR_LIT>' <EOL> c = ClassWithClassAttribute ( ) <EOL> self . assertEqual ( s , c . name ) <EOL> c2 = ClassWithClassAttribute ( ) <EOL> self . assertEqual ( s , c . name ) <EOL> self . assertEqual ( s , c2 . name ) <EOL> s2 = '<STR_LIT>' <EOL> c2 . name = s2 <EOL> self . assertEqual ( s2 , c2 . name ) <EOL> self . assertEqual ( s , c . name ) <EOL> return <EOL> def test_Any_circular_references ( self ) : <EOL> bar = BarAny ( ) <EOL> baz = BazAny ( ) <EOL> bar . other = baz <EOL> baz . other = bar <EOL> bar_copy = bar . clone_traits ( ) <EOL> self . assertIsNot ( bar_copy , bar ) <EOL> self . assertIs ( bar_copy . other , baz ) <EOL> self . assertIs ( bar_copy . other . other , bar ) <EOL> def test_Any_circular_references_deep ( self ) : <EOL> bar = BarAny ( ) <EOL> baz = BazAny ( ) <EOL> bar . other = baz <EOL> baz . other = bar <EOL> bar_copy = bar . clone_traits ( copy = '<STR_LIT>' ) <EOL> self . assertIsNot ( bar_copy , bar ) <EOL> self . assertIsNot ( bar_copy . other , baz ) <EOL> self . assertIsNot ( bar_copy . other . other , bar ) <EOL> self . assertIs ( bar_copy . other . other , bar_copy ) <EOL> def test_Instance_circular_references ( self ) : <EOL> ref = Foo ( s = '<STR_LIT>' ) <EOL> bar_unique = Foo ( s = '<STR_LIT>' ) <EOL> shared = Foo ( s = '<STR_LIT>' ) <EOL> baz_unique = Foo ( s = '<STR_LIT>' ) <EOL> baz = BazInstance ( ) <EOL> baz . unique = baz_unique <EOL> baz . shared = shared <EOL> baz . ref = ref <EOL> bar = BarInstance ( ) <EOL> bar . unique = bar_unique <EOL> bar . shared = shared <EOL> bar . ref = ref <EOL> bar . other = baz <EOL> baz . other = bar <EOL> baz_copy = baz . clone_traits ( ) <EOL> self . assertIsNot ( baz_copy , baz ) <EOL> self . assertIsNot ( baz_copy . other , bar ) <EOL> self . assertIsNot ( baz_copy . unique , baz . unique ) <EOL> self . assertIsNot ( baz_copy . shared , baz . shared ) <EOL> self . assertIs ( baz_copy . ref , ref ) <EOL> bar_copy = baz_copy . other <EOL> self . assertIsNot ( bar_copy . unique , bar . unique ) <EOL> self . assertIs ( bar_copy . ref , ref ) <EOL> self . assertIsNot ( bar_copy . other , baz_copy ) <EOL> self . assertIs ( bar_copy . other , baz ) <EOL> self . assertIsNot ( bar_copy . shared , baz . shared ) <EOL> self . assertIs ( bar_copy . shared , baz_copy . shared ) <EOL> def test_Instance_circular_references_deep ( self ) : <EOL> ref = Foo ( s = '<STR_LIT>' ) <EOL> bar_unique = Foo ( s = '<STR_LIT>' ) <EOL> shared = Foo ( s = '<STR_LIT>' ) <EOL> baz_unique = Foo ( s = '<STR_LIT>' ) <EOL> baz = BazInstance ( ) <EOL> baz . unique = baz_unique <EOL> baz . shared = shared <EOL> baz . ref = ref <EOL> bar = BarInstance ( ) <EOL> bar . unique = bar_unique <EOL> bar . shared = shared <EOL> bar . ref = ref <EOL> bar . other = baz <EOL> baz . other = bar <EOL> baz_copy = baz . clone_traits ( copy = '<STR_LIT>' ) <EOL> self . assertIsNot ( baz_copy , baz ) <EOL> self . assertIsNot ( baz_copy . other , bar ) <EOL> self . assertIsNot ( baz_copy . unique , baz . unique ) <EOL> self . assertIsNot ( baz_copy . shared , baz . shared ) <EOL> bar_copy = baz_copy . other <EOL> self . assertIsNot ( bar_copy . unique , bar . unique ) <EOL> self . assertIs ( baz_copy . ref , bar_copy . ref ) <EOL> self . assertIs ( bar_copy . ref , ref ) <EOL> self . assertIsNot ( bar_copy . other , baz_copy ) <EOL> self . assertIs ( bar_copy . other , baz ) <EOL> self . assertIsNot ( bar_copy . shared , baz . shared ) <EOL> self . assertIs ( bar_copy . shared , baz_copy . shared ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
