diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2012-06-23 10:07:39 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2012-06-23 10:07:39 (GMT) |
commit | 6c6e2545cb6904f78754d799d4cfb180f7a626d9 (patch) | |
tree | c215a68f9c5b75c062b790115f17380b2de6a8c1 /Lib/test | |
parent | fb8dac76328db47535ca121836aaf5553d2cddc1 (diff) | |
download | cpython-6c6e2545cb6904f78754d799d4cfb180f7a626d9.zip cpython-6c6e2545cb6904f78754d799d4cfb180f7a626d9.tar.gz cpython-6c6e2545cb6904f78754d799d4cfb180f7a626d9.tar.bz2 |
Properly test the various builtins lookup cases in inspect.getclosurevars
Diffstat (limited to 'Lib/test')
-rw-r--r-- | 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 index 9d971e0..7ed4ffe 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -763,6 +763,30 @@ class TestGetClosureVars(unittest.TestCase): 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): |