def testSetErrhandler(self): global error_count hamsterdb.set_errhandler(my_error_handler) error_count = 0 try: hamsterdb.env().open("asxxxldjf") except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_FILE_NOT_FOUND == errno
class LibraryTestCase(unittest.TestCase): def testGetVersion(self): print "version: ", hamsterdb.get_version() def testIsPro(self): print "is_pro: ", hamsterdb.is_pro() def testIsDebug(self): print "is_debug: ", hamsterdb.is_debug() def testIsProEvaluation(self): print "is_pro_evaluation: ", hamsterdb.is_pro_evaluation() def testSetErrhandler(self): global error_count hamsterdb.set_errhandler(my_error_handler) error_count = 0 try: hamsterdb.env().open("asxxxldjf") except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_FILE_NOT_FOUND == errno assert error_count == 1 hamsterdb.set_errhandler(None) error_count = 0 try: hamsterdb.env().open("asxxxldjf") except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_FILE_NOT_FOUND == errno
def testEraseDbNegative(self): env = hamsterdb.env() env.create("test.db") try: env.erase_db(1) except hamsterdb.error, (errno, message): assert hamsterdb.HAM_DATABASE_NOT_FOUND == errno
def testBeginAbort(self): env = hamsterdb.env() env.create("test.db", hamsterdb.HAM_ENABLE_TRANSACTIONS) db = env.create_db(1) txn = hamsterdb.txn(env) txn.abort() db.close()
def testSetCompareFuncNegative(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) try: db.set_compare_func(self.callbackCompare1) except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_INV_PARAMETER == errno
def testInsertRecno(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1, hamsterdb.HAM_RECORD_NUMBER) db.insert(None, "key1", "value") db.insert(None, 5, "value") db.insert(None, None, "value") db.close()
def testGetDatabaseNamesNegative(self): env = hamsterdb.env() env.create("test.db") try: n = env.get_database_names(4) except TypeError: pass env.close()
def testCreateDbNegative(self): env = hamsterdb.env() env.create("test.db") try: db = env.create_db(0) db.close() except hamsterdb.error, (errno, message): assert hamsterdb.HAM_INV_PARAMETER == errno
def testEraseNegative(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) try: db.find(None, "key1") except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_KEY_NOT_FOUND == errno
def testCreateInMemory(self): self.remove_file("test.db") env = hamsterdb.env() env.create("", hamsterdb.HAM_IN_MEMORY) env.close() env.create(None, hamsterdb.HAM_IN_MEMORY) env.close() assert(os.path.isfile("test.db") == False)
def testClone(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) c = hamsterdb.cursor(db) clone = c.clone() c.close() clone.close() db.close()
def testOpenDbNegative(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) db.close() try: db = env.open_db(5) except hamsterdb.error, (errno, message): assert hamsterdb.HAM_DATABASE_NOT_FOUND == errno
def testGetOverwrite(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) c = hamsterdb.cursor(db) try: c.overwrite("asdf") except hamsterdb.error, (errno, string): assert hamsterdb.HAM_CURSOR_IS_NIL == errno
def testGetRecordNegative(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) c = hamsterdb.cursor(db) try: c.get_record() except hamsterdb.error, (errno, string): assert hamsterdb.HAM_CURSOR_IS_NIL == errno
def testRenameDb(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) db.close() env.rename_db(1, 2) db = env.open_db(2) db.close() env.close()
def testInsertNegative(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) db.insert(None, "key1", "value") try: db.insert(None, "key1", "value") except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_DUPLICATE_KEY == errno
def testGetDuplicateCountNegative(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1, hamsterdb.HAM_ENABLE_DUPLICATE_KEYS) c = hamsterdb.cursor(db) try: c.get_duplicate_count() except hamsterdb.error, (errno, string): assert hamsterdb.HAM_CURSOR_IS_NIL == errno
def testFind(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) db.insert(None, "key1", "value1") db.insert(None, "key2", "value2", 0) assert "value1" == db.find(None, "key1") assert "value2" == db.find(None, "key2") db.close()
def testOpenExtended(self): env = hamsterdb.env() # TODO if i remove (0,0), a TypeError exception is thrown try: env.open("test.db", 0, \ ((hamsterdb.HAM_PARAM_CACHESIZE, 20), (0, 0))) env.close() except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_FILE_NOT_FOUND == errno
def testInsert(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1, hamsterdb.HAM_ENABLE_DUPLICATE_KEYS) db.insert(None, "key1", "value") db.insert(None, "key2", "value", 0) db.insert(None, "key1", "value", hamsterdb.HAM_OVERWRITE) db.insert(None, "key1", "value", hamsterdb.HAM_DUPLICATE) db.close() env.close()
def testCreateNegative(self): env = hamsterdb.env() try: env.create("test.db", 0, 0644, "asdf") except TypeError: pass try: env.create("test.db", 9999) except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_INV_PARAMETER == errno
def testOpenNegative(self): self.remove_file("test.db") env = hamsterdb.env() try: env.open("test.db", 0, "asdf") except TypeError: pass try: env.open("test.db", hamsterdb.HAM_IN_MEMORY) except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_INV_PARAMETER == errno
def testCreate(self): env = hamsterdb.env() self.remove_file("test.db") env.create("test.db") env.close() assert(os.path.isfile("test.db")) env.create("test.db", 0) env.close() env.create("test.db", 0, 0644) env.close() assert(os.path.isfile("test.db"))
def testCreateDbParam(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(3, hamsterdb.HAM_RECORD_NUMBER64) db.close() db = env.open_db(3) db.close() db = env.create_db(4, 0, ((hamsterdb.HAM_PARAM_KEYSIZE, 20), (0,0))) db.close() db = env.open_db(4) db.close() env.close()
def testFindNegative(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) db.insert(None, "key1", "value1") db.insert(None, "key2", "value2") db.insert(None, "key3", "value3") c = hamsterdb.cursor(db) try: c.find("key4") except hamsterdb.error, (errno, string): assert hamsterdb.HAM_KEY_NOT_FOUND == errno
def testCloneNegative(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) c = hamsterdb.cursor(db) try: clone = c.clone(13) except TypeError: pass c.close() db.close() env.close()
def testErase(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) c = hamsterdb.cursor(db) c.insert("key1", "value1") assert "key1" == c.get_key() assert "value1" == c.get_record() c.erase() try: c.find("key1") except hamsterdb.error, (errno, string): assert hamsterdb.HAM_KEY_NOT_FOUND == errno
def testSetCompareFuncExcept(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1, 0, \ ((hamsterdb.HAM_PARAM_KEY_TYPE, hamsterdb.HAM_TYPE_CUSTOM), (0, 0))) db.set_compare_func(self.callbackCompare2) try: db.insert(None, "1", "value") db.insert(None, "2", "value") except ZeroDivisionError: pass db.close()
def testMoveTo(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(1) db.insert(None, "key1", "value1") db.insert(None, "key2", "value2") db.insert(None, "key3", "value3") c = hamsterdb.cursor(db) c.move_to(hamsterdb.HAM_CURSOR_FIRST) c.move_to(hamsterdb.HAM_CURSOR_NEXT) c.move_to(hamsterdb.HAM_CURSOR_LAST) c.close() db.close() env.close()
def testBeginCommit(self): env = hamsterdb.env() env.create("test.db", hamsterdb.HAM_ENABLE_TRANSACTIONS) db = env.create_db(1) txn = hamsterdb.txn(env) db.insert(txn, "key1", "value1") db.insert(txn, "key2", "value2") db.insert(txn, "key3", "value3") db.erase(txn, "key1") db.erase(txn, "key2") try: db.find(txn, "key1") except hamsterdb.error, (errno, strerror): assert hamsterdb.HAM_KEY_NOT_FOUND == errno
def testRecnoReopen(self): env = hamsterdb.env() env.create("test.db") db = env.create_db(3, hamsterdb.HAM_RECORD_NUMBER) db.insert(None, "key1", "value") db.insert(None, 5, "value") db.insert(None, None, "value") db.close() db = env.open_db(3) db.insert(None, None, "value") #c = hamsterdb.cursor(db) #c.find(4) #assert 4 == c.get_key() db.close() env.close()