Пример #1
0
    def test_get_row(self):
        df = DataFrame([["a", "b"], [1, 2]])

        # test normal usage
        result = df.get_row(1)
        self.assertEqual(result, [1, 2])

        # test index error
        with self.assertRaises(IndexError):
            result = df.get_row(2)
Пример #2
0
    def test_append_row(self):
        # test correct use
        df = DataFrame([["a", "b"], [1, 2], [4, 5], [7, 8]])
        new_row = [10, 11]
        df.append_row(new_row)
        self.assertEqual(df.get_row(4), [10, 11])

        # test if new row has the wrong length
        new_row = [3, 6, 9, 11]
        with self.assertRaises(Exception) as cm:
            df.append_row(new_row)
        e = cm.exception
        self.assertEqual(e.__str__(), "The new row has the wrong length.")