Skip to content

Commit ffb5e46

Browse files
test: add test case for pprint
1 parent 6619690 commit ffb5e46

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

testing/io/test_pprint.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,37 @@ class DataclassWithTwoItems:
406406
)
407407
def test_consistent_pretty_printer(data: Any, expected: str) -> None:
408408
assert PrettyPrinter().pformat(data) == textwrap.dedent(expected).strip()
409+
410+
@pytest.mark.parametrize(
411+
("sort_dicts"),
412+
(
413+
pytest.param(True, id="sort_dicts-True"),
414+
pytest.param(False, id="sort_dicts-False"),
415+
),
416+
)
417+
def test_pretty_printer_sort_dicts(sort_dicts: bool) -> None:
418+
data = {
419+
"b": 2,
420+
"a": 1,
421+
"c": 3,
422+
}
423+
424+
if sort_dicts:
425+
expected = textwrap.dedent("""
426+
{
427+
'a': 1,
428+
'b': 2,
429+
'c': 3,
430+
}
431+
""").strip()
432+
else:
433+
expected = textwrap.dedent("""
434+
{
435+
'b': 2,
436+
'a': 1,
437+
'c': 3,
438+
}
439+
""").strip()
440+
441+
actual = PrettyPrinter(sort_dicts=sort_dicts).pformat(data)
442+
assert actual == expected

0 commit comments

Comments
 (0)