def testCloseAndReopenEmptyDatabase(self): db = esedb.open(self._makeDatabasePath("test.edb"), "n") db.close() db = esedb.open(self._makeDatabasePath("test.edb"), "r") self.assertEqual(0, len(db)) db.close()
def _randomOperations(self): keys = 'abcdefghijklmompqrstuvwzyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-+' db = esedb.open(self._database) for i in xrange(10000): k = random.choice(keys) * random.randint(1, 8) ignored = db.nextkey(k) if random.random() < 0.01: # 1% chance of close and reopen db.close() db = esedb.open(self._database) elif random.random() < 0.05: # 5% chance of deleting a key try: del db[k] except KeyError: # the record wasn't there. retrieve all records instead _ = db.keys() elif random.random() < 0.05: # 5% chance of popping a key db.pop(k, 'default') elif random.random() < 0.05: # 5% chance of popping an item try: db.popitem() except KeyError: # dictionary is empty pass else: v = '#' * random.randint(256, 1024) if random.random() < 0.25: db.setdefault(k, v) else: db[k] = v db.close()
def testCloseAndReopenEmptyDatabase(self): db = esedb.open(self._makeDatabasePath('test.edb'), 'n') db.close() db = esedb.open(self._makeDatabasePath('test.edb'), 'r') self.assertEqual(0, len(db)) db.close()
def _randomOperations(self): keys = "abcdefghijklmompqrstuvwzyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-+" db = esedb.open(self._database) for i in xrange(10000): k = random.choice(keys) * random.randint(1, 8) ignored = db.nextkey(k) if random.random() < 0.01: # 1% chance of close and reopen db.close() db = esedb.open(self._database) elif random.random() < 0.05: # 5% chance of deleting a key try: del db[k] except KeyError: # the record wasn't there. retrieve all records instead _ = db.keys() elif random.random() < 0.05: # 5% chance of popping a key db.pop(k, "default") elif random.random() < 0.05: # 5% chance of popping an item try: db.popitem() except KeyError: # dictionary is empty pass else: v = "#" * random.randint(256, 1024) if random.random() < 0.25: db.setdefault(k, v) else: db[k] = v db.close()
def testCloseAndOverwrite(self): db = esedb.open(self._makeDatabasePath("test.edb"), "n") db["stuff"] = "xxxxxx" db.close() db = esedb.open(self._makeDatabasePath("test.edb"), "n") self.assertEqual(False, db.has_key("stuff")) db.close()
def testCloseAndReopenWithCreate(self): db = esedb.open(self._makeDatabasePath("test.edb"), "n") db["jet blue"] = "ese" db.close() db = esedb.open(self._makeDatabasePath("test.edb"), "c") self.assertEqual("ese", db["jet blue"]) db.close()
def testCloseAndOverwrite(self): db = esedb.open(self._makeDatabasePath('test.edb'), 'n') db['stuff'] = 'xxxxxx' db.close() db = esedb.open(self._makeDatabasePath('test.edb'), 'n') self.assertEqual(False, db.has_key('stuff')) db.close()
def testCloseAndReopenWithCreate(self): db = esedb.open(self._makeDatabasePath('test.edb'), 'n') db['jet blue'] = 'ese' db.close() db = esedb.open(self._makeDatabasePath('test.edb'), 'c') self.assertEqual('ese', db['jet blue']) db.close()
def testCloseAndReopenReadOnly(self): db = esedb.open(self._makeDatabasePath("test.edb"), "n") db["jet blue"] = "ese" db.close() db = esedb.open(self._makeDatabasePath("test.edb"), "r") self.assertEqual("ese", db["jet blue"]) self.assertEqual(1, len(db)) db.close()
def testCloseAndReopenReadOnly(self): db = esedb.open(self._makeDatabasePath('test.edb'), 'n') db['jet blue'] = 'ese' db.close() db = esedb.open(self._makeDatabasePath('test.edb'), 'r') self.assertEqual('ese', db['jet blue']) self.assertEqual(1, len(db)) db.close()
def testCloseAndReopenForWrite(self): db = esedb.open(self._makeDatabasePath('test.edb'), 'n') db['jet blue'] = 'ese' db['ese'] = 'jet blue' db.close() db = esedb.open(self._makeDatabasePath('test.edb'), 'w') self.assertEqual('ese', db['jet blue']) self.assertEqual(2, len(db)) db.close()
def testCloseAndReopenForWrite(self): db = esedb.open(self._makeDatabasePath("test.edb"), "n") db["jet blue"] = "ese" db["ese"] = "jet blue" db.close() db = esedb.open(self._makeDatabasePath("test.edb"), "w") self.assertEqual("ese", db["jet blue"]) self.assertEqual(2, len(db)) db.close()
def testMultipleDatabases(self): db1 = esedb.open(self._makeDatabasePath('db1\\test1.edb'), 'n') db2 = esedb.open(self._makeDatabasePath('db2\\test2.edb'), 'c') db1['hello'] = 'world' db2['hello'] = 'there' self.assertEqual('world', db1['hello']) self.assertEqual('there', db2['hello']) db1.close() db2.close()
def testMultipleDatabases(self): db1 = esedb.open(self._makeDatabasePath("db1\\test1.edb"), "n") db2 = esedb.open(self._makeDatabasePath("db2\\test2.edb"), "c") db1["hello"] = "world" db2["hello"] = "there" self.assertEqual("world", db1["hello"]) self.assertEqual("there", db2["hello"]) db1.close() db2.close()
def insertRetrieveTest(): n = 1000000 db = esedb.open(database, 'n', True) data = '0123456789ABCDEF' timer = Stopwatch.StartNew() for i in xrange(n): db[i] = data timer.Stop() print 'Inserted %d records in %s' % (n, timer.Elapsed) (k, v) = db.first() timer = Stopwatch.StartNew() for i in xrange(n): data = db[k] timer.Stop() print 'Retrieved 1 record %d times in %s' % (n, timer.Elapsed) timer = Stopwatch.StartNew() i = 0 for (k, v) in db: i += 1 timer.Stop() print 'Scanned %d records in %s' % (i, timer.Elapsed) keys = db.keys() random.shuffle(keys) timer = Stopwatch.StartNew() for k in keys: v = db[k] timer.Stop() print 'Retrieved %d records in %s' % (len(keys), timer.Elapsed) db.close()
def insertRetrieveTest(): n = 1000000 db = esedb.open(database, 'n', True) data = '0123456789ABCDEF' timer = Stopwatch.StartNew() for i in xrange(n): db[i] = data timer.Stop() print 'Inserted %d records in %s' % (n, timer.Elapsed) (k,v) = db.first() timer = Stopwatch.StartNew() for i in xrange(n): data = db[k] timer.Stop() print 'Retrieved 1 record %d times in %s' % (n, timer.Elapsed) timer = Stopwatch.StartNew() i = 0 for (k,v) in db: i += 1 timer.Stop() print 'Scanned %d records in %s' % (i, timer.Elapsed) keys = db.keys() random.shuffle(keys) timer = Stopwatch.StartNew() for k in keys: v = db[k] timer.Stop() print 'Retrieved %d records in %s' % (len(keys), timer.Elapsed) db.close()
def _retrieveAllRecords(self, n): """Check that k=v for all records and there are n records""" db = esedb.open(self._database, lazyupdate=True) self.assertEquals(n, len(db)) for k,v in db.iteritems(): self.assertEquals(k, v) db.close()
def _retrieveAllRecords(self, n): """Check that k=v for all records and there are n records""" db = esedb.open(self._database) self.assertEqual(n, len(db)) for k, v in db.iteritems(): self.assertEqual(k, v) db.close()
def setUp(self): self._dataDirectory = 'unittest_data' self._deleteDataDirectory() self._db = esedb.open(self._makeDatabasePath('test.edb'), lazyupdate=True) self._db['d'] = '4' self._db['a'] = '1' self._db['c'] = '3' self._db['b'] = '2'
def _popAllItems(self): db = esedb.open(self._database) try: while True: db.popitem() except KeyError: pass db.close()
def retrieveTest(keys): db = esedb.open(database, 'r') timer = Stopwatch.StartNew() for x in keys: data = db[x] timer.Stop() db.close() return timer.Elapsed
def setUp(self): self._dataDirectory = "unittest_data" self._deleteDataDirectory() self._db = esedb.open(self._makeDatabasePath("test.edb")) self._db["d"] = "4" self._db["a"] = "1" self._db["c"] = "3" self._db["b"] = "2"
def setUp(self): self._dataDirectory = 'unittest_data' self._deleteDataDirectory() self._db = esedb.open(self._makeDatabasePath('test.edb')) self._db['d'] = '4' self._db['a'] = '1' self._db['c'] = '3' self._db['b'] = '2'
def _randomOperations(self): keys = 'abcdefghijklmompqrstuvwzyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-+' db = esedb.open(self._database, lazyupdate=True) for i in xrange(10000): k = random.choice(keys) * random.randint(1,8) if random.random() < 0.01: db.close() db = esedb.open(self._database, lazyupdate=True) elif random.random() < 0.10: try: del db[k] except KeyError: # the record wasn't there. retrieve all records instead _ = db.keys() else: v = '#' * random.randint(256,1024) db[k] = v db.close()
def scanTest(): db = esedb.open(database, 'r') timer = Stopwatch.StartNew() i = 0 for (k,v) in db: i += 1 timer.Stop() db.close() return timer.Elapsed
def repeatedRetrieveTest(numretrieves): db = esedb.open(database, 'r') (key, data) = db.first() timer = Stopwatch.StartNew() for i in xrange(0, numretrieves): data = db[key] timer.Stop() db.close() return timer.Elapsed
def insertTest(keys): db = esedb.open(database, 'n', True) data = 'XXXXXXXXXXXXXXXX' timer = Stopwatch.StartNew() for x in keys: db[x] = data timer.Stop() db.close() return timer.Elapsed
def scanTest(): db = esedb.open(database, 'r') timer = Stopwatch.StartNew() i = 0 for (k, v) in db: i += 1 timer.Stop() db.close() return timer.Elapsed
def testMultipleCursors(self): db1 = esedb.open(self._makeDatabasePath('test.edb'), 'ns') db2 = esedb.open(self._makeDatabasePath('test.edb'), 'cf') db3 = esedb.open(self._makeDatabasePath('test.edb'), 'w') db_ro = esedb.open(self._makeDatabasePath('test.edb'), 'r') db1['foo'] = 123 db2['bar'] = 456 db3['baz'] = 789 db1.close() db3.close() self.assertEqual(['bar', 'baz', 'foo'], db2.keys()) self.assertEqual(['456', '789', '123'], db_ro.values()) db2['foo'] = 'xyzzy' db2.close() self.assertEqual('xyzzy', db_ro['foo']) self.assertEqual(3, len(db_ro)) db_ro.close()
def testMultipleCursors(self): db1 = esedb.open(self._makeDatabasePath("test.edb"), "ns") db2 = esedb.open(self._makeDatabasePath("test.edb"), "cf") db3 = esedb.open(self._makeDatabasePath("test.edb"), "w") db_ro = esedb.open(self._makeDatabasePath("test.edb"), "r") db1["foo"] = 123 db2["bar"] = 456 db3["baz"] = 789 db1.close() db3.close() self.assertEqual(["bar", "baz", "foo"], db2.keys()) self.assertEqual(["456", "789", "123"], db_ro.values()) db2["foo"] = "xyzzy" db2.close() self.assertEqual("xyzzy", db_ro["foo"]) self.assertEqual(3, len(db_ro)) db_ro.close()
def testMultipleCursors(self): db1 = esedb.open(self._makeDatabasePath('test.edb'), 'n') db2 = esedb.open(self._makeDatabasePath('test.edb'), 'c') db3 = esedb.open(self._makeDatabasePath('test.edb'), 'w') db_ro = esedb.open(self._makeDatabasePath('test.edb'), 'r') db1['foo'] = 123 db2['bar'] = 456 db3['baz'] = 789 db1.close() db3.close() self.assertEqual(['bar', 'baz', 'foo'], db2.keys()) self.assertEqual(['456', '789', '123'], db_ro.values()) db2['foo'] = 'xyzzy' db2.close() self.assertEqual('xyzzy', db_ro['foo']) self.assertEqual(3, len(db_ro)) db_ro.close()
def testMultipleCursorsInsertAndDelete(self): db1 = esedb.open(self._makeDatabasePath('test.edb'), 'n') db2 = esedb.open(self._makeDatabasePath('test.edb'), 'cs') db3 = esedb.open(self._makeDatabasePath('test.edb'), 'wf') db_ro = esedb.open(self._makeDatabasePath('test.edb'), 'r') db1['hello'] = 'world' self.assertEqual('world', db1['hello']) self.assertEqual('world', db2['hello']) self.assertEqual('world', db3['hello']) self.assertEqual('world', db_ro['hello']) del db3['hello'] self.assertEqual(False, db1.has_key('hello')) self.assertEqual(False, db2.has_key('hello')) self.assertEqual(False, db3.has_key('hello')) self.assertEqual(False, db_ro.has_key('hello')) db1.close() db2.close() db3.close() db_ro.close()
def testMultipleCursorsInsertAndDelete(self): db1 = esedb.open(self._makeDatabasePath("test.edb"), "n") db2 = esedb.open(self._makeDatabasePath("test.edb"), "cs") db3 = esedb.open(self._makeDatabasePath("test.edb"), "wf") db_ro = esedb.open(self._makeDatabasePath("test.edb"), "r") db1["hello"] = "world" self.assertEqual("world", db1["hello"]) self.assertEqual("world", db2["hello"]) self.assertEqual("world", db3["hello"]) self.assertEqual("world", db_ro["hello"]) del db3["hello"] self.assertEqual(False, db1.has_key("hello")) self.assertEqual(False, db2.has_key("hello")) self.assertEqual(False, db3.has_key("hello")) self.assertEqual(False, db_ro.has_key("hello")) db1.close() db2.close() db3.close() db_ro.close()
def testMultipleCursorsInsertAndDelete(self): db1 = esedb.open(self._makeDatabasePath('test.edb'), 'n') db2 = esedb.open(self._makeDatabasePath('test.edb'), 'c') db3 = esedb.open(self._makeDatabasePath('test.edb'), 'w') db_ro = esedb.open(self._makeDatabasePath('test.edb'), 'r') db1['hello'] = 'world' self.assertEqual('world', db1['hello']) self.assertEqual('world', db2['hello']) self.assertEqual('world', db3['hello']) self.assertEqual('world', db_ro['hello']) del db3['hello'] self.assertEqual(False, db1.has_key('hello')) self.assertEqual(False, db2.has_key('hello')) self.assertEqual(False, db3.has_key('hello')) self.assertEqual(False, db_ro.has_key('hello')) db1.close() db2.close() db3.close() db_ro.close()
def _deleteRange(self, low, high): db = esedb.open(self._database, lazyupdate=True) for i in xrange(low, high): del db[i] db.close()
def _insertRange(self, low, high): db = esedb.open(self._database, lazyupdate=True) for i in xrange(low, high): db[i] = i db.close()
def setUp(self): self._dataDirectory = 'unittest_data' self._deleteDataDirectory() self._database = self._makeDatabasePath('test.edb') self._db = esedb.open(self._database, lazyupdate=True)
def _openDatabase(self): self._db = esedb.open(self._makeDatabasePath('test.edb'))
def setUp(self): self._dataDirectory = 'unittest_data' self._deleteDataDirectory() self._database = self._makeDatabasePath('test.edb') self._db = esedb.open(self._database)
def _insertRange(self, low, high): db = esedb.open(self._database) for i in xrange(low, high): db[i] = i db.close()
def _setdefaultRange(self, low, high): db = esedb.open(self._database) for i in xrange(low, high): db.setdefault(i, i) db.close()
def _deleteRange(self, low, high): db = esedb.open(self._database) for i in xrange(low, high): del db[i] db.close()
def _popRange(self, low, high): db = esedb.open(self._database) for i in xrange(low, high): db.pop(i) db.close()
def __init__(self, filename, flag='cf', protocol=None, writeback=False): shelve.Shelf.__init__(self, esedb.open(filename, flag), protocol, writeback)
def testCloseTwice(self): db = esedb.open(self._makeDatabasePath('test.edb')) db.close() db.close()