Esempio n. 1
0
    def test_that_getDocstring_can_get_the_docstring(self):
        def some_random_method():
            """This is my docstring...."""
            pass

        testDocstring = """This is my docstring...."""
        docstring = util.getDocstring(some_random_method)
        self.assertEqual(testDocstring, docstring)
Esempio n. 2
0
 def help(self, command):
     """
     Look up the docstring for a given module or method from a module.
     """
     command = command[5:]
     cmdClass, cmdMethod, cmdArgs = self._splitCommand(command)
     util.write("Finding docstring for %s.%s" % (cmdClass, cmdMethod))
     try:
         # If there is only a module (ie $test)
         if cmdClass is None or cmdClass == '':
             self.replyWithMessage(
                 "Usage: help module.command to get information on a specific command, or help module to just get info on the module."
             )
         elif cmdMethod is None:
             docString = util.getDocstring(
                 self.grabClass(cmdClass)
             )
             self.replyWithMessage(
                 "%s: %s" % (command.title(), docString)
             )
         # If there is also a method on the module, and it isn't a private
         # method (ie $test.testing)
         elif not cmdMethod.startswith('_'):
             docString = util.getDocstring(
                 cmdMethod,
                 targetClass=self.grabClass(cmdClass)
             )
             self.replyWithMessage(
                 "%s.%s: %s" % (cmdClass.title(), cmdMethod, docString)
             )
         else:
             self.replyWithMessage(
                 "Docstring: Methods starting with _ are private methods!"
             )
     except (AttributeError, KeyError):
         if cmdMethod is not None:
             self.replyWithMessage(
                 "Docstring: Command %s.%s was not found" % (cmdClass, cmdMethod)
             )
         else:
             self.replyWithMessage(
                 "Docstring: Module '%s' was not found" % cmdClass
             )
     except Exception as e:
         self.replyWithMessage("Docstring: Exception occured: %s " % e)
         util.writeException(sys.exc_info())