diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-06-11 15:56:46 -0500 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-06-11 15:56:46 -0500 |
commit | 703f7c4bf5fa98f9b8b11593d3fa37eb68eae896 (patch) | |
tree | a4fe76c58a8cc614a02aaaed497289fcfc345934 /Lib/test/test_inspect.py | |
parent | 3ae42726d4ba3a304d42f0c7df039de777a678bb (diff) | |
parent | 9620cc04634e720d1d016cce4bf02e0c27607e64 (diff) | |
download | cpython-git-703f7c4bf5fa98f9b8b11593d3fa37eb68eae896.tar.gz |
merge 3.2 (#9284)
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index f5dff1e543..7666fe43a7 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -298,6 +298,23 @@ class TestRetrievingSourceCode(GetSourceBase): del sys.modules[name] inspect.getmodule(compile('a=10','','single')) + def test_proceed_with_fake_filename(self): + '''doctest monkeypatches linecache to enable inspection''' + fn, source = '<test>', 'def x(): pass\n' + getlines = linecache.getlines + def monkey(filename, module_globals=None): + if filename == fn: + return source.splitlines(True) + else: + return getlines(filename, module_globals) + linecache.getlines = monkey + try: + ns = {} + exec(compile(source, fn, 'single'), ns) + inspect.getsource(ns["x"]) + finally: + linecache.getlines = getlines + class TestDecorators(GetSourceBase): fodderModule = mod2 |