当前位置: 首页>>代码示例>>Python>>正文


Python pydoc.Helper方法代码示例

本文整理汇总了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") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:20,代码来源:test_pydoc.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_pydoc.py

示例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".
''') 
开发者ID:TechInvestLab,项目名称:dot15926,代码行数:20,代码来源:dot15926.py

示例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 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:36,代码来源:test_pydoc.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_pydoc.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_pydoc.py

示例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)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_pydoc.py

示例8: test_keywords

# 需要导入模块: import pydoc [as 别名]
# 或者: from pydoc import Helper [as 别名]
def test_keywords(self):
        self.assertEqual(sorted(pydoc.Helper.keywords),
                         sorted(keyword.kwlist)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_pydoc.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:43,代码来源:test_pydoc.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_pydoc.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_enum.py

示例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") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:16,代码来源:test_pydoc.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:10,代码来源:test_enum.py

示例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() 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:9,代码来源:query.py


注:本文中的pydoc.Helper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。