File: test_literal.py

package info (click to toggle)
python-ast-decompiler 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 228 kB
  • sloc: python: 1,738; makefile: 3
file content (86 lines) | stat: -rw-r--r-- 992 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from .tests import assert_decompiles


def test_With() -> None:
    assert_decompiles(
        "with x as y, a as b: pass",
        """with x as y, a as b:
    pass
""",
    )


def test_TryFinally() -> None:
    assert_decompiles(
        """
try:
    1 / 0
except Exception as e:
    pass
else:
    z = 3
finally:
    z = 4
""",
        """try:
    1 / 0
except Exception as e:
    pass
else:
    z = 3
finally:
    z = 4
""",
    )


def test_If() -> None:
    assert_decompiles(
        """
if x: pass
else:
    if y: pass
    else: pass
""",
        """if x:
    pass
elif y:
    pass
else:
    pass
""",
    )
    assert_decompiles(
        """
if x: pass
elif a:
    if y: pass
    else:
        if z: pass
        else: pass
else:
    pass
""",
        """if x:
    pass
elif a:
    if y:
        pass
    elif z:
        pass
    else:
        pass
else:
    pass
""",
    )


def test_BinOp() -> None:
    assert_decompiles(
        """
f(a * b)
""",
        """f(a * b)
""",
    )