Python pydoc.render_doc() Examples
The following are 30
code examples of pydoc.render_doc().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pydoc
, or try the search function
.
Example #1
Source File: test_pydoc.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_builtin(self): for name in ('str', 'str.translate', '__builtin__.str', '__builtin__.str.translate'): # test low-level function self.assertIsNotNone(pydoc.locate(name)) # test high-level function try: pydoc.render_doc(name) except ImportError: self.fail('finding the doc of {!r} failed'.format(name)) for name in ('not__builtin__', 'strrr', 'strr.translate', 'str.trrrranslate', '__builtin__.strrr', '__builtin__.str.trrranslate'): self.assertIsNone(pydoc.locate(name)) self.assertRaises(ImportError, pydoc.render_doc, name)
Example #2
Source File: test_pydoc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_builtin(self): for name in ('str', 'str.translate', '__builtin__.str', '__builtin__.str.translate'): # test low-level function self.assertIsNotNone(pydoc.locate(name)) # test high-level function try: pydoc.render_doc(name) except ImportError: self.fail('finding the doc of {!r} failed'.format(o)) for name in ('not__builtin__', 'strrr', 'strr.translate', 'str.trrrranslate', '__builtin__.strrr', '__builtin__.str.trrranslate'): self.assertIsNone(pydoc.locate(name)) self.assertRaises(ImportError, pydoc.render_doc, name)
Example #3
Source File: main.py From pydiscourse with MIT License | 6 votes |
def __getattr__(self, attr): if attr.startswith('do_'): method = getattr(self.client, attr[3:]) def wrapper(arg): args = arg.split() kwargs = dict(a.split('=') for a in args if '=' in a) args = [a for a in args if '=' not in a] try: return method(*args, **kwargs) except DiscourseError as e: print (e, e.response.text) return e.response return wrapper elif attr.startswith('help_'): method = getattr(self.client, attr[5:]) def wrapper(): self.output.write(pydoc.render_doc(method)) return wrapper raise AttributeError
Example #4
Source File: test_pydoc.py From oss-ftp with MIT License | 6 votes |
def test_builtin(self): for name in ('str', 'str.translate', '__builtin__.str', '__builtin__.str.translate'): # test low-level function self.assertIsNotNone(pydoc.locate(name)) # test high-level function try: pydoc.render_doc(name) except ImportError: self.fail('finding the doc of {!r} failed'.format(name)) for name in ('not__builtin__', 'strrr', 'strr.translate', 'str.trrrranslate', '__builtin__.strrr', '__builtin__.str.trrranslate'): self.assertIsNone(pydoc.locate(name)) self.assertRaises(ImportError, pydoc.render_doc, name)
Example #5
Source File: test_pydoc.py From BinderFilter with MIT License | 6 votes |
def test_builtin(self): for name in ('str', 'str.translate', '__builtin__.str', '__builtin__.str.translate'): # test low-level function self.assertIsNotNone(pydoc.locate(name)) # test high-level function try: pydoc.render_doc(name) except ImportError: self.fail('finding the doc of {!r} failed'.format(o)) for name in ('not__builtin__', 'strrr', 'strr.translate', 'str.trrrranslate', '__builtin__.strrr', '__builtin__.str.trrranslate'): self.assertIsNone(pydoc.locate(name)) self.assertRaises(ImportError, pydoc.render_doc, name)
Example #6
Source File: test_pydoc.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_builtin(self): for name in ('str', 'str.translate', 'builtins.str', 'builtins.str.translate'): # test low-level function self.assertIsNotNone(pydoc.locate(name)) # test high-level function try: pydoc.render_doc(name) except ImportError: self.fail('finding the doc of {!r} failed'.format(name)) for name in ('notbuiltins', 'strrr', 'strr.translate', 'str.trrrranslate', 'builtins.strrr', 'builtins.str.trrranslate'): self.assertIsNone(pydoc.locate(name)) self.assertRaises(ImportError, pydoc.render_doc, name)
Example #7
Source File: test_pydoc.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_builtin(self): for name in ('str', 'str.translate', 'builtins.str', 'builtins.str.translate'): # test low-level function self.assertIsNotNone(pydoc.locate(name)) # test high-level function try: pydoc.render_doc(name) except ImportError: self.fail('finding the doc of {!r} failed'.format(name)) for name in ('notbuiltins', 'strrr', 'strr.translate', 'str.trrrranslate', 'builtins.strrr', 'builtins.str.trrranslate'): self.assertIsNone(pydoc.locate(name)) self.assertRaises(ImportError, pydoc.render_doc, name)
Example #8
Source File: test_pydoc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_builtin(self): for name in ('str', 'str.translate', '__builtin__.str', '__builtin__.str.translate'): # test low-level function self.assertIsNotNone(pydoc.locate(name)) # test high-level function try: pydoc.render_doc(name) except ImportError: self.fail('finding the doc of {!r} failed'.format(name)) for name in ('not__builtin__', 'strrr', 'strr.translate', 'str.trrrranslate', '__builtin__.strrr', '__builtin__.str.trrranslate'): self.assertIsNone(pydoc.locate(name)) self.assertRaises(ImportError, pydoc.render_doc, name)
Example #9
Source File: test_pydoc.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_builtin(self): for name in ('str', 'str.translate', '__builtin__.str', '__builtin__.str.translate'): # test low-level function self.assertIsNotNone(pydoc.locate(name)) # test high-level function try: pydoc.render_doc(name) except ImportError: self.fail('finding the doc of {!r} failed'.format(o)) for name in ('not__builtin__', 'strrr', 'strr.translate', 'str.trrrranslate', '__builtin__.strrr', '__builtin__.str.trrranslate'): self.assertIsNone(pydoc.locate(name)) self.assertRaises(ImportError, pydoc.render_doc, name)
Example #10
Source File: test_schema.py From quiz with Apache License 2.0 | 5 votes |
def render_doc(obj): return trim_whitespace(pydoc.render_doc(obj, renderer=pydoc.plaintext))
Example #11
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
def test_typing_pydoc(self): def foo(data: typing.List[typing.Any], x: int) -> typing.Iterator[typing.Tuple[int, typing.Any]]: ... T = typing.TypeVar('T') class C(typing.Generic[T], typing.Mapping[int, str]): ... self.assertEqual(pydoc.render_doc(foo).splitlines()[-1], 'f\x08fo\x08oo\x08o(data: List[Any], x: int)' ' -> Iterator[Tuple[int, Any]]') self.assertEqual(pydoc.render_doc(C).splitlines()[2], 'class C\x08C(collections.abc.Mapping, typing.Generic)')
Example #12
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
def test_field_order_for_named_tuples(self): Person = namedtuple('Person', ['nickname', 'firstname', 'agegroup']) s = pydoc.render_doc(Person) self.assertLess(s.index('nickname'), s.index('firstname')) self.assertLess(s.index('firstname'), s.index('agegroup')) class NonIterableFields: _fields = None class NonHashableFields: _fields = [[]] # Make sure these doesn't fail pydoc.render_doc(NonIterableFields) pydoc.render_doc(NonHashableFields)
Example #13
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
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"
Example #14
Source File: test_pydoc.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_non_str_name(self): # issue14638 # Treat illegal (non-str) name like no name class A: __name__ = 42 class B: pass adoc = pydoc.render_doc(A()) bdoc = pydoc.render_doc(B()) self.assertEqual(adoc.replace("A", "B"), bdoc)
Example #15
Source File: test_schema.py From quiz with Apache License 2.0 | 5 votes |
def test_end_to_end(raw_schema): schema = quiz.Schema.from_raw(raw_schema, module="github") doc = render_doc(schema.Issue) assert ( """\ | viewerDidAuthor | : bool | Did the viewer author this comment.""" in doc ) assert ( """\ | publishedAt | : DateTime or None | Identifies when the comment was published at.""" in doc ) assert ( """\ | viewerCannotUpdateReasons | : [CommentCannotUpdateReason] | Reasons why the current viewer can not update this comment.""" in doc ) assert schema.Issue.__doc__ in doc assert "Labelable" in doc
Example #16
Source File: test_pydoc.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_classic_class(self): class C: "Classic class" c = C() self.assertEqual(pydoc.describe(C), 'class C') self.assertEqual(pydoc.describe(c), 'instance of C') expected = 'instance of C in module %s' % __name__ self.assertIn(expected, pydoc.render_doc(c))
Example #17
Source File: test_pydoc.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_class(self): class C(object): "New-style class" c = C() self.assertEqual(pydoc.describe(C), 'class C') self.assertEqual(pydoc.describe(c), 'C') expected = 'C in module %s object' % __name__ self.assertIn(expected, pydoc.render_doc(c))
Example #18
Source File: python_magic.py From metakernel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_help_on(self, info, level=0, none_on_fail=False): """Implement basic help for functions""" if not info['code']: return None if none_on_fail else '' last = info['obj'] default = None if none_on_fail else ('No help available for "%s"' % last) parts = last.split('.') obj = self.env.get(parts[0], None) if not obj: return default for p in parts[1:]: obj = getattr(obj, p, None) if not obj: return default strhelp = pydoc.render_doc(obj, "Help on %s") if level == 0: return getattr(obj, '__doc__', strhelp) else: return strhelp
Example #19
Source File: test_pydoc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_render_doc(self): # render_doc is robust against unicode in docstrings doc = pydoc.render_doc(self.Q) self.assertIsInstance(doc, str)
Example #20
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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"
Example #21
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_typing_pydoc(self): def foo(data: typing.List[typing.Any], x: int) -> typing.Iterator[typing.Tuple[int, typing.Any]]: ... T = typing.TypeVar('T') class C(typing.Generic[T], typing.Mapping[int, str]): ... self.assertEqual(pydoc.render_doc(foo).splitlines()[-1], 'f\x08fo\x08oo\x08o(data:List[Any], x:int)' ' -> Iterator[Tuple[int, Any]]') self.assertEqual(pydoc.render_doc(C).splitlines()[2], 'class C\x08C(typing.Mapping)')
Example #22
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_class(self): class C: "New-style class" c = C() self.assertEqual(pydoc.describe(C), 'class C') self.assertEqual(pydoc.describe(c), 'C') expected = 'C in module %s object' % __name__ self.assertIn(expected, pydoc.render_doc(c))
Example #23
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_module(self): # Check that pydocfodder module can be described from test import pydocfodder doc = pydoc.render_doc(pydocfodder) self.assertIn("pydocfodder", doc)
Example #24
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_non_str_name(self): # issue14638 # Treat illegal (non-str) name like no name class A: __name__ = 42 class B: pass adoc = pydoc.render_doc(A()) bdoc = pydoc.render_doc(B()) self.assertEqual(adoc.replace("A", "B"), bdoc)
Example #25
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_text_enum_member_with_value_zero(self): # Test issue #20654 to ensure enum member with value 0 can be # displayed. It used to throw KeyError: 'zero'. import enum class BinaryInteger(enum.IntEnum): zero = 0 one = 1 doc = pydoc.render_doc(BinaryInteger) self.assertIn('<BinaryInteger.zero: 0>', doc)
Example #26
Source File: inspector.py From sos-notebook with BSD 3-Clause "New" or "Revised" License | 5 votes |
def inspect(self, name, line, pos): if line.startswith( '%') and name in SoS_Magics.names and pos <= len(name) + 1: try: magic = SoS_Magics(self.kernel).get(name) parser = magic.get_parser() return {'text/plain': parser.format_help()} except Exception as e: return {'text/plain': f'Magic %{name}: {e}'} elif line.startswith(name + ':') and pos <= len(name): if self.kernel.original_keys is None: self.kernel._reset_dict() # input: etc if name in SOS_USAGES: return {'text/plain': SOS_USAGES[name]} elif name in env.sos_dict: # action? return { 'text/plain': pydoc.render_doc( env.sos_dict[name], title='%s', renderer=pydoc.plaintext), 'text/html': pydoc.render_doc( env.sos_dict[name], title='%s', renderer=pydoc.html) } else: return {} else: return {}
Example #27
Source File: test_pydoc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_ttypager(self): # ttypager does not choke on unicode doc = pydoc.render_doc(self.Q) # Test ttypager with test.test_support.temp_cwd(), test.test_support.captured_stdin(): with open('output', 'w') as f: saved, sys.stdout = sys.stdout, f try: pydoc.ttypager(doc) finally: sys.stdout = saved self.assertIn('Rational numbers:', open('output').read())
Example #28
Source File: test_pydoc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_plainpager(self): # plainpager does not choke on unicode doc = pydoc.render_doc(self.Q) # Note: captured_stdout is too permissive when it comes to # unicode, and using it here would make the test always # pass. with test.test_support.temp_cwd(): with open('output', 'w') as f: saved, sys.stdout = sys.stdout, f try: pydoc.plainpager(doc) finally: sys.stdout = saved self.assertIn('Rational numbers:', open('output').read())
Example #29
Source File: test_pydoc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_tempfilepager(self): # tempfilepager does not choke on unicode doc = pydoc.render_doc(self.Q) output = {} def mock_system(cmd): filename = cmd.strip()[1:-1] self.assertEqual('"' + filename + '"', cmd.strip()) output['content'] = open(filename).read() saved, os.system = os.system, mock_system try: pydoc.tempfilepager(doc, '') self.assertEqual(output['content'], pydoc._encode(doc)) finally: os.system = saved
Example #30
Source File: test_pydoc.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_module(self): # Check that pydocfodder module can be described from test import pydocfodder doc = pydoc.render_doc(pydocfodder) self.assertIn("pydocfodder", doc)