diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2006-09-07 10:50:34 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2006-09-07 10:50:34 (GMT) |
commit | c495c66ea922e3ce8d822716a7abbf28ee709b71 (patch) | |
tree | 27b8b57601634af058d059f58fb30777c1401e86 /Lib/test/test_inspect.py | |
parent | c563a1c32b136b5f4d65658d3f5487be206c104b (diff) | |
download | cpython-c495c66ea922e3ce8d822716a7abbf28ee709b71.zip cpython-c495c66ea922e3ce8d822716a7abbf28ee709b71.tar.gz cpython-c495c66ea922e3ce8d822716a7abbf28ee709b71.tar.bz2 |
Fix the speed regression in inspect.py by adding another cache to speed up getmodule(). Patch #1553314
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index fa4bd40..d880e87 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -178,7 +178,18 @@ class TestRetrievingSourceCode(GetSourceBase): self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n') def test_getmodule(self): + # Check actual module + self.assertEqual(inspect.getmodule(mod), mod) + # Check class (uses __module__ attribute) self.assertEqual(inspect.getmodule(mod.StupidGit), mod) + # Check a method (no __module__ attribute, falls back to filename) + self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod) + # Do it again (check the caching isn't broken) + self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod) + # Check a builtin + self.assertEqual(inspect.getmodule(str), sys.modules["__builtin__"]) + # Check filename override + self.assertEqual(inspect.getmodule(None, modfile), mod) def test_getsource(self): self.assertSourceEqual(git.abuse, 29, 39) |