예제 #1
0
    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()
예제 #2
0
 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()
예제 #3
0
	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()		
예제 #4
0
    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()
예제 #5
0
 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()
예제 #6
0
    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()
예제 #7
0
    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()
예제 #8
0
    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()
예제 #9
0
	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()
예제 #10
0
	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()
예제 #11
0
    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()
예제 #12
0
    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()
예제 #13
0
    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()
예제 #14
0
	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()
예제 #15
0
	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()
예제 #16
0
    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()
예제 #17
0
    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()
예제 #18
0
	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()
예제 #19
0
    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()
예제 #20
0
    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()
예제 #21
0
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()
예제 #22
0
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()
예제 #23
0
	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()
예제 #24
0
 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()
예제 #25
0
	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'
예제 #26
0
 def _popAllItems(self):
     db = esedb.open(self._database)
     try:
         while True:
             db.popitem()
     except KeyError:
         pass
     db.close()
예제 #27
0
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
예제 #28
0
 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"
예제 #29
0
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
예제 #30
0
 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'
예제 #31
0
 def _popAllItems(self):
     db = esedb.open(self._database)
     try:
         while True:
             db.popitem()
     except KeyError:
         pass
     db.close()
예제 #32
0
	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()
예제 #33
0
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
예제 #34
0
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
예제 #35
0
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
예제 #36
0
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
예제 #37
0
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
예제 #38
0
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
예제 #39
0
    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()
예제 #40
0
    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()
예제 #41
0
	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()
예제 #42
0
    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()
예제 #43
0
    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()
예제 #44
0
	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()
예제 #45
0
	def _deleteRange(self, low, high):
		db = esedb.open(self._database, lazyupdate=True)
		for i in xrange(low, high):
			del db[i]
		db.close()
예제 #46
0
	def _insertRange(self, low, high):
		db = esedb.open(self._database, lazyupdate=True)
		for i in xrange(low, high):
			db[i] = i
		db.close()
예제 #47
0
	def setUp(self):
		self._dataDirectory = 'unittest_data'
		self._deleteDataDirectory()
		self._database = self._makeDatabasePath('test.edb')
		self._db = esedb.open(self._database, lazyupdate=True)
예제 #48
0
 def _openDatabase(self):
     self._db = esedb.open(self._makeDatabasePath('test.edb'))
예제 #49
0
 def setUp(self):
     self._dataDirectory = 'unittest_data'
     self._deleteDataDirectory()
     self._database = self._makeDatabasePath('test.edb')
     self._db = esedb.open(self._database)
예제 #50
0
 def _insertRange(self, low, high):
     db = esedb.open(self._database)
     for i in xrange(low, high):
         db[i] = i
     db.close()
예제 #51
0
 def _setdefaultRange(self, low, high):
     db = esedb.open(self._database)
     for i in xrange(low, high):
         db.setdefault(i, i)
     db.close()
예제 #52
0
 def _deleteRange(self, low, high):
     db = esedb.open(self._database)
     for i in xrange(low, high):
         del db[i]
     db.close()
예제 #53
0
 def _popRange(self, low, high):
     db = esedb.open(self._database)
     for i in xrange(low, high):
         db.pop(i)
     db.close()
예제 #54
0
 def __init__(self, filename, flag='cf', protocol=None, writeback=False):
     shelve.Shelf.__init__(self, esedb.open(filename, flag), protocol,
                           writeback)
예제 #55
0
 def testCloseTwice(self):
     db = esedb.open(self._makeDatabasePath('test.edb'))
     db.close()
     db.close()