Ticket #1601: 1601v6.patch

File 1601v6.patch, 7.9 KB (added by Stephen Solis, 9 years ago)

Addressed more issues from review

  • twisted/test/test_usage.py

     
    378378        self.failUnless(len(lines) > 0)
    379379        self.failUnless(lines[0].find("flagallicious") >= 0)
    380380
    381     def test_longdescNotWrapped(self):
     381    def test_whitespaceStripLongdesc(self):
    382382        """
    383         L{usage.Options.getUsage} does not wrap lines in C{longdesc}.
     383        Extra whitespace at the beginning and end of C{longdesc} is stripped.
    384384        """
    385         self.nice.longdesc = ("\nA test documentation string.\n"
    386                     "This line has more than 80 characters-"
    387                     "PADDINGXXPADDINGXXPADDINGXXPADDINGXXPADDINGXXPADDING\n")
    388         self.nice.getUsage(width=80)
    389         self.assertTrue(len(self.nice.longdesc.splitlines()[2]) > 80)
     385        self.nice.longdesc = "\n\nA test documentation string.\n\n"
     386        expected = "\nA test documentation string.\n"
     387        self.assertEqual(self.nice._getLongdesc(), expected)
    390388
     389    def test_getLongdescFromAttribute(self):
     390        """
     391        L{usage.Options._getLongdesc} reads C{longdesc} from a class
     392        attribute.
     393        """
     394        self.nice.longdesc = "\nA test documentation string.\n"
     395        self.assertEqual(self.nice.longdesc, self.nice._getLongdesc())
    391396
     397    def test_getLongdescFromMainDoc(self):
     398        """
     399        L{usage.Options._getLongdesc} reads longdesc from
     400        C{__main__.__doc__}.
     401        """
     402        longdesc = "\nA test documentation string.\n"
     403        import __main__
     404        self.patch(__main__, '__doc__', longdesc)
     405        self.assertEqual(longdesc, self.nice._getLongdesc())
     406
     407
    392408class PortCoerceTestCase(unittest.TestCase):
    393409    """
    394410    Test the behavior of L{usage.portCoerce}.
  • twisted/python/usage.py

     
    473473        return synopsis
    474474
    475475    def getUsage(self, width=None):
     476        """
     477        Returns a string which describes the usage details of the program.
     478
     479        It includes descriptions of the following in this order, if they exist:
     480            - options and parameters
     481            - the program itself
     482            - subcommands
     483
     484        The list of options and subcommands is automatically wrapped to the
     485        given width or to the width of the terminal if none is given.
     486        The description of the program itself is not wrapped.
     487        """
     488
    476489        # If subOptions exists by now, then there was probably an error while
    477490        # parsing its options.
    478491        if hasattr(self, 'subOptions'):
     
    524537                 'dispatch': self._dispatch.get(opt, None)
    525538                 })
    526539
    527         if not (getattr(self, "longdesc", None) is None):
     540        if optDicts:
     541            chunks = docMakeChunks(optDicts, width)
     542            s = "Options:\n%s" % (''.join(chunks))
     543        else:
     544            s = "Options: None\n"
     545
     546        return s + self._getLongdesc() + commands
     547
     548    def _getLongdesc(self):
     549        """
     550        Returns a description of the program, looking first in C{self.longdesc}
     551        and then in C{__main__.__doc__}. If found, the description is formatted
     552        to contain exactly one leading and trailing linebreak.
     553        """
     554
     555        longdesc = ''
     556
     557        if getattr(self, "longdesc", None):
    528558            longdesc = self.longdesc
    529559        else:
    530560            import __main__
    531561            if getattr(__main__, '__doc__', None):
    532562                longdesc = __main__.__doc__
    533             else:
    534                 longdesc = ''
    535563
    536564        if longdesc:
    537565            longdesc = '\n' + longdesc.strip() + '\n'
    538566
    539         if optDicts:
    540             chunks = docMakeChunks(optDicts, width)
    541             s = "Options:\n%s" % (''.join(chunks))
    542         else:
    543             s = "Options: None\n"
     567        return longdesc
    544568
    545         return s + longdesc + commands
    546 
    547569    #def __repr__(self):
    548570    #    XXX: It'd be cool if we could return a succinct representation
    549571    #        of which flags and options are set here.
  • twisted/scripts/trial.py

     
    101101    synopsis = """%s [options] [[file|package|module|TestCase|testmethod]...]
    102102    """ % (os.path.basename(sys.argv[0]),)
    103103
    104     longdesc = ("trial loads and executes a suite of unit tests, obtained "
    105                 "from modules, packages and files listed on the command line.")
     104    longdesc = """\
     105trial loads and executes a suite of unit tests, obtained from modules,
     106packages and files listed on the command line."""
    106107
    107108    optFlags = [["help", "h"],
    108109                ["no-recurse", "N", "Don't recurse into packages"],
  • twisted/conch/scripts/conch.py

     
    2121
    2222    synopsis = """Usage:   conch [options] host [command]
    2323"""
    24     longdesc = ("conch is a SSHv2 client that allows logging into a remote "
    25                 "machine and executing commands.")
     24    longdesc = """\
     25conch is a SSHv2 client that allows logging into a remote machine and
     26executing commands."""
    2627
    2728    optParameters = [['escape', 'e', '~'],
    2829                      ['localforward', 'L', None, 'listen-port:host:port   Forward local port to remote address'],
  • twisted/conch/scripts/cftp.py

     
    2222         cftp [options] [user@]host[:dir[/]]
    2323         cftp [options] [user@]host[:file [localfile]]
    2424"""
    25     longdesc = ("cftp is a client for logging into a remote machine and "
    26                 "executing commands to send and receive file information")
     25    longdesc = """\
     26cftp is a client for logging into a remote machine and executing commands to
     27send and receive file information."""
    2728
    2829    optParameters = [
    2930                    ['buffersize', 'B', 32768, 'Size of the buffer to use for sending/receiving.'],
  • twisted/conch/tap.py

     
    2121
    2222class Options(usage.Options, strcred.AuthOptionMixin):
    2323    synopsis = "[-i <interface>] [-p <port>] [-d <dir>] "
    24     longdesc = ("Makes a Conch SSH server.  If no authentication methods are "
    25         "specified, the default authentication methods are UNIX passwords, "
    26         "SSH public keys, and PAM if it is available.  If --auth options are "
    27         "passed, only the measures specified will be used.")
     24    longdesc = """\
     25Makes a Conch SSH server.  If no authentication methods are specified, the
     26default authentication methods are UNIX passwords, SSH public keys, and PAM
     27if it is available.  If --auth options are passed, only the measures specified
     28will be used."""
    2829    optParameters = [
    2930        ["interface", "i", "", "local interface to which we listen"],
    3031        ["port", "p", "tcp:22", "Port on which to listen"],
  • twisted/application/app.py

     
    539539
    540540class ServerOptions(usage.Options, ReactorSelectionMixin):
    541541
    542     longdesc = ("twistd reads a twisted.application.service.Application out "
    543                 "of a file and runs it.")
     542    longdesc = """\
     543twistd reads a twisted.application.service.Application out of a file and
     544runs it."""
    544545
    545546    optFlags = [['savestats', None,
    546547                 "save the Stats object rather than the text output of "