コード例 #1
0
ファイル: test.py プロジェクト: Thewessen/NestedTables
 def test_remove_column(self):
     # TODO: Make sure the proper column is removed!
     # Starting with three rows and three columns
     removehead_expect = [(None, (3, 2, 3)), (0, (3, 2, 3)), (1, (3, 2, 3)),
                          (range(2), (3, 1, 3)), ([0, 2], (3, 1, 3)),
                          ([0, 0], (3, 2, 3)), ([0, 0, 1, 1], (3, 1, 3))]
     for (data, (rows, columns, lines)) in removehead_expect:
         T = Table(rows=3, columns=3)
         # No row sep for testing
         T.row_sep = ''
         T.remove_column(index=data, removehead=True)
         msg = (f'Not {rows} rows, with '
                f'remove_column(index={data},removehead=True)')
         self.assertEqual(T.row_count, rows, msg=msg)
         msg = (f'Not {columns} columns, with '
                f'remove_column(index={data},removehead=True)')
         self.assertEqual(T.column_count, columns, msg=msg)
         msg = (f'Not {lines} lines in table, with '
                f'remove_column(index={data},removehead=True)')
         self.assertEqual(len(str(T).splitlines()), lines, msg=msg)
     # TODO: Same as removehead=True??
     expect = [(None, (3, 3, 3)), (0, (3, 3, 3)), (1, (3, 3, 3)),
               (range(2), (3, 3, 3)), ([0, 2], (3, 3, 3)),
               ([0, 0], (3, 3, 3)), ([0, 0, 1, 1], (3, 3, 3))]
     for (data, (rows, columns, lines)) in expect:
         T = Table(rows=3, columns=3)
         # No row sep for testing
         T.row_sep = ''
         T.remove_column(index=data, removehead=False)
         msg = (f'Not {rows} rows, with '
                f'remove_column(index={data},removehead=False)')
         self.assertEqual(T.row_count, rows, msg=msg)
         msg = (f'Not {columns} columns, with '
                f'remove_column(index={data},removehead=False)')
         self.assertEqual(T.column_count, columns, msg=msg)
         msg = (f'Not {lines} lines in table, with '
                f'remove_column(index={data},removehead=False)')
         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 > 2):
                 T = Table(rows=3, columns=3)
                 with self.assertRaises((ValueError, TypeError),
                                        msg='index={x}'):
                     T.remove_column(index=x)
コード例 #2
0
ファイル: test.py プロジェクト: Thewessen/NestedTables
 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)
コード例 #3
0
ファイル: test.py プロジェクト: Thewessen/NestedTables
 def test_add_row(self):
     # Starting with empty Table
     expect = [(None, (1, 1, 1)), ([], (1, 1, 1)), ([''], (1, 1, 1)),
               ('hey', (1, 3, 1)), ('', (1, 1, 1)), ([None], (1, 1, 1)),
               ([''] * 4, (1, 4, 1)), ([''] * 10, (1, 10, 1)),
               ('helloworld', (1, 10, 1)), (['\n'], (1, 1, 2)),
               ('\n', (1, 1, 2)), (['\n\n\n'], (1, 1, 4)),
               ('\n\n\n\n\n', (1, 5, 2))]
     for data, (rows, columns, lines) in expect:
         T = Table()
         # No row sep for testing
         T.row_sep = ''
         T.add_row(data=data)
         msg = f'Not {rows} rows, with add_row(data={data})'
         self.assertEqual(T.row_count, rows, msg=msg)
         msg = f'Not {columns} columns, with add_row(data={data})'
         self.assertEqual(T.column_count, columns, msg=msg)
         msg = f'Not {lines} lines in table, with add_row(data={data})'
         self.assertEqual(len(str(T).splitlines()), lines, msg=msg)
     # Starting with three rows and three columns
     expect = [(None, (4, 3, 4)), ([], (4, 3, 4)), ([''], (4, 3, 4)),
               ('hey', (4, 3, 4)), ('', (4, 3, 4)), ([None], (4, 3, 4)),
               ([''] * 4, (4, 4, 4)), ([''] * 10, (4, 10, 4)),
               ('helloworld', (4, 10, 4)), (['\n'], (4, 3, 5)),
               ('\n', (4, 3, 5)), (['\n\n\n'], (4, 3, 7)),
               ('\n\n\n\n\n', (4, 5, 5))]
     for data, (rows, columns, lines) in expect:
         T = Table(rows=3, columns=3)
         # No row sep for testing
         T.row_sep = ''
         T.add_row(data=data)
         msg = f'Not {rows} rows, with add_row(data={data})'
         self.assertEqual(T.row_count, rows, msg=msg)
         msg = f'Not {columns} columns, with add_row(data={data})'
         self.assertEqual(T.column_count, columns, msg=msg)
         msg = f'Not {lines} lines in table, with add_row(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_row(data=x)
コード例 #4
0
ファイル: test.py プロジェクト: Thewessen/NestedTables
 def test_fill(self):
     expect = [(None, (3, 3, 3)), ([], (3, 3, 3)), ([''], (3, 3, 3)),
               ('hey', (3, 3, 3)), ('', (3, 3, 3)), ([None], (3, 3, 3)),
               ([''] * 4, (3, 3, 3)), ([''] * 10, (3, 3, 3)),
               ('helloworld', (3, 3, 3)),
               (' ', (3, 3, 3)), ('\n', (3, 3, 6)), (['\n'], (3, 3, 3)),
               ('\n\n\n', (3, 3, 12))]
     for (data, (rows, columns, lines)) in expect:
         T = Table(rows=3, columns=3, fill=data)
         # No row sep for testing
         T.row_sep = ''
         msg = f'Not {rows} rows, with Table(fill={data})'
         self.assertEqual(T.row_count, rows, msg=msg)
         msg = f'Not {columns} columns, with Table(fill={data})'
         self.assertEqual(T.column_count, columns, msg=msg)
         msg = f'Not {lines} lines in table, with Table(fill={data})'
         self.assertEqual(len(str(T).splitlines()), lines, msg=msg)
     for v in self.types.values():
         for x in v:
             self.assertIsInstance(Table(fill=x), Table, msg=f'fill={x}')