summaryrefslogtreecommitdiff
path: root/Lib/test/test_inspect.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r--Lib/test/test_inspect.py17
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