本文整理汇总了Python中pydoc.Helper方法的典型用法代码示例。如果您正苦于以下问题:Python pydoc.Helper方法的具体用法?Python pydoc.Helper怎么用?Python pydoc.Helper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydoc
的用法示例。
在下文中一共展示了pydoc.Helper方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_virtualClassAttributeWithOneMeta
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_virtualClassAttributeWithOneMeta(self):
class Meta(type):
def __dir__(cls):
return ['__class__', '__module__', '__name__', 'LIFE']
def __getattr__(self, name):
if name =='LIFE':
return 42
return super().__getattr(name)
class Class(metaclass=Meta):
pass
output = StringIO()
helper = pydoc.Helper(output=output)
helper(Class)
expected_text = expected_virtualattribute_pattern1 % __name__
result = output.getvalue().strip()
if result != expected_text:
print_diffs(expected_text, result)
self.fail("outputs are not equal, see diff above")
示例2: test_virtualClassAttributeWithOneMeta
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_virtualClassAttributeWithOneMeta(self):
class Meta(type):
def __dir__(cls):
return ['__class__', '__module__', '__name__', 'LIFE']
def __getattr__(self, name):
if name =='LIFE':
return 42
return super().__getattr(name)
class Class(metaclass=Meta):
pass
output = StringIO()
helper = pydoc.Helper(output=output)
helper(Class)
expected_text = expected_virtualattribute_pattern1 % __name__
result = output.getvalue().strip()
self.assertEqual(expected_text, result)
示例3: listmodules
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def listmodules(self, key=''):
if key != '':
pydoc.Helper.listmodules(self, key)
else:
self.output.write('''
Please wait a moment while I gather a list of all available modules...
''')
modules = []
for module_loader, name, ispkg in pkgutil.iter_modules():
if '__main__' in name or '__init__' in name:
continue
modules.append(name)
self.list(modules)
self.output.write('''
Enter any module name to get more help. Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".
''')
示例4: test_help_output_redirect
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_help_output_redirect(self):
# issue 940286, if output is set in Helper, then all output from
# Helper.help should be redirected
old_pattern = expected_text_pattern
getpager_old = pydoc.getpager
getpager_new = lambda: (lambda x: x)
self.maxDiff = None
buf = StringIO()
helper = pydoc.Helper(output=buf)
unused, doc_loc = get_pydoc_text(pydoc_mod)
module = "test.pydoc_mod"
help_header = """
Help on module test.pydoc_mod in test:
""".lstrip()
help_header = textwrap.dedent(help_header)
expected_help_pattern = help_header + expected_text_pattern
pydoc.getpager = getpager_new
try:
with captured_output('stdout') as output, \
captured_output('stderr') as err:
helper.help(module)
result = buf.getvalue().strip()
expected_text = expected_help_pattern % (
(doc_loc,) +
expected_text_data_docstrings +
(inspect.getabsfile(pydoc_mod),))
self.assertEqual('', output.getvalue())
self.assertEqual('', err.getvalue())
self.assertEqual(expected_text, result)
finally:
pydoc.getpager = getpager_old
示例5: test_modules
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
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)
示例6: test_modules_search
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
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)
示例7: test_modules_search_builtin
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
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))
示例8: test_keywords
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_keywords(self):
self.assertEqual(sorted(pydoc.Helper.keywords),
sorted(keyword.kwlist))
示例9: test_virtualClassAttributeWithTwoMeta
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_virtualClassAttributeWithTwoMeta(self):
class Meta1(type):
def __dir__(cls):
return ['__class__', '__module__', '__name__', 'one']
def __getattr__(self, name):
if name =='one':
return 1
return super().__getattr__(name)
class Meta2(type):
def __dir__(cls):
return ['__class__', '__module__', '__name__', 'two']
def __getattr__(self, name):
if name =='two':
return 2
return super().__getattr__(name)
class Meta3(Meta1, Meta2):
def __dir__(cls):
return list(sorted(set(
['__class__', '__module__', '__name__', 'three'] +
Meta1.__dir__(cls) + Meta2.__dir__(cls))))
def __getattr__(self, name):
if name =='three':
return 3
return super().__getattr__(name)
class Class1(metaclass=Meta1):
pass
class Class2(Class1, metaclass=Meta3):
pass
fail1 = fail2 = False
output = StringIO()
helper = pydoc.Helper(output=output)
helper(Class1)
expected_text1 = expected_virtualattribute_pattern2 % __name__
result1 = output.getvalue().strip()
self.assertEqual(expected_text1, result1)
output = StringIO()
helper = pydoc.Helper(output=output)
helper(Class2)
expected_text2 = expected_virtualattribute_pattern3 % __name__
result2 = output.getvalue().strip()
self.assertEqual(expected_text2, result2)
示例10: test_buggy_dir
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_buggy_dir(self):
class M(type):
def __dir__(cls):
return ['__class__', '__name__', 'missing', 'here']
class C(metaclass=M):
here = 'present!'
output = StringIO()
helper = pydoc.Helper(output=output)
helper(C)
expected_text = expected_missingattribute_pattern % __name__
result = output.getvalue().strip()
self.assertEqual(expected_text, result)
示例11: test_pydoc
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_pydoc(self):
# indirectly test __objclass__
if StrEnum.__doc__ is None:
expected_text = expected_help_output_without_docs % __name__
else:
expected_text = expected_help_output_with_docs % __name__
output = StringIO()
helper = pydoc.Helper(output=output)
helper(self.Color)
result = output.getvalue().strip()
self.assertEqual(result, expected_text)
示例12: test_buggy_dir
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_buggy_dir(self):
class M(type):
def __dir__(cls):
return ['__class__', '__name__', 'missing', 'here']
class C(metaclass=M):
here = 'present!'
output = StringIO()
helper = pydoc.Helper(output=output)
helper(C)
expected_text = expected_missingattribute_pattern % __name__
result = output.getvalue().strip()
if result != expected_text:
print_diffs(expected_text, result)
self.fail("outputs are not equal, see diff above")
示例13: test_pydoc
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_pydoc(self):
# indirectly test __objclass__
expected_text = expected_help_output % __name__
output = StringIO()
helper = pydoc.Helper(output=output)
helper(self.Color)
result = output.getvalue().strip()
self.assertEqual(result, expected_text)
示例14: get_pydoc
# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def get_pydoc(spec):
obj = load_obj(spec)
if obj:
output = StringIO()
pydoc.Helper(output=output).help(obj)
output.seek(0)
return output.read()