Skip to content

Commit

Permalink
Add test for decorator expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
dflook committed Oct 15, 2020
1 parent 21ebfad commit 4ecf801
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/test_decorator_expressions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import ast
import sys
import pytest
from python_minifier import unparse
from python_minifier.ast_compare import compare_ast

def test_pep():
if sys.version_info < (3, 9):
pytest.skip('Decorator expression not allowed in python <3.9')

source = """
buttons = [QPushButton(f'Button {i}') for i in range(10)]
# Do stuff with the list of buttons...
@buttons[0].clicked.connect
def spam():
...
@buttons[1].clicked.connect
def eggs():
...
# Do stuff with the list of buttons...
@(f, g)
def a(): pass
@(f, g)
class A:pass
@lambda func: (lambda *p: func(*p).u())
def g(n): pass
@s := lambda func: (lambda *p: func(*p).u())
def g(name): pass
@s
def r(n, t):
pass
@lambda f: lambda *p: f or f(*p).u()
def g(name): pass
@lambda f: lambda *p: \
[_ for _ in [ \
f(*p),
] if _][0]
def c(): pass
@lambda f: lambda *p: \
list(filter(lambda _: _,[
(a := t()) and False,
f(*p),
(b := t()) and False,
]))[0]
def c(): pass
"""

expected_ast = ast.parse(source)
actual_ast = unparse(expected_ast)
compare_ast(expected_ast, ast.parse(actual_ast))

0 comments on commit 4ecf801

Please sign in to comment.