summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt3
-rw-r--r--coverage/cmdline.py99
-rw-r--r--tests/test_cmdline.py290
3 files changed, 28 insertions, 364 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index e9e613ac..2b1f0dda 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -6,6 +6,9 @@ Change history for Coverage.py
Latest
------
+- The original command line switches (`-x` to run a program, etc) are no
+ longer supported.
+
- The ``COVERAGE_OPTIONS`` environment variable is no longer supported. It was
a hack for ``--timid`` before configuration files were available.
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 58f4817f..3d1f5f6a 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -62,12 +62,6 @@ class Opts(object):
help="Show line numbers of statements in each module that weren't "
"executed."
)
- old_omit = optparse.make_option(
- '-o', '--omit', action='store',
- metavar="PAT1,PAT2,...",
- help="Omit files whose paths match one of these patterns. "
- "Accepts shell-style wildcards, which must be quoted."
- )
omit = optparse.make_option(
'', '--omit', action='store',
metavar="PAT1,PAT2,...",
@@ -178,42 +172,17 @@ class CoverageOptionParser(optparse.OptionParser, object):
raise self.OptionParserError
-class ClassicOptionParser(CoverageOptionParser):
- """Command-line parser for coverage.py classic arguments."""
+class GlobalOptionParser(CoverageOptionParser):
+ """Command-line parser for coverage.py global option arguments."""
def __init__(self):
- super(ClassicOptionParser, self).__init__()
-
- self.add_action('-a', '--annotate', 'annotate')
- self.add_action('-b', '--html', 'html')
- self.add_action('-c', '--combine', 'combine')
- self.add_action('-e', '--erase', 'erase')
- self.add_action('-r', '--report', 'report')
- self.add_action('-x', '--execute', 'execute')
+ super(GlobalOptionParser, self).__init__()
self.add_options([
- Opts.directory,
Opts.help,
- Opts.ignore_errors,
- Opts.pylib,
- Opts.show_missing,
- Opts.old_omit,
- Opts.parallel_mode,
- Opts.timid,
Opts.version,
])
- def add_action(self, dash, dashdash, action_code):
- """Add a specialized option that is the action to execute."""
- option = self.add_option(dash, dashdash, action='callback',
- callback=self._append_action
- )
- option.action_code = action_code
-
- def _append_action(self, option, opt_unused, value_unused, parser):
- """Callback for an option that adds to the `actions` list."""
- parser.values.actions.append(option.action_code)
-
class CmdOptionParser(CoverageOptionParser):
"""Parse one of the new-style commands for coverage.py."""
@@ -373,7 +342,7 @@ class CoverageScript(object):
self.run_python_file = _run_python_file or run_python_file
self.run_python_module = _run_python_module or run_python_module
self.help_fn = _help_fn or self.help
- self.classic = False
+ self.global_option = False
self.coverage = None
@@ -390,11 +359,11 @@ class CoverageScript(object):
self.help_fn(topic='minimum_help')
return OK
- # The command syntax we parse depends on the first argument. Classic
- # syntax always starts with an option.
- self.classic = argv[0].startswith('-')
- if self.classic:
- parser = ClassicOptionParser()
+ # The command syntax we parse depends on the first argument. Global
+ # switch syntax always starts with an option.
+ self.global_option = argv[0].startswith('-')
+ if self.global_option:
+ parser = GlobalOptionParser()
else:
parser = CMDS.get(argv[0])
if not parser:
@@ -511,7 +480,7 @@ class CoverageScript(object):
"""
# Handle help.
if options.help:
- if self.classic:
+ if self.global_option:
self.help_fn(topic='help')
else:
self.help_fn(parser=parser)
@@ -659,53 +628,6 @@ def unglob_args(args):
HELP_TOPICS = {
# -------------------------
-'classic':
-r"""Coverage.py version %(__version__)s
-Measure, collect, and report on code coverage in Python programs.
-
-Usage:
-
-coverage -x [-p] [-L] [--timid] MODULE.py [ARG1 ARG2 ...]
- Execute the module, passing the given command-line arguments, collecting
- coverage data. With the -p option, include the machine name and process
- id in the .coverage file name. With -L, measure coverage even inside the
- Python installed library, which isn't done by default. With --timid, use a
- simpler but slower trace method.
-
-coverage -e
- Erase collected coverage data.
-
-coverage -c
- Combine data from multiple coverage files (as created by -p option above)
- and store it into a single file representing the union of the coverage.
-
-coverage -r [-m] [-i] [-o DIR,...] [FILE1 FILE2 ...]
- Report on the statement coverage for the given files. With the -m
- option, show line numbers of the statements that weren't executed.
-
-coverage -b -d DIR [-i] [-o DIR,...] [FILE1 FILE2 ...]
- Create an HTML report of the coverage of the given files. Each file gets
- its own page, with the file listing decorated to show executed, excluded,
- and missed lines.
-
-coverage -a [-d DIR] [-i] [-o DIR,...] [FILE1 FILE2 ...]
- Make annotated copies of the given files, marking statements that
- are executed with > and statements that are missed with !.
-
--d DIR
- Write output files for -b or -a to this directory.
-
--i Ignore errors while reporting or annotating.
-
--o DIR,...
- Omit reporting or annotating files when their filename path starts with
- a directory listed in the omit list.
- e.g. coverage -i -r -o c:\python25,lib\enthought\traits
-
-Coverage data is saved in the file .coverage by default. Set the
-COVERAGE_FILE environment variable to save it somewhere else.
-""",
-# -------------------------
'help': """\
Coverage.py, version %(__version__)s
Measure, collect, and report on code coverage in Python programs.
@@ -723,7 +645,6 @@ Commands:
xml Create an XML report of coverage results.
Use "coverage help <command>" for detailed help on any command.
-Use "coverage help classic" for help on older command syntax.
For more information, see %(__url__)s
""",
# -------------------------
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 36dc8ce8..ff31faeb 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -10,7 +10,7 @@ from tests.coveragetest import CoverageTest, OK, ERR
# TODO: base these tests on new cmdline, not old.
-class CmdLineTest(CoverageTest):
+class BaseCmdLineTest(CoverageTest):
"""Tests of execution paths through the command line interpreter."""
run_in_temp_dir = False
@@ -123,8 +123,8 @@ class CmdLineTest(CoverageTest):
)
-class CmdLineTestTest(CmdLineTest):
- """Tests that our CmdLineTest helpers work."""
+class BaseCmdLineTestTest(BaseCmdLineTest):
+ """Tests that our BaseCmdLineTest helpers work."""
def test_assert_same_method_calls(self):
# All the other tests here use self.cmd_executes_same in successful
# ways, so here we just check that it fails.
@@ -132,275 +132,6 @@ class CmdLineTestTest(CmdLineTest):
self.cmd_executes_same("run", "debug")
-class ClassicCmdLineTest(CmdLineTest):
- """Tests of the classic coverage.py command line."""
-
- def test_erase(self):
- # coverage -e
- self.cmd_executes("-e", """\
- .coverage()
- .erase()
- """)
- self.cmd_executes_same("-e", "--erase")
-
- def test_execute(self):
- # coverage -x [-p] [-L] [--timid] MODULE.py [ARG1 ARG2 ...]
-
- # -x calls coverage.load first.
- self.cmd_executes("-x foo.py", """\
- .coverage()
- .load()
- .start()
- .run_python_file('foo.py', ['foo.py'])
- .stop()
- .save()
- """)
- # -e -x calls coverage.erase first.
- self.cmd_executes("-e -x foo.py", """\
- .coverage()
- .erase()
- .start()
- .run_python_file('foo.py', ['foo.py'])
- .stop()
- .save()
- """)
- # --timid sets a flag, and program arguments get passed through.
- self.cmd_executes("-x --timid foo.py abc 123", """\
- .coverage(timid=True)
- .load()
- .start()
- .run_python_file('foo.py', ['foo.py', 'abc', '123'])
- .stop()
- .save()
- """)
- # -L sets a flag, and flags for the program don't confuse us.
- self.cmd_executes("-x -p -L foo.py -a -b", """\
- .coverage(cover_pylib=True, data_suffix=True)
- .load()
- .start()
- .run_python_file('foo.py', ['foo.py', '-a', '-b'])
- .stop()
- .save()
- """)
-
- # Check that long forms of flags do the same thing as short forms.
- self.cmd_executes_same("-x f.py", "--execute f.py")
- self.cmd_executes_same("-e -x f.py", "--erase --execute f.py")
- self.cmd_executes_same("-x -p f.py", "-x --parallel-mode f.py")
- self.cmd_executes_same("-x -L f.py", "-x --pylib f.py")
-
- def test_combine(self):
- # coverage -c
- self.cmd_executes("-c", """\
- .coverage()
- .load()
- .combine()
- .save()
- """)
- self.cmd_executes_same("-c", "--combine")
-
- def test_report(self):
- # coverage -r [-m] [-i] [-o DIR,...] [FILE1 FILE2 ...]
- self.cmd_executes("-r", """\
- .coverage()
- .load()
- .report(show_missing=None)
- """)
- self.cmd_executes("-r -i", """\
- .coverage()
- .load()
- .report(ignore_errors=True)
- """)
- self.cmd_executes("-r -m", """\
- .coverage()
- .load()
- .report(show_missing=True)
- """)
- self.cmd_executes("-r -o fooey", """\
- .coverage(omit=["fooey"])
- .load()
- .report(omit=["fooey"])
- """)
- self.cmd_executes("-r -o fooey,booey", """\
- .coverage(omit=["fooey", "booey"])
- .load()
- .report(omit=["fooey", "booey"])
- """)
- self.cmd_executes("-r mod1", """\
- .coverage()
- .load()
- .report(morfs=["mod1"])
- """)
- self.cmd_executes("-r mod1 mod2 mod3", """\
- .coverage()
- .load()
- .report(morfs=["mod1", "mod2", "mod3"])
- """)
-
- self.cmd_executes_same("-r", "--report")
- self.cmd_executes_same("-r -i", "-r --ignore-errors")
- self.cmd_executes_same("-r -m", "-r --show-missing")
- self.cmd_executes_same("-r -o f", "-r --omit=f")
- self.cmd_executes_same("-r -o f", "-r --omit f")
- self.cmd_executes_same("-r -o f,b", "-r --omit=f,b")
- self.cmd_executes_same("-r -o f,b", "-r --omit f,b")
- self.cmd_executes_same("-r -of", "-r --omit=f")
- self.cmd_executes_same("-r -of,b", "-r --omit=f,b")
-
- def test_annotate(self):
- # coverage -a [-d DIR] [-i] [-o DIR,...] [FILE1 FILE2 ...]
- self.cmd_executes("-a", """\
- .coverage()
- .load()
- .annotate()
- """)
- self.cmd_executes("-a -d dir1", """\
- .coverage()
- .load()
- .annotate(directory="dir1")
- """)
- self.cmd_executes("-a -i", """\
- .coverage()
- .load()
- .annotate(ignore_errors=True)
- """)
- self.cmd_executes("-a -o fooey", """\
- .coverage(omit=["fooey"])
- .load()
- .annotate(omit=["fooey"])
- """)
- self.cmd_executes("-a -o fooey,booey", """\
- .coverage(omit=["fooey", "booey"])
- .load()
- .annotate(omit=["fooey", "booey"])
- """)
- self.cmd_executes("-a mod1", """\
- .coverage()
- .load()
- .annotate(morfs=["mod1"])
- """)
- self.cmd_executes("-a mod1 mod2 mod3", """\
- .coverage()
- .load()
- .annotate(morfs=["mod1", "mod2", "mod3"])
- """)
-
- self.cmd_executes_same("-a", "--annotate")
- self.cmd_executes_same("-a -d d1", "-a --directory=d1")
- self.cmd_executes_same("-a -i", "-a --ignore-errors")
- self.cmd_executes_same("-a -o f", "-a --omit=f")
- self.cmd_executes_same("-a -o f", "-a --omit f")
- self.cmd_executes_same("-a -o f,b", "-a --omit=f,b")
- self.cmd_executes_same("-a -o f,b", "-a --omit f,b")
- self.cmd_executes_same("-a -of", "-a --omit=f")
- self.cmd_executes_same("-a -of,b", "-a --omit=f,b")
-
- def test_html_report(self):
- # coverage -b -d DIR [-i] [-o DIR,...] [FILE1 FILE2 ...]
- self.cmd_executes("-b", """\
- .coverage()
- .load()
- .html_report()
- """)
- self.cmd_executes("-b -d dir1", """\
- .coverage()
- .load()
- .html_report(directory="dir1")
- """)
- self.cmd_executes("-b -i", """\
- .coverage()
- .load()
- .html_report(ignore_errors=True)
- """)
- self.cmd_executes("-b -o fooey", """\
- .coverage(omit=["fooey"])
- .load()
- .html_report(omit=["fooey"])
- """)
- self.cmd_executes("-b -o fooey,booey", """\
- .coverage(omit=["fooey", "booey"])
- .load()
- .html_report(omit=["fooey", "booey"])
- """)
- self.cmd_executes("-b mod1", """\
- .coverage()
- .load()
- .html_report(morfs=["mod1"])
- """)
- self.cmd_executes("-b mod1 mod2 mod3", """\
- .coverage()
- .load()
- .html_report(morfs=["mod1", "mod2", "mod3"])
- """)
-
- self.cmd_executes_same("-b", "--html")
- self.cmd_executes_same("-b -d d1", "-b --directory=d1")
- self.cmd_executes_same("-b -i", "-b --ignore-errors")
- self.cmd_executes_same("-b -o f", "-b --omit=f")
- self.cmd_executes_same("-b -o f,b", "-b --omit=f,b")
- self.cmd_executes_same("-b -of", "-b --omit=f")
- self.cmd_executes_same("-b -of,b", "-b --omit=f,b")
-
- def test_help(self):
- # coverage -h
- self.cmd_help("-h", topic="help", ret=OK)
- self.cmd_help("--help", topic="help", ret=OK)
-
- def test_version(self):
- # coverage --version
- self.cmd_help("--version", topic="version", ret=OK)
-
- ## Error cases
-
- def test_argless_actions(self):
- self.cmd_help("-e foo bar", "Unexpected arguments: foo bar")
- self.cmd_help("-c baz quux", "Unexpected arguments: baz quux")
-
- def test_need_action(self):
- self.cmd_help("-p", "You must specify at least one of "
- "-e, -x, -c, -r, -a, or -b.")
-
- def test_bad_action_combinations(self):
- self.cmd_help('-e -a',
- "You can't specify the 'erase' and 'annotate' "
- "options at the same time."
- )
- self.cmd_help('-e -r',
- "You can't specify the 'erase' and 'report' "
- "options at the same time."
- )
- self.cmd_help('-e -b',
- "You can't specify the 'erase' and 'html' "
- "options at the same time."
- )
- self.cmd_help('-e -c',
- "You can't specify the 'erase' and 'combine' "
- "options at the same time."
- )
- self.cmd_help('-x -a',
- "You can't specify the 'execute' and 'annotate' "
- "options at the same time."
- )
- self.cmd_help('-x -r',
- "You can't specify the 'execute' and 'report' "
- "options at the same time."
- )
- self.cmd_help('-x -b',
- "You can't specify the 'execute' and 'html' "
- "options at the same time."
- )
- self.cmd_help('-x -c',
- "You can't specify the 'execute' and 'combine' "
- "options at the same time."
- )
-
- def test_nothing_to_do(self):
- self.cmd_help("-x", "Nothing to do.")
-
- def test_unknown_option(self):
- self.cmd_help("-z", "no such option: -z")
-
-
class FakeCoverageForDebugData(object):
"""Just enough of a fake coverage package for the 'debug data' tests."""
def __init__(self, summary):
@@ -428,7 +159,7 @@ class FakeCoverageForDebugData(object):
return self._summary
-class NewCmdLineTest(CmdLineTest):
+class CmdLineTest(BaseCmdLineTest):
"""Tests of the coverage.py command line."""
def test_annotate(self):
@@ -520,7 +251,16 @@ class NewCmdLineTest(CmdLineTest):
.erase()
""")
- def test_help(self):
+ def test_version(self):
+ # coverage --version
+ self.cmd_help("--version", topic="version", ret=OK)
+
+ def test_help_option(self):
+ # coverage -h
+ self.cmd_help("-h", topic="help", ret=OK)
+ self.cmd_help("--help", topic="help", ret=OK)
+
+ def test_help_command(self):
self.cmd_executes("help", ".help_fn(topic='help')")
def test_cmd_help(self):
@@ -806,7 +546,7 @@ class NewCmdLineTest(CmdLineTest):
self.cmd_help("xyzzy", "Unknown command: 'xyzzy'")
-class CmdLineStdoutTest(CmdLineTest):
+class CmdLineStdoutTest(BaseCmdLineTest):
"""Test the command line with real stdout output."""
def test_minimum_help(self):