##// END OF EJS Templates
Uses p.break_() when repr() is used for printing...
Alex Rudy -
Show More
@@ -488,8 +488,12 b' def _default_pprint(obj, p, cycle):'
488 """
488 """
489 klass = getattr(obj, '__class__', None) or type(obj)
489 klass = getattr(obj, '__class__', None) or type(obj)
490 if getattr(klass, '__repr__', None) not in _baseclass_reprs:
490 if getattr(klass, '__repr__', None) not in _baseclass_reprs:
491 # A user-provided repr.
491 # A user-provided repr. Find newlines and replace them with p.break_()
492 p.text(repr(obj))
492 output = repr(obj)
493 for idx,output_line in enumerate(output.splitlines()):
494 if idx:
495 p.break_()
496 p.text(output_line)
493 return
497 return
494 p.begin_group(1, '<')
498 p.begin_group(1, '<')
495 p.pretty(klass)
499 p.pretty(klass)
@@ -65,6 +65,16 b' class Breaking(object):'
65 p.break_()
65 p.break_()
66 p.text(")")
66 p.text(")")
67
67
68 class BreakingRepr(object):
69 def __repr__(self):
70 return "Breaking(\n)"
71
72 class BreakingReprParent(object):
73 def _repr_pretty_(self, p, cycle):
74 with p.group(4,"TG: ",":"):
75 p.pretty(BreakingRepr())
76
77
68
78
69 def test_indentation():
79 def test_indentation():
70 """Test correct indentation in groups"""
80 """Test correct indentation in groups"""
@@ -133,3 +143,11 b' def test_pprint_break():'
133 output = pretty.pretty(Breaking())
143 output = pretty.pretty(Breaking())
134 expected = "TG: Breaking(\n ):"
144 expected = "TG: Breaking(\n ):"
135 nt.assert_equal(output, expected)
145 nt.assert_equal(output, expected)
146
147 def test_pprint_break_repr():
148 """
149 Test that p.break_ is used in repr
150 """
151 output = pretty.pretty(BreakingReprParent())
152 expected = "TG: Breaking(\n ):"
153 nt.assert_equal(output, expected) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now