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_b_branch.py View on Github external
def html_it():
    """Run coverage.py with branches and make an HTML report for b."""
    import coverage
    cov = coverage.Coverage(branch=True)
    cov.start()
    import b            # pragma: nested
    cov.stop()          # pragma: nested
    cov.html_report(b, directory="../html_b_branch")
github miguelgrinberg / flack / tests / __init__.py View on Github external
def run():
    os.environ['FLACK_CONFIG'] = 'testing'

    # start coverage engine
    cov = coverage.Coverage(branch=True)
    cov.start()

    # run tests
    tests = unittest.TestLoader().discover('.')
    ok = unittest.TextTestRunner(verbosity=2).run(tests).wasSuccessful()

    # print coverage report
    cov.stop()
    print('')
    cov.report(omit=['manage.py', 'tests/*', 'venv*/*'])

    sys.exit(0 if ok else 1)
github PavelBlend / blender-xray / tests / runner.py View on Github external
import coverage
import os
import unittest
import sys

cov = coverage.Coverage()
cov.start()

suite = unittest.defaultTestLoader.discover('.')
if not unittest.TextTestRunner().run(suite).wasSuccessful():
    exit(1)

cov.stop()
cov.xml_report()

if '--save-html-report' in sys.argv:
    cov.html_report()
github nedbat / coveragepy / tests / test_plugins.py View on Github external
b = other.f(3)
            c = another.g(4)
            d = another.g(5)
            """)
        # The names of these files are important: some plugins apply themselves
        # to "*other.py".
        self.make_file("other.py", """\
            def f(x):
                return x+1
            """)
        self.make_file("another.py", """\
            def g(x):
                return x-1
            """)

        cov = coverage.Coverage()
        cov.set_option("run:plugins", [module_name])
        self.start_import_stop(cov, "simple")
        return cov
github nedbat / coveragepy / tests / test_api.py View on Github external
def test_start_save_stop(self):
        self.skipTest("Expected failure: https://bitbucket.org/ned/coveragepy/issue/79")
        self.make_code1_code2()
        cov = coverage.Coverage()
        cov.start()
        self.import_local_file("code1")
        cov.save()
        self.import_local_file("code2")
        cov.stop()

        self.check_code1_code2(cov)
github nedbat / coveragepy / tests / test_context.py View on Github external
def run_red_blue(self, **options):
        """Run red.py and blue.py, and return their CoverageData objects."""
        self.make_file("red.py", self.SOURCE)
        red_cov = coverage.Coverage(context="red", data_suffix="r", source=["."], **options)
        self.start_import_stop(red_cov, "red")
        red_cov.save()
        red_data = red_cov.get_data()

        self.make_file("blue.py", self.SOURCE)
        blue_cov = coverage.Coverage(context="blue", data_suffix="b", source=["."], **options)
        self.start_import_stop(blue_cov, "blue")
        blue_cov.save()
        blue_data = blue_cov.get_data()

        return red_data, blue_data
github Teradata / stacki / test-framework / provisioning / roles / system-coverage / files / sitecustomize.py View on Github external
import atexit
import os.path

import coverage


if os.path.exists("/etc/SuSE-release"):
	config_file = "/export/test-suites/_common/sles.coveragerc"
else:
	config_file = "/export/test-suites/_common/redhat.coveragerc"

cov = coverage.Coverage(
	data_file="/root/.coverage",
	data_suffix=True,
	config_file=config_file,
	source=["stack", "wsclient"]
)
cov.start()


@atexit.register
def stop_coverage():
	cov.stop()
	cov.save()
github nedbat / coveragepy / tests / test_xml.py View on Github external
def test_nonascii_directory(self):
        # https://bitbucket.org/ned/coveragepy/issues/573/cant-generate-xml-report-if-some-source
        self.make_file("테스트/program.py", "a = 1")
        with change_dir("테스트"):
            cov = coverage.Coverage()
            self.start_import_stop(cov, "program")
            cov.xml_report()
github castorini / anserini / src / main / python / ecir2019_axiomatic / run_batch.py View on Github external
def cal_coverage(collection_yaml, model_yaml, output_root):
    index_path = get_index_path(collection_yaml)
    this_output_root = os.path.join(output_root, collection_yaml['name'])
    Coverage(index_path).cal_coverage(
        model_yaml,
        os.path.join(collection_yaml['anserini_root'], collection_yaml['qrels_root'], collection_yaml['qrel']),
        this_output_root
    )
github terrapower / armi / armi / cases / case.py View on Github external
Run an ARMI case.

        This initializes an ``Operator``, a ``Reactor`` and invokes
        :py:meth:`Operator.operate`!

        It also activates supervisory things like code coverage checking, profiling,
        or tracing, if requested by users during debugging.

        Notes
        -----
        Room for improvement: The coverage, profiling, etc. stuff can probably be moved
        out of here to a more elegant place (like a context manager?).
        """
        cov = None
        if self.cs["coverage"]:
            cov = coverage.Coverage(
                config_file=os.path.join(armi.RES, "coveragerc"), debug=["dataio"]
            )
            if context.MPI_SIZE > 1:
                # interestingly, you cannot set the parallel flag in the constructor
                # without auto-specifying the data suffix. This should enable
                # parallel coverage with auto-generated data file suffixes and
                # combinations.
                cov.config.parallel = True
            cov.start()

        profiler = None
        if self.cs["profile"]:
            profiler = cProfile.Profile()
            profiler.enable(subcalls=True, builtins=True)

        self.checkInputs()