Esempio n. 1
0
 def __init__(self, filename, flag, key_type='str', dump_method=None,
              cached=True, writeback=False):
     if flag=='r':
         Shelf.__init__(self, tinycdb.read(filename), -1, writeback)
     elif flag=='c':
         Shelf.__init__(self, tinycdb.create(filename), -1, writeback)
     self._setup_methods(cached, key_type, dump_method)
Esempio n. 2
0
 def test( self ) :
     db = tinycdb.create(self._TEST_DB_FILENAME)
     data = os.urandom(100)
     db['foo'] = data
     db['bar'] = 'hello world'
     self.assertEqual('foo' in db,True)
     self.assertEqual('moo' in db,False)
     self.assertRaises(TypeError,lambda : db['foo'])
     db.close()
     db1 = tinycdb.read(self._TEST_DB_FILENAME)
     self.assertEqual(db1['foo'],data)
     self.assertRaises(KeyError,lambda : db1['moo'])
     self.assertRaises(TypeError,lambda : self._setitem(db1,'foo','bar'))