##// END OF EJS Templates
elide long containers in pretty...
MinRK -
Show More
@@ -122,6 +122,7 b' else:'
122 __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter',
122 __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter',
123 'for_type', 'for_type_by_name']
123 'for_type', 'for_type_by_name']
124
124
125 SEQ_LENGTH_LIMIT = 1000
125
126
126 _re_pattern_type = type(re.compile(''))
127 _re_pattern_type = type(re.compile(''))
127
128
@@ -599,6 +600,12 b' def _seq_pprinter_factory(start, end, basetype):'
599 step = len(start)
600 step = len(start)
600 p.begin_group(step, start)
601 p.begin_group(step, start)
601 for idx, x in enumerate(obj):
602 for idx, x in enumerate(obj):
603 if idx >= SEQ_LENGTH_LIMIT:
604 p.text(',')
605 p.breakable()
606 p.text('...')
607 p.end_group(step, end)
608 return
602 if idx:
609 if idx:
603 p.text(',')
610 p.text(',')
604 p.breakable()
611 p.breakable()
@@ -636,6 +643,12 b' def _set_pprinter_factory(start, end, basetype):'
636 # Sometimes the items don't sort.
643 # Sometimes the items don't sort.
637 pass
644 pass
638 for idx, x in enumerate(items):
645 for idx, x in enumerate(items):
646 if idx >= SEQ_LENGTH_LIMIT:
647 p.text(',')
648 p.breakable()
649 p.text('...')
650 p.end_group(step, end)
651 return
639 if idx:
652 if idx:
640 p.text(',')
653 p.text(',')
641 p.breakable()
654 p.breakable()
@@ -665,6 +678,12 b' def _dict_pprinter_factory(start, end, basetype=None):'
665 # Sometimes the keys don't sort.
678 # Sometimes the keys don't sort.
666 pass
679 pass
667 for idx, key in enumerate(keys):
680 for idx, key in enumerate(keys):
681 if idx >= SEQ_LENGTH_LIMIT:
682 p.text(',')
683 p.breakable()
684 p.text('...')
685 p.end_group(1, end)
686 return
668 if idx:
687 if idx:
669 p.text(',')
688 p.text(',')
670 p.breakable()
689 p.breakable()
@@ -196,4 +196,29 b' def test_super_repr():'
196 sb = SB()
196 sb = SB()
197 output = pretty.pretty(super(SA, sb))
197 output = pretty.pretty(super(SA, sb))
198 nt.assert_in("SA", output)
198 nt.assert_in("SA", output)
199 No newline at end of file
199
200
201 def test_long_list():
202 lis = list(range(10000))
203 p = pretty.pretty(lis)
204 last2 = p.rsplit('\n', 2)[-2:]
205 nt.assert_equal(last2, [' 999,', ' ...]'])
206
207 def test_long_set():
208 s = set(range(10000))
209 p = pretty.pretty(s)
210 last2 = p.rsplit('\n', 2)[-2:]
211 nt.assert_equal(last2, [' 999,', ' ...}'])
212
213 def test_long_tuple():
214 tup = tuple(range(10000))
215 p = pretty.pretty(tup)
216 last2 = p.rsplit('\n', 2)[-2:]
217 nt.assert_equal(last2, [' 999,', ' ...)'])
218
219 def test_long_dict():
220 d = { n:n for n in range(10000) }
221 p = pretty.pretty(d)
222 last2 = p.rsplit('\n', 2)[-2:]
223 nt.assert_equal(last2, [' 999: 999,', ' ...}'])
224
General Comments 0
You need to be logged in to leave comments. Login now