def test_read(self): with TemporaryDirectory() as root: config, _ = self.get_config(root) dbase = db.Database(config).update() result = dbase.read() expected = dbase.data expected.date = expected.date.apply(lambda x: x.isoformat()) expected = expected.replace({ np.nan: None }).to_dict(orient='records') self.assertEqual(result, expected) expected = 'Database not updated. Please call update.' with self.assertRaisesRegexp(RuntimeError, expected): db.Database(config).read()
def test_data(self): with TemporaryDirectory() as root: config, _ = self.get_config(root) temp = db.Database(config).update() result = temp.data result['new_col'] = None result = result.columns.tolist() expected = temp._data.columns.tolist() self.assertNotEqual(result, expected)
def test_update(self): with TemporaryDirectory() as root: config, _ = self.get_config(root) result = db.Database(config).update()._data expected = pd.read_csv(config['data_path'], index_col=None) expected = sdt.conform(expected, actions=config['conform'], columns=config['columns']) eft.enforce_dataframes_are_equal(result, expected)
def test_search(self): with TemporaryDirectory() as root: config, _ = self.get_config(root) query = "SELECT * FROM data WHERE description LIKE 'Ignore'" result = db.Database(config).update().search(query) self.assertEqual(len(result), 1)
def test_config(self): with TemporaryDirectory() as root: expected, _ = self.get_config(root) result = db.Database(expected).config self.assertEqual(result, expected)
def test_init(self): with TemporaryDirectory() as root: config, _ = self.get_config(root) result = db.Database(config) self.assertEqual(result._config, config) self.assertIs(result._data, None)