[Python-checkins] cpython: Properly test the various builtins lookup cases in inspect.getclosurevars
nick.coghlan
python-checkins at python.org
Sat Jun 23 18:28:53 CEST 2012
http://hg.python.org/cpython/rev/61c1aeb7fb10
changeset: 77637:61c1aeb7fb10
user: Nick Coghlan <ncoghlan at gmail.com>
date: Sat Jun 23 20:07:39 2012 +1000
summary:
Properly test the various builtins lookup cases in inspect.getclosurevars
files:
Lib/test/test_inspect.py | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -763,6 +763,30 @@
self.assertRaises(TypeError, inspect.getclosurevars, list)
self.assertRaises(TypeError, inspect.getclosurevars, {})
+ def _private_globals(self):
+ code = """def f(): print(path)"""
+ ns = {}
+ exec(code, ns)
+ return ns["f"], ns
+
+ def test_builtins_fallback(self):
+ f, ns = self._private_globals()
+ ns.pop("__builtins__", None)
+ expected = inspect.ClosureVars({}, {}, {"print":print}, {"path"})
+ self.assertEqual(inspect.getclosurevars(f), expected)
+
+ def test_builtins_as_dict(self):
+ f, ns = self._private_globals()
+ ns["__builtins__"] = {"path":1}
+ expected = inspect.ClosureVars({}, {}, {"path":1}, {"print"})
+ self.assertEqual(inspect.getclosurevars(f), expected)
+
+ def test_builtins_as_module(self):
+ f, ns = self._private_globals()
+ ns["__builtins__"] = os
+ expected = inspect.ClosureVars({}, {}, {"path":os.path}, {"print"})
+ self.assertEqual(inspect.getclosurevars(f), expected)
+
class TestGetcallargsFunctions(unittest.TestCase):
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list