def test_use_case_csv_json(self): """Simple use case using core tools for reading, computing and writing""" raised = False try: data = dr.DataReader(data=data_paths['csv'], f_format='csv').read() table = st.StashTable(data=data, table='data') table.save() subset = table.get(key='gender', value='Female', operator='==', reindex=True) dw.write_json(data=subset, file='subset.json', allow_nan=False, sort_keys=False) dw.write_json(data=subset, file='subset.json', allow_nan=True, sort_keys=True) table.un_stash() os.remove('subset.json') except: raised = True self.assertIs(raised, False)
def test_list_tables(self): """Tests the list tables util method""" data = self.get_data() table = st.StashTable(data=data, table='basic') table.save() self.assertEqual(utils.list_tables(), ['basic']) table.delete()
def test_stash_table(self): """Assert table dir exists""" data = self.get_data() table = st.StashTable(data=data, table='basic') table.save() self.assertTrue(os.path.exists('stash/basic')) table.delete()
def test_get(self): """Ensure row method works""" data = self.get_data() table = st.StashTable(data=data, table='basic') table.save() tmp = table.get(key='gender', value='Female', operator='==') self.assertGreater(len(tmp), 1)
def test_row(self): """Ensure row method works""" data = self.get_data() table = st.StashTable(data=data, table='basic') table.save() tmp = table.row(index=0) self.assertGreater(len(tmp), 1)
def test_col(self): """Ensure col method works""" data = self.get_data() table = st.StashTable(data=data, table='basic') table.save() tmp = table.col(key='gender') self.assertGreater(len(tmp), 1)
def test_stash_table_content(self): """Assert table sub dirs exists adn test structure""" data = self.get_data() table = st.StashTable(data=data, table='basic') table.save() cols = table.col_names() for i in cols: self.assertTrue(os.path.exists(f'stash/basic/{i}')) table.delete()
def test_use_case_yaml_csv(self): """Simple use case using core tools for reading, computing and writing""" raised = False try: data = dr.DataReader(data=data_paths['yaml'], f_format='yaml').read() table = st.StashTable(data=data, table='data') table.save() subset = table.get(key='gender', value='Female', operator='==', reindex=True) dw.write_csv(data=subset, file='subset.csv', header=True) dw.write_csv(data=subset, file='subset.csv', header=True, quoting='all') dw.write_csv(data=subset, file='subset.csv', header=True, quoting='minimal') dw.write_csv(data=subset, file='subset.csv', header=True, quoting='nonumeric') table.un_stash() os.remove('subset.csv') except: raised = True self.assertIs(raised, False)