def test_multi_handle(self): """ Test the case of open multiple handle for the same database. This test is for: https://github.com/wanji/dbarray/issues/1 """ dbpath = os.path.join(self.tempdir, self.DBTYPE, 'test_multi_handle.db') for idx in range(2): # Create random array nrows = 1 ncols = 5 dtype = np.float32 arr = np.random.random((nrows, ncols)) arr = np.require(arr, dtype) """ `DBArray` from scratch """ # Create `DBArray` dba1 = DBArray(dbpath) # Initialize dba1.set_shape((nrows, ncols)) dba1.set_dtype(dtype) # Set rows dba1[:] = arr[:] # Convert to ndarray dba1.tondarray() """ Open exsiting `DBArray` """ # Open another DB dba2 = DBArray(dbpath) dba2.tondarray() # Check if a error rises while accessing closed db dba1._storage.env.close() self.assertRaises(lmdb.Error, dba2.tondarray)
def test_from_and_to(self): for key, val in self.commdbs.iteritems(): dbpath = os.path.join(self.tempdir, self.DBTYPE, 'test_from_%s.db' % key) dba = DBArray.fromndarray(val, dbpath, self.DBTYPE) self._info_eq(dba, val) arr = dba.tondarray() self._arr_eq(arr, val) # cloase and re-open del dba dba = DBArray(dbpath, self.DBTYPE) self._info_eq(dba, val) arr = dba.tondarray() self._arr_eq(arr, val)