Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Add more tests.
  • Loading branch information
brandtbucher committed Feb 20, 2020
commit 3d61c247d3bf8f1c6ae2b2743067eb7fc0a29105
7 changes: 5 additions & 2 deletions Lib/test/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def double(x):
def test_errors(self):

# Test SyntaxErrors:
for stmt in ("x, y", "x = y", "pass", "import sys"):
for stmt in ("x,", "x, y", "x = y", "pass", "import sys"):
compile(stmt, "test", "exec") # Sanity check.
with self.assertRaises(SyntaxError):
compile(f"@{stmt}\ndef f(): pass", "test", "exec")
Expand All @@ -177,7 +177,10 @@ def unimp(func):
self.assertRaises(exc, eval, code, context)

def test_expressions(self):
for expr in ("(x, y)", "x := y", "(x := y)", "x @y", "(x @ y)"):
for expr in (
"(x,)", "(x, y)", "x := y", "(x := y)", "x @y", "(x @ y)", "x[0]",
"w[x].y.z", "w + x - (y + z)", "x(y)()(z)", "[w, x, y][z]", "x.y",
):
compile(f"@{expr}\ndef f(): pass", "test", "exec")

def test_double(self):
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ def f(x): pass
def f(x): pass
@null(null)(null)
def f(x): pass
@[null][0].__call__.__call__
def f(x): pass

# test closures with a variety of opargs
closure = 1
Expand Down Expand Up @@ -1543,6 +1545,8 @@ class J: pass
class K: pass
@class_decorator(class_decorator)(class_decorator)
class L: pass
@[class_decorator][0].__call__.__call__
class L: pass

def test_dictcomps(self):
# dictorsetmaker: ( (test ':' test (comp_for |
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ def test_function_defs(self):
"def f(): pass")
self.check_suite("@w @(x @y) @(z)\n"
"def f(): pass")
self.check_suite("@w[x].y.z\n"
"def f(): pass")

# keyword-only arguments
self.check_suite("def f(*, a): pass")
Expand Down