diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2020-05-12 06:56:21 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2020-05-12 06:56:21 -0400 |
commit | dc48c725fe4a95b64939f67cbb97d259ba47fe9f (patch) | |
tree | baaa7080d8fac753543eab3e2b92c001809def70 | |
parent | bbd0c0fe16e0fa02b9023b3703fd0c91ca2cf855 (diff) | |
download | python-coveragepy-git-dc48c725fe4a95b64939f67cbb97d259ba47fe9f.tar.gz |
Finish up --precision
-rw-r--r-- | CHANGES.rst | 4 | ||||
-rw-r--r-- | CONTRIBUTORS.txt | 1 | ||||
-rw-r--r-- | coverage/cmdline.py | 4 | ||||
-rw-r--r-- | coverage/control.py | 18 | ||||
-rw-r--r-- | doc/cmd.rst | 6 | ||||
-rw-r--r-- | tests/test_cmdline.py | 16 |
6 files changed, 39 insertions, 10 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index b63ad42b..49016e9f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -24,7 +24,9 @@ want to know what's different in 5.0 since 4.5.x, see :ref:`whatsnew5x`. Unreleased ---------- -Nothing yet. +- The ``coverage report`` and ``coverage html`` commands now accept a + ``--precision`` option to control the number of decimal points displayed. + Thanks, Teake Nutma. .. _changes_51: diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index a3cc9be7..82ec3251 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -127,6 +127,7 @@ Stephen Finucane Steve Leonard Steve Peak S. Y. Lee +Teake Nutma Ted Wexler Thijs Triemstra Titus Brown diff --git a/coverage/cmdline.py b/coverage/cmdline.py index db604dbd..08e116b6 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -366,6 +366,7 @@ CMDS = { Opts.ignore_errors, Opts.include, Opts.omit, + Opts.precision, Opts.show_contexts, Opts.skip_covered, Opts.skip_empty, @@ -578,7 +579,6 @@ class CoverageScript(object): omit=omit, include=include, contexts=contexts, - precision=options.precision, ) # We need to be able to import from the current directory, because @@ -593,6 +593,7 @@ class CoverageScript(object): show_missing=options.show_missing, skip_covered=options.skip_covered, skip_empty=options.skip_empty, + precision=options.precision, **report_args ) elif options.action == "annotate": @@ -604,6 +605,7 @@ class CoverageScript(object): skip_covered=options.skip_covered, skip_empty=options.skip_empty, show_contexts=options.show_contexts, + precision=options.precision, **report_args ) elif options.action == "xml": diff --git a/coverage/control.py b/coverage/control.py index c0e4c73c..c2f40e70 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -857,6 +857,9 @@ class Coverage(object): expressions (using :func:`re.search <python:re.search>`) will be included in the report. + `precision` is the number of digits to display after the decimal + point for percentages. + All of the arguments default to the settings read from the :ref:`configuration file <config>`. @@ -868,6 +871,9 @@ class Coverage(object): .. versionadded:: 5.0 The `contexts` and `skip_empty` parameters. + .. versionadded:: 5.2 + The `precision` parameter. + """ with override_config( self, @@ -899,10 +905,12 @@ class Coverage(object): reporter = AnnotateReporter(self) reporter.report(morfs, directory=directory) - def html_report(self, morfs=None, directory=None, ignore_errors=None, - omit=None, include=None, extra_css=None, title=None, - skip_covered=None, show_contexts=None, contexts=None, - skip_empty=None): + def html_report( + self, morfs=None, directory=None, ignore_errors=None, + omit=None, include=None, extra_css=None, title=None, + skip_covered=None, show_contexts=None, contexts=None, + skip_empty=None, precision=None, + ): """Generate an HTML report. The HTML is written to `directory`. The file "index.html" is the @@ -930,7 +938,7 @@ class Coverage(object): ignore_errors=ignore_errors, report_omit=omit, report_include=include, html_dir=directory, extra_css=extra_css, html_title=title, skip_covered=skip_covered, show_contexts=show_contexts, report_contexts=contexts, - skip_empty=skip_empty, + skip_empty=skip_empty, precision=precision, ): reporter = HtmlReporter(self) return reporter.report(morfs) diff --git a/doc/cmd.rst b/doc/cmd.rst index cbbb26bb..31ae6e01 100644 --- a/doc/cmd.rst +++ b/doc/cmd.rst @@ -371,6 +371,9 @@ If you have :ref:`recorded contexts <contexts>`, the ``--contexts`` option lets you choose which contexts to report on. See :ref:`context_reporting` for details. +The ``--precision`` option controls the number of digits displayed after the +decimal point in coverage percentages, defaulting to none. + Other common reporting options are described above in :ref:`cmd_reporting`. @@ -418,6 +421,9 @@ The ``--skip-covered`` switch will skip any file with 100% coverage, letting you focus on the files that still need attention. The ``--skip-empty`` switch will skip any file with no executable statements. +The ``--precision`` option controls the number of digits displayed after the +decimal point in coverage percentages, defaulting to none. + If you have :ref:`recorded contexts <contexts>`, the ``--contexts`` option lets you choose which contexts to report on, and the ``--show-contexts`` option will annotate lines with the contexts that ran them. See :ref:`context_reporting` diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index f5e8e96a..742df18b 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -37,11 +37,11 @@ class BaseCmdLineTest(CoverageTest): _defaults.Coverage().html_report( directory=None, ignore_errors=None, include=None, omit=None, morfs=[], skip_covered=None, show_contexts=None, title=None, contexts=None, - skip_empty=None, + skip_empty=None, precision=None, ) _defaults.Coverage().report( ignore_errors=None, include=None, omit=None, morfs=[], - show_missing=None, skip_covered=None, contexts=None, skip_empty=None, + show_missing=None, skip_covered=None, contexts=None, skip_empty=None, precision=None, ) _defaults.Coverage().xml_report( ignore_errors=None, include=None, omit=None, morfs=[], outfile=None, @@ -49,7 +49,7 @@ class BaseCmdLineTest(CoverageTest): ) _defaults.Coverage().json_report( ignore_errors=None, include=None, omit=None, morfs=[], outfile=None, - contexts=None, pretty_print=None, show_contexts=None + contexts=None, pretty_print=None, show_contexts=None, ) _defaults.Coverage( cover_pylib=None, data_suffix=None, timid=None, branch=None, @@ -324,6 +324,11 @@ class CmdLineTest(BaseCmdLineTest): cov.load() cov.html_report(morfs=["mod1", "mod2", "mod3"]) """) + self.cmd_executes("html --precision=3", """\ + cov = Coverage() + cov.load() + cov.html_report(precision=3) + """) self.cmd_executes("html --title=Hello_there", """\ cov = Coverage() cov.load() @@ -367,6 +372,11 @@ class CmdLineTest(BaseCmdLineTest): cov.load() cov.report(morfs=["mod1", "mod2", "mod3"]) """) + self.cmd_executes("report --precision=7", """\ + cov = Coverage() + cov.load() + cov.report(precision=7) + """) self.cmd_executes("report --skip-covered", """\ cov = Coverage() cov.load() |