def test_biom_open_gz(self): with biom_open(get_data_path('test.json.gz')) as f: self.assertTrue(isinstance(f, gzip.GzipFile)) with biom_open(get_data_path('test_writing.json.gz'), 'w') as f: self.assertTrue(isinstance(f, gzip.GzipFile)) remove(get_data_path('test_writing.json.gz'))
def test_biom_open_hdf5(self): with biom_open(get_data_path('test.biom')) as f: self.assertTrue(isinstance(f, h5py.File)) with biom_open(get_data_path('test_writing.biom'), 'w') as f: self.assertTrue(isinstance(f, h5py.File)) remove(get_data_path('test_writing.biom'))
def test_load_classic(self): tab = load_table(get_data_path('test.json')) with NamedTemporaryFile(mode='w') as fp: fp.write(str(tab)) fp.flush() obs = load_table(fp.name) npt.assert_equal(obs.ids(), tab.ids()) npt.assert_equal(obs.ids(axis='observation'), tab.ids(axis='observation')) npt.assert_equal(obs.matrix_data.toarray(), tab.matrix_data.toarray())
def test_biom_open_json(self): with biom_open(get_data_path('test.json')) as f: self.assertTrue(isinstance(f, file))
def test_is_hdf5_file(self): self.assertTrue(is_hdf5_file(get_data_path('test.biom'))) self.assertFalse(is_hdf5_file(get_data_path('test.json')))
def test_load_table_unicode(self): t = load_table(get_data_path('bad_table.txt')) self.assertEqual(u's__Cortinarius grosmornënsis', t.metadata('otu1', 'observation')['taxonomy'])
def test_biom_open_json(self): with biom_open(get_data_path('test.json')) as f: self.assertTrue(hasattr(f, 'read'))
def test_biom_open_hdf5_no_h5py(self): with self.assertRaises(RuntimeError): with biom_open(get_data_path('test.biom')) as f: pass
def test_biom_open_empty(self): with self.assertRaises(ValueError) as e: with biom_open(get_data_path('no-contents.biom'), 'r') as f: pass self.assertTrue("is empty and can't be parsed" in str(e.exception))
def test_biom_open_json(self): with biom_open(get_data_path("test.json")) as f: self.assertTrue(hasattr(f, "read"))
def test_biom_open_empty(self): with self.assertRaises(ValueError) as e: with biom_open(get_data_path("no-contents.biom"), "r") as f: pass self.assertTrue("is empty and can't be parsed" in str(e.exception))