From: Daira Hopwood Date: Mon, 13 Jul 2015 17:07:52 +0000 (+0100) Subject: Eliminate near-duplicate code in CLITestMixin. X-Git-Url: https://git.rkrishnan.org/specifications/%5B/%5D%20//%22%22?a=commitdiff_plain;h=e61130395d7260bb686588b744873bd456dc7dc9;p=tahoe-lafs%2Ftahoe-lafs.git Eliminate near-duplicate code in CLITestMixin. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index 2bf4a086..9cfaf659 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -48,28 +48,12 @@ def parse_options(basedir, command, args): return o class CLITestMixin(ReallyEqualMixin): - def do_cli_n(self, client_num, verb, *args, **kwargs): - """ - do_cli_n is used to execute client CLI commands when there is more - than one client in the test grid... you can specify clients by number. - """ - nodeargs = [ - "--node-directory", 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 do_cli(self, verb, *args, **kwargs): + # client_num is used to execute client CLI commands on a specific client. + client_num = kwargs.get("client_num", 0) + nodeargs = [ - "--node-directory", self.get_clientdir(), + "--node-directory", self.get_clientdir(i=client_num), ] argv = nodeargs + [verb] + list(args) stdin = kwargs.get("stdin", "") diff --git a/src/allmydata/test/test_cli_magic_folder.py b/src/allmydata/test/test_cli_magic_folder.py index c5dc368e..f6e9a16d 100644 --- a/src/allmydata/test/test_cli_magic_folder.py +++ b/src/allmydata/test/test_cli_magic_folder.py @@ -17,7 +17,7 @@ from allmydata.frontends.magic_folder import MagicFolder class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): def create_magic_folder(self, client_num): - d = self.do_cli_n(client_num, "magic-folder", "create", "magic") + d = self.do_cli("magic-folder", "create", "magic", client_num=client_num) def _done((rc,stdout,stderr)): self.failUnless(rc == 0) self.failUnless("Alias 'magic' created" in stdout) @@ -29,7 +29,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): return d def invite(self, client_num, nickname): - d = self.do_cli_n(client_num, "magic-folder", "invite", u"magic", nickname) + d = self.do_cli("magic-folder", "invite", u"magic", nickname, client_num=client_num) def _done((rc,stdout,stderr)): self.failUnless(rc == 0) return (rc,stdout,stderr) @@ -38,7 +38,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): def join(self, client_num, local_dir, invite_code): magic_readonly_cap, dmd_write_cap = invite_code.split(magic_folder_cli.INVITE_SEPERATOR) - d = self.do_cli_n(client_num, "magic-folder", "join", invite_code, local_dir) + d = self.do_cli("magic-folder", "join", invite_code, local_dir, client_num=client_num) def _done((rc,stdout,stderr)): self.failUnless(rc == 0) return (rc,stdout,stderr) @@ -59,7 +59,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): our upload directory. """ collective_readonly_cap = fileutil.read(os.path.join(self.get_clientdir(i=client_num), "private/collective_dircap")) - d = self.do_cli_n(client_num, "ls", "--json", collective_readonly_cap) + d = self.do_cli("ls", "--json", collective_readonly_cap, client_num=client_num) def _done((rc,stdout,stderr)): self.failUnless(rc == 0) return (rc,stdout,stderr)