diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2018-10-21 17:31:27 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2018-10-21 17:31:27 -0400 |
commit | bf86427e1861aa353d7e80de0d373d9a30edb462 (patch) | |
tree | d8e24d69795d6c3096ed0af65d64eec4d3fd09b0 | |
parent | 8271bf4c4d5272043677f37a65e16d21621133cb (diff) | |
download | python-coveragepy-git-bf86427e1861aa353d7e80de0d373d9a30edb462.tar.gz |
Always include a documentation link at the end of help messages
-rw-r--r-- | coverage/cmdline.py | 18 | ||||
-rw-r--r-- | tests/test_cmdline.py | 20 |
2 files changed, 24 insertions, 14 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index d04da399..23107c01 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -548,23 +548,27 @@ class CoverageScript(object): def help(self, error=None, topic=None, parser=None): """Display an error message, or the named topic.""" assert error or topic or parser + + help_params = dict(self.covpkg.__dict__) + help_params['program_name'] = self.program_name + if CTracer is not None: + help_params['extension_modifier'] = 'with C extension' + else: + help_params['extension_modifier'] = 'without C extension' + if error: print(error, file=sys.stderr) print("Use '%s help' for help." % (self.program_name,), file=sys.stderr) elif parser: print(parser.format_help().strip()) + print() else: - help_params = dict(self.covpkg.__dict__) - help_params['program_name'] = self.program_name - if CTracer is not None: - help_params['extension_modifier'] = 'with C extension' - else: - help_params['extension_modifier'] = 'without C extension' help_msg = textwrap.dedent(HELP_TOPICS.get(topic, '')).strip() if help_msg: print(help_msg.format(**help_params)) else: print("Don't know topic %r" % topic) + print("Full documentation is at {__url__}".format(**help_params)) def do_help(self, options, args, parser): """Deal with help requests. @@ -744,7 +748,6 @@ HELP_TOPICS = { xml Create an XML report of coverage results. Use "{program_name} help <command>" for detailed help on any command. - For full documentation, see {__url__} """, 'minimum_help': """\ @@ -753,7 +756,6 @@ HELP_TOPICS = { 'version': """\ Coverage.py, version {__version__} {extension_modifier} - Documentation at {__url__} """, } diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index ff035764..fec0787b 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -18,6 +18,7 @@ from coverage import env from coverage.config import CoverageConfig from coverage.data import CoverageData from coverage.misc import ExceptionDuringRun +from coverage.version import __url__ from tests.coveragetest import CoverageTest, OK, ERR, command_line @@ -714,21 +715,25 @@ class CmdLineStdoutTest(BaseCmdLineTest): def test_help(self): self.command_line("help") - out = self.stdout() - self.assertIn("readthedocs.io", out) - self.assertGreater(out.count("\n"), 10) + lines = self.stdout().splitlines() + self.assertGreater(len(lines), 10) + self.assertEqual(lines[-1], "Full documentation is at {}".format(__url__)) def test_cmd_help(self): self.command_line("help run") out = self.stdout() - self.assertIn("<pyfile>", out) + lines = out.splitlines() + self.assertIn("<pyfile>", lines[0]) self.assertIn("--timid", out) - self.assertGreater(out.count("\n"), 10) + self.assertGreater(len(lines), 30) + self.assertEqual(lines[-1], "Full documentation is at {}".format(__url__)) def test_unknown_topic(self): # Should probably be an ERR return, but meh. self.command_line("help foobar") - self.assertEqual(self.stdout(), "Don't know topic 'foobar'\n") + lines = self.stdout().splitlines() + self.assertEqual(lines[0], "Don't know topic 'foobar'") + self.assertEqual(lines[-1], "Full documentation is at {}".format(__url__)) def test_error(self): self.command_line("fooey kablooey", ret=ERR) @@ -736,6 +741,9 @@ class CmdLineStdoutTest(BaseCmdLineTest): self.assertIn("fooey", err) self.assertIn("help", err) + def test_doc_url(self): + self.assertTrue(__url__.startswith("https://coverage.readthedocs.io")) + class CmdMainTest(CoverageTest): """Tests of coverage.cmdline.main(), using mocking for isolation.""" |