Ejemplo n.º 1
0
    def test_export_to_csv(self):
        data1 = Table.from_csv(self.input['csv'])
        data1.to_csv(self.tmp_name)

        data2 = Table.from_csv(self.tmp_name)
        self.assertEqual(data1, data2)
        os.remove(self.tmp_name)
Ejemplo n.º 2
0
 def test_filter_without_funcs_3(self):
     data = Table.from_csv(self.input['csv'])
     d = datetime.datetime(year=1972, day=12, month=12)
     data_filtered = data.filter(birthday=d, name='kevin')
     self.assertEqual(data_filtered.count(), 1)
     self.assertEqual(data_filtered[0]['birthday'], d)
     self.assertEqual(data_filtered[0]['name'], 'kevin')
Ejemplo n.º 3
0
 def test_get_row(self):
     data = Table.from_csv(self.input['csv'])
     data_row_0 = [
         'name: john', 'birthday: 1988-12-12 00:00:00', 'salary: 100'
     ]
     self.assertEqual(str(data[0]), '\n'.join(data_row_0))
     with self.assertRaises(TypeError):
         d = data['first']
         del d
Ejemplo n.º 4
0
    def test_filter_custom_with_custom_name(self):
        data = Table.from_csv(self.input['csv'])

        @Table.add_filter(types=(datetime.datetime, ),
                          name='year_not_multiple')
        def other_name(x, value):
            return x.year % value

        data_filtered = data.filter(birthday__year_not_multiple=2)
        self.assertEqual(data_filtered.count(), 0)
        data_filtered = data.filter(birthday__year_not_multiple=3)
        self.assertEqual(data_filtered.count(), 3)
Ejemplo n.º 5
0
    def test_filter_custom(self):
        data = Table.from_csv(self.input['csv'])

        @Table.add_filter(types=(int, ))
        def multiple(x, value):
            return not x % value

        data_filtered = data.filter(salary__multiple=10)
        self.assertEqual(data_filtered.count(), 3)

        data_filtered = data.filter(salary__multiple=30)
        self.assertEqual(data_filtered.count(), 1)
Ejemplo n.º 6
0
    def test_order_by(self):
        data = Table.from_csv(self.input['csv'])
        data_order_salary = data.copy()
        data_order_salary_rev = Table(rows=(
            ('barney', '1972-12-12 00:00:00', 300),
            ('kevin', '1972-12-12 00:00:00', 200),
            ('john', '1988-12-12 00:00:00', 100),
        ),
                                      col_names=('name', 'birthday', 'salary'))

        self.assertEqual(data.order_by('salary'), data_order_salary)
        self.assertEqual(
            data.order_by('salary', reverse=True),
            data_order_salary_rev,
        )
Ejemplo n.º 7
0
 def test_filter_without_funcs_1(self):
     data = Table.from_csv(self.input['csv'])
     data_filtered = data.filter(salary=200, )
     self.assertEqual(data_filtered.count(), 1)
     self.assertEqual(data_filtered[0]['salary'], 200)
     self.assertEqual(data_filtered[0]['name'], 'kevin')
Ejemplo n.º 8
0
 def test_headers(self):
     data = Table.from_csv(self.input['csv'])
     headers = data.headers
     result = ['name', 'birthday', 'salary']
     self.assertListEqual(headers, result)
Ejemplo n.º 9
0
 def test_avg(self):
     data = Table.from_csv(self.input['csv'])
     self.assertEqual(data.avg('salary'), 200)
Ejemplo n.º 10
0
 def test_sum(self):
     data = Table.from_csv(self.input['csv'])
     self.assertEqual(data.sum('salary'), 600)
Ejemplo n.º 11
0
 def test_count(self):
     data = Table.from_csv(self.input['csv'])
     self.assertEqual(data.count(), 3)
Ejemplo n.º 12
0
 def test_init_from_csv(self):
     data = Table.from_csv(self.input['csv'])
     self.assertEqual(str(data), self.init_result)
Ejemplo n.º 13
0
 def test_filter_str_endswith(self):
     data = Table.from_csv(self.input['csv'])
     data_filtered = data.filter(name__endswith='vin', )
     self.assertEqual(data_filtered.count(), 1)
     self.assertTrue(data_filtered[0]['name'].endswith('vin'))
Ejemplo n.º 14
0
 def test_columns_two(self):
     data = Table.from_csv(self.input['csv'])
     data_name_and_salary = Table(rows=(('john', 100), ('kevin', 200),
                                        ('barney', 300)),
                                  col_names=('name', 'salary'))
     self.assertEqual(data.columns('name', 'salary'), data_name_and_salary)
Ejemplo n.º 15
0
    def test_filter_date_day(self):
        data = Table.from_csv(self.input['csv'])

        data_filtered = data.filter(birthday__day=12, )
        self.assertEqual(data_filtered.count(), 3)
Ejemplo n.º 16
0
    def test_filter_date_gt(self):
        data = Table.from_csv(self.input['csv'])
        d = datetime.datetime(year=1972, day=13, month=12)

        data_filtered = data.filter(birthday__lt=d, )
        self.assertEqual(data_filtered.count(), 2)
Ejemplo n.º 17
0
 def test_filter_int_gt(self):
     data = Table.from_csv(self.input['csv'])
     data_filtered = data.filter(salary__gt=200, )
     self.assertEqual(data_filtered.count(), 1)
     self.assertTrue(data_filtered[0]['salary'] > 200)
Ejemplo n.º 18
0
 def test_unique(self):
     data = Table.from_csv(self.input['csv'])
     self.assertSetEqual(data.unique('salary'), {100, 200, 300})
     self.assertSetEqual(data.unique('name'), {'john', 'kevin', 'barney'})
Ejemplo n.º 19
0
 def test_export_to_html(self):
     data1 = Table.from_csv(self.input['csv'])
     data1.to_html(self.tmp_name)
     # don't now how check
     os.remove(self.tmp_name)
Ejemplo n.º 20
0
 def test_columns_one(self):
     data = Table.from_csv(self.input['csv'])
     data_name = Table(rows=(('john', ), ('kevin', ), ('barney', )),
                       col_names=('name', ))
     self.assertEqual(data.columns('name'), data_name)
Ejemplo n.º 21
0
    def test_filter_not_supported_func(self):
        data = Table.from_csv(self.input['csv'])

        with self.assertRaises(NotSupported):
            d = data.filter(birthday__startswith=100)
            del d
Ejemplo n.º 22
0
 def test_columns_two_reverse(self):
     data = Table.from_csv(self.input['csv'])
     data_salary_and_name = Table(rows=((100, 'john'), (200, 'kevin'),
                                        (300, 'barney')),
                                  col_names=('salary', 'name'))
     self.assertEqual(data.columns('salary', 'name'), data_salary_and_name)
Ejemplo n.º 23
0
 def test_get_cell_value(self):
     data = Table.from_csv(self.input['csv'])
     self.assertEqual(data[0]['name'], 'john')
     self.assertEqual(data[1]['salary'], 200)