File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -406,3 +406,37 @@ class DataclassWithTwoItems:
406
406
)
407
407
def test_consistent_pretty_printer (data : Any , expected : str ) -> None :
408
408
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
You can’t perform that action at this time.
0 commit comments