Skip to content

Commit

Permalink
fix: more cleanup of --data-file options
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 25, 2022
1 parent f9a5451 commit bf8cbe1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 43 deletions.
29 changes: 18 additions & 11 deletions coverage/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Opts:
combine_datafile = optparse.make_option(
'', '--data-file', action='store', metavar="DATAFILE",
help=(
"Base name of the data files to combine and write. " +
"Base name of the data files to operate on. " +
"Defaults to '.coverage'. [env: COVERAGE_FILE]"
),
)
Expand Down Expand Up @@ -344,17 +344,16 @@ def get_prog_name(self):
Opts.rcfile,
]

REPORT_ARGS = [Opts.input_datafile]

CMDS = {
'annotate': CmdOptionParser(
"annotate",
[
Opts.directory,
Opts.input_datafile,
Opts.ignore_errors,
Opts.include,
Opts.omit,
] + REPORT_ARGS + GLOBAL_ARGS,
] + GLOBAL_ARGS,
usage="[options] [modules]",
description=(
"Make annotated copies of the given files, marking statements that are executed " +
Expand All @@ -366,9 +365,9 @@ def get_prog_name(self):
"combine",
[
Opts.append,
Opts.combine_datafile,
Opts.keep,
Opts.quiet,
Opts.combine_datafile
] + GLOBAL_ARGS,
usage="[options] <path1> <path2> ... <pathN>",
description=(
Expand Down Expand Up @@ -396,7 +395,10 @@ def get_prog_name(self):
),

'erase': CmdOptionParser(
"erase", [Opts.input_datafile] + GLOBAL_ARGS,
"erase",
[
Opts.combine_datafile
] + GLOBAL_ARGS,
description="Erase previously collected coverage data.",
),

Expand All @@ -411,6 +413,7 @@ def get_prog_name(self):
[
Opts.contexts,
Opts.directory,
Opts.input_datafile,
Opts.fail_under,
Opts.ignore_errors,
Opts.include,
Expand All @@ -422,7 +425,7 @@ def get_prog_name(self):
Opts.no_skip_covered,
Opts.skip_empty,
Opts.title,
] + REPORT_ARGS + GLOBAL_ARGS,
] + GLOBAL_ARGS,
usage="[options] [modules]",
description=(
"Create an HTML report of the coverage of the files. " +
Expand All @@ -435,6 +438,7 @@ def get_prog_name(self):
"json",
[
Opts.contexts,
Opts.input_datafile,
Opts.fail_under,
Opts.ignore_errors,
Opts.include,
Expand All @@ -443,14 +447,15 @@ def get_prog_name(self):
Opts.json_pretty_print,
Opts.quiet,
Opts.show_contexts,
] + REPORT_ARGS + GLOBAL_ARGS,
] + GLOBAL_ARGS,
usage="[options] [modules]",
description="Generate a JSON report of coverage results.",
),

