Skip to content

Commit dc48c72

Browse files
committed
Finish up --precision
1 parent bbd0c0f commit dc48c72

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ want to know what's different in 5.0 since 4.5.x, see :ref:`whatsnew5x`.
2424
Unreleased
2525
----------
2626

27-
Nothing yet.
27+
- The ``coverage report`` and ``coverage html`` commands now accept a
28+
``--precision`` option to control the number of decimal points displayed.
29+
Thanks, Teake Nutma.
2830

2931

3032
.. _changes_51:

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Stephen Finucane
127127
Steve Leonard
128128
Steve Peak
129129
S. Y. Lee
130+
Teake Nutma
130131
Ted Wexler
131132
Thijs Triemstra
132133
Titus Brown

coverage/cmdline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ def get_prog_name(self):
366366
Opts.ignore_errors,
367367
Opts.include,
368368
Opts.omit,
369+
Opts.precision,
369370
Opts.show_contexts,
370371
Opts.skip_covered,
371372
Opts.skip_empty,
@@ -578,7 +579,6 @@ def command_line(self, argv):
578579
omit=omit,
579580
include=include,
580581
contexts=contexts,
581-
precision=options.precision,
582582
)
583583

584584
# We need to be able to import from the current directory, because
@@ -593,6 +593,7 @@ def command_line(self, argv):
593593
show_missing=options.show_missing,
594594
skip_covered=options.skip_covered,
595595
skip_empty=options.skip_empty,
596+
precision=options.precision,
596597
**report_args
597598
)
598599
elif options.action == "annotate":
@@ -604,6 +605,7 @@ def command_line(self, argv):
604605
skip_covered=options.skip_covered,
605606
skip_empty=options.skip_empty,
606607
show_contexts=options.show_contexts,
608+
precision=options.precision,
607609
**report_args
608610
)
609611
elif options.action == "xml":

coverage/control.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,9 @@ def report(
857857
expressions (using :func:`re.search <python:re.search>`) will be
858858
included in the report.
859859
860+
`precision` is the number of digits to display after the decimal
861+
point for percentages.
862+
860863
All of the arguments default to the settings read from the
861864
:ref:`configuration file <config>`.
862865
@@ -868,6 +871,9 @@ def report(
868871
.. versionadded:: 5.0
869872
The `contexts` and `skip_empty` parameters.
870873
874+
.. versionadded:: 5.2
875+
The `precision` parameter.
876+
871877
"""
872878
with override_config(
873879
self,
@@ -899,10 +905,12 @@ def annotate(
899905
reporter = AnnotateReporter(self)
900906
reporter.report(morfs, directory=directory)
901907

902-
def html_report(self, morfs=None, directory=None, ignore_errors=None,
903-
omit=None, include=None, extra_css=None, title=None,
904-
skip_covered=None, show_contexts=None, contexts=None,
905-
skip_empty=None):
908+
def html_report(
909+
self, morfs=None, directory=None, ignore_errors=None,
910+
omit=None, include=None, extra_css=None, title=None,
911+
skip_covered=None, show_contexts=None, contexts=None,
912+
skip_empty=None, precision=None,
913+
):
906914
"""Generate an HTML report.
907915
908916
The HTML is written to `directory`. The file "index.html" is the
@@ -930,7 +938,7 @@ def html_report(self, morfs=None, directory=None, ignore_errors=None,
930938
ignore_errors=ignore_errors, report_omit=omit, report_include=include,
931939
html_dir=directory, extra_css=extra_css, html_title=title,
932940
skip_covered=skip_covered, show_contexts=show_contexts, report_contexts=contexts,
933-
skip_empty=skip_empty,
941+
skip_empty=skip_empty, precision=precision,
934942
):
935943
reporter = HtmlReporter(self)
936944
return reporter.report(morfs)

doc/cmd.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ If you have :ref:`recorded contexts <contexts>`, the ``--contexts`` option lets
371371
you choose which contexts to report on. See :ref:`context_reporting` for
372372
details.
373373

374+
The ``--precision`` option controls the number of digits displayed after the
375+
decimal point in coverage percentages, defaulting to none.
376+
374377
Other common reporting options are described above in :ref:`cmd_reporting`.
375378

376379

@@ -418,6 +421,9 @@ The ``--skip-covered`` switch will skip any file with 100% coverage, letting
418421
you focus on the files that still need attention. The ``--skip-empty`` switch
419422
will skip any file with no executable statements.
420423

424+
The ``--precision`` option controls the number of digits displayed after the
425+
decimal point in coverage percentages, defaulting to none.
426+
421427
If you have :ref:`recorded contexts <contexts>`, the ``--contexts`` option lets
422428
you choose which contexts to report on, and the ``--show-contexts`` option will
423429
annotate lines with the contexts that ran them. See :ref:`context_reporting`

tests/test_cmdline.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ class BaseCmdLineTest(CoverageTest):
3737
_defaults.Coverage().html_report(
3838
directory=None, ignore_errors=None, include=None, omit=None, morfs=[],
3939
skip_covered=None, show_contexts=None, title=None, contexts=None,
40-
skip_empty=None,
40+
skip_empty=None, precision=None,
4141
)
4242
_defaults.Coverage().report(
4343
ignore_errors=None, include=None, omit=None, morfs=[],
44-
show_missing=None, skip_covered=None, contexts=None, skip_empty=None,
44+
show_missing=None, skip_covered=None, contexts=None, skip_empty=None, precision=None,
4545
)
4646
_defaults.Coverage().xml_report(
4747
ignore_errors=None, include=None, omit=None, morfs=[], outfile=None,
4848
contexts=None,
4949
)
5050
_defaults.Coverage().json_report(
5151
ignore_errors=None, include=None, omit=None, morfs=[], outfile=None,
52-
contexts=None, pretty_print=None, show_contexts=None
52+
contexts=None, pretty_print=None, show_contexts=None,
5353
)
5454
_defaults.Coverage(
5555
cover_pylib=None, data_suffix=None, timid=None, branch=None,
@@ -324,6 +324,11 @@ def test_html(self):
324324
cov.load()
325325
cov.html_report(morfs=["mod1", "mod2", "mod3"])
326326
""")
327+
self.cmd_executes("html --precision=3", """\
328+
cov = Coverage()
329+
cov.load()
330+
cov.html_report(precision=3)
331+
""")
327332
self.cmd_executes("html --title=Hello_there", """\
328333
cov = Coverage()
329334
cov.load()
@@ -367,6 +372,11 @@ def test_report(self):
367372
cov.load()
368373
cov.report(morfs=["mod1", "mod2", "mod3"])
369374
""")
375+
self.cmd_executes("report --precision=7", """\
376+
cov = Coverage()
377+
cov.load()
378+
cov.report(precision=7)
379+
""")
370380
self.cmd_executes("report --skip-covered", """\
371381
cov = Coverage()
372382
cov.load()

0 commit comments

Comments
 (0)