示例#1
0
    def test_from_sequence_rows(self):
        data = [('x', 1),
                ('y', 2),
                ('z', 3)]

        source = datatest.DataSource(data, fieldnames=('A', 'B'))
        table_contents = self.get_table_contents(source)
        self.assertEqual(set(table_contents), set(data))
示例#2
0
    def test_from_dict_rows(self):
        data = [{'A': 'x', 'B': 1}, {'A': 'y', 'B': 2}, {'A': 'z', 'B': 3}]

        source = datatest.DataSource(data,
                                     fieldnames=['B',
                                                 'A'])  # <- Set field order.
        table_contents = self.get_table_contents(source)
        expected = [(1, 'x'), (2, 'y'), (3, 'z')]
        self.assertEqual(set(table_contents), set(expected))
示例#3
0
    def test_duplicate_fieldnames(self):
        regex = 'duplicate column name: A'
        with self.assertRaisesRegex(Exception, regex):
            records = [
                ('A', 'A'),
                ('1', '2'),
                ('1', '2'),
            ]
            source = datatest.DataSource(records)

        regex = 'contains multiple columns where names are empty strings or whitespace'
        with self.assertRaisesRegex(Exception, regex):
            records = [
                ('', ''),
                ('1', '2'),
                ('1', '2'),
            ]
            source = datatest.DataSource(records, fieldnames=['', ''])
示例#4
0
 def test_columns(self):
     source = datatest.DataSource([[1, 2]], ('A', 'B'))
     self.assertEqual(source.columns(), ['A', 'B'])