Skip to main content

This allows you to assess the coverage of changes you have in a repo. It is intended for use, when preparing to push code up for review upstream.

Usage

As a prerequisite to using this script, run coverage in the repo, to produce coverage report files in a ‘cover’ directory at the root of the repo’s tree. This coverage should be done on the code that will be upstreamed (either what is in the working directory, or what has been committed to the local repo).

Behavior

Assuming you have a repo with uncommitted changes, you can run the command as follows:

commit_coverage /opt/stack/networking-cisco

The argument must be the root of a git repo that has coverage data in a ‘cover’ subdirectory.

By default, this will create diffs comparing the working directory, to the latest commit (HEAD), with (up to) three lines of context. That output will be checked against coverage data and a report produced. Here’s what the output looks like:

devstack/csr1kv/cisco_neutron (No coverage data)

networking_cisco/apps/saf/agent/dfa_agent.py (No added/changed lines)

networking_cisco/apps/saf/server/dfa_server.py (run=1, mis=1, par=0, ign=0) 47%
   32 run  import time
   33
   34
   35 run +from networking_cisco._i18n import _LE, _LI, _LW
   36 run  from oslo_serialization import jsonutils
   37
   38

  382              # it is created by openstack.
  383 run          part_name = self.cfg.dcnm.default_partition_name
  384 par          if len(':'.join((proj_name, part_name))) > 32:
  385 mis +            LOG.error(_LE('Invalid project name length: %s. The length of '
  386                                'org:part name is greater than 32'),
  387                            len(':'.join((proj_name, part_name))))
  388 mis              return

Each file from the diff will be reported. If the file was not processed by the coverage test, or there were no added or changed lines in the diff for the file, this will be reported, as shown in the first two files.

For files with coverage data and added/changes lines, the output will look like the third file. Each line number from the diff is shown, with the coverage status, which can be:

  • ‘run’ The line was invoked as part of coverage run

  • ‘mis’ The line was not invoked during coverage

  • ‘par’ The line was partially covered

  • ‘ ‘ The line was not considered for coverage (e.g. blank, non-executable)

Next, if the line was added/changed, a ‘+’ is shown. If it was a context line for the diff region, a ‘ ‘ is shown. Deleted lines are not shown. After that, the source code is show.

Next to the filename is summary information, ONLY for lines that were added or changed. In the example, there was one line run and one missing in the change set (lines with a plus sign). At the end, we can see the overall coverage report for the FILE - 47% in this example.

There are a few knobs that you can use with this script. First, you can change the number of context lines shown by using the –context argument. The default is three, and can be zero or more. Note: if a diff region is at the start or end of a file, there may be fewer or no context lines.

Second, you can select which commits are used for the diff calculation, by specifying the –which argument. The default is ‘working’, which will do a diff between the working directory and latest commit (HEAD). Instead, you can provide ‘committed’, which will compare the current commit against the previous commit (HEAD^..HEAD). Otherwise, you can provide the commit versions to use for the diff, just make sure that the most recent corresponds to the coverage report. For example, you can do:

cd /opt/stack/neutron
commit_coverage --context 5 --which HEAD~5..HEAD~ .

This runs the tool on a neutron repo, shows more context lines, and will do a diff between HEAD~5 and HEAD~ commits.

You can use the -h option to see what the arguments are for this script.

Metadata

Release files for commit-coverage 0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for commit-coverage 0.7
File Size Uploaded Provenance
commit-coverage-0.7.tar.gz 6.9 kB Without provenance Details

Release files / commit-coverage-0.7.tar.gz

Download URL commit-coverage-0.7.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
20a373cca16996cc33680f4589a8a33c10a388c8f2919ca545a27110712c1389
BLAKE2b-256 checksum
How to use checksums
ed5648c9426bbb26bf7851421a83a805575a2151f9f4d2d1072e9f3bc83932d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for commit-coverage 0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page