Пример #1
0
    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()
Пример #2
0
 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)
Пример #3
0
    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)
Пример #4
0
 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)
Пример #5
0
 def test_config(self):
     with TemporaryDirectory() as root:
         expected, _ = self.get_config(root)
         result = db.Database(expected).config
         self.assertEqual(result, expected)
Пример #6
0
 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)