diff options
author | Larry Hastings <larry@hastings.org> | 2014-02-21 07:34:46 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2014-02-21 07:34:46 (GMT) |
commit | 24a882bb7bc638644b9e66a082439416bfbcf66c (patch) | |
tree | 2aaabe7bf4cb4d0ab0fa4b0b0be09b436d64b4cf /Lib/test/test_pydoc.py | |
parent | 8c185ee12e334007b974b3a421704ffb09ecfca8 (diff) | |
download | cpython-24a882bb7bc638644b9e66a082439416bfbcf66c.zip cpython-24a882bb7bc638644b9e66a082439416bfbcf66c.tar.gz cpython-24a882bb7bc638644b9e66a082439416bfbcf66c.tar.bz2 |
Issue #20710: The pydoc summary line no longer displays the "self" parameter
for bound methods. Previous to this change, it displayed "self" for methods
implemented in Python but not methods implemented in C; it is now both
internally consistent and consistent with inspect.Signature.
Diffstat (limited to 'Lib/test/test_pydoc.py')
-rw-r--r-- | Lib/test/test_pydoc.py | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 9909b9a..96b9230 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -6,6 +6,7 @@ import difflib import inspect import pydoc import keyword +import _pickle import pkgutil import re import string @@ -699,12 +700,41 @@ class TestDescriptions(unittest.TestCase): self.assertIsNone(pydoc.locate(name)) self.assertRaises(ImportError, pydoc.render_doc, name) + @staticmethod + def _get_summary_line(o): + text = pydoc.plain(pydoc.render_doc(o)) + lines = text.split('\n') + assert len(lines) >= 2 + return lines[2] + + # these should include "self" + def test_unbound_python_method(self): + self.assertEqual(self._get_summary_line(textwrap.TextWrapper.wrap), + "wrap(self, text)") + + @requires_docstrings + def test_unbound_builtin_method(self): + self.assertEqual(self._get_summary_line(_pickle.Pickler.dump), + "dump(self, obj, /)") + + # these no longer include "self" + def test_bound_python_method(self): + t = textwrap.TextWrapper() + self.assertEqual(self._get_summary_line(t.wrap), + "wrap(text) method of textwrap.TextWrapper instance") + + @requires_docstrings + def test_bound_builtin_method(self): + s = StringIO() + p = _pickle.Pickler(s) + self.assertEqual(self._get_summary_line(p.dump), + "dump(obj, /) method of _pickle.Pickler instance") + + # this should *never* include self! @requires_docstrings - def test_builtin_signatures(self): - # test producing signatures from builtins - stat_sig = pydoc.render_doc(os.stat) - self.assertEqual(pydoc.plain(stat_sig).splitlines()[2], - 'stat(path, *, dir_fd=None, follow_symlinks=True)') + def test_module_level_callable(self): + self.assertEqual(self._get_summary_line(os.stat), + "stat(path, *, dir_fd=None, follow_symlinks=True)") @unittest.skipUnless(threading, 'Threading required for this test.') |