summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/cmdline.py74
-rw-r--r--tests/test_cmdline.py106
2 files changed, 90 insertions, 90 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 5f972035..81b87edf 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -55,6 +55,14 @@ class Opts:
'', '--context', action='store', metavar="LABEL",
help="The context label to record for this coverage run.",
)
+ contexts = optparse.make_option(
+ '', '--contexts', action='store',
+ metavar="REGEX1,REGEX2,...",
+ help=(
+ "Only display data from lines covered in the given contexts. " +
+ "Accepts Python regexes, which must be quoted."
+ ),
+ )
debug = optparse.make_option(
'', '--debug', action='store', metavar="OPTS",
help="Debug options, separated by commas. [env: COVERAGE_DEBUG]",
@@ -90,30 +98,16 @@ class Opts:
"which isn't done by default."
),
)
- sort = optparse.make_option(
- '--sort', action='store', metavar='COLUMN',
- help="Sort the report by the named column: name, stmts, miss, branch, brpart, or cover. " +
- "Default is name."
- )
show_missing = optparse.make_option(
'-m', '--show-missing', action='store_true',
help="Show line numbers of statements in each module that weren't executed.",
)
- skip_covered = optparse.make_option(
- '--skip-covered', action='store_true',
- help="Skip files with 100% coverage.",
- )
- no_skip_covered = optparse.make_option(
- '--no-skip-covered', action='store_false', dest='skip_covered',
- help="Disable --skip-covered.",
- )
- skip_empty = optparse.make_option(
- '--skip-empty', action='store_true',
- help="Skip files with no code.",
- )
- show_contexts = optparse.make_option(
- '--show-contexts', action='store_true',
- help="Show contexts for covered lines.",
+ module = optparse.make_option(
+ '-m', '--module', action='store_true',
+ help=(
+ "<pyfile> is an importable Python module, not a script path, " +
+ "to be run as 'python -m' would run it."
+ ),
)
omit = optparse.make_option(
'', '--omit', action='store',
@@ -123,14 +117,6 @@ class Opts:
"Accepts shell-style wildcards, which must be quoted."
),
)
- contexts = optparse.make_option(
- '', '--contexts', action='store',
- metavar="REGEX1,REGEX2,...",
- help=(
- "Only display data from lines covered in the given contexts. " +
- "Accepts Python regexes, which must be quoted."
- ),
- )
output_xml = optparse.make_option(
'-o', '', action='store', dest="outfile",
metavar="OUTFILE",
@@ -153,13 +139,6 @@ class Opts:
"many processes."
),
)
- module = optparse.make_option(
- '-m', '--module', action='store_true',
- help=(
- "<pyfile> is an importable Python module, not a script path, " +
- "to be run as 'python -m' would run it."
- ),
- )
precision = optparse.make_option(
'', '--precision', action='store', metavar='N', type=int,
help=(
@@ -175,6 +154,27 @@ class Opts:
"'pyproject.toml' are tried. [env: COVERAGE_RCFILE]"
),
)
+ show_contexts = optparse.make_option(
+ '--show-contexts', action='store_true',
+ help="Show contexts for covered lines.",
+ )
+ skip_covered = optparse.make_option(
+ '--skip-covered', action='store_true',
+ help="Skip files with 100% coverage.",
+ )
+ no_skip_covered = optparse.make_option(
+ '--no-skip-covered', action='store_false', dest='skip_covered',
+ help="Disable --skip-covered.",
+ )
+ skip_empty = optparse.make_option(
+ '--skip-empty', action='store_true',
+ help="Skip files with no code.",
+ )
+ sort = optparse.make_option(
+ '--sort', action='store', metavar='COLUMN',
+ help="Sort the report by the named column: name, stmts, miss, branch, brpart, or cover. " +
+ "Default is name."
+ )
source = optparse.make_option(
'', '--source', action='store', metavar="SRC1,SRC2,...",
help="A list of directories or importable names of code to measure.",
@@ -214,6 +214,7 @@ class CoverageOptionParser(optparse.OptionParser):
branch=None,
concurrency=None,
context=None,
+ contexts=None,
debug=None,
directory=None,
fail_under=None,
@@ -223,15 +224,14 @@ class CoverageOptionParser(optparse.OptionParser):
keep=None,
module=None,
omit=None,
- contexts=None,
parallel_mode=None,
precision=None,
pylib=None,
rcfile=True,
+ show_contexts=None,
show_missing=None,
skip_covered=None,
skip_empty=None,
- show_contexts=None,
sort=None,
source=None,
timid=None,
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 7b558bbb..b0716e6d 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -336,6 +336,59 @@ class CmdLineTest(BaseCmdLineTest):
cov.html_report(title='Hello_there')
""")
+ def test_json(self):
+ # coverage json [-i] [--omit DIR,...] [FILE1 FILE2 ...]
+ self.cmd_executes("json", """\
+ cov = Coverage()
+ cov.load()
+ cov.json_report()
+ """)
+ self.cmd_executes("json --pretty-print", """\
+ cov = Coverage()
+ cov.load()
+ cov.json_report(pretty_print=True)
+ """)
+ self.cmd_executes("json --pretty-print --show-contexts", """\
+ cov = Coverage()
+ cov.load()
+ cov.json_report(pretty_print=True, show_contexts=True)
+ """)
+ self.cmd_executes("json -i", """\
+ cov = Coverage()
+ cov.load()
+ cov.json_report(ignore_errors=True)
+ """)
+ self.cmd_executes("json -o myjson.foo", """\
+ cov = Coverage()
+ cov.load()
+ cov.json_report(outfile="myjson.foo")
+ """)
+ self.cmd_executes("json -o -", """\
+ cov = Coverage()
+ cov.load()
+ cov.json_report(outfile="-")
+ """)
+ self.cmd_executes("json --omit fooey", """\
+ cov = Coverage(omit=["fooey"])
+ cov.load()
+ cov.json_report(omit=["fooey"])
+ """)
+ self.cmd_executes("json --omit fooey,booey", """\
+ cov = Coverage(omit=["fooey", "booey"])
+ cov.load()
+ cov.json_report(omit=["fooey", "booey"])
+ """)
+ self.cmd_executes("json mod1", """\
+ cov = Coverage()
+ cov.load()
+ cov.json_report(morfs=["mod1"])
+ """)
+ self.cmd_executes("json mod1 mod2 mod3", """\
+ cov = Coverage()
+ cov.load()
+ cov.json_report(morfs=["mod1", "mod2", "mod3"])
+ """)
+
def test_report(self):
# coverage report [-m] [-i] [-o DIR,...] [FILE1 FILE2 ...]
self.cmd_executes("report", """\
@@ -701,59 +754,6 @@ class CmdLineTest(BaseCmdLineTest):
cov.xml_report(morfs=["mod1", "mod2", "mod3"])
""")
- def test_json(self):
- # coverage json [-i] [--omit DIR,...] [FILE1 FILE2 ...]
- self.cmd_executes("json", """\
- cov = Coverage()
- cov.load()
- cov.json_report()
- """)
- self.cmd_executes("json --pretty-print", """\
- cov = Coverage()
- cov.load()
- cov.json_report(pretty_print=True)
- """)
- self.cmd_executes("json --pretty-print --show-contexts", """\
- cov = Coverage()
- cov.load()
- cov.json_report(pretty_print=True, show_contexts=True)
- """)
- self.cmd_executes("json -i", """\
- cov = Coverage()
- cov.load()
- cov.json_report(ignore_errors=True)
- """)
- self.cmd_executes("json -o myjson.foo", """\
- cov = Coverage()
- cov.load()
- cov.json_report(outfile="myjson.foo")
- """)
- self.cmd_executes("json -o -", """\
- cov = Coverage()
- cov.load()
- cov.json_report(outfile="-")
- """)
- self.cmd_executes("json --omit fooey", """\
- cov = Coverage(omit=["fooey"])
- cov.load()
- cov.json_report(omit=["fooey"])
- """)
- self.cmd_executes("json --omit fooey,booey", """\
- cov = Coverage(omit=["fooey", "booey"])
- cov.load()
- cov.json_report(omit=["fooey", "booey"])
- """)
- self.cmd_executes("json mod1", """\
- cov = Coverage()
- cov.load()
- cov.json_report(morfs=["mod1"])
- """)
- self.cmd_executes("json mod1 mod2 mod3", """\
- cov = Coverage()
- cov.load()
- cov.json_report(morfs=["mod1", "mod2", "mod3"])
- """)
-
def test_no_arguments_at_all(self):
self.cmd_help("", topic="minimum_help", ret=OK)