summaryrefslogtreecommitdiff
path: root/Lib/test/test_inspect.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r--Lib/test/test_inspect.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 38d161898f..b664c14020 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -585,6 +585,20 @@ class TestRetrievingSourceCode(GetSourceBase):
def test_getsource_on_code_object(self):
self.assertSourceEqual(mod.eggs.__code__, 12, 18)
+class TestGetsourceInteractive(unittest.TestCase):
+ def tearDown(self):
+ mod.ParrotDroppings.__module__ = mod
+ sys.modules['__main__'] = self.main
+
+ def test_getclasses_interactive(self):
+ self.main = sys.modules['__main__']
+ class MockModule:
+ __file__ = None
+ sys.modules['__main__'] = MockModule
+ mod.ParrotDroppings.__module__ = '__main__'
+ with self.assertRaisesRegex(OSError, 'source code not available') as e:
+ inspect.getsource(mod.ParrotDroppings)
+
class TestGettingSourceOfToplevelFrames(GetSourceBase):
fodderModule = mod
@@ -4349,7 +4363,8 @@ def test_main():
TestBoundArguments, TestSignaturePrivateHelpers,
TestSignatureDefinitions, TestIsDataDescriptor,
TestGetClosureVars, TestUnwrap, TestMain, TestReload,
- TestGetCoroutineState, TestGettingSourceOfToplevelFrames
+ TestGetCoroutineState, TestGettingSourceOfToplevelFrames,
+ TestGetsourceInteractive,
)
if __name__ == "__main__":