當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。