Show More
@@ -353,8 +353,8 b' class RepresentationPrinter(PrettyPrinter):' | |||||
353 | # Some objects automatically create any requested |
|
353 | # Some objects automatically create any requested | |
354 | # attribute. Try to ignore most of them by checking for |
|
354 | # attribute. Try to ignore most of them by checking for | |
355 | # callability. |
|
355 | # callability. | |
356 |
if '_repr_pretty_' in |
|
356 | if '_repr_pretty_' in cls.__dict__: | |
357 |
meth = |
|
357 | meth = cls._repr_pretty_ | |
358 | if callable(meth): |
|
358 | if callable(meth): | |
359 | return meth(obj, self, cycle) |
|
359 | return meth(obj, self, cycle) | |
360 | return _default_pprint(obj, self, cycle) |
|
360 | return _default_pprint(obj, self, cycle) |
@@ -45,6 +45,14 b' class MyDict(dict):' | |||||
45 | p.text("MyDict(...)") |
|
45 | p.text("MyDict(...)") | |
46 |
|
46 | |||
47 |
|
47 | |||
|
48 | class Dummy1(object): | |||
|
49 | def _repr_pretty_(self, p, cycle): | |||
|
50 | p.text("Dummy1(...)") | |||
|
51 | ||||
|
52 | class Dummy2(Dummy1): | |||
|
53 | _repr_pretty_ = None | |||
|
54 | ||||
|
55 | ||||
48 | def test_indentation(): |
|
56 | def test_indentation(): | |
49 | """Test correct indentation in groups""" |
|
57 | """Test correct indentation in groups""" | |
50 | count = 40 |
|
58 | count = 40 | |
@@ -63,3 +71,14 b' def test_dispatch():' | |||||
63 | expectedoutput = "MyDict(...)" |
|
71 | expectedoutput = "MyDict(...)" | |
64 |
|
72 | |||
65 | nt.assert_equals(gotoutput, expectedoutput) |
|
73 | nt.assert_equals(gotoutput, expectedoutput) | |
|
74 | ||||
|
75 | ||||
|
76 | def test_callability_checking(): | |||
|
77 | """ | |||
|
78 | Test that the _repr_pretty_ method is tested for callability and skipped if | |||
|
79 | not. | |||
|
80 | """ | |||
|
81 | gotoutput = pretty.pretty(Dummy2()) | |||
|
82 | expectedoutput = "Dummy1(...)" | |||
|
83 | ||||
|
84 | nt.assert_equals(gotoutput, expectedoutput) |
General Comments 0
You need to be logged in to leave comments.
Login now