<s> """<STR_LIT>""" <EOL> import datetime <EOL> import logging <EOL> import unittest <EOL> import ast <EOL> from bson . objectid import ObjectId <EOL> import tornado . gen <EOL> import tornado . testing <EOL> import motor <EOL> import twcommon . misc <EOL> import two . propcache <EOL> import twest . mock <EOL> from twest . mock import NotFound <EOL> class TestPropcache ( twest . mock . MockAppTestCase ) : <EOL> @ tornado . gen . coroutine <EOL> def resetTables ( self ) : <EOL> self . exwid = ObjectId ( ) <EOL> self . exiid = ObjectId ( ) <EOL> self . exlocid = ObjectId ( ) <EOL> yield motor . Op ( self . app . mongodb . instanceprop . remove , <EOL> { } ) <EOL> yield motor . Op ( self . app . mongodb . instanceprop . insert , <EOL> { '<STR_LIT>' : self . exiid , '<STR_LIT>' : self . exlocid , <EOL> '<STR_LIT:key>' : '<STR_LIT:x>' , '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> yield motor . Op ( self . app . mongodb . instanceprop . insert , <EOL> { '<STR_LIT>' : self . exiid , '<STR_LIT>' : self . exlocid , <EOL> '<STR_LIT:key>' : '<STR_LIT:y>' , '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> yield motor . Op ( self . app . mongodb . instanceprop . insert , <EOL> { '<STR_LIT>' : self . exiid , '<STR_LIT>' : self . exlocid , <EOL> '<STR_LIT:key>' : '<STR_LIT:true>' , '<STR_LIT>' : True } ) <EOL> yield motor . Op ( self . app . mongodb . instanceprop . insert , <EOL> { '<STR_LIT>' : self . exiid , '<STR_LIT>' : self . exlocid , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] } ) <EOL> yield motor . Op ( self . app . mongodb . instanceprop . insert , <EOL> { '<STR_LIT>' : self . exiid , '<STR_LIT>' : self . exlocid , <EOL> '<STR_LIT:key>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> } } ) <EOL> @ tornado . testing . gen_test <EOL> def test_simple_ops ( self ) : <EOL> yield self . resetTables ( ) <EOL> cache = two . propcache . PropCache ( self . app ) <EOL> deps = set ( ) <EOL> instq = lambda key : ( '<STR_LIT>' , self . exiid , self . exlocid , key ) <EOL> res = yield cache . get ( instq ( '<STR_LIT:x>' ) , dependencies = deps ) <EOL> self . assertEqual ( res . val , <NUM_LIT:1> ) <EOL> self . assertTrue ( res . found ) <EOL> self . assertFalse ( res . dirty ) <EOL> self . assertFalse ( res . haschanged ( ) ) <EOL> self . assertEqual ( res . key , '<STR_LIT:x>' ) <EOL> self . assertFalse ( res . mutable ) <EOL> self . assertTrue ( instq ( '<STR_LIT:x>' ) in deps ) <EOL> self . assertTrue ( cache . get_by_object ( res . val ) is None ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) , dependencies = deps ) <EOL> self . assertTrue ( res is None ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) , dependencies = deps ) <EOL> self . assertTrue ( res is None ) <EOL> self . assertTrue ( instq ( '<STR_LIT>' ) in deps ) <EOL> res = cache . propmap [ instq ( '<STR_LIT>' ) ] <EOL> self . assertFalse ( res . found ) <EOL> self . assertFalse ( res . dirty ) <EOL> self . assertFalse ( res . haschanged ( ) ) <EOL> self . assertEqual ( res . key , '<STR_LIT>' ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) , dependencies = deps ) <EOL> self . assertEqual ( res . val , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . assertTrue ( res . found ) <EOL> self . assertFalse ( res . dirty ) <EOL> self . assertFalse ( res . haschanged ( ) ) <EOL> self . assertEqual ( res . key , '<STR_LIT>' ) <EOL> self . assertTrue ( res . mutable ) <EOL> self . assertTrue ( instq ( '<STR_LIT>' ) in deps ) <EOL> self . assertTrue ( cache . get_by_object ( res . val ) is res ) <EOL> res2 = yield cache . get ( instq ( '<STR_LIT>' ) , dependencies = deps ) <EOL> self . assertTrue ( res is res2 ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) , dependencies = deps ) <EOL> self . assertEqual ( res . val , { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> } ) <EOL> self . assertTrue ( res . found ) <EOL> self . assertFalse ( res . dirty ) <EOL> self . assertFalse ( res . haschanged ( ) ) <EOL> self . assertEqual ( res . key , '<STR_LIT>' ) <EOL> self . assertTrue ( res . mutable ) <EOL> self . assertTrue ( instq ( '<STR_LIT>' ) in deps ) <EOL> self . assertTrue ( cache . get_by_object ( res . val ) is res ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> yield cache . set ( instq ( '<STR_LIT:y>' ) , <NUM_LIT:7> ) <EOL> res = yield cache . get ( instq ( '<STR_LIT:y>' ) , dependencies = deps ) <EOL> self . assertEqual ( res . val , <NUM_LIT:7> ) <EOL> self . assertTrue ( res . dirty ) <EOL> self . assertFalse ( res . haschanged ( ) ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT:y>' ) ) <EOL> self . assertEqual ( res , <NUM_LIT:2> ) <EOL> yield cache . set ( instq ( '<STR_LIT:z>' ) , <NUM_LIT:3> ) <EOL> res = yield cache . get ( instq ( '<STR_LIT:z>' ) , dependencies = deps ) <EOL> self . assertEqual ( res . val , <NUM_LIT:3> ) <EOL> self . assertTrue ( res . dirty ) <EOL> self . assertFalse ( res . haschanged ( ) ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT:z>' ) ) <EOL> self . assertEqual ( res , NotFound ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> self . assertEqual ( len ( cache . dirty_entries ( ) ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> res = yield cache . get ( instq ( '<STR_LIT:y>' ) , dependencies = deps ) <EOL> self . assertEqual ( res . val , <NUM_LIT:7> ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT:y>' ) ) <EOL> self . assertEqual ( res , <NUM_LIT:7> ) <EOL> res = yield cache . get ( instq ( '<STR_LIT:z>' ) , dependencies = deps ) <EOL> self . assertEqual ( res . val , <NUM_LIT:3> ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT:z>' ) ) <EOL> self . assertEqual ( res , <NUM_LIT:3> ) <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) , dependencies = deps ) <EOL> self . assertEqual ( res . val , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> yield cache . delete ( instq ( '<STR_LIT:x>' ) ) <EOL> res = yield cache . get ( instq ( '<STR_LIT:x>' ) , dependencies = deps ) <EOL> self . assertTrue ( res is None ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT:x>' ) ) <EOL> self . assertEqual ( res , <NUM_LIT:1> ) <EOL> yield cache . delete ( instq ( '<STR_LIT>' ) ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) , dependencies = deps ) <EOL> self . assertTrue ( res is None ) <EOL> yield cache . delete ( instq ( '<STR_LIT>' ) ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) , dependencies = deps ) <EOL> self . assertTrue ( res is None ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res , { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> } ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> self . assertEqual ( len ( cache . dirty_entries ( ) ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT:x>' ) ) <EOL> self . assertEqual ( res , NotFound ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res , NotFound ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res , NotFound ) <EOL> yield cache . delete ( instq ( '<STR_LIT:x>' ) ) <EOL> res = yield cache . get ( instq ( '<STR_LIT:x>' ) , dependencies = deps ) <EOL> self . assertTrue ( res is None ) <EOL> @ tornado . testing . gen_test <EOL> def test_mutable_values ( self ) : <EOL> yield self . resetTables ( ) <EOL> cache = two . propcache . PropCache ( self . app ) <EOL> instq = lambda key : ( '<STR_LIT>' , self . exiid , self . exlocid , key ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( res . haschanged ( ) ) <EOL> ls = res . val <EOL> ls . append ( <NUM_LIT:4> ) <EOL> self . assertFalse ( res . dirty ) <EOL> self . assertTrue ( res . haschanged ( ) ) <EOL> res2 = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res2 . val , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . assertEqual ( len ( cache . note_changed_entries ( ) ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( cache . dirty_entries ( ) ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> res2 = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res2 . val , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> map = res . val <EOL> self . assertTrue ( cache . get_by_object ( map ) is res ) <EOL> ls [ <NUM_LIT:0> ] = '<STR_LIT>' <EOL> map [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . assertTrue ( cache . get_by_object ( map ) is res ) <EOL> self . assertEqual ( len ( cache . note_changed_entries ( ) ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( cache . dirty_entries ( ) ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> res2 = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res2 . val , [ '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> res2 = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res2 . val , { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res , [ '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res , { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> map [ '<STR_LIT>' ] = <NUM_LIT> <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> map [ '<STR_LIT>' ] = <NUM_LIT> <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> self . assertEqual ( len ( cache . dirty_entries ( ) ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> res2 = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res2 . val , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> self . assertFalse ( res2 . val is map ) <EOL> res = yield self . get_db_prop ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> @ tornado . testing . gen_test <EOL> def test_prop_aliasing ( self ) : <EOL> yield self . resetTables ( ) <EOL> cache = two . propcache . PropCache ( self . app ) <EOL> instq = lambda key : ( '<STR_LIT>' , self . exiid , self . exlocid , key ) <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , True ) <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , True ) <EOL> yield cache . delete ( instq ( '<STR_LIT>' ) ) <EOL> yield cache . delete ( instq ( '<STR_LIT>' ) ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( res is None ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( res is None ) <EOL> self . assertTrue ( cache . get_by_object ( True ) is None ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> ls = [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , ls ) <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , ls ) <EOL> res = cache . get_by_object ( ls ) <EOL> self . assertTrue ( res . val is ls ) <EOL> self . assertTrue ( res . key in ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> yield cache . delete ( instq ( '<STR_LIT>' ) ) <EOL> yield cache . delete ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( res is None ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( res is None ) <EOL> ls = [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , ls ) <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , ls ) <EOL> ls . append ( <NUM_LIT:1> ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res . val , [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:1> ] ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res . val , [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:1> ] ) <EOL> ls . insert ( <NUM_LIT:0> , - <NUM_LIT:1> ) <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res . val , [ - <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:1> ] ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res . val , [ - <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:1> ] ) <EOL> map = { } <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , map ) <EOL> yield cache . set ( instq ( '<STR_LIT>' ) , map ) <EOL> map [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> self . assertEqual ( cache . note_changed_entries ( ) , [ ] ) <EOL> yield cache . write_all_dirty ( ) <EOL> self . assertEqual ( cache . dirty_entries ( ) , [ ] ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res . val , { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> res = yield cache . get ( instq ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( res . val , { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> class TestCheckWritable ( unittest . TestCase ) : <EOL> def test_checkwritable ( self ) : <EOL> checkwritable = two . propcache . checkwritable <EOL> checkwritable ( None ) <EOL> checkwritable ( True ) <EOL> checkwritable ( False ) <EOL> checkwritable ( <NUM_LIT:1> ) <EOL> checkwritable ( - <NUM_LIT:1> ) <EOL> checkwritable ( <NUM_LIT> ) <EOL> checkwritable ( '<STR_LIT:x>' ) <EOL> checkwritable ( "<STR_LIT>" ) <EOL> checkwritable ( b'<STR_LIT:x>' ) <EOL> checkwritable ( ObjectId ( ) ) <EOL> checkwritable ( twcommon . misc . now ( ) ) <EOL> checkwritable ( ( ) ) <EOL> checkwritable ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> checkwritable ( [ ] ) <EOL> checkwritable ( [ None , True , <NUM_LIT:5> , "<STR_LIT:x>" , ObjectId ( ) ] ) <EOL> checkwritable ( { } ) <EOL> checkwritable ( { '<STR_LIT:none>' : None , '<STR_LIT:int>' : <NUM_LIT:1> , '<STR_LIT:list>' : [ ] , '<STR_LIT>' : ( ) } ) <EOL> checkwritable ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( object ( ) ) <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( set ( ) ) <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( datetime . timedelta ( ) ) <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( [ [ [ object ( ) ] ] ] ) <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , self ] ) <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( { <NUM_LIT:1> : <NUM_LIT:2> } ) <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> loopobj = [ ] <EOL> loopobj . append ( loopobj ) <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( loopobj ) <EOL> loopobj = { } <EOL> loopobj [ '<STR_LIT:key>' ] = loopobj <EOL> with self . assertRaises ( TypeError ) : <EOL> checkwritable ( loopobj ) <EOL> class TestDeepCopy ( unittest . TestCase ) : <EOL> def test_deepcopy ( self ) : <EOL> deepcopy = two . propcache . deepcopy <EOL> val = None <EOL> self . assertTrue ( deepcopy ( val ) is val ) <EOL> val = True <EOL> self . assertTrue ( deepcopy ( val ) is val ) <EOL> val = <NUM_LIT:5> <EOL> self . assertTrue ( deepcopy ( val ) is val ) <EOL> val = - <NUM_LIT> <EOL> self . assertTrue ( deepcopy ( val ) is val ) <EOL> val = ObjectId ( ) <EOL> self . assertTrue ( deepcopy ( val ) is val ) <EOL> val = [ ] <EOL> res = deepcopy ( val ) <EOL> self . assertFalse ( val is res ) <EOL> self . assertEqual ( val , res ) <EOL> val . append ( <NUM_LIT:1> ) <EOL> self . assertNotEqual ( val , res ) <EOL> val = { } <EOL> res = deepcopy ( val ) <EOL> self . assertFalse ( val is res ) <EOL> self . assertEqual ( val , res ) <EOL> val = [ <NUM_LIT:1> , [ <NUM_LIT:2> , { } ] , { '<STR_LIT:x>' : '<STR_LIT:y>' , '<STR_LIT:z>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] } ] <EOL> res = deepcopy ( val ) <EOL> self . assertFalse ( val is res ) <EOL> self . assertEqual ( val , res ) <EOL> self . assertTrue ( val [ <NUM_LIT:0> ] is res [ <NUM_LIT:0> ] ) <EOL> self . assertFalse ( val [ <NUM_LIT:1> ] is res [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( val [ <NUM_LIT:1> ] , res [ <NUM_LIT:1> ] ) <EOL> self . assertFalse ( val [ <NUM_LIT:2> ] is res [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( val [ <NUM_LIT:2> ] , res [ <NUM_LIT:2> ] ) <EOL> self . assertFalse ( val [ <NUM_LIT:2> ] [ '<STR_LIT:z>' ] is res [ <NUM_LIT:2> ] [ '<STR_LIT:z>' ] ) <EOL> self . assertEqual ( val [ <NUM_LIT:2> ] [ '<STR_LIT:z>' ] , res [ <NUM_LIT:2> ] [ '<STR_LIT:z>' ] ) <EOL> loopobj = [ ] <EOL> loopobj . append ( loopobj ) <EOL> with self . assertRaises ( TypeError ) : <EOL> deepcopy ( loopobj ) <EOL> loopobj = { } <EOL> loopobj [ '<STR_LIT:key>' ] = loopobj <EOL> with self . assertRaises ( TypeError ) : <EOL> deepcopy ( loopobj ) </s>
