mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-20 13:33:09 +00:00
test_runner: factor out parse_cli() helper
This commit is contained in:
parent
7193bff48b
commit
97c29a3c0b
@ -36,6 +36,18 @@ def run_cli(verb, *args, **kwargs):
|
||||
d.addCallback(_done)
|
||||
return d
|
||||
|
||||
def parse_cli(*argv):
|
||||
# This parses the CLI options (synchronously), and throws
|
||||
# usage.UsageError if something went wrong.
|
||||
|
||||
# As a temporary side-effect, if the arguments can be parsed correctly,
|
||||
# it also executes the command. This side-effect will be removed when
|
||||
# runner.py is refactored. After the refactoring, this will return the
|
||||
# Options object, and this method can be used for success testing, not
|
||||
# just failure testing.
|
||||
runner.runner(argv, run_by_human=False)
|
||||
assert False, "eek, I can't be used for success testing yet"
|
||||
|
||||
class DevNullDictionary(dict):
|
||||
def __setitem__(self, key, value):
|
||||
return
|
||||
|
@ -9,12 +9,11 @@ from twisted.internet.defer import inlineCallbacks, returnValue
|
||||
from allmydata.util import fileutil, pollmixin
|
||||
from allmydata.util.encodingutil import unicode_to_argv, unicode_to_output, \
|
||||
get_filesystem_encoding
|
||||
from allmydata.scripts import runner
|
||||
from allmydata.client import Client
|
||||
from allmydata.test import common_util
|
||||
import allmydata
|
||||
from allmydata import __appname__
|
||||
from .common_util import run_cli
|
||||
from .common_util import parse_cli, run_cli
|
||||
|
||||
|
||||
timeout = 240
|
||||
@ -253,18 +252,14 @@ class CreateNode(unittest.TestCase):
|
||||
self.failUnless(os.path.exists(os.path.join(n4, tac)))
|
||||
|
||||
# make sure it rejects too many arguments
|
||||
argv = [command, "basedir", "extraarg"]
|
||||
self.failUnlessRaises(usage.UsageError,
|
||||
runner.runner, argv,
|
||||
run_by_human=False)
|
||||
self.failUnlessRaises(usage.UsageError, parse_cli,
|
||||
command, "basedir", "extraarg")
|
||||
|
||||
# when creating a non-client, there is no default for the basedir
|
||||
if not is_client:
|
||||
argv = [command]
|
||||
self.failUnlessRaises(usage.UsageError,
|
||||
runner.runner, argv,
|
||||
run_by_human=False)
|
||||
|
||||
self.failUnlessRaises(usage.UsageError, parse_cli,
|
||||
command)
|
||||
|
||||
def test_node(self):
|
||||
self.do_create("node")
|
||||
@ -281,49 +276,42 @@ class CreateNode(unittest.TestCase):
|
||||
|
||||
def test_subcommands(self):
|
||||
# no arguments should trigger a command listing, via UsageError
|
||||
self.failUnlessRaises(usage.UsageError,
|
||||
runner.runner,
|
||||
[],
|
||||
run_by_human=False)
|
||||
self.failUnlessRaises(usage.UsageError, parse_cli,
|
||||
)
|
||||
|
||||
@inlineCallbacks
|
||||
def test_stats_gatherer_good_args(self):
|
||||
rc = runner.runner(["create-stats-gatherer", "--hostname=foo",
|
||||
self.mktemp()])
|
||||
rc,out,err = yield run_cli("create-stats-gatherer", "--hostname=foo",
|
||||
self.mktemp())
|
||||
self.assertEqual(rc, 0)
|
||||
rc = runner.runner(["create-stats-gatherer", "--location=tcp:foo:1234",
|
||||
"--port=tcp:1234", self.mktemp()])
|
||||
rc,out,err = yield run_cli("create-stats-gatherer",
|
||||
"--location=tcp:foo:1234",
|
||||
"--port=tcp:1234", self.mktemp())
|
||||
self.assertEqual(rc, 0)
|
||||
|
||||
|
||||
def test_stats_gatherer_bad_args(self):
|
||||
def _test(args):
|
||||
argv = args.split()
|
||||
self.assertRaises(usage.UsageError, parse_cli, *argv)
|
||||
|
||||
# missing hostname/location/port
|
||||
argv = "create-stats-gatherer D"
|
||||
self.assertRaises(usage.UsageError, runner.runner, argv.split(),
|
||||
run_by_human=False)
|
||||
_test("create-stats-gatherer D")
|
||||
|
||||
# missing port
|
||||
argv = "create-stats-gatherer --location=foo D"
|
||||
self.assertRaises(usage.UsageError, runner.runner, argv.split(),
|
||||
run_by_human=False)
|
||||
_test("create-stats-gatherer --location=foo D")
|
||||
|
||||
# missing location
|
||||
argv = "create-stats-gatherer --port=foo D"
|
||||
self.assertRaises(usage.UsageError, runner.runner, argv.split(),
|
||||
run_by_human=False)
|
||||
_test("create-stats-gatherer --port=foo D")
|
||||
|
||||
# can't provide both
|
||||
argv = "create-stats-gatherer --hostname=foo --port=foo D"
|
||||
self.assertRaises(usage.UsageError, runner.runner, argv.split(),
|
||||
run_by_human=False)
|
||||
_test("create-stats-gatherer --hostname=foo --port=foo D")
|
||||
|
||||
# can't provide both
|
||||
argv = "create-stats-gatherer --hostname=foo --location=foo D"
|
||||
self.assertRaises(usage.UsageError, runner.runner, argv.split(),
|
||||
run_by_human=False)
|
||||
_test("create-stats-gatherer --hostname=foo --location=foo D")
|
||||
|
||||
# can't provide all three
|
||||
argv = "create-stats-gatherer --hostname=foo --location=foo --port=foo D"
|
||||
self.assertRaises(usage.UsageError, runner.runner, argv.split(),
|
||||
run_by_human=False)
|
||||
_test("create-stats-gatherer --hostname=foo --location=foo --port=foo D")
|
||||
|
||||
class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
|
||||
RunBinTahoeMixin):
|
||||
|
Loading…
Reference in New Issue
Block a user