summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_inspect.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-09-22 12:46:49 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2013-09-22 12:46:49 (GMT)
commitf94a16b494a2b21b8fcb90d666a31f6d78cabc26 (patch)
tree6c57e1aa09150175d484a45ae8351f0692cd04b3 /Lib/test/test_inspect.py
parent4c7fe6a5add2d773ae3a85679d22414d8eafe66c (diff)
downloadcpython-f94a16b494a2b21b8fcb90d666a31f6d78cabc26.zip
cpython-f94a16b494a2b21b8fcb90d666a31f6d78cabc26.tar.gz
cpython-f94a16b494a2b21b8fcb90d666a31f6d78cabc26.tar.bz2
Close #18626: add a basic CLI for the inspect module
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r--Lib/test/test_inspect.py46
1 files changed, 44 insertions, 2 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index be55fe4..bcb7d8a 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -9,10 +9,11 @@ import collections
import os
import shutil
import functools
+import importlib
from os.path import normcase
from test.support import run_unittest, TESTFN, DirsOnSysPath
-
+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
@@ -2372,6 +2373,47 @@ class TestUnwrap(unittest.TestCase):
__wrapped__ = func
self.assertIsNone(inspect.unwrap(C()))
+class TestMain(unittest.TestCase):
+ def test_only_source(self):
+ module = importlib.import_module('unittest')
+ rc, out, err = assert_python_ok('-m', 'inspect',
+ 'unittest')
+ lines = out.decode().splitlines()
+ # ignore the final newline
+ self.assertEqual(lines[:-1], inspect.getsource(module).splitlines())
+ self.assertEqual(err, b'')
+
+ def test_qualname_source(self):
+ module = importlib.import_module('concurrent.futures')
+ member = getattr(module, 'ThreadPoolExecutor')
+ rc, out, err = assert_python_ok('-m', 'inspect',
+ 'concurrent.futures:ThreadPoolExecutor')
+ lines = out.decode().splitlines()
+ # ignore the final newline
+ self.assertEqual(lines[:-1],
+ inspect.getsource(member).splitlines())
+ self.assertEqual(err, b'')
+
+ def test_builtins(self):
+ module = importlib.import_module('unittest')
+ _, out, err = assert_python_failure('-m', 'inspect',
+ 'sys')
+ lines = err.decode().splitlines()
+ self.assertEqual(lines, ["Can't get info for builtin modules."])
+
+ def test_details(self):
+ module = importlib.import_module('unittest')
+ rc, out, err = assert_python_ok('-m', 'inspect',
+ 'unittest', '--details')
+ output = out.decode()
+ # Just a quick sanity check on the output
+ self.assertIn(module.__name__, output)
+ self.assertIn(module.__file__, output)
+ self.assertIn(module.__cached__, output)
+ self.assertEqual(err, b'')
+
+
+
def test_main():
run_unittest(
@@ -2380,7 +2422,7 @@ def test_main():
TestGetcallargsFunctions, TestGetcallargsMethods,
TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState,
TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject,
- TestBoundArguments, TestGetClosureVars, TestUnwrap
+ TestBoundArguments, TestGetClosureVars, TestUnwrap, TestMain
)
if __name__ == "__main__":