Beispiel #1
0
 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
Beispiel #2
0
 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
Beispiel #3
0
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
Beispiel #4
0
 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
Beispiel #5
0
 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()
Beispiel #6
0
 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
Beispiel #7
0
 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()
Beispiel #8
0
 def testGetDatabaseNamesNegative(self):
   env = hamsterdb.env()
   env.create("test.db")
   try:
     n = env.get_database_names(4)
   except TypeError:
     pass
   env.close()
Beispiel #9
0
 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
Beispiel #10
0
 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
Beispiel #11
0
 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)
Beispiel #12
0
 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()
Beispiel #13
0
 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
Beispiel #14
0
 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
Beispiel #15
0
 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
Beispiel #16
0
 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()
Beispiel #17
0
 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
Beispiel #18
0
 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
Beispiel #19
0
 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
Beispiel #20
0
 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
Beispiel #21
0
 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()
Beispiel #22
0
 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()
Beispiel #23
0
 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
Beispiel #24
0
 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()
Beispiel #25
0
 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
Beispiel #26
0
 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
Beispiel #27
0
 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"))
Beispiel #28
0
 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()
Beispiel #29
0
 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
Beispiel #30
0
 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()
Beispiel #31
0
 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
Beispiel #32
0
 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
Beispiel #33
0
  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()
Beispiel #34
0
 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()
Beispiel #35
0
 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
Beispiel #36
0
 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()