<s> """<STR_LIT>""" <EOL> import os , sys <EOL> import unittest <EOL> from test import test_support <EOL> test_support . import_module ( '<STR_LIT>' ) <EOL> bsddb = test_support . import_module ( '<STR_LIT>' , deprecated = True ) <EOL> test_support . import_module ( '<STR_LIT>' , deprecated = True ) <EOL> class TestBSDDB ( unittest . TestCase ) : <EOL> openflag = '<STR_LIT:c>' <EOL> def setUp ( self ) : <EOL> self . f = self . openmethod [ <NUM_LIT:0> ] ( self . fname , self . openflag , cachesize = <NUM_LIT> ) <EOL> self . d = dict ( q = '<STR_LIT>' , w = '<STR_LIT>' , e = '<STR_LIT>' , r = '<STR_LIT>' , t = '<STR_LIT>' , y = '<STR_LIT>' ) <EOL> for k , v in self . d . iteritems ( ) : <EOL> self . f [ k ] = v <EOL> def tearDown ( self ) : <EOL> self . f . sync ( ) <EOL> self . f . close ( ) <EOL> if self . fname is None : <EOL> return <EOL> try : <EOL> os . remove ( self . fname ) <EOL> except os . error : <EOL> pass <EOL> def test_getitem ( self ) : <EOL> for k , v in self . d . iteritems ( ) : <EOL> self . assertEqual ( self . f [ k ] , v ) <EOL> def test_len ( self ) : <EOL> self . assertEqual ( len ( self . f ) , len ( self . d ) ) <EOL> def test_change ( self ) : <EOL> self . f [ '<STR_LIT:r>' ] = '<STR_LIT>' <EOL> self . assertEqual ( self . f [ '<STR_LIT:r>' ] , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT:r>' , self . f . keys ( ) ) <EOL> self . assertIn ( '<STR_LIT>' , self . f . values ( ) ) <EOL> def test_close_and_reopen ( self ) : <EOL> self . assertIsNotNone ( self . fname ) <EOL> self . f . close ( ) <EOL> self . f = self . openmethod [ <NUM_LIT:0> ] ( self . fname , '<STR_LIT:w>' ) <EOL> for k , v in self . d . iteritems ( ) : <EOL> self . assertEqual ( self . f [ k ] , v ) <EOL> def assertSetEquals ( self , seqn1 , seqn2 ) : <EOL> self . assertEqual ( set ( seqn1 ) , set ( seqn2 ) ) <EOL> def test_mapping_iteration_methods ( self ) : <EOL> f = self . f <EOL> d = self . d <EOL> self . assertSetEquals ( d , f ) <EOL> self . assertSetEquals ( d . keys ( ) , f . keys ( ) ) <EOL> self . assertSetEquals ( d . values ( ) , f . values ( ) ) <EOL> self . assertSetEquals ( d . items ( ) , f . items ( ) ) <EOL> self . assertSetEquals ( d . iterkeys ( ) , f . iterkeys ( ) ) <EOL> self . assertSetEquals ( d . itervalues ( ) , f . itervalues ( ) ) <EOL> self . assertSetEquals ( d . iteritems ( ) , f . iteritems ( ) ) <EOL> def test_iter_while_modifying_values ( self ) : <EOL> di = iter ( self . d ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> key = di . next ( ) <EOL> self . d [ key ] = '<STR_LIT>' + key <EOL> except StopIteration : <EOL> break <EOL> loops_left = len ( self . f ) <EOL> fi = iter ( self . f ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> key = fi . next ( ) <EOL> self . f [ key ] = '<STR_LIT>' + key <EOL> loops_left -= <NUM_LIT:1> <EOL> except StopIteration : <EOL> break <EOL> self . assertEqual ( loops_left , <NUM_LIT:0> ) <EOL> self . test_mapping_iteration_methods ( ) <EOL> def test_iter_abort_on_changed_size ( self ) : <EOL> def DictIterAbort ( ) : <EOL> di = iter ( self . d ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> di . next ( ) <EOL> self . d [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> except StopIteration : <EOL> break <EOL> self . assertRaises ( RuntimeError , DictIterAbort ) <EOL> def DbIterAbort ( ) : <EOL> fi = iter ( self . f ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> fi . next ( ) <EOL> self . f [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> except StopIteration : <EOL> break <EOL> self . assertRaises ( RuntimeError , DbIterAbort ) <EOL> def test_iteritems_abort_on_changed_size ( self ) : <EOL> def DictIteritemsAbort ( ) : <EOL> di = self . d . iteritems ( ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> di . next ( ) <EOL> self . d [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> except StopIteration : <EOL> break <EOL> self . assertRaises ( RuntimeError , DictIteritemsAbort ) <EOL> def DbIteritemsAbort ( ) : <EOL> fi = self . f . iteritems ( ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> key , value = fi . next ( ) <EOL> del self . f [ key ] <EOL> except StopIteration : <EOL> break <EOL> self . assertRaises ( RuntimeError , DbIteritemsAbort ) <EOL> def test_iteritems_while_modifying_values ( self ) : <EOL> di = self . d . iteritems ( ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> k , v = di . next ( ) <EOL> self . d [ k ] = '<STR_LIT>' + v <EOL> except StopIteration : <EOL> break <EOL> loops_left = len ( self . f ) <EOL> fi = self . f . iteritems ( ) <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> k , v = fi . next ( ) <EOL> self . f [ k ] = '<STR_LIT>' + v <EOL> loops_left -= <NUM_LIT:1> <EOL> except StopIteration : <EOL> break <EOL> self . assertEqual ( loops_left , <NUM_LIT:0> ) <EOL> self . test_mapping_iteration_methods ( ) <EOL> def test_first_next_looping ( self ) : <EOL> items = [ self . f . first ( ) ] <EOL> for i in xrange ( <NUM_LIT:1> , len ( self . f ) ) : <EOL> items . append ( self . f . next ( ) ) <EOL> self . assertSetEquals ( items , self . d . items ( ) ) <EOL> def test_previous_last_looping ( self ) : <EOL> items = [ self . f . last ( ) ] <EOL> for i in xrange ( <NUM_LIT:1> , len ( self . f ) ) : <EOL> items . append ( self . f . previous ( ) ) <EOL> self . assertSetEquals ( items , self . d . items ( ) ) <EOL> def test_first_while_deleting ( self ) : <EOL> self . assertTrue ( len ( self . d ) >= <NUM_LIT:2> , "<STR_LIT>" ) <EOL> for _ in self . d : <EOL> key = self . f . first ( ) [ <NUM_LIT:0> ] <EOL> del self . f [ key ] <EOL> self . assertEqual ( [ ] , self . f . items ( ) , "<STR_LIT>" ) <EOL> def test_last_while_deleting ( self ) : <EOL> self . assertTrue ( len ( self . d ) >= <NUM_LIT:2> , "<STR_LIT>" ) <EOL> for _ in self . d : <EOL> key = self . f . last ( ) [ <NUM_LIT:0> ] <EOL> del self . f [ key ] <EOL> self . assertEqual ( [ ] , self . f . items ( ) , "<STR_LIT>" ) <EOL> def test_set_location ( self ) : <EOL> self . assertEqual ( self . f . set_location ( '<STR_LIT:e>' ) , ( '<STR_LIT:e>' , self . d [ '<STR_LIT:e>' ] ) ) <EOL> def test_contains ( self ) : <EOL> for k in self . d : <EOL> self . assertIn ( k , self . f ) <EOL> self . assertNotIn ( '<STR_LIT>' , self . f ) <EOL> def test_has_key ( self ) : <EOL> for k in self . d : <EOL> self . assertTrue ( self . f . has_key ( k ) ) <EOL> self . assertTrue ( not self . f . has_key ( '<STR_LIT>' ) ) <EOL> def test_clear ( self ) : <EOL> self . f . clear ( ) <EOL> self . assertEqual ( len ( self . f ) , <NUM_LIT:0> ) <EOL> def test__no_deadlock_first ( self , debug = <NUM_LIT:0> ) : <EOL> sys . stdout . flush ( ) <EOL> if debug : print "<STR_LIT:A>" <EOL> k , v = self . f . first ( ) <EOL> if debug : print "<STR_LIT:B>" , k <EOL> self . f [ k ] = "<STR_LIT>" <EOL> if debug : print "<STR_LIT:C>" <EOL> if True : <EOL> if debug : print "<STR_LIT:D>" <EOL> i = self . f . iteritems ( ) <EOL> k , v = i . next ( ) <EOL> if debug : print "<STR_LIT:E>" <EOL> self . f [ k ] = "<STR_LIT>" <EOL> if debug : print "<STR_LIT:F>" <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> k , v = i . next ( ) <EOL> except StopIteration : <EOL> break <EOL> if debug : print "<STR_LIT>" <EOL> i = iter ( self . f ) <EOL> if debug : print "<STR_LIT>" <EOL> while i : <EOL> try : <EOL> if debug : print "<STR_LIT:H>" <EOL> k = i . next ( ) <EOL> if debug : print "<STR_LIT:I>" <EOL> self . f [ k ] = "<STR_LIT>" <EOL> if debug : print "<STR_LIT>" <EOL> except StopIteration : <EOL> i = None <EOL> if debug : print "<STR_LIT>" <EOL> self . assertIn ( self . f . first ( ) [ <NUM_LIT:0> ] , self . d ) <EOL> k = self . f . next ( ) [ <NUM_LIT:0> ] <EOL> self . assertIn ( k , self . d ) <EOL> self . f [ k ] = "<STR_LIT>" <EOL> self . assertTrue ( self . f [ k ] , "<STR_LIT>" ) <EOL> def test_for_cursor_memleak ( self ) : <EOL> nc1 = len ( self . f . _cursor_refs ) <EOL> i = self . f . iteritems ( ) <EOL> nc2 = len ( self . f . _cursor_refs ) <EOL> k , v = i . next ( ) <EOL> nc3 = len ( self . f . _cursor_refs ) <EOL> del i <EOL> nc4 = len ( self . f . _cursor_refs ) <EOL> self . assertEqual ( nc1 , nc2 ) <EOL> self . assertEqual ( nc1 , nc4 ) <EOL> self . assertTrue ( nc3 == nc1 + <NUM_LIT:1> ) <EOL> def test_popitem ( self ) : <EOL> k , v = self . f . popitem ( ) <EOL> self . assertIn ( k , self . d ) <EOL> self . assertIn ( v , self . d . values ( ) ) <EOL> self . assertNotIn ( k , self . f ) <EOL> self . assertEqual ( len ( self . d ) - <NUM_LIT:1> , len ( self . f ) ) <EOL> def test_pop ( self ) : <EOL> k = '<STR_LIT:w>' <EOL> v = self . f . pop ( k ) <EOL> self . assertEqual ( v , self . d [ k ] ) <EOL> self . assertNotIn ( k , self . f ) <EOL> self . assertNotIn ( v , self . f . values ( ) ) <EOL> self . assertEqual ( len ( self . d ) - <NUM_LIT:1> , len ( self . f ) ) <EOL> def test_get ( self ) : <EOL> self . assertEqual ( self . f . get ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( self . f . get ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . f . get ( '<STR_LIT:q>' , '<STR_LIT>' ) , self . d [ '<STR_LIT:q>' ] ) <EOL> def test_setdefault ( self ) : <EOL> self . assertEqual ( self . f . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . f . setdefault ( '<STR_LIT:r>' , '<STR_LIT>' ) , self . d [ '<STR_LIT:r>' ] ) <EOL> def test_update ( self ) : <EOL> new = dict ( y = '<STR_LIT>' , u = '<STR_LIT>' , i = '<STR_LIT>' ) <EOL> self . f . update ( new ) <EOL> self . d . update ( new ) <EOL> for k , v in self . d . iteritems ( ) : <EOL> self . assertEqual ( self . f [ k ] , v ) <EOL> def test_keyordering ( self ) : <EOL> self . assertIs ( self . openmethod [ <NUM_LIT:0> ] , bsddb . btopen ) <EOL> keys = self . d . keys ( ) <EOL> keys . sort ( ) <EOL> self . assertEqual ( self . f . first ( ) [ <NUM_LIT:0> ] , keys [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( self . f . next ( ) [ <NUM_LIT:0> ] , keys [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( self . f . last ( ) [ <NUM_LIT:0> ] , keys [ - <NUM_LIT:1> ] ) <EOL> self . assertEqual ( self . f . previous ( ) [ <NUM_LIT:0> ] , keys [ - <NUM_LIT:2> ] ) <EOL> self . assertEqual ( list ( self . f ) , keys ) <EOL> class TestBTree ( TestBSDDB ) : <EOL> fname = test_support . TESTFN <EOL> openmethod = [ bsddb . btopen ] <EOL> class TestBTree_InMemory ( TestBSDDB ) : <EOL> fname = None <EOL> openmethod = [ bsddb . btopen ] <EOL> test_close_and_reopen = None <EOL> class TestBTree_InMemory_Truncate ( TestBSDDB ) : <EOL> fname = None <EOL> openflag = '<STR_LIT:n>' <EOL> openmethod = [ bsddb . btopen ] <EOL> test_close_and_reopen = None <EOL> class TestHashTable ( TestBSDDB ) : <EOL> fname = test_support . TESTFN <EOL> openmethod = [ bsddb . hashopen ] <EOL> test_keyordering = None <EOL> class TestHashTable_InMemory ( TestBSDDB ) : <EOL> fname = None <EOL> openmethod = [ bsddb . hashopen ] <EOL> test_close_and_reopen = None <EOL> test_keyordering = None <EOL> def test_main ( verbose = None ) : <EOL> test_support . run_unittest ( <EOL> TestBTree , <EOL> TestHashTable , <EOL> TestBTree_InMemory , <EOL> TestHashTable_InMemory , <EOL> TestBTree_InMemory_Truncate , <EOL> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( verbose = True ) </s>
