diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2015-02-20 10:10:33 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2015-02-20 10:10:33 (GMT) |
commit | dc9d41d71820b255ba21683578aac7c9129cf0ce (patch) | |
tree | 7eb0ad04ef244ab67fd05bd1e96bd72c4b2c18ac /Lib/test/test_pydoc.py | |
parent | bbdad5442b874f497d0c8b5d9612dc9d1c3594de (diff) | |
download | cpython-dc9d41d71820b255ba21683578aac7c9129cf0ce.zip cpython-dc9d41d71820b255ba21683578aac7c9129cf0ce.tar.gz cpython-dc9d41d71820b255ba21683578aac7c9129cf0ce.tar.bz2 |
Issue #21548: Fix pydoc.synopsis() and pydoc.apropos() on modules with empty
docstrings.
Initial patch by Yuyang Guo.
Diffstat (limited to 'Lib/test/test_pydoc.py')
-rw-r--r-- | Lib/test/test_pydoc.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index c11c06b..5bb97e2 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -3,6 +3,7 @@ import sys import difflib import __builtin__ import re +import py_compile import pydoc import contextlib import inspect @@ -382,6 +383,34 @@ class PydocDocTest(unittest.TestCase): self.assertEqual(stripid("<type 'exceptions.Exception'>"), "<type 'exceptions.Exception'>") + def test_synopsis(self): + with test.test_support.temp_cwd() as test_dir: + init_path = os.path.join(test_dir, 'dt.py') + with open(init_path, 'w') as fobj: + fobj.write('''\ +""" +my doc + +second line +""" +foo = 1 +''') + py_compile.compile(init_path) + synopsis = pydoc.synopsis(init_path, {}) + self.assertEqual(synopsis, 'my doc') + + def test_synopsis_sourceless_empty_doc(self): + with test.test_support.temp_cwd() as test_dir: + init_path = os.path.join(test_dir, 'foomod42.py') + cached_path = os.path.join(test_dir, 'foomod42.pyc') + with open(init_path, 'w') as fobj: + fobj.write("foo = 1") + py_compile.compile(init_path) + synopsis = pydoc.synopsis(init_path, {}) + self.assertIsNone(synopsis) + synopsis_cached = pydoc.synopsis(cached_path, {}) + self.assertIsNone(synopsis_cached) + class PydocImportTest(PydocBaseTest): |