Skip to content

Commit bcaa184

Browse files
test: add test case nested dicts
1 parent 9205e51 commit bcaa184

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

testing/test_error_diffs.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -230,33 +230,51 @@ def test_this():
230230
pytest.param(
231231
"""
232232
def test_this():
233-
result = {'c': 3, 'd': 4, 'b': 2, 'a': 1}
234-
expected = {'d': 5, 'c': 3, 'b': 1}
233+
result = {
234+
"b": {"m": 3, "n": 4},
235+
"a": {"x": 1, "y": 2},
236+
"c": {"k": 5, "l": 6}
237+
}
238+
expected = {
239+
"c": {"l": 6, "k": 5},
240+
"e": {"v": 8},
241+
"d": {"u": 7}
242+
}
235243
assert result == expected
236244
""",
237245
"""
238246
> assert result == expected
239-
E AssertionError: assert {'c': 3, 'd': 4, 'b': 2, 'a': 1} == {'d': 5, 'c': 3, 'b': 1}
247+
E AssertionError: assert {'b': {'m': 3, 'n': 4}, 'a': {'x': 1, 'y': 2}, 'c': {'k': 5, 'l': 6}} == {'c': {'l': 6, 'k': 5}, 'e': {'v': 8}, 'd': {'u': 7}}
240248
E Common items:
241-
E {'c': 3}
242-
E Differing items:
243-
E {'d': 4} != {'d': 5}
244-
E {'b': 2} != {'b': 1}
245-
E Left contains 1 more item:
246-
E {'a': 1}
249+
E {'c': {'k': 5, 'l': 6}}
250+
E Left contains 2 more items:
251+
E {'b': {'m': 3, 'n': 4}, 'a': {'x': 1, 'y': 2}}
252+
E Right contains 2 more items:
253+
E {'e': {'v': 8}, 'd': {'u': 7}}
247254
E Full diff:
248255
E {
249-
E - 'd': 5,
250-
E 'c': 3,
251-
E + 'd': 4,
252-
E - 'b': 1,
253-
E ? ^
254-
E + 'b': 2,
255-
E ? ^
256-
E + 'a': 1,
256+
E + 'b': {
257+
E + 'm': 3,
258+
E + 'n': 4,
259+
E + },
260+
E + 'a': {
261+
E + 'x': 1,
262+
E + 'y': 2,
263+
E + },
264+
E 'c': {
265+
E + 'k': 5,
266+
E 'l': 6,
267+
E - 'k': 5,
268+
E - },
269+
E - 'e': {
270+
E - 'v': 8,
271+
E - },
272+
E - 'd': {
273+
E - 'u': 7,
274+
E },
257275
E }
258-
""",
259-
id="Compare dicts with different order and values",
276+
""",
277+
id="Compare nested dicts and check order of diff",
260278
),
261279
pytest.param(
262280
"""

0 commit comments

Comments
 (0)