我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pydoc.render_doc()。
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(o)) 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)
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)
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)
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)
def all_indicators_doc(): all_funcs = inspect.getmembers(sys.modules[__name__], inspect.isfunction) ret = "" for f in all_funcs: ret += pydoc.render_doc(f[1], renderer = pydoc.plaintext).splitlines()[2] + "\n" return ret
def test_help_command(self): # Regression test for SPARK-5464 rdd = self.sc.parallelize(['{"foo":"bar"}', '{"foo":"baz"}']) df = self.spark.read.json(rdd) # render_doc() reproduces the help() exception without printing output pydoc.render_doc(df) pydoc.render_doc(df.foo) pydoc.render_doc(df.take(1))
def test_module(self): # Check that pydocfodder module can be described from test import pydocfodder doc = pydoc.render_doc(pydocfodder) self.assertIn("pydocfodder", doc)
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))
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)
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))
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))
def test_render_doc(self): # render_doc is robust against unicode in docstrings doc = pydoc.render_doc(self.Q) self.assertIsInstance(doc, str)
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
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())
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())
def test_help_command(self): # Regression test for SPARK-5464 rdd = self.sc.parallelize(['{"foo":"bar"}', '{"foo":"baz"}']) df = self.sqlCtx.read.json(rdd) # render_doc() reproduces the help() exception without printing output pydoc.render_doc(df) pydoc.render_doc(df.foo) pydoc.render_doc(df.take(1))
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)