File: test_pretty.py

package info (click to toggle)
xonsh 0.13.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,024 kB
  • sloc: python: 46,350; makefile: 136; sh: 41; xml: 17
file content (71 lines) | stat: -rw-r--r-- 1,379 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import re

import pytest

from xonsh import pretty

long_list = ["str"] * 30
long_list_exp = "[" + (",\n ".join(["'str'"] * 30) + "]")
nested_long_list_exp = "[[" + (",\n  ".join(["'str'"] * 30) + "]]")
cases = [
    (1, "1"),
    (1.0, "1.0"),
    pytest.param(long_list, long_list_exp, id="long-list"),
    pytest.param([long_list], nested_long_list_exp, id="nested-long-list"),
    pytest.param(re.compile, "<function re.compile>", id="function"),
    (Exception, "Exception"),
    ({}, "{}"),
    pytest.param(
        dict(zip(range(30), range(100, 130))),
        """\
{0: 100,
 1: 101,
 2: 102,
 3: 103,
 4: 104,
 5: 105,
 6: 106,
 7: 107,
 8: 108,
 9: 109,
 10: 110,
 11: 111,
 12: 112,
 13: 113,
 14: 114,
 15: 115,
 16: 116,
 17: 117,
 18: 118,
 19: 119,
 20: 120,
 21: 121,
 22: 122,
 23: 123,
 24: 124,
 25: 125,
 26: 126,
 27: 127,
 28: 128,
 29: 129}""",
        id="long-dict",
    ),
    (re.compile("1"), "re.compile(r'1', re.UNICODE)"),
    pytest.param(
        dict([(0, 0), (2, 1), (1, 2), (4, 3), (3, 4)]),
        "{0: 0, 2: 1, 1: 2, 4: 3, 3: 4}",
        id="dict-preserve-order",
    ),
]


@pytest.mark.parametrize("obj, exp", cases)
def test_pretty_fn(obj, exp):
    result = pretty.pretty(obj)
    assert result == exp


def test_pretty_printer(capsys):
    pretty.pretty_print({})
    captured = capsys.readouterr()
    assert captured.out == "{}\n"