Skip to content

Commit c075cc5

Browse files
committed
test: add test for Object._repr_pretty() method
Since _repr_pretty() uses output of str(obj), and the latter is already heavily tested in tests/test_language_c.py, we can simply test whether p.text is call made instead of duplicating all the test cases. Signed-off-by: Shung-Hsi Yu <[email protected]>
1 parent dd1d59e commit c075cc5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/test_object.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import math
55
import operator
66
import struct
7+
import unittest
78

89
from drgn import (
910
FaultError,
@@ -1718,3 +1719,13 @@ def test_iter(self):
17181719
iter,
17191720
Object(self.prog, "int []", address=0),
17201721
)
1722+
1723+
def test__repr_pretty_(self):
1724+
obj = Object(self.prog, "int", value=0)
1725+
pretty_printer_mock = unittest.mock.Mock()
1726+
1727+
obj._repr_pretty_(pretty_printer_mock, False)
1728+
pretty_printer_mock.text.assert_called_with(str(obj))
1729+
1730+
obj._repr_pretty_(p=pretty_printer_mock, cycle=True)
1731+
pretty_printer_mock.text.assert_called_with("...")

0 commit comments

Comments
 (0)