Beispiel #1
0
 def test_tmp(self, tmpdir):
     filename = str(tmpdir) + "/test.file"
     f = FileBased(file_name=filename, mode='a', tmpdir='/tmp')
     assert not os.path.isfile(filename)
     assert os.path.isfile(f.tmp_file_name)
     f.close()
     assert os.path.isfile(filename)
     assert not os.path.isfile(f.tmp_file_name)
Beispiel #2
0
    def test_load(self, tmpdir):
        with FileBased(file_name=str(tmpdir) + '/test.h5') as f:
            f.meta.test = 'test'
            f.meta.test2 = 1

        with FileBased(file_name=str(tmpdir) + '/test.h5', mode='r') as f:
            assert f.meta.test == 'test'
            assert f.meta.test2 == 1

            with pytest.raises(t.FileModeError):
                f.meta.test = 'foo'

            with pytest.raises(t.FileModeError):
                f.meta['test'] = 'foo'
Beispiel #3
0
 def test_tmp_with(self, tmpdir):
     filename = str(tmpdir) + "/test.file"
     with FileBased(file_name=filename, mode='a', tmpdir='/tmp') as f:
         assert not os.path.isfile(filename)
         assert os.path.isfile(f.tmp_file_name)
     assert os.path.isfile(filename)
     assert not os.path.isfile(f.tmp_file_name)
Beispiel #4
0
    def test_read_only(self, tmpdir):
        f = FileBased(str(tmpdir) + "/test.file")
        f.file.create_table("/", "test1", {'a': t.Int32Col()})
        f.close()

        r = FileBased(str(tmpdir) + "/test.file", mode='r')
        with pytest.raises(t.FileModeError):
            r.file.create_table("/", "test2", {'b': t.Int32Col()})
        r.close()
Beispiel #5
0
 def test_tmp_with_exception(self, tmpdir):
     filename = str(tmpdir) + "/test.file"
     with pytest.raises(Exception):
         with FileBased(file_name=filename, mode='a', tmpdir='/tmp') as f:
             assert not os.path.isfile(filename)
             assert os.path.isfile(f.tmp_file_name)
             try:
                 raise Exception
             finally:
                 assert not os.path.isfile(filename)
                 assert not os.path.isfile(f.tmp_file_name)
Beispiel #6
0
    def test_create(self):
        with FileBased() as f:
            f.meta.test = 'test'
            assert f.meta.test == 'test'

            f.meta['test2'] = 1
            assert f.meta['test2'] == 1

            assert f.meta._classid == 'FILEBASED'

            with pytest.raises(AttributeError):
                _ = f.meta.foo

            with pytest.raises(KeyError):
                _ = f.meta['foo']
Beispiel #7
0
 def test_tmp_with_existing(self, tmpdir):
     filename = str(tmpdir) + "/test.file"
     f = FileBased(str(tmpdir) + "/test.file")
     f.file.create_table("/", "test1", {'a': t.Int32Col()})
     f.close()
     assert os.path.isfile(filename)
     with FileBased(file_name=filename, mode='a', tmpdir='/tmp') as f:
         f.file.create_table("/", "test2", {'b': t.Int32Col()})
         assert os.path.isfile(f.tmp_file_name)
     assert os.path.isfile(filename)
     assert not os.path.isfile(f.tmp_file_name)
     with FileBased(file_name=filename, mode='r') as f:
         assert 'test1' in f.file.root
         assert 'test2' in f.file.root