当前位置: 首页>>代码示例>>Python>>正文


Python coverage.coverage方法代码示例

本文整理汇总了Python中coverage.coverage方法的典型用法代码示例。如果您正苦于以下问题:Python coverage.coverage方法的具体用法?Python coverage.coverage怎么用?Python coverage.coverage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coverage的用法示例。


在下文中一共展示了coverage.coverage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pytest_addoption

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def pytest_addoption(parser):
    """Add options to control coverage."""

    group = parser.getgroup(
        'smother', 'smother reporting')
    group.addoption('--smother', action='append', default=[], metavar='path',
                    nargs='?', const=True, dest='smother_source',
                    help='measure coverage for filesystem path '
                    '(multi-allowed)')
    group.addoption('--smother-config', action='store', default='.coveragerc',
                    help='config file for coverage, default: .coveragerc')
    group.addoption('--smother-append', action='store_true', default=False,
                    help='append to existing smother report, '
                         'default: False')
    group.addoption('--smother-output', action='store', default='.smother',
                    help='output file for smother data. '
                         'default: .smother')
    group.addoption('--smother-cover', action='store_true', default=False,
                    help='Create a vanilla coverage file in addition to '
                         'the smother output') 
开发者ID:ChrisBeaumont,项目名称:smother,代码行数:22,代码来源:pytest_plugin.py

示例2: __init__

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def __init__(self, options):
        self.coverage = coverage.coverage(
            source=options.smother_source,
            config_file=options.smother_config,
        )

        # The unusual import statement placement is so that
        # smother's own test suite can measure coverage of
        # smother import statements
        self.coverage.start()
        from smother.control import Smother
        self.smother = Smother(self.coverage)

        self.output = options.smother_output
        self.append = options.smother_append
        self.cover_report = options.smother_cover
        self.first_test = True 
开发者ID:ChrisBeaumont,项目名称:smother,代码行数:19,代码来源:pytest_plugin.py

示例3: test

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def test(coverage=False):
    """Run the unit tests."""
    if coverage and not os.environ.get('FLASK_COVERAGE'):
        import sys
        os.environ['FLASK_COVERAGE'] = '1'
        os.execvp(sys.executable, [sys.executable] + sys.argv)
    import unittest
    import xmlrunner
    tests = unittest.TestLoader().discover('tests')
    # run tests with unittest-xml-reporting and output to $CIRCLE_TEST_REPORTS on CircleCI or test-reports locally
    xmlrunner.XMLTestRunner(output=os.environ.get('CIRCLE_TEST_REPORTS','test-reports')).run(tests)
    if COV:
        COV.stop()
        COV.save()
        print('Coverage Summary:')
        COV.report()
        basedir = os.path.abspath(os.path.dirname(__file__))
        covdir = os.path.join(basedir, 'tmp/coverage')
        COV.html_report(directory=covdir)
        print('HTML version: file://%s/index.html' % covdir)
        COV.erase() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:23,代码来源:manage.py

示例4: run_tests_coverage

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def run_tests_coverage():
    if __name__ == "__main__":
        os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
        django.setup()
        TestRunner = get_runner(settings)
        test_runner = TestRunner()

        # Setup Coverage
        cov = coverage(source=["rest_framework_docs"], omit=["rest_framework_docs/__init__.py"])
        cov.start()

        failures = test_runner.run_tests(["tests"])

        if bool(failures):
            cov.erase()
            sys.exit("Tests Failed. Coverage Cancelled.")

        # If success show coverage results
        cov.stop()
        cov.save()
        cov.report()
        cov.html_report(directory='covhtml') 
开发者ID:manosim,项目名称:django-rest-framework-docs,代码行数:24,代码来源:runtests.py

