Improve the full diff by having more consistent indentation in the PrettyPrinter (#11571)
The normal default pretty printer is not great when objects are nested and it can get hard to read the diff. Instead, provide a pretty printer that behaves more like when json get indented, which allows for smaller, more meaningful differences, at the expense of a slightly longer diff. This does not touch the other places where the pretty printer is used, and only updated the full diff one.
This commit is contained in:
committed by
GitHub
parent
fe8cda051b
commit
2d1710e0e9
@@ -40,15 +40,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
DataclassWithOneItem(foo="bar"),
|
||||
"""
|
||||
DataclassWithOneItem(foo='bar')
|
||||
DataclassWithOneItem(
|
||||
foo='bar',
|
||||
)
|
||||
""",
|
||||
id="dataclass-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
DataclassWithTwoItems(foo="foo", bar="bar"),
|
||||
"""
|
||||
DataclassWithTwoItems(foo='foo',
|
||||
bar='bar')
|
||||
DataclassWithTwoItems(
|
||||
foo='foo',
|
||||
bar='bar',
|
||||
)
|
||||
""",
|
||||
id="dataclass-two-items",
|
||||
),
|
||||
@@ -60,15 +64,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
{"one": 1},
|
||||
"""
|
||||
{'one': 1}
|
||||
{
|
||||
'one': 1,
|
||||
}
|
||||
""",
|
||||
id="dict-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
{"one": 1, "two": 2},
|
||||
"""
|
||||
{'one': 1,
|
||||
'two': 2}
|
||||
{
|
||||
'one': 1,
|
||||
'two': 2,
|
||||
}
|
||||
""",
|
||||
id="dict-two-items",
|
||||
),
|
||||
@@ -76,18 +84,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
OrderedDict({"one": 1}),
|
||||
"""
|
||||
OrderedDict([('one',
|
||||
1)])
|
||||
OrderedDict({
|
||||
'one': 1,
|
||||
})
|
||||
""",
|
||||
id="ordereddict-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
OrderedDict({"one": 1, "two": 2}),
|
||||
"""
|
||||
OrderedDict([('one',
|
||||
1),
|
||||
('two',
|
||||
2)])
|
||||
OrderedDict({
|
||||
'one': 1,
|
||||
'two': 2,
|
||||
})
|
||||
""",
|
||||
id="ordereddict-two-items",
|
||||
),
|
||||
@@ -99,15 +108,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
[1],
|
||||
"""
|
||||
[1]
|
||||
[
|
||||
1,
|
||||
]
|
||||
""",
|
||||
id="list-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
[1, 2],
|
||||
"""
|
||||
[1,
|
||||
2]
|
||||
[
|
||||
1,
|
||||
2,
|
||||
]
|
||||
""",
|
||||
id="list-two-items",
|
||||
),
|
||||
@@ -119,15 +132,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
(1,),
|
||||
"""
|
||||
(1,)
|
||||
(
|
||||
1,
|
||||
)
|
||||
""",
|
||||
id="tuple-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
(1, 2),
|
||||
"""
|
||||
(1,
|
||||
2)
|
||||
(
|
||||
1,
|
||||
2,
|
||||
)
|
||||
""",
|
||||
id="tuple-two-items",
|
||||
),
|
||||
@@ -139,15 +156,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
{1},
|
||||
"""
|
||||
{1}
|
||||
{
|
||||
1,
|
||||
}
|
||||
""",
|
||||
id="set-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
{1, 2},
|
||||
"""
|
||||
{1,
|
||||
2}
|
||||
{
|
||||
1,
|
||||
2,
|
||||
}
|
||||
""",
|
||||
id="set-two-items",
|
||||
),
|
||||
@@ -159,15 +180,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
MappingProxyType({"one": 1}),
|
||||
"""
|
||||
mappingproxy({'one': 1})
|
||||
mappingproxy({
|
||||
'one': 1,
|
||||
})
|
||||
""",
|
||||
id="mappingproxy-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
MappingProxyType({"one": 1, "two": 2}),
|
||||
"""
|
||||
mappingproxy({'one': 1,
|
||||
'two': 2})
|
||||
mappingproxy({
|
||||
'one': 1,
|
||||
'two': 2,
|
||||
})
|
||||
""",
|
||||
id="mappingproxy-two-items",
|
||||
),
|
||||
@@ -179,15 +204,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
SimpleNamespace(one=1),
|
||||
"""
|
||||
namespace(one=1)
|
||||
namespace(
|
||||
one=1,
|
||||
)
|
||||
""",
|
||||
id="simplenamespace-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
SimpleNamespace(one=1, two=2),
|
||||
"""
|
||||
namespace(one=1,
|
||||
two=2)
|
||||
namespace(
|
||||
one=1,
|
||||
two=2,
|
||||
)
|
||||
""",
|
||||
id="simplenamespace-two-items",
|
||||
),
|
||||
@@ -197,17 +226,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
defaultdict(str, {"one": "1"}),
|
||||
"""
|
||||
defaultdict(<class 'str'>,
|
||||
{'one': '1'})
|
||||
defaultdict(<class 'str'>, {
|
||||
'one': '1',
|
||||
})
|
||||
""",
|
||||
id="defaultdict-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
defaultdict(str, {"one": "1", "two": "2"}),
|
||||
"""
|
||||
defaultdict(<class 'str'>,
|
||||
{'one': '1',
|
||||
'two': '2'})
|
||||
defaultdict(<class 'str'>, {
|
||||
'one': '1',
|
||||
'two': '2',
|
||||
})
|
||||
""",
|
||||
id="defaultdict-two-items",
|
||||
),
|
||||
@@ -219,15 +250,19 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
Counter("1"),
|
||||
"""
|
||||
Counter({'1': 1})
|
||||
Counter({
|
||||
'1': 1,
|
||||
})
|
||||
""",
|
||||
id="counter-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
Counter("121"),
|
||||
"""
|
||||
Counter({'1': 2,
|
||||
'2': 1})
|
||||
Counter({
|
||||
'1': 2,
|
||||
'2': 1,
|
||||
})
|
||||
""",
|
||||
id="counter-two-items",
|
||||
),
|
||||
@@ -235,16 +270,26 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
ChainMap({"one": 1, "two": 2}),
|
||||
"""
|
||||
ChainMap({'one': 1,
|
||||
'two': 2})
|
||||
ChainMap(
|
||||
{
|
||||
'one': 1,
|
||||
'two': 2,
|
||||
},
|
||||
)
|
||||
""",
|
||||
id="chainmap-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
ChainMap({"one": 1}, {"two": 2}),
|
||||
"""
|
||||
ChainMap({'one': 1},
|
||||
{'two': 2})
|
||||
ChainMap(
|
||||
{
|
||||
'one': 1,
|
||||
},
|
||||
{
|
||||
'two': 2,
|
||||
},
|
||||
)
|
||||
""",
|
||||
id="chainmap-two-items",
|
||||
),
|
||||
@@ -256,24 +301,29 @@ class DataclassWithTwoItems:
|
||||
pytest.param(
|
||||
deque([1]),
|
||||
"""
|
||||
deque([1])
|
||||
deque([
|
||||
1,
|
||||
])
|
||||
""",
|
||||
id="deque-one-item",
|
||||
),
|
||||
pytest.param(
|
||||
deque([1, 2]),
|
||||
"""
|
||||
deque([1,
|
||||
2])
|
||||
deque([
|
||||
1,
|
||||
2,
|
||||
])
|
||||
""",
|
||||
id="deque-two-items",
|
||||
),
|
||||
pytest.param(
|
||||
deque([1, 2], maxlen=3),
|
||||
"""
|
||||
deque([1,
|
||||
2],
|
||||
maxlen=3)
|
||||
deque(maxlen=3, [
|
||||
1,
|
||||
2,
|
||||
])
|
||||
""",
|
||||
id="deque-maxlen",
|
||||
),
|
||||
@@ -293,34 +343,60 @@ class DataclassWithTwoItems:
|
||||
"tuple": (1, 2),
|
||||
},
|
||||
"""
|
||||
{'chainmap': ChainMap({'one': 1},
|
||||
{'two': 2}),
|
||||
'counter': Counter({'2': 2,
|
||||
'1': 1}),
|
||||
'dataclass': DataclassWithTwoItems(foo='foo',
|
||||
bar='bar'),
|
||||
'defaultdict': defaultdict(<class 'str'>,
|
||||
{'one': '1',
|
||||
'two': '2'}),
|
||||
'deque': deque([1,
|
||||
2],
|
||||
maxlen=3),
|
||||
'dict': {'one': 1,
|
||||
'two': 2},
|
||||
'list': [1,
|
||||
2],
|
||||
'mappingproxy': mappingproxy({'one': 1,
|
||||
'two': 2}),
|
||||
'ordereddict': OrderedDict([('one',
|
||||
1),
|
||||
('two',
|
||||
2)]),
|
||||
'set': {1,
|
||||
2},
|
||||
'simplenamespace': namespace(one=1,
|
||||
two=2),
|
||||
'tuple': (1,
|
||||
2)}
|
||||
{
|
||||
'chainmap': ChainMap(
|
||||
{
|
||||
'one': 1,
|
||||
},
|
||||
{
|
||||
'two': 2,
|
||||
},
|
||||
),
|
||||
'counter': Counter({
|
||||
'2': 2,
|
||||
'1': 1,
|
||||
}),
|
||||
'dataclass': DataclassWithTwoItems(
|
||||
foo='foo',
|
||||
bar='bar',
|
||||
),
|
||||
'defaultdict': defaultdict(<class 'str'>, {
|
||||
'one': '1',
|
||||
'two': '2',
|
||||
}),
|
||||
'deque': deque(maxlen=3, [
|
||||
1,
|
||||
2,
|
||||
]),
|
||||
'dict': {
|
||||
'one': 1,
|
||||
'two': 2,
|
||||
},
|
||||
'list': [
|
||||
1,
|
||||
2,
|
||||
],
|
||||
'mappingproxy': mappingproxy({
|
||||
'one': 1,
|
||||
'two': 2,
|
||||
}),
|
||||
'ordereddict': OrderedDict({
|
||||
'one': 1,
|
||||
'two': 2,
|
||||
}),
|
||||
'set': {
|
||||
1,
|
||||
2,
|
||||
},
|
||||
'simplenamespace': namespace(
|
||||
one=1,
|
||||
two=2,
|
||||
),
|
||||
'tuple': (
|
||||
1,
|
||||
2,
|
||||
),
|
||||
}
|
||||
""",
|
||||
id="deep-example",
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user