Ticket #1601: 1601v7.patch

File 1601v7.patch, 8.5 KB (added by Stephen Solis, 9 years ago)

Addressed more issues from review

  • twisted/test/test_usage.py

     
    359359
    360360        self.nice = WellBehaved()
    361361
     362
    362363    def test_noGoBoom(self):
    363364        """
    364365        __str__ shouldn't go boom.
     
    368369        except Exception, e:
    369370            self.fail(e)
    370371
     372
    371373    def test_whitespaceStripFlagsAndParameters(self):
    372374        """
    373375        Extra whitespace in flag and parameters docs is stripped.
     
    378380        self.failUnless(len(lines) > 0)
    379381        self.failUnless(lines[0].find("flagallicious") >= 0)
    380382
    381     def test_longdescNotWrapped(self):
     383
     384    def test_whitespaceStripLongdesc(self):
    382385        """
    383         L{usage.Options.getUsage} does not wrap lines in C{longdesc}.
     386        Extra whitespace at the beginning and end of C{longdesc} is stripped.
    384387        """
    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)
     388        self.nice.longdesc = "\n\nA test documentation string.\n\n"
     389        expected = "\nA test documentation string.\n"
     390        self.assertEqual(self.nice._getLongdesc(), expected)
    390391
    391392
     393    def test_getLongdescFromAttribute(self):
     394        """
     395        L{usage.Options._getLongdesc} reads C{longdesc} from a class
     396        attribute.
     397        """
     398        self.nice.longdesc = "\nA test documentation string.\n"
     399        self.assertEqual(self.nice.longdesc, self.nice._getLongdesc())
     400
     401
     402    def test_getLongdescFromMainDoc(self):
     403        """
     404        L{usage.Options._getLongdesc} reads longdesc from
     405        C{__main__.__doc__}.
     406        """
     407        longdesc = "\nA test documentation string.\n"
     408        import __main__
     409        self.patch(__main__, '__doc__', longdesc)
     410        self.assertEqual(longdesc, self.nice._getLongdesc())
     411
     412
     413
    392414class PortCoerceTestCase(unittest.TestCase):
    393415    """
    394416    Test the behavior of L{usage.portCoerce}.
  • twisted/python/usage.py

     
    472472
    473473        return synopsis
    474474
     475
    475476    def getUsage(self, width=None):
     477        """
     478        Returns a string which describes the usage details of the program.
     479
     480        It includes descriptions of the following in this order, if they exist:
     481            1. Options and parameters
     482            2. The program itself
     483            3. Subcommands
     484
     485        The list of options and subcommands is automatically wrapped to the
     486        given width or to the width of the current terminal if none is
     487        given. The description of the program itself is not wrapped.
     488
     489        @param width: The width of the terminal, used to wrap the list of
     490                      options and subcommands. It will be autodetected if
     491                      not specified.
     492        @type  width: number
     493        """
     494
    476495        # If subOptions exists by now, then there was probably an error while
    477496        # parsing its options.
    478497        if hasattr(self, 'subOptions'):
     
    524543                 'dispatch': self._dispatch.get(opt, None)
    525544                 })
    526545
    527         if not (getattr(self, "longdesc", None) is None):
     546        if optDicts:
     547            chunks = docMakeChunks(optDicts, width)
     548            s = "Options:\n%s" % (''.join(chunks))
     549        else:
     550            s = "Options: None\n"
     551
     552        return s + self._getLongdesc() + commands
     553
     554
     555    def _getLongdesc(self):
     556        """
     557        Returns a description of the program, looking first in C{self.longdesc}
     558        and then in C{__main__.__doc__}. If found, the description is formatted
     559        to contain exactly one leading and trailing linebreak.
     560        """
     561
     562        longdesc = ''
     563
     564        if getattr(self, "longdesc", None):
    528565            longdesc = self.longdesc
    529566        else:
    530567            import __main__
    531568            if getattr(__main__, '__doc__', None):
    532569                longdesc = __main__.__doc__
    533             else:
    534                 longdesc = ''
    535570
    536571        if longdesc:
    537572            longdesc = '\n' + longdesc.strip() + '\n'
    538573
    539         if optDicts:
    540             chunks = docMakeChunks(optDicts, width)
    541             s = "Options:\n%s" % (''.join(chunks))
    542         else:
    543             s = "Options: None\n"
     574        return longdesc
    544575
    545         return s + longdesc + commands
    546576
    547577    #def __repr__(self):
    548578    #    XXX: It'd be cool if we could return a succinct representation
    549579    #        of which flags and options are set here.
    550580
    551581
     582
    552583_ZSH = 'zsh'
    553584_BASH = 'bash'
    554585
  • 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 "