Exemplo n.º 1
0
    def test_from_json_newline_delimited(self):
        table1 = Table(self.rows, self.column_names, self.column_types)
        table2 = Table.from_json('examples/test_newline.json', newline=True)

        self.assertColumnNames(table2, self.column_names)
        self.assertColumnTypes(table2, [Number, Text, Boolean, Date, DateTime, TimeDelta])
        self.assertRows(table2, table1.rows)
Exemplo n.º 2
0
    def test_from_json_with_key(self):
        table1 = Table(self.rows, self.column_names, self.column_types)
        table2 = Table.from_json('examples/test_key.json', key='data')

        self.assertColumnNames(table2, self.column_names)
        self.assertColumnTypes(table2, [Number, Text, Boolean, Date, DateTime, TimeDelta])
        self.assertRows(table2, table1.rows)
Exemplo n.º 3
0
    def test_from_json_mixed_keys(self):
        table = Table.from_json('examples/test_mixed.json')

        self.assertColumnNames(table, ['one', 'two', 'three', 'four', 'five'])
        self.assertColumnTypes(table, [Number, Number, Text, Text, Number])
        self.assertRows(table,
                        [[1, 4, 'a', None, None], [2, 3, 'b', 'd', None],
                         [None, 2, u'👍', None, 5]])
Exemplo n.º 4
0
    def test_from_json_with_key(self):
        table1 = Table(self.rows, self.column_names, self.column_types)
        table2 = Table.from_json('examples/test_key.json', key='data')

        self.assertColumnNames(table2, self.column_names)
        self.assertColumnTypes(
            table2, [Number, Text, Boolean, Date, DateTime, TimeDelta])
        self.assertRows(table2, table1.rows)
Exemplo n.º 5
0
    def test_from_json_newline_delimited(self):
        table1 = Table(self.rows, self.column_names, self.column_types)
        table2 = Table.from_json('examples/test_newline.json', newline=True)

        self.assertColumnNames(table2, self.column_names)
        self.assertColumnTypes(
            table2, [Number, Text, Boolean, Date, DateTime, TimeDelta])
        self.assertRows(table2, table1.rows)
Exemplo n.º 6
0
    def test_from_json_nested(self):
        table = Table.from_json('examples/test_nested.json')

        self.assertColumnNames(table, ['one', 'two/two_a', 'two/two_b', 'three/0', 'three/1', 'three/2'])
        self.assertColumnTypes(table, [Number, Text, Text, Text, Number, Text])
        self.assertRows(table, [
            [1, 'a', 'b', 'a', 2, 'c'],
            [2, 'c', 'd', 'd', 2, 'f']
        ])
Exemplo n.º 7
0
    def test_from_json_file_like_object(self):
        table1 = Table(self.rows, self.column_names, self.column_types)

        with open('examples/test.json') as f:
            table2 = Table.from_json(f)

        self.assertColumnNames(table2, self.column_names)
        self.assertColumnTypes(table2, [Number, Text, Boolean, Date, DateTime, TimeDelta])
        self.assertRows(table2, table1.rows)
Exemplo n.º 8
0
    def test_from_json_nested(self):
        table = Table.from_json('examples/test_nested.json')

        self.assertColumnNames(table, ['one', 'two/two_a', 'two/two_b', 'three/0', 'three/1', 'three/2'])
        self.assertColumnTypes(table, [Number, Text, Text, Text, Number, Text])
        self.assertRows(table, [
            [1, 'a', 'b', 'a', 2, 'c'],
            [2, 'c', 'd', 'd', 2, 'f']
        ])
Exemplo n.º 9
0
    def test_from_json_file_like_object(self):
        table1 = Table(self.rows, self.column_names, self.column_types)

        with open('examples/test.json') as f:
            table2 = Table.from_json(f)

        self.assertColumnNames(table2, self.column_names)
        self.assertColumnTypes(table2, [Number, Text, Boolean, Date, DateTime, TimeDelta])
        self.assertRows(table2, table1.rows)
Exemplo n.º 10
0
    def test_from_json_mixed_keys(self):
        table = Table.from_json('examples/test_mixed.json')

        self.assertColumnNames(table, ['one', 'two', 'three', 'four', 'five'])
        self.assertColumnTypes(table, [Number, Number, Text, Text, Number])
        self.assertRows(table, [
            [1, 4, 'a', None, None],
            [2, 3, 'b', 'd', None],
            [None, 2, u'👍', None, 5]
        ])
Exemplo n.º 11
0
    def test_from_json_with_key(self):
        from agate import table

        table1 = Table(self.rows, self.columns)
        table2 = Table.from_json('examples/testKey.json',key='data')

        self.assertSequenceEqual(table1.column_names, table2.column_names)
        # self.assertSequenceEqual(table1.column_types, table2.column_types)

        self.assertEqual(len(table1.columns), len(table2.columns))
        self.assertEqual(len(table1.rows), len(table2.rows))

        self.assertSequenceEqual(table1.rows[0], table2.rows[0])
        self.assertSequenceEqual(table1.rows[1], table2.rows[1])
        self.assertSequenceEqual(table1.rows[2], table2.rows[2])
Exemplo n.º 12
0
    def test_from_json_file_like_object(self):

        table1 = Table.from_csv('examples/test.csv', self.columns)

        with open('examples/test.json') as fh:
            table2 = Table.from_json(fh, self.columns)

            self.assertSequenceEqual(table1.column_names, table2.column_names)
            self.assertSequenceEqual(table1.column_types, table2.column_types)

            self.assertEqual(len(table1.columns), len(table2.columns))
            self.assertEqual(len(table1.rows), len(table2.rows))

            self.assertSequenceEqual(table1.rows[0], table2.rows[0])
            self.assertSequenceEqual(table1.rows[1], table2.rows[1])
            self.assertSequenceEqual(table1.rows[2], table2.rows[2])
Exemplo n.º 13
0
 def test_from_json_error_newline_key(self):
     with self.assertRaises(ValueError):
         table = Table.from_json('examples/test.json', newline=True, key='test')  # noqa
Exemplo n.º 14
0
    def test_from_json_no_type_tester(self):
        tester = TypeTester(limit=0)

        table = Table.from_json('examples/test.json', column_types=tester)

        self.assertColumnTypes(table, [Text, Text, Text, Text, Text, Text])
Exemplo n.º 15
0
 def test_from_json_error_newline_key(self):
     with self.assertRaises(ValueError):
         table = Table.from_json('examples/test.json', newline=True, key='test')  # noqa
Exemplo n.º 16
0
    def test_from_json_no_type_tester(self):
        tester = TypeTester(limit=0)

        table = Table.from_json('examples/test.json', column_types=tester)

        self.assertColumnTypes(table, [Text, Text, Text, Text, Text, Text])