Exemplo n.º 1
0
def test_data(comm):

    with temporary_data() as (data, tmpfile):

        # read
        f = HDFFile(tmpfile, header='Header')

        # check columns
        cols = ['X/Mass', 'X/Position', 'Y/Mass', 'Y/Position']
        assert (all(col in cols for col in f.columns))

        assert f.attrs['Value'] == 333

        # make sure data is the same
        for col in cols:
            field = col.rsplit('/', 1)[-1]
            numpy.testing.assert_almost_equal(data[field], f[col][:])

        # try a slice
        data2 = f.read(cols, 0, 512, 1)
        for col in cols:
            field = col.rsplit('/', 1)[-1]
            numpy.testing.assert_almost_equal(data[field][:512], data2[col])

        # check size
        numpy.testing.assert_equal(f.size, 1024)
Exemplo n.º 2
0
def test_data(comm):

    with temporary_data() as (data, tmpfile):

        # read
        f = HDFFile(tmpfile, header='Header')

        # check columns
        cols = ['X/Mass', 'X/Position', 'Y/Mass', 'Y/Position']
        assert(all(col in cols for col in f.columns))

        assert f.attrs['Value'] == 333

        # make sure data is the same
        for col in cols:
            field = col.rsplit('/', 1)[-1]
            numpy.testing.assert_almost_equal(data[field], f[col][:])
            
        # try a slice
        data2 = f.read(cols, 0, 512, 1)
        for col in cols:
            field = col.rsplit('/', 1)[-1]
            numpy.testing.assert_almost_equal(data[field][:512], data2[col])

        # check size
        numpy.testing.assert_equal(f.size, 1024)
Exemplo n.º 3
0
def test_nonzero_root(comm):

    with temporary_data() as (data, tmpfile):

        # read
        f = HDFFile(tmpfile, dataset='Y')

        # non-zero root
        f = HDFFile(tmpfile, dataset='Y')
        assert (all(col in ['Mass', 'Position'] for col in f.columns))

        # wrong root
        with pytest.raises(ValueError):
            f = HDFFile(tmpfile, dataset='Z')
Exemplo n.º 4
0
def test_nonzero_exclude(comm):

    with temporary_data() as (data, tmpfile):

        # read
        f = HDFFile(tmpfile, exclude=['Y', 'Header'])

        # non-zero exclude
        f = HDFFile(tmpfile, exclude=['Y', 'Header'])
        assert (all(col in ['Mass', 'Position'] for col in f.columns))

        # non-zero exclude and root
        f = HDFFile(tmpfile, exclude=['Mass'], dataset='Y')
        assert all(col in ['Position'] for col in f.columns)

        # bad exclude
        with pytest.raises(ValueError):
            f = HDFFile(tmpfile, exclude=['Z'])
Exemplo n.º 5
0
def test_empty(comm):

    # create empty file
    tmpfile = tempfile.mkstemp()[1]
    with h5py.File(tmpfile, 'w') as ff:
        ff.create_group('Y')

    # no datasets!
    with pytest.raises(ValueError):
        f = HDFFile(tmpfile)

    os.unlink(tmpfile)
Exemplo n.º 6
0
def test_data_mismatch(comm):

    # generate data
    pos = numpy.random.random(size=(1024, 3))
    mass = numpy.random.random(size=512)

    # write to file
    tmpfile = tempfile.mkstemp()[1]
    with h5py.File(tmpfile, 'w') as ff:
        ff.create_dataset('Mass', data=mass)
        ff.create_dataset('Position', data=pos)

    # fails due to mismatched sizes
    with pytest.raises(ValueError):
        f = HDFFile(tmpfile)

    # only one dataset now, so this works
    f = HDFFile(tmpfile, exclude=['Mass'])
    assert f.size == 1024

    os.unlink(tmpfile)