def test_remove_head(self): expect = [(None, (1, 5, 1)), (0, (1, 5, 3)), (1, (1, 5, 3)), (range(2), (1, 5, 3)), ([1, 3], (1, 5, 3)), ([0, 0], (1, 5, 3)), ([0, 0, 1, 1], (1, 5, 3))] for data, (rows, columns, lines) in expect: T = Table(columns=5, fill='test') T.add_head() T.remove_head(index=data) msg = f'Not {rows} rows, with remove_head(index={data})' self.assertEqual(T.row_count, rows, msg=msg) msg = f'Not {columns} columns, remove_head(index={data})' self.assertEqual(T.column_count, columns, msg=msg) msg = f'Not {lines} lines in table, with remove_head(index={data})' self.assertEqual(len(str(T).splitlines()), lines, msg=msg) for k, v in self.types.items(): for x in v: if k != 'positive_int' and k != 'single_iter'\ or (k == 'positive_int' and x > 5): T = Table(rows=1, columns=5, fill='test') T.add_head() with self.assertRaises((ValueError, TypeError), msg=f'index={x}'): T.remove_head(index=x)
def test_add_head(self): # Starting with empty table (no head) expect = [(None, (0, 0)), ([], (0, 0)), ([''], (1, 2)), ('hey', (3, 2)), ('', (0, 0)), ([None], (1, 2)), ([''] * 4, (4, 2)), ([''] * 10, (10, 2)), ('helloworld', (10, 2)), (['\n'], (1, 3)), ('\n', (1, 3)), (['\n\n\n'], (1, 5)), ('\n\n\n\n\n', (5, 3))] for data, (columns, lines) in expect: T = Table() # No row sep for testing T.row_sep = '' T.add_head(data=data) msg = f'Not three rows, with add_head(data={data})' self.assertEqual(T.row_count, 0, msg=msg) msg = f'Not {columns} column, with add_head(data={data})' self.assertEqual(T.column_count, columns, msg=msg) msg = f'Not {columns} column head, with add_head(data={data})' self.assertEqual(len(T._head), columns, msg=msg) msg = f'Not {lines} lines in table, with add_head(data={data})' self.assertEqual(len(str(T).splitlines()), lines, msg=msg) # Starting with three columns and three rows (no head) expect = [(None, (3, 5)), ([], (3, 5)), ([''], (3, 5)), ('hey', (3, 5)), ('', (3, 5)), ([None], (3, 5)), ([''] * 4, (4, 5)), ([''] * 10, (10, 5)), ('helloworld', (10, 5)), (['\n'], (3, 6)), ('\n', (3, 6)), (['\n\n\n'], (3, 8)), ('\n\n\n\n\n', (5, 6))] for data, (columns, lines) in expect: T = Table(rows=3, columns=3) # No row sep for testing T.row_sep = '' T.add_head(data=data) msg = f'Not three rows, with add_head(data={data})' self.assertEqual(T.row_count, 3, msg=msg) msg = f'Not {columns} columns, with add_head(data={data})' self.assertEqual(T.column_count, columns, msg=msg) msg = f'Not {columns} column head, with add_head(data={data})' self.assertEqual(len(T._head), columns, msg=msg) msg = f'Not {lines} lines in table, with add_head(data={data})' self.assertEqual(len(str(T).splitlines()), lines, msg=msg) for k, v in self.types.items(): if k != 'single_iter' and k != 'double_iter' and k != 'str': for x in v: T = Table(rows=3, columns=3) with self.assertRaises((ValueError, TypeError, KeyError), msg=f'data={x}'): T.add_head(data=x)