コード例 #1
0
ファイル: test_denormalize.py プロジェクト: wireservice/agate
    def test_denormalize_no_key(self):
        table = Table(self.rows, self.column_names, self.column_types)

        normalized_table = table.denormalize(None, 'property', 'value')

        # NB: value has been overwritten
        normal_rows = (('male', 24), )

        self.assertRows(normalized_table, normal_rows)
        self.assertColumnNames(normalized_table, ['gender', 'age'])
        self.assertColumnTypes(normalized_table, [Text, Number])
コード例 #2
0
    def test_denormalize_column_type_tester(self):
        table = Table(self.rows, self.column_names, self.column_types)

        normalized_table = table.denormalize(None, 'property', 'value', column_types=TypeTester(force={'gender': Text()}))

        # NB: value has been overwritten
        normal_rows = (
            ('male', 24),
        )

        self.assertRows(normalized_table, normal_rows)
        self.assertColumnNames(normalized_table, ['gender', 'age'])
        self.assertColumnTypes(normalized_table, [Text, Number])
コード例 #3
0
    def test_denormalize_default_value(self):
        table = Table(self.rows, self.column_names, self.column_types)

        normalized_table = table.denormalize(['first_name', 'last_name'], 'property', 'value', default_value='hello')

        normal_rows = (
            ('Jane', 'Code', 'female', '27'),
            ('Jim', 'Program', 'male', 'hello'),
            ('Jim', 'Bytes', 'hello', '24'),
        )

        self.assertRows(normalized_table, normal_rows)
        self.assertColumnNames(normalized_table, ['first_name', 'last_name', 'gender', 'age'])
        self.assertColumnTypes(normalized_table, [Text, Text, Text, Text])
コード例 #4
0
    def test_denormalize(self):
        table = Table(self.rows, self.column_names, self.column_types)

        normalized_table = table.denormalize('first_name', 'property', 'value')

        normal_rows = (
            ('Jane', 'female', 27),
            ('Jim', 'male', 24),
        )

        self.assertRows(normalized_table, normal_rows)
        self.assertColumnNames(normalized_table, ['first_name', 'gender', 'age'])
        self.assertColumnTypes(normalized_table, [Text, Text, Number])
        self.assertRowNames(normalized_table, ['Jane', 'Jim'])
コード例 #5
0
    def test_denormalize_default_value(self):
        table = Table(self.rows, self.column_names, self.column_types)

        normalized_table = table.denormalize(['first_name', 'last_name'], 'property', 'value', default_value='hello')

        normal_rows = (
            ('Jane', 'Code', 'female', '27'),
            ('Jim', 'Program', 'male', 'hello'),
            ('Jim', 'Bytes', 'hello', '24'),
        )

        self.assertRows(normalized_table, normal_rows)
        self.assertColumnNames(normalized_table, ['first_name', 'last_name', 'gender', 'age'])
        self.assertColumnTypes(normalized_table, [Text, Text, Text, Text])
コード例 #6
0
    def test_denormalize(self):
        table = Table(self.rows, self.column_names, self.column_types)

        normalized_table = table.denormalize('first_name', 'property', 'value')

        normal_rows = (
            ('Jane', 'female', 27),
            ('Jim', 'male', 24),
        )

        self.assertRows(normalized_table, normal_rows)
        self.assertColumnNames(normalized_table, ['first_name', 'gender', 'age'])
        self.assertColumnTypes(normalized_table, [Text, Text, Number])
        self.assertRowNames(normalized_table, ['Jane', 'Jim'])
コード例 #7
0
ファイル: test_denormalize.py プロジェクト: wireservice/agate
    def test_denormalize_column_type_tester(self):
        table = Table(self.rows, self.column_names, self.column_types)

        type_tester = TypeTester(force={'gender': Text()})
        normalized_table = table.denormalize(None,
                                             'property',
                                             'value',
                                             column_types=type_tester)

        # NB: value has been overwritten
        normal_rows = (('male', 24), )

        self.assertRows(normalized_table, normal_rows)
        self.assertColumnNames(normalized_table, ['gender', 'age'])
        self.assertColumnTypes(normalized_table, [Text, Number])
コード例 #8
0
    def test_denormalize_multiple_keys(self):
        table = Table(self.rows, self.column_names, self.column_types)

        normalized_table = table.denormalize(['first_name', 'last_name'], 'property', 'value')

        normal_rows = (
            ('Jane', 'Code', 'female', 27),
            ('Jim', 'Program', 'male', None),
            ('Jim', 'Bytes', None, 24),
        )

        self.assertRows(normalized_table, normal_rows)
        self.assertColumnNames(normalized_table, ['first_name', 'last_name', 'gender', 'age'])
        self.assertColumnTypes(normalized_table, [Text, Text, Text, Number])
        self.assertRowNames(normalized_table, [('Jane', 'Code'), ('Jim', 'Program'), ('Jim', 'Bytes')])
コード例 #9
0
    def test_denormalize_multiple_keys(self):
        table = Table(self.rows, self.column_names, self.column_types)

        normalized_table = table.denormalize(['first_name', 'last_name'], 'property', 'value')

        normal_rows = (
            ('Jane', 'Code', 'female', 27),
            ('Jim', 'Program', 'male', None),
            ('Jim', 'Bytes', None, 24),
        )

        self.assertRows(normalized_table, normal_rows)
        self.assertColumnNames(normalized_table, ['first_name', 'last_name', 'gender', 'age'])
        self.assertColumnTypes(normalized_table, [Text, Text, Text, Number])
        self.assertRowNames(normalized_table, [('Jane', 'Code'), ('Jim', 'Program'), ('Jim', 'Bytes')])