示例#1
0
 def _create_dba(self, dbpath, shape, dtype):
     """ Initialize a `DBArray` with provided information.
     """
     dba = DBArray(dbpath, self.DBTYPE)
     dba.set_shape(shape)
     dba.set_dtype(dtype)
     return dba
示例#2
0
    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)