From: david-sarah Date: Tue, 18 Jan 2011 20:46:59 +0000 (-0800) Subject: src/allmydata/scripts/debug.py: add 'tahoe debug trial' command (rebased for trunk... X-Git-Url: https://git.rkrishnan.org/frontends/specifications/about.html?a=commitdiff_plain;h=7a887871b06af4a64dde38556a28b6a2b7229bf2;p=tahoe-lafs%2Ftahoe-lafs.git src/allmydata/scripts/debug.py: add 'tahoe debug trial' command (rebased for trunk). refs #1296 --- diff --git a/src/allmydata/scripts/debug.py b/src/allmydata/scripts/debug.py index 10bfa024..168c2ae0 100644 --- a/src/allmydata/scripts/debug.py +++ b/src/allmydata/scripts/debug.py @@ -1,9 +1,10 @@ # do not import any allmydata modules at this level. Do that from inside # individual functions instead. -import struct, time, os +import struct, time, os, sys from twisted.python import usage, failure from twisted.internet import defer +from twisted.scripts import trial as twisted_trial class DumpOptions(usage.Options): @@ -784,6 +785,35 @@ def repl(options): return code.interact() +DEFAULT_TESTSUITE = 'allmydata' + +class TrialOptions(twisted_trial.Options): + def getSynopsis(self): + return "Usage: tahoe debug trial [options] [[file|package|module|TestCase|testmethod]...]" + + def parseOptions(self, all_subargs, *a, **kw): + self.trial_args = list(all_subargs) + return twisted_trial.Options.parseOptions(self, all_subargs, *a, **kw) + + def parseArgs(self, *nonoption_args): + if not nonoption_args: + self.trial_args.append(DEFAULT_TESTSUITE) + + def getUsage(self, width=None): + t = twisted_trial.Options.getUsage(self, width) + t += """ +The 'tahoe debug trial' command uses the correct imports for this instance of +Tahoe-LAFS. The default test suite is '%s'. +""" % (DEFAULT_TESTSUITE,) + return t + +def trial(config): + sys.argv = ['trial'] + config.trial_args + + # This does not return. + twisted_trial.run() + + class DebugCommand(usage.Options): subCommands = [ ["dump-share", None, DumpOptions, @@ -793,6 +823,7 @@ class DebugCommand(usage.Options): ["catalog-shares", None, CatalogSharesOptions, "Describe all shares in node dirs."], ["corrupt-share", None, CorruptShareOptions, "Corrupt a share by flipping a bit."], ["repl", None, ReplOptions, "Open a Python interpreter."], + ["trial", None, TrialOptions, "Run tests using Twisted Trial with the right imports."], ] def postOptions(self): if not hasattr(self, 'subOptions'): @@ -809,6 +840,7 @@ Subcommands: tahoe debug catalog-shares Describe all shares in node dirs. tahoe debug corrupt-share Corrupt a share by flipping a bit. tahoe debug repl Open a Python interpreter. + tahoe debug trial Run tests using Twisted Trial with the right imports. Please run e.g. 'tahoe debug dump-share --help' for more details on each subcommand. @@ -822,6 +854,7 @@ subDispatch = { "catalog-shares": catalog_shares, "corrupt-share": corrupt_share, "repl": repl, + "trial": trial, }