diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-02-11 13:18:39 -0800 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-02-11 13:18:39 -0800 |
commit | 836e5f97e84088cd3104cb3a30bf02e8a6c0a9a5 (patch) | |
tree | 89d1b80846f6feca036096ecbb6b28323fa0eb21 /test/test_ast.py | |
parent | a5740079856fcb2244dcebc7fb81da739a4094fd (diff) | |
download | external_python_mako-836e5f97e84088cd3104cb3a30bf02e8a6c0a9a5.tar.gz external_python_mako-836e5f97e84088cd3104cb3a30bf02e8a6c0a9a5.tar.bz2 external_python_mako-836e5f97e84088cd3104cb3a30bf02e8a6c0a9a5.zip |
Support Python 3's keyword-only arguments.
Previously, they would parse correctly in Python 3, but any keyword-only
arguments would be quietly lost, and the user would either get
`TypeError: foo() got an unexpected keyword argument...` or the
confusing behavior of having the keyword argument overwritten with
whatever's in the context with the same name.
Diffstat (limited to 'test/test_ast.py')
-rw-r--r-- | test/test_ast.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/test/test_ast.py b/test/test_ast.py index be93751..9f9ec10 100644 --- a/test/test_ast.py +++ b/test/test_ast.py @@ -1,7 +1,7 @@ import unittest from mako import ast, exceptions, pyparser, util, compat -from test import eq_, requires_python_2 +from test import eq_, requires_python_2, requires_python_3 exception_kwargs = { 'source': '', @@ -263,6 +263,8 @@ import x as bar eq_(parsed.funcname, 'foo') eq_(parsed.argnames, ['a', 'b', 'c', 'd', 'e', 'f']) + eq_(parsed.kwargnames, + []) def test_function_decl_2(self): """test getting the arguments from a function""" @@ -270,7 +272,20 @@ import x as bar parsed = ast.FunctionDecl(code, **exception_kwargs) eq_(parsed.funcname, 'foo') eq_(parsed.argnames, - ['a', 'b', 'c', 'args', 'kwargs']) + ['a', 'b', 'c', 'args']) + eq_(parsed.kwargnames, + ['kwargs']) + + @requires_python_3 + def test_function_decl_3(self): + """test getting the arguments from a fancy py3k function""" + code = "def foo(a, b, *c, d, e, **f):pass" + parsed = ast.FunctionDecl(code, **exception_kwargs) + eq_(parsed.funcname, 'foo') + eq_(parsed.argnames, + ['a', 'b', 'c']) + eq_(parsed.kwargnames, + ['d', 'e', 'f']) def test_expr_generate(self): """test the round trip of expressions to AST back to python source""" |