diff options
author | Vladimir Matveev <v2matveev@outlook.com> | 2018-08-24 14:18:00 (GMT) |
---|---|---|
committer | Tal Einat <taleinat+github@gmail.com> | 2018-08-24 14:18:00 (GMT) |
commit | 91cb298f811961277fd4cc4a32211899d48bedcb (patch) | |
tree | 6b833e01b19fdae681b767cc44f4b8d3e676e88a /Lib/test/test_inspect.py | |
parent | 075b3c325913475be16650f7cb2a99f3136623b9 (diff) | |
download | cpython-91cb298f811961277fd4cc4a32211899d48bedcb.zip cpython-91cb298f811961277fd4cc4a32211899d48bedcb.tar.gz cpython-91cb298f811961277fd4cc4a32211899d48bedcb.tar.bz2 |
bpo-6700: Fix inspect.getsourcelines for module level frames/tracebacks (GH-8864)
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index cda8d5c..e523dd4 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -344,7 +344,7 @@ class GetSourceBase(unittest.TestCase): def sourcerange(self, top, bottom): lines = self.source.split("\n") - return "\n".join(lines[top-1:bottom]) + "\n" + return "\n".join(lines[top-1:bottom]) + ("\n" if bottom else "") def assertSourceEqual(self, obj, top, bottom): self.assertEqual(inspect.getsource(obj), @@ -527,6 +527,16 @@ class TestRetrievingSourceCode(GetSourceBase): def test_getsource_on_code_object(self): self.assertSourceEqual(mod.eggs.__code__, 12, 18) +class TestGettingSourceOfToplevelFrames(GetSourceBase): + fodderModule = mod + + def test_range_toplevel_frame(self): + self.maxDiff = None + self.assertSourceEqual(mod.currentframe, 1, None) + + def test_range_traceback_toplevel_frame(self): + self.assertSourceEqual(mod.tb, 1, None) + class TestDecorators(GetSourceBase): fodderModule = mod2 @@ -3870,7 +3880,7 @@ def test_main(): TestBoundArguments, TestSignaturePrivateHelpers, TestSignatureDefinitions, TestIsDataDescriptor, TestGetClosureVars, TestUnwrap, TestMain, TestReload, - TestGetCoroutineState + TestGetCoroutineState, TestGettingSourceOfToplevelFrames ) if __name__ == "__main__": |