bpo-6700: Fix inspect.getsourcelines for module level frames/tracebac… · python/cpython@3e6020c (original) (raw)
`@@ -344,7 +344,7 @@ def setUp(self):
`
344
344
``
345
345
`def sourcerange(self, top, bottom):
`
346
346
`lines = self.source.split("\n")
`
347
``
`-
return "\n".join(lines[top-1:bottom]) + "\n"
`
``
347
`+
return "\n".join(lines[top-1:bottom]) + ("\n" if bottom else "")
`
348
348
``
349
349
`def assertSourceEqual(self, obj, top, bottom):
`
350
350
`self.assertEqual(inspect.getsource(obj),
`
`@@ -527,6 +527,16 @@ def monkey(filename, module_globals=None):
`
527
527
`def test_getsource_on_code_object(self):
`
528
528
`self.assertSourceEqual(mod.eggs.code, 12, 18)
`
529
529
``
``
530
`+
class TestGettingSourceOfToplevelFrames(GetSourceBase):
`
``
531
`+
fodderModule = mod
`
``
532
+
``
533
`+
def test_range_toplevel_frame(self):
`
``
534
`+
self.maxDiff = None
`
``
535
`+
self.assertSourceEqual(mod.currentframe, 1, None)
`
``
536
+
``
537
`+
def test_range_traceback_toplevel_frame(self):
`
``
538
`+
self.assertSourceEqual(mod.tb, 1, None)
`
``
539
+
530
540
`class TestDecorators(GetSourceBase):
`
531
541
`fodderModule = mod2
`
532
542
``
`@@ -3815,7 +3825,7 @@ def test_main():
`
3815
3825
`TestBoundArguments, TestSignaturePrivateHelpers,
`
3816
3826
`TestSignatureDefinitions,
`
3817
3827
`TestGetClosureVars, TestUnwrap, TestMain, TestReload,
`
3818
``
`-
TestGetCoroutineState
`
``
3828
`+
TestGetCoroutineState, TestGettingSourceOfToplevelFrames
`
3819
3829
` )
`
3820
3830
``
3821
3831
`if name == "main":
`