Python pydoc.Helper() Examples
The following are 30
code examples of pydoc.Helper().
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 android_universal with MIT License | 6 votes |
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)
Example #2
Source File: test_pydoc.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #3
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: test_pydoc.py From ironpython3 with Apache License 2.0 | 6 votes |
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")
Example #5
Source File: dot15926.py From dot15926 with GNU Lesser General Public License v3.0 | 6 votes |
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". ''')
Example #6
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #7
Source File: query.py From insights-core with Apache License 2.0 | 5 votes |
def get_pydoc(spec): obj = load_obj(spec) if obj: output = StringIO() pydoc.Helper(output=output).help(obj) output.seek(0) return output.read()
Example #8
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #9
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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))
Example #10
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_keywords(self): self.assertEqual(sorted(pydoc.Helper.keywords), sorted(keyword.kwlist))
Example #11
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #12
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #13
Source File: test_enum.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #14
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
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
Example #15
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
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)
Example #16
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
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)
Example #17
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
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))
Example #18
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
def test_keywords(self): self.assertEqual(sorted(pydoc.Helper.keywords), sorted(keyword.kwlist))
Example #19
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
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)
Example #20
Source File: test_pydoc.py From android_universal with MIT License | 5 votes |
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)
Example #21
Source File: test_pydoc.py From ironpython3 with Apache License 2.0 | 5 votes |
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)
Example #22
Source File: test_pydoc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #23
Source File: test_pydoc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #24
Source File: test_pydoc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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))
Example #25
Source File: test_pydoc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_keywords(self): self.assertEqual(sorted(pydoc.Helper.keywords), sorted(keyword.kwlist))
Example #26
Source File: test_pydoc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #27
Source File: test_pydoc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #28
Source File: test_enum.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #29
Source File: test_pydoc.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #30
Source File: test_pydoc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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