Beispiel #1
0
 def test_close_on_delete(self):
     writer = hdf5Writer(self.filename, self.file_mode)
     with self.assertRaises(OSError):
         newwriter = hdf5Writer(self.filename, self.file_mode)
     del writer
     newwriter = hdf5Writer(self.filename, self.file_mode)
     del newwriter
Beispiel #2
0
 def test_given_filename(self):
     writer = hdf5Writer(self.filename, self.file_mode)
     self.assertFalse(writer.check_type(writer.target))
     self.assertTrue(writer.check_type(writer.base))
     self.assertTrue(writer._close_base_)
     writer.close()
     self.assertFalse(writer._close_base_)
Beispiel #3
0
 def test_given_file(self):
     f = h5py.File(self.filename, self.file_mode)
     writer = hdf5Writer(f, self.file_mode)
     self.assertTrue(writer.check_type(writer.target))
     self.assertTrue(writer.check_type(writer.base))
     self.assertFalse(writer._close_base_)
     #with self.assertWarns(RuntimeWarning):
     #    writer.close()
     self.assertFalse(writer._close_base_)
     f.close()
Beispiel #4
0
 def test_write_obj(self):
     mo = MockObject()
     writer = hdf5Writer(self.filename, self.file_mode)
     #writer should throw runtime warning if any save_attrs are undefined
     with self.assertWarns(RuntimeWarning):
         writer.write_obj(mo)
     writer.close()
     writer = hdf5Writer(self.filename, self.file_mode)
     for name in mo._save_attrs_:
         setattr(mo, name, name)
     writer.write_obj(mo)
     groupname = 'initial'
     writer.write_obj(mo, where=writer.sub(groupname))
     writer.close()
     f = h5py.File(self.filename, 'r')
     for key in mo._save_attrs_:
         self.assertTrue(key in f.keys())
     self.assertTrue(groupname in f.keys())
     initial = f[groupname]
     for key in mo._save_attrs_:
         self.assertTrue(key in initial.keys())
     f.close()
Beispiel #5
0
 def test_write_dict(self):
     thedict = {'1': 1, '2': 2, '3': 3}
     writer = hdf5Writer(self.filename, self.file_mode)
     writer.write_dict(thedict)
     writer.write_dict(thedict, where=writer.sub('subgroup'))
     with self.assertRaises(SyntaxError):
         writer.write_dict(thedict, where='not a writable type')
     writer.close()
     f = h5py.File(self.filename, 'r')
     g = f['subgroup']
     for key in thedict.keys():
         self.assertTrue(key in f.keys())
         self.assertTrue(key in g.keys())
     f.close()