'lcov': CmdOptionParser(
"lcov",
[
Opts.input_datafile,
Opts.fail_under,
Opts.ignore_errors,
Opts.include,
Expand All @@ -466,6 +471,7 @@ def get_prog_name(self):
"report",
[
Opts.contexts,
Opts.input_datafile,
Opts.fail_under,
Opts.ignore_errors,
Opts.include,
Expand All @@ -476,7 +482,7 @@ def get_prog_name(self):
Opts.skip_covered,
Opts.no_skip_covered,
Opts.skip_empty,
] + REPORT_ARGS + GLOBAL_ARGS,
] + GLOBAL_ARGS,
usage="[options] [modules]",
description="Report coverage statistics on modules.",
),
Expand All @@ -488,10 +494,10 @@ def get_prog_name(self):
Opts.branch,
Opts.concurrency,
Opts.context,
Opts.output_datafile,
Opts.include,
Opts.module,
Opts.omit,
Opts.output_datafile,
Opts.pylib,
Opts.parallel_mode,
Opts.source,
Expand All @@ -504,14 +510,15 @@ def get_prog_name(self):
'xml': CmdOptionParser(
"xml",
[
Opts.input_datafile,
Opts.fail_under,
Opts.ignore_errors,
Opts.include,
Opts.omit,
Opts.output_xml,
Opts.quiet,
Opts.skip_empty,
] + REPORT_ARGS + GLOBAL_ARGS,
] + GLOBAL_ARGS,
usage="[options] [modules]",
description="Generate an XML report of coverage results.",
),
Expand Down
64 changes: 33 additions & 31 deletions doc/cmd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ There are many options:
Valid values are: eventlet, gevent, greenlet,
multiprocessing, thread, or a comma-list of them.
--context=LABEL The context label to record for this coverage run.
--data-file=OUTFILE Write the recorded coverage data to this file.
Defaults to '.coverage'. [env: COVERAGE_FILE]
--include=PAT1,PAT2,...
Include only files whose paths match one of these
patterns. Accepts shell-style wildcards, which must be
Expand All @@ -142,8 +144,6 @@ There are many options:
path, to be run as 'python -m' would run it.
--omit=PAT1,PAT2,... Omit files whose paths match one of these patterns.
Accepts shell-style wildcards, which must be quoted.
--data-file=OUTFILE Write the recorded coverage data to this file.
Defaults to '.coverage'. [env: COVERAGE_FILE]
-L, --pylib Measure coverage even inside the Python installed
library, which isn't done by default.
-p, --parallel-mode Append the machine name, process id and random number
Expand All @@ -160,7 +160,7 @@ There are many options:
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
tried. [env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: 3ec48d96422f8b3aed3cf5a8b223891f)
.. [[[end]]] (checksum: 05d15818e42e6f989c42894fb2b3c753)
If you want :ref:`branch coverage <branch>` measurement, use the ``--branch``
flag. Otherwise only statement coverage is measured.
Expand Down Expand Up @@ -391,18 +391,18 @@ want to keep those files, use the ``--keep`` command-line option.
Options:
-a, --append Append coverage data to .coverage, otherwise it starts
clean each time.
--data-file=DATAFILE Base name of the data files to operate on. Defaults to
'.coverage'. [env: COVERAGE_FILE]
--keep Keep original coverage files, otherwise they are
deleted.
-q, --quiet Don't print messages about what is happening.
--data-file=DATAFILE Base name of the data files to combine and write.
Defaults to '.coverage'. [env: COVERAGE_FILE]
--debug=OPTS Debug options, separated by commas. [env:
COVERAGE_DEBUG]
-h, --help Get help on this command.
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
tried. [env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: 6cba18a0531f9d2f7af67e472b96eb6b)
.. [[[end]]] (checksum: 0ac91b0781d7146b87953f09090dab92)
.. _cmd_erase:
Expand All @@ -421,15 +421,15 @@ To erase the collected data, use the **erase** command:
Erase previously collected coverage data.
Options:
--data-file=INFILE Read coverage data for report generation from this file.
Defaults to '.coverage'. [env: COVERAGE_FILE]
--debug=OPTS Debug options, separated by commas. [env:
COVERAGE_DEBUG]
-h, --help Get help on this command.
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are tried.
[env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: e3dec8ef7687d3525682904340e8cf54)
--data-file=DATAFILE Base name of the data files to operate on. Defaults to
'.coverage'. [env: COVERAGE_FILE]
--debug=OPTS Debug options, separated by commas. [env:
COVERAGE_DEBUG]
-h, --help Get help on this command.
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
tried. [env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: cfeaef66ce8d5154dc6914831030b46b)
If your configuration file indicates parallel data collection, **erase** will
remove all of the data files.
Expand Down Expand Up @@ -496,6 +496,8 @@ as a percentage.
Only display data from lines covered in the given
contexts. Accepts Python regexes, which must be
quoted.
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--fail-under=MIN Exit with a status of 2 if the total coverage is less
than MIN.
-i, --ignore-errors Ignore errors while reading source files.
Expand All @@ -514,15 +516,13 @@ as a percentage.
--skip-covered Skip files with 100% coverage.
--no-skip-covered Disable --skip-covered.
--skip-empty Skip files with no code.
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--debug=OPTS Debug options, separated by commas. [env:
COVERAGE_DEBUG]
-h, --help Get help on this command.
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
tried. [env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: 97565fdb6f1eefbeeb12d56151fa5e63)
.. [[[end]]] (checksum: 2f8dde61bab2f44fbfe837aeae87dfd2)
The ``-m`` flag also shows the line numbers of missing statements::

