Skip to content

Commit

Permalink
test: add test for Object._repr_pretty() method
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
shunghsiyu committed Aug 15, 2022
1 parent dd1d59e commit c075cc5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import math
import operator
import struct
import unittest

from drgn import (
FaultError,
Expand Down Expand Up @@ -1718,3 +1719,13 @@ def test_iter(self):
iter,
Object(self.prog, "int []", address=0),
)

def test__repr_pretty_(self):
obj = Object(self.prog, "int", value=0)
pretty_printer_mock = unittest.mock.Mock()

obj._repr_pretty_(pretty_printer_mock, False)
pretty_printer_mock.text.assert_called_with(str(obj))

obj._repr_pretty_(p=pretty_printer_mock, cycle=True)
pretty_printer_mock.text.assert_called_with("...")

0 comments on commit c075cc5

Please sign in to comment.