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))
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))
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=['', ''])
def test_columns(self): source = datatest.DataSource([[1, 2]], ('A', 'B')) self.assertEqual(source.columns(), ['A', 'B'])