Commits

Maciej Fijalkowski  committed c003cd1

some tests and some fixes

  • Participants
  • Parent commits 590bbc7

Comments (0)

Files changed (2)

File lib-python/2.7/test/test_gdbm.py

         size2 = os.path.getsize(filename)
         self.assertTrue(size1 > size2 >= size0)
 
+    def test_sync(self):
+        # check if sync works at all, not sure how to check it
+        self.g = gdbm.open(filename, 'cf')
+        self.g['x'] = 'x' * 10000
+        self.g.sync()
+
+    def test_get_key(self):
+        self.g = gdbm.open(filename, 'cf')
+        self.g['x'] = 'x' * 10000
+        self.g.close()
+        self.g = gdbm.open(filename, 'r')
+        self.assertEquals(self.g['x'], 'x' * 10000)
 
 def test_main():
     run_unittest(TestGdbm)

File lib_pypy/gdbm.py

 
 datum gdbm_firstkey(void*);
 datum gdbm_nextkey(void*, datum);
+void gdbm_sync(void*);
 
 char* gdbm_strerror(int);
 int gdbm_errno;
     ll_dbm = None
     
     def __init__(self, filename, iflags, mode):
-        self.size = -1
         res = lib.gdbm_open(filename, 0, iflags, mode, ffi.NULL)
         if not res:
             self._raise_from_errno()
         drec = lib.gdbm_fetch(self.ll_dbm, _fromstr(key))
         if not drec.dptr:
             raise KeyError(key)
-        res = ffi.string(drec.dptr, drec.size)
+        res = ffi.string(drec.dptr, drec.dsize)
         lib.free(drec.dptr)
         return res
 
 
     __del__ = close
 
+    def sync(self):
+        self._check_closed()
+        lib.gdbm_sync(self.ll_dbm)
+
 def open(filename, flags='r', mode=0666):
     if flags[0] == 'r':
         iflags = lib.GDBM_READER