Skip to content

Commit 086603c

Browse files
committed
Adjust tests to keep a smaller output diff
1 parent cfb5a76 commit 086603c

1 file changed

Lines changed: 37 additions & 42 deletions

File tree

Lib/test/test_pprint.py

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -366,81 +366,76 @@ def test_basic_line_wrap(self):
366366
self.assertEqual(_pformat(frozendict2(o)), exp)
367367

368368
o = range(100)
369-
line_ranges = [(0, 22), (22, 42), (42, 62), (62, 82), (82, 100)]
370-
ints = ",\n ".join(
371-
", ".join(str(i) for i in range(a, b)) for a, b in line_ranges
372-
)
373-
exp = f"dict_keys([{ints}])"
369+
exp = 'dict_keys([%s])' % ',\n '.join(map(str, o))
374370
keys = dict.fromkeys(o).keys()
375-
self.assertEqual(_pformat(keys), exp)
371+
self.assertEqual(_pformat(keys, width=1), exp)
376372
keys = frozendict.fromkeys(o).keys()
377-
self.assertEqual(_pformat(keys), exp)
373+
self.assertEqual(_pformat(keys, width=1), exp)
378374

379-
exp = f"dict_values([{ints}])"
375+
o = range(100)
376+
exp = 'dict_values([%s])' % ',\n '.join(map(str, o))
380377
values = {v: v for v in o}.values()
381-
self.assertEqual(_pformat(values), exp)
378+
self.assertEqual(_pformat(values, width=1), exp)
382379
values = frozendict({v: v for v in o}).values()
383-
self.assertEqual(_pformat(values), exp)
380+
self.assertEqual(_pformat(values, width=1), exp)
384381

385-
line_ranges = [
386-
(0, 10), (10, 18), (18, 26), (26, 34), (34, 42), (42, 50), (50, 58),
387-
(58, 66), (66, 74), (74, 82), (82, 90), (90, 98), (98, 100),
388-
]
389-
tups = ",\n ".join(
390-
", ".join(f"({i}, {i})" for i in range(a, b)) for a, b in line_ranges
391-
)
392-
exp = f"dict_items([{tups}])"
382+
o = range(100)
383+
exp = 'dict_items([%s])' % ',\n '.join("(%s, %s)" % (i, i) for i in o)
393384
items = {v: v for v in o}.items()
394-
self.assertEqual(_pformat(items), exp)
385+
self.assertEqual(_pformat(items, width=11), exp)
395386
items = frozendict({v: v for v in o}).items()
396-
self.assertEqual(_pformat(items), exp)
387+
self.assertEqual(_pformat(items, width=11), exp)
397388

398-
exp = f"odict_keys([{ints}])"
389+
o = range(100)
390+
exp = 'odict_keys([%s])' % ',\n '.join(map(str, o))
399391
keys = collections.OrderedDict.fromkeys(o).keys()
400-
self.assertEqual(_pformat(keys), exp)
392+
self.assertEqual(_pformat(keys, width=1), exp)
401393

402-
exp = f"odict_values([{ints}])"
394+
o = range(100)
395+
exp = 'odict_values([%s])' % ',\n '.join(map(str, o))
403396
values = collections.OrderedDict({v: v for v in o}).values()
404-
self.assertEqual(_pformat(values), exp)
397+
self.assertEqual(_pformat(values, width=1), exp)
405398

406-
exp = f"odict_items([{tups}])"
399+
o = range(100)
400+
exp = 'odict_items([%s])' % ',\n '.join("(%s, %s)" % (i, i) for i in o)
407401
items = collections.OrderedDict({v: v for v in o}).items()
408-
self.assertEqual(_pformat(items), exp)
402+
self.assertEqual(_pformat(items, width=11), exp)
409403

410-
# KeysView etc. wrap a dict, which always formats one item per line.
411-
none_pairs = ": None,\n ".join(map(str, o)) + ": None"
412-
exp = f"KeysView({{{none_pairs}}})"
404+
o = range(100)
405+
exp = 'KeysView({%s})' % (': None,\n '.join(map(str, o)) + ': None')
413406
keys_view = KeysView(dict.fromkeys(o))
414407
self.assertEqual(_pformat(keys_view), exp)
415408

416-
exp = f"ItemsView({{{none_pairs}}})"
409+
o = range(100)
410+
exp = 'ItemsView({%s})' % (': None,\n '.join(map(str, o)) + ': None')
417411
items_view = ItemsView(dict.fromkeys(o))
418412
self.assertEqual(_pformat(items_view), exp)
419413

420-
exp = f"MappingView({{{none_pairs}}})"
414+
o = range(100)
415+
exp = 'MappingView({%s})' % (': None,\n '.join(map(str, o)) + ': None')
421416
mapping_view = MappingView(dict.fromkeys(o))
422417
self.assertEqual(_pformat(mapping_view), exp)
423418

424-
exp = f"ValuesView({{{none_pairs}}})"
419+
o = range(100)
420+
exp = 'ValuesView({%s})' % (': None,\n '.join(map(str, o)) + ': None')
425421
values_view = ValuesView(dict.fromkeys(o))
426422
self.assertEqual(_pformat(values_view), exp)
427423

428-
exp = f"[{ints}]"
424+
o = range(100)
425+
exp = '[%s]' % ',\n '.join(map(str, o))
429426
for type in [list, list2]:
430-
self.assertEqual(_pformat(type(o)), exp)
427+
self.assertEqual(_pformat(type(o), width=1), exp)
431428

432-
exp = f"({ints})"
429+
o = tuple(range(100))
430+
exp = '(%s)' % ',\n '.join(map(str, o))
433431
for type in [tuple, tuple2]:
434-
self.assertEqual(_pformat(type(o)), exp)
432+
self.assertEqual(_pformat(type(o), width=1), exp)
435433

436434
# indent parameter
437-
line_ranges = [(0, 21), (21, 40), (40, 59), (59, 78), (78, 97), (97, 100)]
438-
ints = ",\n ".join(
439-
", ".join(str(i) for i in range(a, b)) for a, b in line_ranges
440-
)
441-
exp = f"[ {ints}]"
435+
o = range(100)
436+
exp = '[ %s]' % ',\n '.join(map(str, o))
442437
for type in [list, list2]:
443-
self.assertEqual(_pformat(type(o), indent=4), exp)
438+
self.assertEqual(_pformat(type(o), indent=4, width=1), exp)
444439

445440
def test_nested_indentations(self):
446441
o1 = list(range(10))

0 commit comments

Comments
 (0)