diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2014-01-05 03:38:11 (GMT) |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2014-01-05 03:38:11 (GMT) |
commit | aed5b22ead9127103cea2de8722d36b90a320142 (patch) | |
tree | eb9adde0605f92165fffd2f30f52df29cbab5911 /Lib/test/test_pydoc.py | |
parent | 244ad600e9735448a50ce7a9bb7cbec3336e526a (diff) | |
download | cpython-aed5b22ead9127103cea2de8722d36b90a320142.zip cpython-aed5b22ead9127103cea2de8722d36b90a320142.tar.gz cpython-aed5b22ead9127103cea2de8722d36b90a320142.tar.bz2 |
Issue 20123: Fix pydoc.synopsis() for "binary" modules.
Also add missing tests to test_pydoc.
Diffstat (limited to 'Lib/test/test_pydoc.py')
-rw-r--r-- | Lib/test/test_pydoc.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index cdf28a4..7fe0644 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -487,6 +487,13 @@ class PydocDocTest(unittest.TestCase): synopsis = pydoc.synopsis(TESTFN, {}) self.assertEqual(synopsis, 'line 1: h\xe9') + def test_synopsis_sourceless(self): + expected = os.__doc__.splitlines()[0] + filename = os.__cached__ + synopsis = pydoc.synopsis(filename) + + self.assertEqual(synopsis, expected) + def test_splitdoc_with_description(self): example_string = "I Am A Doc\n\n\nHere is my description" self.assertEqual(pydoc.splitdoc(example_string), @@ -600,6 +607,50 @@ class PydocImportTest(PydocBaseTest): self.assertEqual(out.getvalue(), '') self.assertEqual(err.getvalue(), '') + def test_modules(self): + # See Helper.listmodules(). + num_header_lines = 2 + num_module_lines_min = 5 # Playing it safe. + num_footer_lines = 3 + expected = num_header_lines + num_module_lines_min + num_footer_lines + + output = StringIO() + helper = pydoc.Helper(output=output) + helper('modules') + result = output.getvalue().strip() + num_lines = len(result.splitlines()) + + self.assertGreaterEqual(num_lines, expected) + + def test_modules_search(self): + # See Helper.listmodules(). + expected = 'pydoc - ' + + output = StringIO() + helper = pydoc.Helper(output=output) + with captured_stdout() as help_io: + helper('modules pydoc') + result = help_io.getvalue() + + self.assertIn(expected, result) + + def test_modules_search_builtin(self): + expected = 'gc - ' + + output = StringIO() + helper = pydoc.Helper(output=output) + with captured_stdout() as help_io: + helper('modules garbage') + result = help_io.getvalue() + + self.assertTrue(result.startswith(expected)) + + def test_importfile(self): + loaded_pydoc = pydoc.importfile(pydoc.__file__) + + self.assertEqual(loaded_pydoc.__name__, 'pydoc') + self.assertEqual(loaded_pydoc.__file__, pydoc.__file__) + class TestDescriptions(unittest.TestCase): @@ -827,6 +878,7 @@ class PydocWithMetaClasses(unittest.TestCase): print_diffs(expected_text, result) self.fail("outputs are not equal, see diff above") + @reap_threads def test_main(): try: |