Ejemplo n.º 1
0
    def test_remove_methods(self):
        table = OutputTable(headers=TEST_HEADERS)
        for row in TEST_ROWS:
            table.add_row(row)

        # Pick a row
        row_idx = 4
        self.assertEqual(table.get_row(index=row_idx),
                         [f"value 4{j}" for j in range(10)])

        # remove row and check that the next one is in its place
        table.remove_row_by_index(index=row_idx)
        self.assertEqual(table.get_row(index=row_idx),
                         [f"value 5{j}" for j in range(10)])

        table = OutputTable(headers=TEST_HEADERS)
        for row in TEST_ROWS:
            table.add_row(row)

        # Pick column, remove and check that is replaced
        col_idx = 7
        self.assertEqual(table.get_column(index=col_idx),
                         ["Column 7"] + [f"value {i}7" for i in range(10)])

        table.remove_column_by_index(index=col_idx)
        self.assertEqual(table.get_column(index=col_idx),
                         ["Column 8"] + [f"value {i}8" for i in range(10)])

        table.remove_column_by_header(header="Column 8")
        self.assertEqual(table.get_column(index=col_idx),
                         ["Column 9"] + [f"value {i}9" for i in range(10)])
Ejemplo n.º 2
0
    def test_add_get_methods(self):
        table = OutputTable(headers=["Column 0"])

        # add/get single row/col
        table.add_row(["value 0,0"])
        self.assertEqual(table.get_row(index=0), ["value 0,0"])

        table.add_column(["Column 1", "value 0,1"])
        self.assertEqual(table.headers(), ["Column 0", "Column 1"])
        self.assertEqual(table.get_row(index=0), ["value 0,0", "value 0,1"])
        self.assertEqual(table.get_column(index=1), ["Column 1", "value 0,1"])

        # add/get row and column by index
        table.add_row(["value -1,0", "value -1,1"], index=0)
        self.assertEqual(table.get_row(index=0), ["value -1,0", "value -1,1"])
        self.assertEqual(table.get_column(index=0),
                         ["Column 0", "value -1,0", "value 0,0"])
        self.assertEqual(table.get_column(index=1),
                         ["Column 1", "value -1,1", "value 0,1"])

        table.add_column(["Column 0.5", "value -1,0.5", "value 0,0.5"],
                         index=1)
        self.assertEqual(table.get_column(index=1),
                         ["Column 0.5", "value -1,0.5", "value 0,0.5"])
        self.assertEqual(table.get_row(index=0),
                         ["value -1,0", "value -1,0.5", "value -1,1"])
        self.assertEqual(table.get_row(index=1),
                         ["value 0,0", "value 0,0.5", "value 0,1"])