wrap long lines, and tolerate various-width wrappings of the --help output
test_cli.Help was too sensitive to the way that the --help output was wrapped, which caused failures on travis when COLUMNS= was set low and the expected strings were split across separate lines.
This commit is contained in:
parent
8f41713fe9
commit
45ebbbf44b
|
@ -11,22 +11,26 @@ from allmydata.util.encodingutil import listdir_unicode, quote_local_unicode_pat
|
||||||
class StartOptions(BasedirOptions):
|
class StartOptions(BasedirOptions):
|
||||||
subcommand_name = "start"
|
subcommand_name = "start"
|
||||||
optParameters = [
|
optParameters = [
|
||||||
("basedir", "C", None, "Specify which Tahoe base directory should be used. This has the same effect as the global --node-directory option. [default: %s]"
|
("basedir", "C", None,
|
||||||
% quote_local_unicode_path(_default_nodedir)),
|
"Specify which Tahoe base directory should be used."
|
||||||
|
" This has the same effect as the global --node-directory option."
|
||||||
|
" [default: %s]" % quote_local_unicode_path(_default_nodedir)),
|
||||||
]
|
]
|
||||||
|
|
||||||
def parseArgs(self, basedir=None, *twistd_args):
|
def parseArgs(self, basedir=None, *twistd_args):
|
||||||
# This can't handle e.g. 'tahoe start --nodaemon', since '--nodaemon'
|
# This can't handle e.g. 'tahoe start --nodaemon', since '--nodaemon'
|
||||||
# looks like an option to the tahoe subcommand, not to twistd.
|
# looks like an option to the tahoe subcommand, not to twistd. So you
|
||||||
# So you can either use 'tahoe start' or 'tahoe start NODEDIR --TWISTD-OPTIONS'.
|
# can either use 'tahoe start' or 'tahoe start NODEDIR
|
||||||
# Note that 'tahoe --node-directory=NODEDIR start --TWISTD-OPTIONS' also
|
# --TWISTD-OPTIONS'. Note that 'tahoe --node-directory=NODEDIR start
|
||||||
# isn't allowed, unfortunately.
|
# --TWISTD-OPTIONS' also isn't allowed, unfortunately.
|
||||||
|
|
||||||
BasedirOptions.parseArgs(self, basedir)
|
BasedirOptions.parseArgs(self, basedir)
|
||||||
self.twistd_args = twistd_args
|
self.twistd_args = twistd_args
|
||||||
|
|
||||||
def getSynopsis(self):
|
def getSynopsis(self):
|
||||||
return "Usage: %s [global-options] %s [options] [NODEDIR [twistd-options]]" % (self.command_name, self.subcommand_name)
|
return ("Usage: %s [global-options] %s [options]"
|
||||||
|
" [NODEDIR [twistd-options]]"
|
||||||
|
% (self.command_name, self.subcommand_name))
|
||||||
|
|
||||||
def getUsage(self, width=None):
|
def getUsage(self, width=None):
|
||||||
t = BasedirOptions.getUsage(self, width) + "\n"
|
t = BasedirOptions.getUsage(self, width) + "\n"
|
||||||
|
@ -45,7 +49,8 @@ class StopOptions(BasedirOptions):
|
||||||
BasedirOptions.parseArgs(self, basedir)
|
BasedirOptions.parseArgs(self, basedir)
|
||||||
|
|
||||||
def getSynopsis(self):
|
def getSynopsis(self):
|
||||||
return "Usage: %s [global-options] stop [options] [NODEDIR]" % (self.command_name,)
|
return ("Usage: %s [global-options] stop [options] [NODEDIR]"
|
||||||
|
% (self.command_name,))
|
||||||
|
|
||||||
class RestartOptions(StartOptions):
|
class RestartOptions(StartOptions):
|
||||||
subcommand_name = "restart"
|
subcommand_name = "restart"
|
||||||
|
@ -235,9 +240,9 @@ def restart(config, stdout, stderr):
|
||||||
|
|
||||||
def run(config, stdout, stderr):
|
def run(config, stdout, stderr):
|
||||||
config.twistd_args = config.twistd_args + ("--nodaemon",)
|
config.twistd_args = config.twistd_args + ("--nodaemon",)
|
||||||
# Previously we would do the equivalent of adding ("--logfile", "tahoesvc.log"),
|
# Previously we would do the equivalent of adding ("--logfile",
|
||||||
# but that redirects stdout/stderr which is often unhelpful, and the user can
|
# "tahoesvc.log"), but that redirects stdout/stderr which is often
|
||||||
# add that option explicitly if they want.
|
# unhelpful, and the user can add that option explicitly if they want.
|
||||||
|
|
||||||
return start(config, stdout, stderr)
|
return start(config, stdout, stderr)
|
||||||
|
|
||||||
|
|
|
@ -561,6 +561,11 @@ class CLI(CLITestMixin, unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
class Help(unittest.TestCase):
|
class Help(unittest.TestCase):
|
||||||
|
def failUnlessInNormalized(self, x, y):
|
||||||
|
# helper function to deal with the --help output being wrapped to
|
||||||
|
# various widths, depending on the $COLUMNS environment variable
|
||||||
|
self.failUnlessIn(x.replace("\n", " "), y.replace("\n", " "))
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
help = str(cli.GetOptions())
|
help = str(cli.GetOptions())
|
||||||
self.failUnlessIn("[options] REMOTE_FILE LOCAL_FILE", help)
|
self.failUnlessIn("[options] REMOTE_FILE LOCAL_FILE", help)
|
||||||
|
@ -586,22 +591,22 @@ class Help(unittest.TestCase):
|
||||||
def test_mv(self):
|
def test_mv(self):
|
||||||
help = str(cli.MvOptions())
|
help = str(cli.MvOptions())
|
||||||
self.failUnlessIn("[options] FROM TO", help)
|
self.failUnlessIn("[options] FROM TO", help)
|
||||||
self.failUnlessIn("Use 'tahoe mv' to move files", help)
|
self.failUnlessInNormalized("Use 'tahoe mv' to move files", help)
|
||||||
|
|
||||||
def test_cp(self):
|
def test_cp(self):
|
||||||
help = str(cli.CpOptions())
|
help = str(cli.CpOptions())
|
||||||
self.failUnlessIn("[options] FROM.. TO", help)
|
self.failUnlessIn("[options] FROM.. TO", help)
|
||||||
self.failUnlessIn("Use 'tahoe cp' to copy files", help)
|
self.failUnlessInNormalized("Use 'tahoe cp' to copy files", help)
|
||||||
|
|
||||||
def test_ln(self):
|
def test_ln(self):
|
||||||
help = str(cli.LnOptions())
|
help = str(cli.LnOptions())
|
||||||
self.failUnlessIn("[options] FROM_LINK TO_LINK", help)
|
self.failUnlessIn("[options] FROM_LINK TO_LINK", help)
|
||||||
self.failUnlessIn("Use 'tahoe ln' to duplicate a link", help)
|
self.failUnlessInNormalized("Use 'tahoe ln' to duplicate a link", help)
|
||||||
|
|
||||||
def test_mkdir(self):
|
def test_mkdir(self):
|
||||||
help = str(cli.MakeDirectoryOptions())
|
help = str(cli.MakeDirectoryOptions())
|
||||||
self.failUnlessIn("[options] [REMOTE_DIR]", help)
|
self.failUnlessIn("[options] [REMOTE_DIR]", help)
|
||||||
self.failUnlessIn("Create a new directory", help)
|
self.failUnlessInNormalized("Create a new directory", help)
|
||||||
|
|
||||||
def test_backup(self):
|
def test_backup(self):
|
||||||
help = str(cli.BackupOptions())
|
help = str(cli.BackupOptions())
|
||||||
|
@ -670,13 +675,13 @@ class Help(unittest.TestCase):
|
||||||
def test_debug_trial(self):
|
def test_debug_trial(self):
|
||||||
help = str(debug.TrialOptions())
|
help = str(debug.TrialOptions())
|
||||||
self.failUnlessIn(" [global-options] debug trial [options] [[file|package|module|TestCase|testmethod]...]", help)
|
self.failUnlessIn(" [global-options] debug trial [options] [[file|package|module|TestCase|testmethod]...]", help)
|
||||||
self.failUnlessIn("The 'tahoe debug trial' command uses the correct imports", help)
|
self.failUnlessInNormalized("The 'tahoe debug trial' command uses the correct imports", help)
|
||||||
|
|
||||||
def test_debug_flogtool(self):
|
def test_debug_flogtool(self):
|
||||||
options = debug.FlogtoolOptions()
|
options = debug.FlogtoolOptions()
|
||||||
help = str(options)
|
help = str(options)
|
||||||
self.failUnlessIn(" [global-options] debug flogtool ", help)
|
self.failUnlessIn(" [global-options] debug flogtool ", help)
|
||||||
self.failUnlessIn("The 'tahoe debug flogtool' command uses the correct imports", help)
|
self.failUnlessInNormalized("The 'tahoe debug flogtool' command uses the correct imports", help)
|
||||||
|
|
||||||
for (option, shortcut, oClass, desc) in options.subCommands:
|
for (option, shortcut, oClass, desc) in options.subCommands:
|
||||||
subhelp = str(oClass())
|
subhelp = str(oClass())
|
||||||
|
|
Loading…
Reference in New Issue