From b34165d4fb7e285ae518671bafc4324876a7fe60 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 10 Jul 2017 10:15:03 -0400 Subject: [PATCH 1/3] 'wormhole help' should print the same thing as 'wormhole --help' refs #61 --- src/wormhole/cli/cli.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wormhole/cli/cli.py b/src/wormhole/cli/cli.py index 154250a..baa04c6 100644 --- a/src/wormhole/cli/cli.py +++ b/src/wormhole/cli/cli.py @@ -168,6 +168,11 @@ TorArgs = _compose( ), ) +@wormhole.command() +@click.pass_context +def help(context, **kwargs): + print(context.find_root().get_help()) + # wormhole send (or "wormhole tx") @wormhole.command() @CommonArgs From 1ca51168c5be1fb40646eede1582ddc7373ff0e2 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 10 Jul 2017 11:19:56 -0700 Subject: [PATCH 2/3] add test for 'wormhole help' --- src/wormhole/test/test_cli.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/wormhole/test/test_cli.py b/src/wormhole/test/test_cli.py index 7466ce7..a830e51 100644 --- a/src/wormhole/test/test_cli.py +++ b/src/wormhole/test/test_cli.py @@ -3,7 +3,7 @@ import os, sys, re, io, zipfile, six, stat from textwrap import fill, dedent from humanize import naturalsize import mock -import click.testing +from click.testing import CliRunner from zope.interface import implementer from twisted.trial import unittest from twisted.python import procutils, log @@ -1171,6 +1171,24 @@ class Dispatch(unittest.TestCase): expected = "\nERROR: abcd\n" self.assertEqual(cfg.stderr.getvalue(), expected) +class Help(unittest.TestCase): + def _check_top_level_help(self, got): + # the main wormhole.cli.cli.wormhole docstring should be in the + # output, but formatted differently + self.assertIn("Create a Magic Wormhole and communicate through it.", + got) + self.assertIn("--relay-url", got) + self.assertIn("Receive a text message, file, or directory", got) + + def test_help(self): + result = CliRunner().invoke(cli.wormhole, ["help"]) + self._check_top_level_help(result.output) + self.assertEqual(result.exit_code, 0) + + def test_dash_dash_help(self): + result = CliRunner().invoke(cli.wormhole, ["--help"]) + self._check_top_level_help(result.output) + self.assertEqual(result.exit_code, 0) class FakeConfig(object): no_daemon = True @@ -1187,7 +1205,7 @@ class FakeConfig(object): class Server(unittest.TestCase): def setUp(self): - self.runner = click.testing.CliRunner() + self.runner = CliRunner() @mock.patch('wormhole.server.cmd_server.twistd') def test_server_disallow_list(self, fake_twistd): From fb03620fe95335f0998cc5e19adb6ccab84c22b0 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 10 Jul 2017 11:57:51 -0700 Subject: [PATCH 3/3] test_cli: hush Click unicode_literals warnings --- src/wormhole/test/test_cli.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/wormhole/test/test_cli.py b/src/wormhole/test/test_cli.py index a830e51..ba532bb 100644 --- a/src/wormhole/test/test_cli.py +++ b/src/wormhole/test/test_cli.py @@ -1,4 +1,4 @@ -from __future__ import print_function, unicode_literals +from __future__ import print_function import os, sys, re, io, zipfile, six, stat from textwrap import fill, dedent from humanize import naturalsize @@ -335,7 +335,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): cfg.relay_url = self.relayurl cfg.transit_helper = "" cfg.listen = True - cfg.code = "1-abc" + cfg.code = u"1-abc" cfg.stdout = io.StringIO() cfg.stderr = io.StringIO() @@ -649,7 +649,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): cfg.relay_url = self.relayurl cfg.transit_helper = "" cfg.listen = False - cfg.code = "1-abc" + cfg.code = u"1-abc" cfg.stdout = io.StringIO() cfg.stderr = io.StringIO() @@ -861,7 +861,7 @@ class NotWelcome(ServerBase, unittest.TestCase): @inlineCallbacks def test_sender(self): self.cfg.text = "hi" - self.cfg.code = "1-abc" + self.cfg.code = u"1-abc" send_d = cmd_send.send(self.cfg) f = yield self.assertFailure(send_d, WelcomeError) @@ -869,7 +869,7 @@ class NotWelcome(ServerBase, unittest.TestCase): @inlineCallbacks def test_receiver(self): - self.cfg.code = "1-abc" + self.cfg.code = u"1-abc" receive_d = cmd_receive.receive(self.cfg) f = yield self.assertFailure(receive_d, WelcomeError) @@ -892,7 +892,7 @@ class NoServer(ServerBase, unittest.TestCase): cfg.stderr = io.StringIO() cfg.text = "hi" - cfg.code = "1-abc" + cfg.code = u"1-abc" send_d = cmd_send.send(cfg) e = yield self.assertFailure(send_d, ServerConnectionError) @@ -924,7 +924,7 @@ class NoServer(ServerBase, unittest.TestCase): cfg.stdout = io.StringIO() cfg.stderr = io.StringIO() - cfg.code = "1-abc" + cfg.code = u"1-abc" receive_d = cmd_receive.receive(cfg) e = yield self.assertFailure(receive_d, ServerConnectionError) @@ -948,7 +948,7 @@ class Cleanup(ServerBase, unittest.TestCase): # the rendezvous channel should be deleted after success cfg = self.make_config() cfg.text = "hello" - cfg.code = "1-abc" + cfg.code = u"1-abc" send_d = cmd_send.send(cfg) receive_d = cmd_receive.receive(cfg) @@ -965,11 +965,11 @@ class Cleanup(ServerBase, unittest.TestCase): # deleted send_cfg = self.make_config() send_cfg.text = "secret message" - send_cfg.code = "1-abc" + send_cfg.code = u"1-abc" send_d = cmd_send.send(send_cfg) rx_cfg = self.make_config() - rx_cfg.code = "1-WRONG" + rx_cfg.code = u"1-WRONG" receive_d = cmd_receive.receive(rx_cfg) # both sides should be capable of detecting the mismatch @@ -982,7 +982,7 @@ class Cleanup(ServerBase, unittest.TestCase): class ExtractFile(unittest.TestCase): def test_filenames(self): args = mock.Mock() - args.relay_url = "" + args.relay_url = u"" ef = cmd_receive.Receiver(args)._extract_file extract_dir = os.path.abspath(self.mktemp()) @@ -1037,8 +1037,8 @@ class AppID(ServerBase, unittest.TestCase): def test_override(self): # make sure we use the overridden appid, not the default self.cfg.text = "hello" - self.cfg.appid = "appid2" - self.cfg.code = "1-abc" + self.cfg.appid = u"appid2" + self.cfg.code = u"1-abc" send_d = cmd_send.send(self.cfg) receive_d = cmd_receive.receive(self.cfg) @@ -1163,7 +1163,7 @@ class Dispatch(unittest.TestCase): # out here. f = mock.Mock() def mock_print(file): - file.write("\n") + file.write(u"\n") f.printTraceback = mock_print with mock.patch("wormhole.cli.cli.Failure", return_value=f): yield self.assertFailure(cli._dispatch_command(reactor, cfg, fake),