Coder Social home page Coder Social logo

coverage-badge's Introduction

Coverage.py Badge

Build status PyPI Downloads

⚠️ coverage-badge is in maintenance mode. I might still do occasional updates and fixes from time to time, but there will be no added features. Most people using coverage-badge might want to use genbadge instead, which has more features (e.g. test badges, flake8 reports, etc).

A small script to generate coverage badges using Coverage.py.

Example of a generated badge: Example coverage badge

The badge template has been taken from shields.io, therefore it should look mostly good. (The spec is a bit stricter on the margins, but I can't easily do text width calculations in Python so the margins might not always be 4px.)

Installation

Run:

pip install coverage-badge

Usage

First, run Coverage.py to generate the necessary coverage data. Then you can either return the badge SVG to stdout:

$ coverage-badge

...or write it to a file:

$ coverage-badge -o coverage.svg

It's important that you run coverage-badge from the directory where the .coverage data file is located.

Different colors for cover ranges:

15%

45%

65%

80%

93%

97%


The full usage text:

usage: __main__.py [-h] [-o FILEPATH] [-p] [-f] [-q] [-v]

Generate coverage badges for Coverage.py.

optional arguments:
  -h, --help   show this help message and exit
  -o FILEPATH  Save the file to the specified path.
  -p           Plain color mode. Standard green badge.
  -f           Force overwrite image, use with -o key.
  -q           Don't output any non-error messages.
  -v           Show version.

License

MIT License, see LICENSE.txt file..

coverage-badge's People

Contributors

astariul avatar danielpodrazka avatar dbrgn avatar didorothy avatar inquire avatar jackton1 avatar samael500 avatar simonfagerholm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

coverage-badge's Issues

Incompatible with `coverage` 7.5.0

I upgraded the package coverage from 7.4.4 to 7.5.0 and coverage-badge began to error.

When running poetry run coverage-badge -o coverage.svg, I get the following error:

Traceback (most recent call last):

File "/Users/Repositories/repo/.venv/bin/coverage-badge", line 8, in <module>
  sys.exit(main())
File "/Users/Repositories/repo/.venv/lib/python3.10/site-packages/coverage_badge/__main__.py", line 171, in main
  total = get_total()
File "/Users/Repositories/repo/.venv/lib/python3.10/site-packages/coverage_badge/__main__.py", line 76, in get_total
  return coverage.results.Numbers(precision=cov.config.precision).display_covered(total)
AttributeError: 'Numbers' object has no attribute 'display_covered'

I believe this is a bug in coverage-badge in relation to the newest version of coverage.

Push Coverage 6.x compatible Release

I have noticed that the change to allow for Coverage 6.x was merged but no release was made to pypi.

Would it be possible to get a new release published soon?

I apologize if I have missed docs about a regular release schedule.

Thanks.

displaying svg file badge in readme.md

hi, i want to display the svg file badge in readme file, so i used rawgit.com for converting the file,
it gived me an error when the file get parsed, is there another way to get coverage badge displayed in readme.md

Does not work in python 3.12 environments

Collecting coverage-badge
  Downloading coverage_badge-1.1.0-py2.py3-none-any.whl.metadata (3.2 kB)
Collecting coverage (from coverage-badge)
  Downloading coverage-7.4.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (8.2 kB)
Downloading coverage_badge-1.1.0-py2.py3-none-any.whl (6.4 kB)
Downloading coverage-7.4.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (238 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 238.2/238.2 kB 9.7 MB/s eta 0:00:00
Installing collected packages: coverage, coverage-badge
Successfully installed coverage-7.4.4 coverage-badge-1.1.0
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.2/x64/bin/coverage-badge", line 5, in <module>
    from coverage_badge.__main__ import main
  File "/opt/hostedtoolcache/Python/3.12.2/x64/lib/python3.12/site-packages/coverage_badge/__main__.py", line 7, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

pkg_resources is deprecated, please use importlib

Coverage Badge

Hi,

I utilize jest as test library. The configuration file below generates a folder .coverage. I am pretty sure it is not the file you mention on README file. Is it suitable only for python? Could you inform which files are them? Thank you.

export default {
  // The bail config option can be used here to have Jest stop running tests after
  // the first failure.
  bail: false,

  // Indicates whether each individual test should be reported during the run.
  verbose: false,

  // Indicates whether the coverage information should be collected while executing the test
  collectCoverage: true,

  // The directory where Jest should output its coverage files.
  coverageDirectory: './.coverage/',

  // If the test path matches any of the patterns, it will be skipped.
  testPathIgnorePatterns: ['<rootDir>/node_modules/'],

  // If the file path matches any of the patterns, coverage information will be skipped.
  coveragePathIgnorePatterns: ['<rootDir>/node_modules/'],

  // The pattern Jest uses to detect test files.
  testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$',

  // This option sets the URL for the jsdom environment.
  // It is reflected in properties such as location.href.
  // @see: https://github.com/facebook/jest/issues/6769
  testURL: 'http://localhost/',

  // @see: https://jestjs.io/docs/en/configuration#coveragethreshold-object
  coverageThreshold: {
    global: {
      statements: 95,
      branches: 90,
      functions: 95,
      lines: 95,
    },
  },
};

Incompatible with coverage 6.0.0

Describe the bug
A clear and concise description of the bug.

The coverage bade package is incompatible with coverage version 6.0.0.
The following attribute error AttributeError: 'Precision' object has no attribute '_near0' is observed if coverage 6.0.0 is used

To Reproduce
How can we reproduce the problem? Please be specific. Don't just link to a failing CI job. Answer the questions below:

  1. What version of Python are you using?
    3.8.5

  2. What version of coverage.py are you using? The output of coverage debug sys is helpful.

-- sys -------------------------------------------------------
               coverage_version: 6.0
                coverage_module: /Users/max/anaconda3/lib/python3.8/site-packages/coverage/__init__.py
                         tracer: -none-
                        CTracer: available
           plugins.file_tracers: -none-
            plugins.configurers: -none-
      plugins.context_switchers: -none-
              configs_attempted: .coveragerc
                                 setup.cfg
                                 tox.ini
                                 pyproject.toml
                   configs_read: /Users/max/dwh-partner-config/setup.cfg
                                 /Users/max/dwh-partner-config/pyproject.toml
                    config_file: None
                config_contents: -none-
                      data_file: -none-
                         python: 3.8.5 (default, Sep  4 2020, 02:22:02) [Clang 10.0.0 ]
                       platform: macOS-10.16-x86_64-i386-64bit
                 implementation: CPython
                     executable: /Users/max/anaconda3/bin/python
                   def_encoding: utf-8
                    fs_encoding: utf-8
                            pid: 21446
                            cwd: /Users/max/dwh-partner-config
                           path: /Users/max/anaconda3/bin
                                 /Users/max/anaconda3/lib/python38.zip
                                 /Users/max/anaconda3/lib/python3.8
                                 /Users/max/anaconda3/lib/python3.8/lib-dynload
                                 /Users/max/anaconda3/lib/python3.8/site-packages
                                 /Users/max/anaconda3/lib/python3.8/site-packages/aeosa
                    environment: CONDA_PYTHON_EXE = /Users/max/anaconda3/bin/python
                                 HOME = /Users/max
                   command_line: /Users/max/anaconda3/bin/coverage debug sys
                sqlite3_version: 2.6.0
         sqlite3_sqlite_version: 3.33.0
             sqlite3_temp_store: 0
        sqlite3_compile_options: COMPILER=clang-10.0.0; ENABLE_COLUMN_METADATA; ENABLE_DBSTAT_VTAB
                                 ENABLE_FTS3; ENABLE_FTS3_TOKENIZER; ENABLE_FTS4
                                 ENABLE_FTS5; ENABLE_GEOPOLY; ENABLE_JSON1
                                 ENABLE_RTREE; ENABLE_UNLOCK_NOTIFY; MAX_DEFAULT_PAGE_SIZE=32768
                                 MAX_EXPR_DEPTH=10000; MAX_VARIABLE_NUMBER=250000; SECURE_DELETE
                                 THREADSAFE=1
  1. What versions of what packages do you have installed? The output of pip freeze is helpful.
    The coverage-badge version is 1.0.1

  2. What code are you running? Give us a specific commit of a specific repo that we can check out.
    coverage-badge -o coverage.svg inside the root of repo after the .coverage/ has been generated.

Expected behavior
A clear and concise description of what you expected to happen.

I expect the package to handle both versions of coverage (5.x.x and 6).
All works fine when coverage is reverted back to coverage==5.3.0

Additional context
Add any other context about the problem here.

Docs: Usage as a pre-commit hook

Summary (docs)

I've been using this package a lot for my own projects, and I'm loving it!

One of the ways that I'm starting to use it is as a pre-commit hook so that it'll run automatically after each commit. I also have the command to run the test coverage (and update the .coverage file) right before this one so that the badge is always using the latest coverage.

To let other people know that it can be used this way, would it be worth adding this usage to the README.rst?

If "no", I'll close this issue 😋

Usage Details

The reST below is a minimal example to illustrate this usage as a local pre-commit hook.

As a pre-commit hook
^^^^^^^^^^^^^^^^^^^^

To generate the badge with each commit, you can use a `local pre-commit hook`_
in the ``.pre-commit-config.yaml`` file:

.. _local pre-commit hook: https://pre-commit.com/#repository-local-hooks

.. code-block::

    -   repo: local
        hooks:
        -   id: coverage-badge
            name: Generate coverage badge
            entry: coverage-badge -o coverage.svg -f
            language: system
            pass_filenames: false
            always_run: true

Extending the scope

This is a great and useful package !

For internal and public projects I had to create similar commands for pytest test results and flake8 analysis results.

About to create dedicated libraries, I think that it would probably be wiser to put all of these as subcommands of a single badge generator.

Would you agree ? If so I can propose some PR where we would move from argparse to click and where you would have subcommands for each kind of badge to generate.

We would also have to rename the package to something more general such as makebadge or genbadge.

The result would look like:

genbadge coverage -o <file.svg> ...
genbadge flake8 -o <file.svg> ...
genbadge pytest -o <file.svg> ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.