summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-09-13 08:28:08 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-09-13 08:28:08 -0400
commit44b9351f801018d76230914db956b404940f8461 (patch)
tree17de09f2d9e8b27b591483183247bb25f6683f2f
parent2de10ba25de0c09ddffa6626a936468f43aa7343 (diff)
downloadpython-coveragepy-44b9351f801018d76230914db956b404940f8461.tar.gz
A nicer way to write help text.
-rw-r--r--coverage/cmdline.py18
-rw-r--r--test/test_cmdline.py7
2 files changed, 15 insertions, 10 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index e046425..69be0c9 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -273,7 +273,10 @@ class CoverageScript:
elif parser:
print parser.format_help(),
else:
- print HELP_TOPICS[topic].strip() % self.covpkg.__dict__
+ import re
+ topic_list = re.split("(?m)^=+ (\w+) =+$", HELP_TOPICS)
+ topics = dict(zip(topic_list[1::2], topic_list[2::2]))
+ print topics[topic].strip() % self.covpkg.__dict__
def command_line(self, argv):
"""The bulk of the command line interface to Coverage.
@@ -401,9 +404,9 @@ class CoverageScript:
return OK
-HELP_TOPICS = {
+HELP_TOPICS = r"""
-'classic_usage': r"""
+== classic_usage ==============================================================
Coverage version %(__version__)s
Measure, collect, and report on code coverage in Python programs.
@@ -450,9 +453,8 @@ coverage -a [-d DIR] [-i] [-o DIR,...] [FILE1 FILE2 ...]
Coverage data is saved in the file .coverage by default. Set the
COVERAGE_FILE environment variable to save it somewhere else.
-""",
-'help': r"""
+== help =======================================================================
Coverage version %(__version__)s
Measure, collect, and report on code coverage in Python programs.
@@ -469,13 +471,11 @@ Commands:
Use "coverage help <command>" for detailed help on each command.
For more information, see http://nedbatchelder.com/code/coverage
-""",
-'minimum_help': r"""
+== minimum_help ===============================================================
Code coverage for Python. Use 'coverage help' for help.
-""",
-}
+"""
def main():
diff --git a/test/test_cmdline.py b/test/test_cmdline.py
index b92fcc3..f06e915 100644
--- a/test/test_cmdline.py
+++ b/test/test_cmdline.py
@@ -12,6 +12,11 @@ class CmdLineTest(CoverageTest):
"""Tests of execution paths through the command line interpreter."""
def command_line(self, args, ret=OK):
+ """Run `args` through the command line.
+
+ Checks that `ret` is returned.
+
+ """
ret_actual = coverage.CoverageScript().command_line(shlex.split(args))
self.assertEqual(ret_actual, ret)
@@ -22,7 +27,7 @@ class CmdLineTest(CoverageTest):
return mk
def mock_command_line(self, args):
- """Run `args` through command_line.
+ """Run `args` through the command line, with a Mock.
Returns the Mock it used and the status code returned.