Example #1
0
class TestWriteAppendable:
    """Test of the _appendable() method."""

    def setup(self):
        # init default parameters
        self.filename = 'test.h5'
        self.group = 'features'
        remove(self.filename)

        # create a simple feature file
        items, times, feat = generate.full(10)
        items2 = [i+'2' for i in items]
        self.data = Data(items, times, feat)
        self.data2 = Data(items2, times, feat)

        self.writer = Writer(self.filename)
        self.writer.write(self.data, self.group)

        # read it with h5py
        self.f = h5py.File(self.filename, 'r')
        self.g = self.f.get(self.group)

    def teardown(self):
        self.f.close()
        remove(self.filename)

    def test_basic_works(self):
        self.data2.is_appendable_to(self.g)

    def test_version(self):
        assert self.g.attrs['version'] == Writer('toto').version
        remove('toto')
Example #2
0
def converter(filein, fileout, version='1.1', groupname='features',verb=False):
    reader = Reader(filein, 'features')
    reed = reader.read()
    if verb:
        print('version readed =', reader.version)
        print('index keys are', list(reader.index.keys()))

    if os.path.exists(fileout):
        os.remove(fileout)

    writer = Writer(fileout, version=version)
    writer.write({'items':reed[0], 'times':reed[1], 'features':reed[2]},
                 groupname=groupname, append=False)
    if verb:
        print('version writed =', writer.version)
        print('index keys are', list(writer.index.keys()))
Example #3
0
 def test_chunk_bad(self):
     args = [0.008 - 1e-2, .0001, 0, -1e30]
     msg = 'chunk size is below 8 Ko'
     for arg in args:
         with pytest.raises(IOError) as err:
             Writer(self.filename, chunk_size=arg)
         assert msg in str(err.value)
Example #4
0
    def setup(self):
        # init default parameters
        self.filename = 'test.h5'
        self.group = 'features'
        remove(self.filename)

        # create a simple feature file
        items, times, feat = generate.full(10)
        items2 = [i + '2' for i in items]
        self.data = Data(items, times, feat)
        self.data2 = Data(items2, times, feat)

        self.writer = Writer(self.filename)
        self.writer.write(self.data, self.group)

        # read it with h5py
        self.f = h5py.File(self.filename, 'r')
        self.g = self.f.get(self.group)
Example #5
0
class TestWrite:
    """test the Writer.write method"""
    def setup(self):
        self.data = generate.full_data(10)
        self.filename = 'test.h5'
        remove(self.filename)
        self.group = 'group'
        self.writer = Writer(self.filename)

    def teardown(self):
        remove(self.filename)

    def test_no_append(self):
        self.writer.write(self.data, self.group, append=False)
        with h5py.File(self.filename, 'r') as f:
            g = f[self.group]
            assert len(g['items'][...]) == 10
            assert not all([(l == 0).all() for l in g['features'][...]])
Example #6
0
class TestWriteAppendable:
    """Test of the _appendable() method.

    This functionnality is removed since h5features-1.2 so this test
    is deprecated...

    """
    def setup(self):
        # init default parameters
        self.filename = 'test.h5'
        self.group = 'features'
        remove(self.filename)

        # create a simple feature file
        items, times, feat = generate.full(10)
        items2 = [i + '2' for i in items]
        self.data = Data(items, times, feat)
        self.data2 = Data(items2, times, feat)

        self.writer = Writer(self.filename)
        self.writer.write(self.data, self.group)

        # read it with h5py
        self.f = h5py.File(self.filename, 'r')
        self.g = self.f.get(self.group)

    def teardown(self):
        self.f.close()
        remove(self.filename)

    def test_basic_works(self):
        self.data2.is_appendable_to(self.g)

    def test_version(self):
        assert self.g.attrs['version'] == Writer('toto').version
        remove('toto')
Example #7
0
    def setup(self):
        # init default parameters
        self.filename = 'test.h5'
        self.group = 'features'
        remove(self.filename)

        # create a simple feature file
        items, times, feat = generate.full(10)
        items2 = [i+'2' for i in items]
        self.data = Data(items, times, feat)
        self.data2 = Data(items2, times, feat)

        self.writer = Writer(self.filename)
        self.writer.write(self.data, self.group)

        # read it with h5py
        self.f = h5py.File(self.filename, 'r')
        self.g = self.f.get(self.group)
Example #8
0
 def test_basic_works(self):
     w = Writer(self.filename)
     w.is_appendable_to(self.g, {'features':self.features,
                              'items':self.items2,
                              'times':self.times})
Example #9
0
 def test_version(self):
     assert self.g.attrs['version'] == Writer('toto').version
     remove('toto')
Example #10
0
 def test_chunk_good(self):
     args = [0.008, 0.01, 12, 1e30]
     for arg in args:
         Writer(self.filename, chunk_size=arg)
Example #11
0
 def test_good_file(self):
     for arg in self.filename, 'abc', 'toto.zip':
         Writer(self.filename)
Example #12
0
def test_create_a_file():
    name = 'azecqgxqsdqxws.eztcqezxf'
    assert not os.path.exists(name)
    Writer(name)
    assert os.path.exists(name)
    remove(name)
Example #13
0
 def setup(self):
     self.data = generate.full_data(10)
     self.filename = 'test.h5'
     remove(self.filename)
     self.group = 'group'
     self.writer = Writer(self.filename)