Exemplo n.º 1
0
def getdoc(thing, title='Help on %s', forceload=0):

    #g.trace(thing)

    if 1: # Both seem to work.

        # Redirect stdout to a "file like object".
        old_stdout = sys.stdout
        sys.stdout = fo = g.fileLikeObject()
        # Python's builtin help function writes to stdout.
        help(str(thing))
        # Restore original stdout.
        sys.stdout = old_stdout
        # Return what was written to fo.
        return fo.get()

    else:
        # Similar to doc function from pydoc module.
        from pydoc import resolve, describe, inspect, text, plain
        object, name = resolve(thing, forceload)
        desc = describe(object)
        module = inspect.getmodule(object)
        if name and '.' in name:
            desc += ' in ' + name[:name.rfind('.')]
        elif module and module is not object:
            desc += ' in module ' + module.__name__
        doc = title % desc + '\n\n' + text.document(object, name)
        return plain(doc)
 def testHelp(self):
     from pydoc import text, plain
     s = plain(text.document(validators))
     self.assertTrue('Validator/Converters for use with FormEncode.' in s)
     self.assertTrue('class Bool' in s)
     self.assertTrue('Always Valid, returns True or False' in s)
     self.assertTrue('class Email' in s)
     self.assertTrue('Validate an email address.' in s)
     self.assertTrue('class FieldsMatch' in s)
     self.assertTrue('Tests that the given fields match' in s)
Exemplo n.º 3
0
 def testHelp(self):
     from pydoc import text, plain
     s = plain(text.document(validators))
     self.assertTrue('Validator/Converters for use with FormEncode.' in s)
     self.assertTrue('class Bool' in s)
     self.assertTrue('Always Valid, returns True or False' in s)
     self.assertTrue('class Email' in s)
     self.assertTrue('Validate an email address.' in s)
     self.assertTrue('class FieldsMatch' in s)
     self.assertTrue('Tests that the given fields match' in s)