示例5: report

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def report(self, stream):
        """
        Output code coverage report.
        """
        log.debug("Coverage report")
        self.coverInstance.stop()
        self.coverInstance.combine()
        self.coverInstance.save()
        modules = [module
                    for name, module in sys.modules.items()
                    if self.wantModuleCoverage(name, module)]
        log.debug("Coverage report will cover modules: %s", modules)
        self.coverInstance.report(modules, file=stream)

        import coverage
        if self.coverHtmlDir:
            log.debug("Generating HTML coverage report")
            try:
                self.coverInstance.html_report(modules, self.coverHtmlDir)
            except coverage.misc.CoverageException, e:
                log.warning("Failed to generate HTML report: %s" % str(e)) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:23,代码来源:cover.py

示例6: measurable_line

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def measurable_line(l):
    """Is this a line of code coverage will measure?

    Not blank, not a comment, and not "else"
    """
    l = l.strip()
    if not l:
        return False
    if l.startswith('#'):
        return False
    if l.startswith('else:'):
        return False
    if env.JYTHON and l.startswith(('try:', 'except:', 'except ', 'break', 'with ')):
        # Jython doesn't measure these statements.
        return False                    # pragma: only jython
    return True 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:18,代码来源:test_concurrency.py

示例7: cant_trace_msg

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def cant_trace_msg(concurrency, the_module):
    """What might coverage.py say about a concurrency setting and imported module?"""
    # In the concurrency choices, "multiprocessing" doesn't count, so remove it.
    if "multiprocessing" in concurrency:
        parts = concurrency.split(",")
        parts.remove("multiprocessing")
        concurrency = ",".join(parts)

    if the_module is None:
        # We don't even have the underlying module installed, we expect
        # coverage to alert us to this fact.
        expected_out = (
            "Couldn't trace with concurrency=%s, "
            "the module isn't installed.\n" % concurrency
        )
    elif env.C_TRACER or concurrency == "thread" or concurrency == "":
        expected_out = None
    else:
        expected_out = (
            "Can't support concurrency=%s with PyTracer, "
            "only threads are supported\n" % concurrency
        )
    return expected_out 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:25,代码来源:test_concurrency.py

示例8: test_stopTestRun

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def test_stopTestRun(self, mock_printErrors):
        """
        We ignore coverage's error about not having anything to cover.
        """
        self.args.cov = MagicMock()
        self.args.cov.stop = MagicMock(
            side_effect=CoverageException("Different Exception")
        )
        self.args.run_coverage = True
        gtr = GreenTestResult(self.args, GreenStream(self.stream))
        gtr.startTestRun()
        self.assertRaises(CoverageException, gtr.stopTestRun)

        self.args.cov.stop = MagicMock(
            side_effect=CoverageException("No data to report")
        ) 
开发者ID:CleanCut,项目名称:green,代码行数:18,代码来源:test_result.py

示例9: test

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def test(coverage=False):
    """Run the unit tests."""
    import sys
    if coverage and not os.environ.get('FLASK_COVERAGE'):
        os.environ['FLASK_COVERAGE'] = '1'
        os.execvp(sys.executable, [sys.executable] + sys.argv)
    import unittest
    import xmlrunner
    tests = unittest.TestLoader().discover('tests')
    results = xmlrunner.XMLTestRunner(output='test-reports').run(tests)
    if COV:
        COV.stop()
        COV.save()
        print('Coverage Summary:')
        COV.report()
        basedir = os.path.abspath(os.path.dirname(__file__))
        covdir = os.path.join(basedir, 'test-reports/coverage')
        COV.html_report(directory=covdir)
        print('HTML version: file://%s/index.html' % covdir)
        COV.erase()
    if (len(results.failures) > 0 or len(results.errors) > 0):
        sys.exit(1) 
开发者ID:levlaz,项目名称:braindump,代码行数:24,代码来源:manage.py

示例10: test

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def test(coverage=False):
    """Run the unit tests."""
    if coverage and not os.environ.get('FLASK_COVERAGE'):
        import sys
        os.environ['FLASK_COVERAGE'] = '1'
        os.execvp(sys.executable, [sys.executable] + sys.argv)
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)
    if COV:
        COV.stop()
        COV.save()
        print('Coverage Summary:')
        COV.report()
        basedir = os.path.abspath(os.path.dirname(__file__))
        covdir = os.path.join(basedir, 'tmp/coverage')
        COV.html_report(directory=covdir)
        print('HTML version: file://%s/index.html' % covdir)
        COV.erase() 
