Address PR comments
This commit is contained in:
parent
85807ba368
commit
55a78b6973
|
@ -178,7 +178,7 @@ class PrettyPrinter:
|
||||||
return
|
return
|
||||||
cls = object.__class__
|
cls = object.__class__
|
||||||
stream.write(cls.__name__ + "(")
|
stream.write(cls.__name__ + "(")
|
||||||
self._pprint_dict(object, stream, indent, allowance, context, level)
|
self._format(list(object.items()), stream, indent, allowance, context, level)
|
||||||
stream.write(")")
|
stream.write(")")
|
||||||
|
|
||||||
_dispatch[_collections.OrderedDict.__repr__] = _pprint_ordered_dict
|
_dispatch[_collections.OrderedDict.__repr__] = _pprint_ordered_dict
|
||||||
|
@ -373,15 +373,9 @@ class PrettyPrinter:
|
||||||
item_indent = indent + self._indent_per_level
|
item_indent = indent + self._indent_per_level
|
||||||
delimnl = "\n" + " " * item_indent
|
delimnl = "\n" + " " * item_indent
|
||||||
|
|
||||||
it = iter(items)
|
for item in items:
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
next_ent = next(it)
|
|
||||||
except StopIteration:
|
|
||||||
break
|
|
||||||
|
|
||||||
write(delimnl)
|
write(delimnl)
|
||||||
self._format(next_ent, stream, item_indent, 1, context, level)
|
self._format(item, stream, item_indent, 1, context, level)
|
||||||
write(",")
|
write(",")
|
||||||
|
|
||||||
write("\n" + " " * indent)
|
write("\n" + " " * indent)
|
||||||
|
@ -412,10 +406,15 @@ class PrettyPrinter:
|
||||||
_dispatch[_collections.defaultdict.__repr__] = _pprint_default_dict
|
_dispatch[_collections.defaultdict.__repr__] = _pprint_default_dict
|
||||||
|
|
||||||
def _pprint_counter(self, object, stream, indent, allowance, context, level):
|
def _pprint_counter(self, object, stream, indent, allowance, context, level):
|
||||||
stream.write(object.__class__.__name__ + "({")
|
stream.write(object.__class__.__name__ + "(")
|
||||||
items = object.most_common()
|
|
||||||
self._format_dict_items(items, stream, indent, allowance, context, level)
|
if object:
|
||||||
stream.write("})")
|
stream.write("{")
|
||||||
|
items = object.most_common()
|
||||||
|
self._format_dict_items(items, stream, indent, allowance, context, level)
|
||||||
|
stream.write("}")
|
||||||
|
|
||||||
|
stream.write(")")
|
||||||
|
|
||||||
_dispatch[_collections.Counter.__repr__] = _pprint_counter
|
_dispatch[_collections.Counter.__repr__] = _pprint_counter
|
||||||
|
|
||||||
|
|
|
@ -84,19 +84,28 @@ class DataclassWithTwoItems:
|
||||||
pytest.param(
|
pytest.param(
|
||||||
OrderedDict({"one": 1}),
|
OrderedDict({"one": 1}),
|
||||||
"""
|
"""
|
||||||
OrderedDict({
|
OrderedDict([
|
||||||
'one': 1,
|
(
|
||||||
})
|
'one',
|
||||||
|
1,
|
||||||
|
),
|
||||||
|
])
|
||||||
""",
|
""",
|
||||||
id="ordereddict-one-item",
|
id="ordereddict-one-item",
|
||||||
),
|
),
|
||||||
pytest.param(
|
pytest.param(
|
||||||
OrderedDict({"one": 1, "two": 2}),
|
OrderedDict({"one": 1, "two": 2}),
|
||||||
"""
|
"""
|
||||||
OrderedDict({
|
OrderedDict([
|
||||||
'one': 1,
|
(
|
||||||
'two': 2,
|
'one',
|
||||||
})
|
1,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'two',
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
])
|
||||||
""",
|
""",
|
||||||
id="ordereddict-two-items",
|
id="ordereddict-two-items",
|
||||||
),
|
),
|
||||||
|
@ -244,7 +253,7 @@ class DataclassWithTwoItems:
|
||||||
),
|
),
|
||||||
pytest.param(
|
pytest.param(
|
||||||
Counter(),
|
Counter(),
|
||||||
"Counter({})",
|
"Counter()",
|
||||||
id="counter-empty",
|
id="counter-empty",
|
||||||
),
|
),
|
||||||
pytest.param(
|
pytest.param(
|
||||||
|
@ -380,10 +389,16 @@ class DataclassWithTwoItems:
|
||||||
'one': 1,
|
'one': 1,
|
||||||
'two': 2,
|
'two': 2,
|
||||||
}),
|
}),
|
||||||
'ordereddict': OrderedDict({
|
'ordereddict': OrderedDict([
|
||||||
'one': 1,
|
(
|
||||||
'two': 2,
|
'one',
|
||||||
}),
|
1,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'two',
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
]),
|
||||||
'set': {
|
'set': {
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
|
|
|
@ -754,6 +754,19 @@ class TestAssert_reprcompare:
|
||||||
"+ 3,",
|
"+ 3,",
|
||||||
" )",
|
" )",
|
||||||
]
|
]
|
||||||
|
lines = callequal((1, 2, 3), (1, 20, 3), verbose=2)
|
||||||
|
assert lines == [
|
||||||
|
"(1, 2, 3) == (1, 20, 3)",
|
||||||
|
"At index 1 diff: 2 != 20",
|
||||||
|
"Full diff:",
|
||||||
|
" (",
|
||||||
|
" 1,",
|
||||||
|
"- 20,",
|
||||||
|
"? -",
|
||||||
|
"+ 2,",
|
||||||
|
" 3,",
|
||||||
|
" )",
|
||||||
|
]
|
||||||
|
|
||||||
def test_set(self) -> None:
|
def test_set(self) -> None:
|
||||||
expl = callequal({0, 1}, {0, 2})
|
expl = callequal({0, 1}, {0, 2})
|
||||||
|
|
Loading…
Reference in New Issue