Пример #1
0
    def testReadHDF5Execution(self):
        test_array = np.random.RandomState(0).rand(20, 10)
        group_name = 'test_group'
        dataset_name = 'test_dataset'

        with self.assertRaises(TypeError):
            fromhdf5(object())

        with tempfile.TemporaryDirectory() as d:
            filename = os.path.join(
                d, 'test_read_{}.hdf5'.format(int(time.time())))
            with h5py.File(filename, 'w') as f:
                g = f.create_group(group_name)
                g.create_dataset(dataset_name, chunks=(7, 4), data=test_array)

            # test filename
            r = fromhdf5(filename, group=group_name, dataset=dataset_name)

            result = self.executor.execute_tensor(r, concat=True)[0]
            np.testing.assert_array_equal(result, test_array)
            self.assertEqual(r.extra_params['raw_chunk_size'], (7, 4))

            with self.assertRaises(ValueError):
                fromhdf5(filename)

            with self.assertRaises(ValueError):
                fromhdf5(filename, dataset='non_exist')

            with h5py.File(filename, 'r') as f:
                # test file
                r = fromhdf5(f, group=group_name, dataset=dataset_name)

                result = self.executor.execute_tensor(r, concat=True)[0]
                np.testing.assert_array_equal(result, test_array)

                with self.assertRaises(ValueError):
                    fromhdf5(f)

                with self.assertRaises(ValueError):
                    fromhdf5(f, dataset='non_exist')

                # test dataset
                ds = f['{}/{}'.format(group_name, dataset_name)]
                r = fromhdf5(ds)

                result = self.executor.execute_tensor(r, concat=True)[0]
                np.testing.assert_array_equal(result, test_array)
Пример #2
0
def test_read_hdf5_execution(setup):
    test_array = np.random.RandomState(0).rand(20, 10)
    group_name = 'test_group'
    dataset_name = 'test_dataset'

    with pytest.raises(TypeError):
        fromhdf5(object())

    with tempfile.TemporaryDirectory() as d:
        filename = os.path.join(d, f'test_read_{int(time.time())}.hdf5')
        with h5py.File(filename, 'w') as f:
            g = f.create_group(group_name)
            g.create_dataset(dataset_name, chunks=(7, 4), data=test_array)

        # test filename
        r = fromhdf5(filename, group=group_name, dataset=dataset_name)

        result = r.execute().fetch()
        np.testing.assert_array_equal(result, test_array)
        assert r.extra_params['raw_chunk_size'] == (7, 4)

        with pytest.raises(ValueError):
            fromhdf5(filename)

        with pytest.raises(ValueError):
            fromhdf5(filename, dataset='non_exist')

        with h5py.File(filename, 'r') as f:
            # test file
            r = fromhdf5(f, group=group_name, dataset=dataset_name)

            result = r.execute().fetch()
            np.testing.assert_array_equal(result, test_array)

            with pytest.raises(ValueError):
                fromhdf5(f)

            with pytest.raises(ValueError):
                fromhdf5(f, dataset='non_exist')

            # test dataset
            ds = f[f'{group_name}/{dataset_name}']
            r = fromhdf5(ds)

            result = r.execute().fetch()
            np.testing.assert_array_equal(result, test_array)