开发者ID:miguelgrinberg,项目名称:flasky-first-edition,代码行数:21,代码来源:manage.py

示例11: cov

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def cov():
    """Runs the unit tests with coverage."""
    tests = unittest.TestLoader().discover('project/tests')
    result = unittest.TextTestRunner(verbosity=2).run(tests)
    if result.wasSuccessful():
        COV.stop()
        COV.save()
        print('Coverage Summary:')
        COV.report()
        basedir = os.path.abspath(os.path.dirname(__file__))
        covdir = os.path.join(basedir, 'tmp/coverage')
        COV.html_report(directory=covdir)
        print('HTML version: file://%s/index.html' % covdir)
        COV.erase()
        return 0
    return 1 
开发者ID:realpython,项目名称:flask-jwt-auth,代码行数:18,代码来源:manage.py

示例12: test

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def test(coverage=False):
    """Run the unit tests."""
    if coverage and not os.environ.get('FLASK_COVERAGE'):
        import sys
        os.environ['FLASK_COVERAGE'] = '1'
        os.execvp(sys.executable, [sys.executable] + sys.argv)
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)
    if COV:
        COV.stop()
        COV.save()
        print("Coverage Summary:")
        COV.report()
        basedir = os.path.abspath(os.path.dirname(__file__))
        covdir = os.path.join(basedir, 'temp/coverage')
        COV.html_report(directory=covdir)
        print('HTML version: file://{covdir}index.html'.format(covdir=covdir))
        COV.erase() 
开发者ID:Piusdan,项目名称:USSD-Python-Demo,代码行数:21,代码来源:manage.py

示例13: analyze

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def analyze(self, suite, case, examples):
        failed, attempted = self.run_examples(examples)
        self.cov.stop()
        passed = attempted - failed
        format.print_test_progress_bar( '{} summary'.format(self.tstfile_name), 
                                        passed, failed, verbose=self.verb)
        # only support test coverage stats when running everything
        if not suite:
            self.print_coverage()
            if self.args.coverage:
                if self.lines_exec == self.lines_total:
                    print("Maximum coverage achieved! Great work!")
                else:
                    self.give_suggestions()
        return {'suites_total' : self.num_suites, 'cases_total': self.num_cases, 
                'exs_failed' : failed, 'exs_passed' : passed, 'attempted' : attempted,
                'actual_cov' : self.lines_exec, 'total_cov' : self.lines_total} 
开发者ID:okpy,项目名称:ok-client,代码行数:19,代码来源:testing.py

示例14: cov

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def cov():
    """
    Runs the unit tests and generates a coverage report on success.

    While the application is running, you can run the following command in a new terminal:
    'docker-compose run --rm flask python manage.py cov' to run all the tests in the
    'tests' directory. If all the tests pass, it will generate a coverage report.

    :return int: 0 if all tests pass, 1 if not
    """

    tests = unittest.TestLoader().discover('tests')
    result = unittest.TextTestRunner(verbosity=2).run(tests)
    if result.wasSuccessful():
        COV.stop()
        COV.save()
        print('Coverage Summary:')
        COV.report()
        COV.html_report()
        COV.erase()
        return 0
    else:
        return 1 
开发者ID:Radu-Raicea,项目名称:Dockerized-Flask,代码行数:25,代码来源:manage.py

示例15: test

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import coverage [as 别名]
def test():
    """
    Runs the unit tests without generating a coverage report.

    Enter 'docker-compose run --rm flask python manage.py test' to run all the tests in the
    'tests' directory, with no coverage report.

    :return int: 0 if all tests pass, 1 if not
    """

    tests = unittest.TestLoader().discover('tests', pattern='test*.py')
    result = unittest.TextTestRunner(verbosity=2).run(tests)
    if result.wasSuccessful():
        return 0
    else:
        return 1 
开发者ID:Radu-Raicea,项目名称:Dockerized-Flask,代码行数:18,代码来源:manage.py


注:本文中的coverage.coverage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。