diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-06-17 02:04:29 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-06-17 02:04:29 (GMT) |
commit | a1b3740d042206efada2b8e1d97349c4d95e34e1 (patch) | |
tree | bb4ecfebe47e1aeab871fce9dcd55dc3bbadd420 /Lib/test/test_inspect.py | |
parent | 2bdab2406332e8f9094bac22cc796f2385bcd116 (diff) | |
download | cpython-a1b3740d042206efada2b8e1d97349c4d95e34e1.zip cpython-a1b3740d042206efada2b8e1d97349c4d95e34e1.tar.gz cpython-a1b3740d042206efada2b8e1d97349c4d95e34e1.tar.bz2 |
Merged revisions 82039 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r82039 | r.david.murray | 2010-06-16 21:36:52 -0400 (Wed, 16 Jun 2010) | 10 lines
#8720: fix inspect regression by teaching getsourcefile about linecache.
The fix for issue 4050 caused a regression: before that fix, source
lines in the linecache would eventually be found by inspect. After the
fix inspect reports an error earlier, and the source isn't found.
The fix for the fix is to have getsourcefile look in the linecache for
the file and return the psuedo-filename if the source is there, just as
it already returns it if there is a PEP 302 loader.
........
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index b89f8075..b515c1f 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -3,6 +3,7 @@ import sys import types import unittest import inspect +import linecache import datetime import collections from os.path import normcase @@ -275,6 +276,11 @@ class TestRetrievingSourceCode(GetSourceBase): def test_getsourcefile(self): self.assertEqual(normcase(inspect.getsourcefile(mod.spam)), modfile) self.assertEqual(normcase(inspect.getsourcefile(git.abuse)), modfile) + fn = "_non_existing_filename_used_for_sourcefile_test.py" + co = compile("None", fn, "exec") + self.assertEqual(normcase(inspect.getsourcefile(co)), None) + linecache.cache[co.co_filename] = (1, None, "None", co.co_filename) + self.assertEqual(normcase(inspect.getsourcefile(co)), fn) def test_getfile(self): self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__) @@ -373,6 +379,15 @@ class TestBuggyCases(GetSourceBase): self.assertRaises(IOError, inspect.getsource, unicodedata) self.assertRaises(IOError, inspect.findsource, unicodedata) + def test_findsource_code_in_linecache(self): + lines = ["x=1"] + co = compile(lines[0], "_dynamically_created_file", "exec") + self.assertRaises(IOError, inspect.findsource, co) + self.assertRaises(IOError, inspect.getsource, co) + linecache.cache[co.co_filename] = (1, None, lines, co.co_filename) + self.assertEquals(inspect.findsource(co), (lines,0)) + self.assertEquals(inspect.getsource(co), lines[0]) + # Helper for testing classify_class_attrs. def attrs_wo_objs(cls): return [t[:3] for t in inspect.classify_class_attrs(cls)] |