|
13 | 13 | from skypy.pipeline import Pipeline |
14 | 14 | from skypy.pipeline._items import Call, Ref |
15 | 15 |
|
| 16 | +try: |
| 17 | + import h5py # noqa |
| 18 | +except ImportError: |
| 19 | + HAS_H5PY = False |
| 20 | +else: |
| 21 | + HAS_H5PY = True |
| 22 | + |
16 | 23 |
|
17 | 24 | def test_pipeline(): |
18 | 25 |
|
@@ -44,13 +51,7 @@ def test_pipeline(): |
44 | 51 | with fits.open(output_filename) as hdu: |
45 | 52 | assert np.all(Table(hdu['test_table'].data) == pipeline['test_table']) |
46 | 53 |
|
47 | | - # Test hdf5 |
48 | | - hdf5_filename = 'output.hdf5' |
49 | | - pipeline.write(hdf5_filename) |
50 | | - hdf5_table = read_table_hdf5(hdf5_filename, 'tables/test_table', character_as_bytes=False) |
51 | | - assert np.all(hdf5_table == pipeline['test_table']) |
52 | | - |
53 | | - # Test invalid extensions |
| 54 | + # Test invalid file extension |
54 | 55 | with pytest.raises(ValueError): |
55 | 56 | pipeline.write('output.invalid') |
56 | 57 |
|
@@ -249,8 +250,30 @@ def value_in_cm(q): |
249 | 250 | np.testing.assert_array_less(pipeline['test_table.lengths_in_cm'], 100) |
250 | 251 |
|
251 | 252 |
|
| 253 | +@pytest.mark.skipif(not HAS_H5PY, reason='Requires h5py') |
| 254 | +def test_hdf5(): |
| 255 | + size = 100 |
| 256 | + string = size*'a' |
| 257 | + config = {'tables': { |
| 258 | + 'test_table': { |
| 259 | + 'column1': Call(np.random.uniform, [], { |
| 260 | + 'size': size}), |
| 261 | + 'column2': Call(np.random.uniform, [], { |
| 262 | + 'low': Ref('test_table.column1')}), |
| 263 | + 'column3': Call(list, [string], {})}}} |
| 264 | + |
| 265 | + pipeline = Pipeline(config) |
| 266 | + pipeline.execute() |
| 267 | + pipeline.write('output.hdf5') |
| 268 | + hdf_table = read_table_hdf5('output.hdf5', 'table/test_table', character_as_bytes=False) |
| 269 | + assert np.all(hdf_table == pipeline['test_table']) |
| 270 | + |
| 271 | + |
252 | 272 | def teardown_module(module): |
253 | 273 |
|
254 | 274 | # Remove fits file generated in test_pipeline |
255 | 275 | os.remove('output.fits') |
256 | | - os.remove('output.hdf5') |
| 276 | + |
| 277 | + # Remove hdf5 file generated in test_hdf5 |
| 278 | + if HAS_H5PY: |
| 279 | + os.remove('output.hdf5') |
0 commit comments