Expand Down Expand Up @@ -613,6 +613,8 @@ Click the keyboard icon in the upper right to see the complete list.
quoted.
-d DIR, --directory=DIR
Write the output files to DIR.
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--fail-under=MIN Exit with a status of 2 if the total coverage is less
than MIN.
-i, --ignore-errors Ignore errors while reading source files.
Expand All @@ -630,15 +632,13 @@ Click the keyboard icon in the upper right to see the complete list.
--no-skip-covered Disable --skip-covered.
--skip-empty Skip files with no code.
--title=TITLE A text string to use as the title on the HTML.
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--debug=OPTS Debug options, separated by commas. [env:
COVERAGE_DEBUG]
-h, --help Get help on this command.
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
tried. [env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: e3208f3b38a44ca81e0235e867f4fd1c)
.. [[[end]]] (checksum: e3a1a6e24ad9b303ba06d42880ed0219)
The title of the report can be set with the ``title`` setting in the
``[html]`` section of the configuration file, or the ``--title`` switch on
Expand Down Expand Up @@ -691,6 +691,8 @@ compatible with `Cobertura`_.
Generate an XML report of coverage results.
Options:
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--fail-under=MIN Exit with a status of 2 if the total coverage is less
than MIN.
-i, --ignore-errors Ignore errors while reading source files.
Expand All @@ -704,15 +706,13 @@ compatible with `Cobertura`_.
'coverage.xml'
-q, --quiet Don't print messages about what is happening.
--skip-empty Skip files with no code.
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--debug=OPTS Debug options, separated by commas. [env:
COVERAGE_DEBUG]
-h, --help Get help on this command.
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
tried. [env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: 3dc4450c0a723109f987c4b6f968be43)
.. [[[end]]] (checksum: 8b239d89534be0b2c69489e10b1352a9)
You can specify the name of the output file with the ``-o`` switch.

Expand Down Expand Up @@ -777,6 +777,8 @@ The **json** command writes coverage data to a "coverage.json" file.
Only display data from lines covered in the given
contexts. Accepts Python regexes, which must be
quoted.
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--fail-under=MIN Exit with a status of 2 if the total coverage is less
than MIN.
-i, --ignore-errors Ignore errors while reading source files.
Expand All @@ -791,15 +793,13 @@ The **json** command writes coverage data to a "coverage.json" file.
--pretty-print Format the JSON for human readers.
-q, --quiet Don't print messages about what is happening.
--show-contexts Show contexts for covered lines.
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--debug=OPTS Debug options, separated by commas. [env:
COVERAGE_DEBUG]
-h, --help Get help on this command.
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
tried. [env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: fdc9af899380fbb78599d08a70e564fc)
.. [[[end]]] (checksum: e53e60cb65d971c35d1db1c08324b72e)
You can specify the name of the output file with the ``-o`` switch. The JSON
can be nicely formatted by specifying the ``--pretty-print`` switch.
Expand All @@ -820,6 +820,8 @@ The **lcov** command writes coverage data to a "coverage.lcov" file.
Generate an LCOV report of coverage results.
Options:
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--fail-under=MIN Exit with a status of 2 if the total coverage is less
than MIN.
-i, --ignore-errors Ignore errors while reading source files.
Expand All @@ -838,7 +840,7 @@ The **lcov** command writes coverage data to a "coverage.lcov" file.
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
tried. [env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: 4d078e4637e5b507cbb997803a0d4758)
.. [[[end]]] (checksum: 16acfbae8011d2e3b620695c5fe13746)
Other common reporting options are described above in :ref:`cmd_reporting`.

Expand Down Expand Up @@ -890,22 +892,22 @@ For example::
Options:
-d DIR, --directory=DIR
Write the output files to DIR.
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
-i, --ignore-errors Ignore errors while reading source files.
--include=PAT1,PAT2,...
Include only files whose paths match one of these
patterns. Accepts shell-style wildcards, which must be
quoted.
--omit=PAT1,PAT2,... Omit files whose paths match one of these patterns.
Accepts shell-style wildcards, which must be quoted.
--data-file=INFILE Read coverage data for report generation from this
file. Defaults to '.coverage'. [env: COVERAGE_FILE]
--debug=OPTS Debug options, separated by commas. [env:
COVERAGE_DEBUG]
-h, --help Get help on this command.
--rcfile=RCFILE Specify configuration file. By default '.coveragerc',
'setup.cfg', 'tox.ini', and 'pyproject.toml' are
tried. [env: COVERAGE_RCFILE]
.. [[[end]]] (checksum: aa41bad1cd4c08efc3276b5dca01dea3)
.. [[[end]]] (checksum: fd7d8fbd2dd6e24d37f868b389c2ad6d)
Other common reporting options are described above in :ref:`cmd_reporting`.

Expand Down
Loading

0 comments on commit bf8cbe1

Please sign in to comment.