Skip to content

Commit 4ecf801

Browse files
committed
Add test for decorator expressions
1 parent 21ebfad commit 4ecf801

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test/test_decorator_expressions.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import ast
2+
import sys
3+
import pytest
4+
from python_minifier import unparse
5+
from python_minifier.ast_compare import compare_ast
6+
7+
def test_pep():
8+
if sys.version_info < (3, 9):
9+
pytest.skip('Decorator expression not allowed in python <3.9')
10+
11+
source = """
12+
buttons = [QPushButton(f'Button {i}') for i in range(10)]
13+
14+
# Do stuff with the list of buttons...
15+
16+
@buttons[0].clicked.connect
17+
def spam():
18+
...
19+
20+
@buttons[1].clicked.connect
21+
def eggs():
22+
...
23+
24+
# Do stuff with the list of buttons...
25+
@(f, g)
26+
def a(): pass
27+
28+
@(f, g)
29+
class A:pass
30+
31+
@lambda func: (lambda *p: func(*p).u())
32+
def g(n): pass
33+
34+
@s := lambda func: (lambda *p: func(*p).u())
35+
def g(name): pass
36+
37+
@s
38+
def r(n, t):
39+
pass
40+
41+
@lambda f: lambda *p: f or f(*p).u()
42+
def g(name): pass
43+
44+
@lambda f: lambda *p: \
45+
[_ for _ in [ \
46+
f(*p),
47+
] if _][0]
48+
def c(): pass
49+
50+
@lambda f: lambda *p: \
51+
list(filter(lambda _: _,[
52+
(a := t()) and False,
53+
f(*p),
54+
(b := t()) and False,
55+
]))[0]
56+
def c(): pass
57+
58+
"""
59+
60+
expected_ast = ast.parse(source)
61+
actual_ast = unparse(expected_ast)
62+
compare_ast(expected_ast, ast.parse(actual_ast))

0 commit comments

Comments
 (0)