aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_ast.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-11-10 12:09:30 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-11-10 12:09:30 -0500
commitca21a5353a4c88f3477a53f2f45cd9ca280b0479 (patch)
tree45649d02b5b83ce56ff1a6ad702c955823ebbc6b /test/test_ast.py
parentc8598ab628a0da0d55857196627753dad9849a39 (diff)
downloadexternal_python_mako-ca21a5353a4c88f3477a53f2f45cd9ca280b0479.tar.gz
external_python_mako-ca21a5353a4c88f3477a53f2f45cd9ca280b0479.tar.bz2
external_python_mako-ca21a5353a4c88f3477a53f2f45cd9ca280b0479.zip
- The range of Python identifiers that
are considered "undefined", meaning they are pulled from the context, has been trimmed back to not include variables declared inside of expressions (i.e. from list comprehensions), as well as in the argument list of lambdas. This to better support the strict_undefined feature.
Diffstat (limited to 'test/test_ast.py')
-rw-r--r--test/test_ast.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/test_ast.py b/test/test_ast.py
index bfdfd90..b9fe948 100644
--- a/test/test_ast.py
+++ b/test/test_ast.py
@@ -156,7 +156,39 @@ class Hi(object):
parsed = ast.PythonCode(code, **exception_kwargs)
assert parsed.declared_identifiers == set(['Hi'])
assert parsed.undeclared_identifiers == set()
+
+ def test_locate_identifiers_9(self):
+ code = """
+ ",".join([t for t in ("a", "b", "c")])
+"""
+ parsed = ast.PythonCode(code, **exception_kwargs)
+ assert parsed.declared_identifiers == set(['t'])
+ assert parsed.undeclared_identifiers == set(['t'])
+
+ code = """
+ [(val, name) for val, name in x]
+"""
+ parsed = ast.PythonCode(code, **exception_kwargs)
+ assert parsed.declared_identifiers == set(['val', 'name'])
+ assert parsed.undeclared_identifiers == set(['val', 'name', 'x'])
+ def test_locate_identifiers_10(self):
+ code = """
+lambda q: q + 5
+"""
+ parsed = ast.PythonCode(code, **exception_kwargs)
+ eq_(parsed.declared_identifiers, set())
+ eq_(parsed.undeclared_identifiers, set())
+
+ def test_locate_identifiers_11(self):
+ code = """
+def x(q):
+ return q + 5
+"""
+ parsed = ast.PythonCode(code, **exception_kwargs)
+ eq_(parsed.declared_identifiers, set(['x']))
+ eq_(parsed.undeclared_identifiers, set())
+
def test_no_global_imports(self):
code = """
from foo import *