summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_inspect.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2014-12-08 21:05:34 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2014-12-08 21:05:34 (GMT)
commitef1e7502256cfd550fe264a9832e3fc517cbcb42 (patch)
tree84abe5524a7944761d2b9c07fd39110f28de5008 /Lib/test/test_inspect.py
parentb532df62b95920c380190f4a468fe15ad0c7d39c (diff)
downloadcpython-ef1e7502256cfd550fe264a9832e3fc517cbcb42.zip
cpython-ef1e7502256cfd550fe264a9832e3fc517cbcb42.tar.gz
cpython-ef1e7502256cfd550fe264a9832e3fc517cbcb42.tar.bz2
inspect: Fix getsource() to load updated source of reloaded module
Issue #1218234. Initial patch by Berker Peksag.
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r--Lib/test/test_inspect.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 9586041..bbc5385 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -14,6 +14,7 @@ import re
import shutil
import sys
import types
+import textwrap
import unicodedata
import unittest
import unittest.mock
@@ -29,6 +30,8 @@ from test.script_helper import assert_python_ok, assert_python_failure
from test import inspect_fodder as mod
from test import inspect_fodder2 as mod2
+from test.test_import import _ready_to_import
+
# Functions tested in this suite:
# ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode,
@@ -3262,6 +3265,34 @@ class TestMain(unittest.TestCase):
self.assertEqual(err, b'')
+class TestReload(unittest.TestCase):
+
+ src_before = textwrap.dedent("""\
+def foo():
+ print("Bla")
+ """)
+
+ src_after = textwrap.dedent("""\
+def foo():
+ print("Oh no!")
+ """)
+
+ def assertInspectEqual(self, path, source):
+ inspected_src = inspect.getsource(source)
+ with open(path) as src:
+ self.assertEqual(
+ src.read().splitlines(True),
+ inspected_src.splitlines(True)
+ )
+
+ def test_getsource_reload(self):
+ # see issue 1218234
+ with _ready_to_import('reload_bug', self.src_before) as (name, path):
+ module = importlib.import_module(name)
+ self.assertInspectEqual(path, module)
+ with open(path, 'w') as src:
+ src.write(self.src_after)
+ self.assertInspectEqual(path, module)
def test_main():
@@ -3272,7 +3303,7 @@ def test_main():
TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState,
TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject,
TestBoundArguments, TestSignaturePrivateHelpers, TestGetClosureVars,
- TestUnwrap, TestMain
+ TestUnwrap, TestMain, TestReload
)
if __name__ == "__main__":