How to use the coverage.coverage function in coverage

To help you get started, we’ve selected a few coverage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nedbat / coveragepy / tests / farm / html / run_tabbed.py View on Github external
def html_it():
    """Run coverage and make an HTML report for tabbed."""
    import coverage
    cov = coverage.coverage()
    cov.start()
    import tabbed           # pragma: nested
    cov.stop()              # pragma: nested
    cov.html_report(tabbed, directory="../html_tabbed")
github jarus / flask-testing / tests / run.py View on Github external
def run():
    if coverage_available:
        cov = coverage(source=['flask_testing'])
        cov.start()

    from tests import suite
    result = unittest.TextTestRunner(verbosity=2).run(suite())
    if not result.wasSuccessful():
        sys.exit(1)

    if coverage_available:
        cov.stop()

        print("\nCode Coverage")
        cov.report()
        cov.html_report(directory='cover')
    else:
        print("\nTipp:\n\tUse 'pip install coverage' to get great code "
              "coverage stats")
github nedbat / coveragepy / tests / farm / html / run_partial.py View on Github external
def html_it():
    """Run coverage and make an HTML report for partial."""
    import coverage
    cov = coverage.coverage(branch=True)
    cov.start()
    import partial          # pragma: nested
    cov.stop()              # pragma: nested
    cov.html_report(partial, directory="../html_partial")
github nedbat / coveragepy / tests / test_summary.py View on Github external
self.make_file("main.py", "import mod\n")

        # Make one into a .pyc, and remove the .py.
        py_compile.compile("mod.py")
        os.remove("mod.py")

        # Python 3 puts the .pyc files in a __pycache__ directory, and will
        # not import from there without source.  It will import a .pyc from
        # the source location though.
        if not os.path.exists("mod.pyc"):
            pycs = glob.glob("__pycache__/mod.*.pyc")
            self.assertEqual(len(pycs), 1)
            os.rename(pycs[0], "mod.pyc")

        # Run the program.
        cov = coverage.coverage()
        cov.start()
        import main     # pragma: nested # pylint: disable=import-error,unused-variable
        cov.stop()      # pragma: nested

        # Put back the missing Python file.
        self.make_file("mod.py", "a = 1\n")
        report = self.get_report(cov).splitlines()
        self.assertIn("mod.py 1 0 100%", report)
github vbmendes / django-dynamic-sprites / run_tests.py View on Github external
def start_coverage():
    files_to_cover = get_files_to_cover()
    if not files_to_cover:
        coverage_ = None
        print "Not running coverage. No *.py files to test."
    else:
        coverage_ = coverage.coverage(include=files_to_cover, branch=True)
        coverage_.start()
        import_files(files_to_cover)
    return coverage_
github ch3pjw / junction / run_tests_with_coverage.py View on Github external
#! /usr/bin/env python
from __future__ import division
import nose
import coverage
import os
import sys
import blessings

term = blessings.Terminal()

this_dir = os.path.dirname(os.path.abspath(__file__))

c = coverage.coverage()
c.start()
nose.run(defaultTest=os.path.join(this_dir, 'test'))
c.stop()

analysis = []
for cur_dir, sub_dir, file_names in os.walk(
        os.path.join(this_dir, 'junction')):
    for file_name in file_names:
        file_name = os.path.join(cur_dir, file_name)
        if file_name.endswith('.py'):
            fn, executable, not_run, missing_lines_str = c.analysis(file_name)
            analysis.append((len(executable), len(not_run)))

executable = 0
run = 0
for e, r in analysis:
github ros / ros / tools / rosunit / scripts / pycoverage_to_html.py View on Github external
def coverage_html():
    import os.path
    if not os.path.isfile('.coverage-modules'):
        sys.stderr.write('No .coverage-modules file; nothing to do\n')
        return

    with open('.coverage-modules', 'r') as f:
        modules = [x for x in f.read().split('\n') if x.strip()]

    cov = coverage.coverage()
    cov.load()

    # import everything
    for m in modules:
        try:
            base = m.split('.')[0]
            roslib.load_manifest(base)
            __import__(m)
        except Exception:
            sys.stderr.write('WARN: cannot import %s\n' % (base))

    modlist = '\n'.join([' * %s' % m for m in modules])
    sys.stdout.write('Generating for\n%s\n' % (modlist))

    # load the module instances to pass to coverage so it can generate annotation html reports
    mods = []
github Southpaw-TACTIC / TACTIC / 3rd_party / python2 / site-packages / cherrypy / lib / covercp.py View on Github external
def serve(path=localFile, port=8080, root=None):
    if coverage is None:
        raise ImportError('The coverage module could not be imported.')
    from coverage import coverage
    cov = coverage(data_file=path)
    cov.load()

    cherrypy.config.update({'server.socket_port': int(port),
                            'server.thread_pool': 10,
                            'environment': 'production',
                            })
    cherrypy.quickstart(CoverStats(cov, root))
github h3llrais3r / Auto-Subliminal / lib / cherrypy / lib / covercp.py View on Github external
import sys
import cgi
import os
import os.path

from six.moves import urllib

import cherrypy


localFile = os.path.join(os.path.dirname(__file__), 'coverage.cache')

the_coverage = None
try:
    from coverage import coverage
    the_coverage = coverage(data_file=localFile)

    def start():
        the_coverage.start()
except ImportError:
    # Setting the_coverage to None will raise errors
    # that need to be trapped downstream.
    the_coverage = None

    import warnings
    warnings.warn(
        'No code coverage will be performed; '
        'coverage.py could not be imported.')

    def start():
        pass
start.priority = 20