mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-30 01:38:55 +00:00
CLITestMixin: move into common.py
Also move parse_options(). It was kind of awkward having other test files import these from test_cli.py.
This commit is contained in:
parent
45e5d5b891
commit
d85d1ea499
48
src/allmydata/test/cli/common.py
Normal file
48
src/allmydata/test/cli/common.py
Normal file
@ -0,0 +1,48 @@
|
||||
from cStringIO import StringIO
|
||||
from twisted.trial import unittest
|
||||
from twisted.internet import threads # CLI tests use deferToThread
|
||||
from ...util.assertutil import precondition
|
||||
from ...util.encodingutil import (unicode_platform,
|
||||
get_filesystem_encoding,
|
||||
unicode_to_argv)
|
||||
from ...scripts import runner
|
||||
from ..common_util import ReallyEqualMixin
|
||||
|
||||
def parse_options(basedir, command, args):
|
||||
o = runner.Options()
|
||||
o.parseOptions(["--node-directory", basedir, command] + args)
|
||||
while hasattr(o, "subOptions"):
|
||||
o = o.subOptions
|
||||
return o
|
||||
|
||||
class CLITestMixin(ReallyEqualMixin):
|
||||
def do_cli(self, verb, *args, **kwargs):
|
||||
precondition(not [True for arg in args if not isinstance(arg, str)],
|
||||
"arguments to do_cli must be strs -- convert using unicode_to_argv", args=args)
|
||||
|
||||
# client_num is used to execute client CLI commands on a specific client.
|
||||
client_num = kwargs.get("client_num", 0)
|
||||
|
||||
nodeargs = [
|
||||
"--node-directory", unicode_to_argv(self.get_clientdir(i=client_num)),
|
||||
]
|
||||
argv = nodeargs + [verb] + list(args)
|
||||
stdin = kwargs.get("stdin", "")
|
||||
stdout, stderr = StringIO(), StringIO()
|
||||
d = threads.deferToThread(runner.runner, argv, run_by_human=False,
|
||||
stdin=StringIO(stdin),
|
||||
stdout=stdout, stderr=stderr)
|
||||
def _done(rc):
|
||||
return rc, stdout.getvalue(), stderr.getvalue()
|
||||
d.addCallback(_done)
|
||||
return d
|
||||
|
||||
def skip_if_cannot_represent_filename(self, u):
|
||||
precondition(isinstance(u, unicode))
|
||||
|
||||
enc = get_filesystem_encoding()
|
||||
if not unicode_platform():
|
||||
try:
|
||||
u.encode(enc)
|
||||
except UnicodeEncodeError:
|
||||
raise unittest.SkipTest("A non-ASCII filename could not be encoded on this platform.")
|
@ -14,7 +14,7 @@ from allmydata.util.namespace import Namespace
|
||||
from allmydata.scripts import cli, backupdb
|
||||
from ..common_util import StallMixin
|
||||
from ..no_network import GridTestMixin
|
||||
from .test_cli import CLITestMixin, parse_options
|
||||
from .common import CLITestMixin, parse_options
|
||||
|
||||
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s
|
||||
|
||||
|
@ -10,7 +10,7 @@ from allmydata.mutable.publish import MutableData
|
||||
from allmydata.immutable import upload
|
||||
from allmydata.scripts import debug
|
||||
from ..no_network import GridTestMixin
|
||||
from .test_cli import CLITestMixin
|
||||
from .common import CLITestMixin
|
||||
|
||||
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s
|
||||
|
||||
|
@ -31,55 +31,14 @@ from allmydata.scripts.common import DEFAULT_ALIAS, get_aliases, get_alias, \
|
||||
from allmydata.scripts import cli, debug, runner
|
||||
from ..common_util import ReallyEqualMixin
|
||||
from ..no_network import GridTestMixin
|
||||
from .common import CLITestMixin, parse_options
|
||||
from twisted.internet import threads # CLI tests use deferToThread
|
||||
from twisted.python import usage
|
||||
|
||||
from allmydata.util.assertutil import precondition
|
||||
from allmydata.util.encodingutil import listdir_unicode, unicode_platform, \
|
||||
get_io_encoding, get_filesystem_encoding, unicode_to_argv
|
||||
from allmydata.util.encodingutil import listdir_unicode, get_io_encoding
|
||||
|
||||
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s
|
||||
|
||||
def parse_options(basedir, command, args):
|
||||
o = runner.Options()
|
||||
o.parseOptions(["--node-directory", basedir, command] + args)
|
||||
while hasattr(o, "subOptions"):
|
||||
o = o.subOptions
|
||||
return o
|
||||
|
||||
class CLITestMixin(ReallyEqualMixin):
|
||||
def do_cli(self, verb, *args, **kwargs):
|
||||
precondition(not [True for arg in args if not isinstance(arg, str)],
|
||||
"arguments to do_cli must be strs -- convert using unicode_to_argv", args=args)
|
||||
|
||||
# client_num is used to execute client CLI commands on a specific client.
|
||||
client_num = kwargs.get("client_num", 0)
|
||||
|
||||
nodeargs = [
|
||||
"--node-directory", unicode_to_argv(self.get_clientdir(i=client_num)),
|
||||
]
|
||||
argv = nodeargs + [verb] + list(args)
|
||||
stdin = kwargs.get("stdin", "")
|
||||
stdout, stderr = StringIO(), StringIO()
|
||||
d = threads.deferToThread(runner.runner, argv, run_by_human=False,
|
||||
stdin=StringIO(stdin),
|
||||
stdout=stdout, stderr=stderr)
|
||||
def _done(rc):
|
||||
return rc, stdout.getvalue(), stderr.getvalue()
|
||||
d.addCallback(_done)
|
||||
return d
|
||||
|
||||
def skip_if_cannot_represent_filename(self, u):
|
||||
precondition(isinstance(u, unicode))
|
||||
|
||||
enc = get_filesystem_encoding()
|
||||
if not unicode_platform():
|
||||
try:
|
||||
u.encode(enc)
|
||||
except UnicodeEncodeError:
|
||||
raise unittest.SkipTest("A non-ASCII filename could not be encoded on this platform.")
|
||||
|
||||
|
||||
class CLI(CLITestMixin, unittest.TestCase):
|
||||
def _dump_cap(self, *args):
|
||||
config = debug.DumpCapOptions()
|
||||
|
@ -9,7 +9,7 @@ from allmydata.util.encodingutil import (quote_output, get_io_encoding,
|
||||
unicode_to_output, to_str)
|
||||
from allmydata.util.assertutil import _assert
|
||||
from ..no_network import GridTestMixin
|
||||
from .test_cli import CLITestMixin
|
||||
from .common import CLITestMixin
|
||||
|
||||
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s
|
||||
|
||||
|
@ -6,7 +6,7 @@ from allmydata.scripts.common import get_aliases
|
||||
from allmydata.scripts import cli, runner
|
||||
from ..no_network import GridTestMixin
|
||||
from allmydata.util.encodingutil import quote_output, get_io_encoding
|
||||
from .test_cli import CLITestMixin
|
||||
from .common import CLITestMixin
|
||||
|
||||
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s
|
||||
|
||||
|
@ -6,7 +6,7 @@ from allmydata.interfaces import MDMF_VERSION, SDMF_VERSION
|
||||
from allmydata.mutable.publish import MutableData
|
||||
from ..no_network import GridTestMixin
|
||||
from allmydata.util.encodingutil import quote_output, get_io_encoding
|
||||
from .test_cli import CLITestMixin
|
||||
from .common import CLITestMixin
|
||||
|
||||
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s
|
||||
|
||||
|
@ -10,7 +10,7 @@ from allmydata.util.assertutil import precondition
|
||||
from allmydata.util import fileutil
|
||||
from allmydata.scripts.common import get_aliases
|
||||
from ..no_network import GridTestMixin
|
||||
from .test_cli import CLITestMixin
|
||||
from .common import CLITestMixin
|
||||
from allmydata.scripts import magic_folder_cli
|
||||
from allmydata.util.fileutil import abspath_expanduser_unicode
|
||||
from allmydata.util.encodingutil import unicode_to_argv
|
||||
|
@ -3,7 +3,7 @@ from twisted.trial import unittest
|
||||
from allmydata.util import fileutil
|
||||
from ..no_network import GridTestMixin
|
||||
from allmydata.scripts import tahoe_mv
|
||||
from .test_cli import CLITestMixin
|
||||
from .common import CLITestMixin
|
||||
|
||||
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s
|
||||
|
||||
|
@ -8,7 +8,7 @@ from allmydata.scripts import cli
|
||||
from ..no_network import GridTestMixin
|
||||
from allmydata.util.encodingutil import get_io_encoding, unicode_to_argv
|
||||
from allmydata.util.fileutil import abspath_expanduser_unicode
|
||||
from .test_cli import CLITestMixin
|
||||
from .common import CLITestMixin
|
||||
|
||||
timeout = 480 # deep_check takes 360s on Zandr's linksys box, others take > 240s
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user