本文整理汇总了Python中coverage.Coverage.save方法的典型用法代码示例。如果您正苦于以下问题:Python Coverage.save方法的具体用法?Python Coverage.save怎么用?Python Coverage.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.Coverage
的用法示例。
在下文中一共展示了Coverage.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_tests
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def run_tests(context, app=None, module=None, doctype=None, test=(),
driver=None, profile=False, coverage=False, junit_xml_output=False, ui_tests = False,
doctype_list_path=None, skip_test_records=False, skip_before_tests=False, failfast=False):
"Run tests"
import frappe.test_runner
tests = test
site = get_site(context)
frappe.init(site=site)
frappe.flags.skip_before_tests = skip_before_tests
frappe.flags.skip_test_records = skip_test_records
if coverage:
# Generate coverage report only for app that is being tested
source_path = os.path.join(get_bench_path(), 'apps', app or 'frappe')
cov = Coverage(source=[source_path], omit=['*.html', '*.js', '*.css'])
cov.start()
ret = frappe.test_runner.main(app, module, doctype, context.verbose, tests=tests,
force=context.force, profile=profile, junit_xml_output=junit_xml_output,
ui_tests = ui_tests, doctype_list_path = doctype_list_path, failfast=failfast)
if coverage:
cov.stop()
cov.save()
if len(ret.failures) == 0 and len(ret.errors) == 0:
ret = 0
if os.environ.get('CI'):
sys.exit(ret)
示例2: run_tests
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def run_tests(self):
" Run coverage on unit test "
# need to import here cause we are in a venv
import six
from coverage import Coverage
coverage = Coverage()
coverage.start()
# Purge modules under test from sys.modules. The test loader will
# re-import them from the build location. Required when 2to3 is used
# with namespace packages.
if six.PY3 and getattr(self.distribution, 'use_2to3', False):
module = self.test_suite.split('.')[0]
if module in _namespace_packages:
del_modules = []
if module in sys.modules:
del_modules.append(module)
module += '.'
for name in sys.modules:
if name.startswith(module):
del_modules.append(name)
list(map(sys.modules.__delitem__, del_modules))
unittest_main(
None, None, self._argv,
testLoader=self._resolve_as_ep(self.test_loader),
testRunner=self._resolve_as_ep(self.test_runner),
exit=False,
)
coverage.stop()
coverage.save()
coverage.report(show_missing=False)
示例3: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def _bootstrap(self):
from coverage import Coverage
cov = Coverage(data_suffix=True)
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例4: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage
cov = Coverage(data_suffix=True)
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例5: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage
rcfile = getattr(multiprocessing, PATCHED_MARKER)
cov = Coverage(data_suffix=True, config_file=rcfile)
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例6: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage # avoid circular import
rcfile = os.environ[COVERAGE_RCFILE_ENV]
cov = Coverage(data_suffix=True, config_file=rcfile)
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例7: run
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def run(self):
import pytest
cov = Coverage()
cov.erase()
cov.start()
result = pytest.main()
cov.stop()
cov.save()
cov.html_report(directory="covhtml")
sys.exit(int(bool(len(result.failures) > 0 or len(result.errors) > 0)))
示例8: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage
coverage_config = getattr(multiprocessing, PATCHED_MARKER)
coverage_config.parallel = True
cov = Coverage()
cov.config = coverage_config
cov.start()
try:
return original_bootstrap(self)
finally:
cov.stop()
cov.save()
示例9: run_test_suite
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def run_test_suite():
cov = Coverage(config_file=True)
cov.erase()
cov.start()
# Announce the test suite
sys.stdout.write(colored(text="\nWelcome to the ", color="magenta", attrs=["bold"]))
sys.stdout.write(colored(text="python-doc-inherit", color="green", attrs=["bold"]))
sys.stdout.write(colored(text=" test suite.\n\n", color="magenta", attrs=["bold"]))
# Announce test run
print(colored(text="Step 1: Running unit tests.\n", color="yellow", attrs=["bold"]))
test_suite = TestLoader().discover(str(Path("tests").absolute()))
result = TextTestRunner(verbosity=1).run(test_suite)
if not result.wasSuccessful():
sys.exit(len(result.failures) + len(result.errors))
# Announce coverage run
print(colored(text="\nStep 2: Generating coverage results.\n", color="yellow", attrs=["bold"]))
cov.stop()
percentage = round(cov.report(show_missing=True), 2)
cov.html_report(directory='cover')
cov.save()
if percentage < TESTS_THRESHOLD:
print(colored(text="YOUR CHANGES HAVE CAUSED TEST COVERAGE TO DROP. " +
"WAS {old}%, IS NOW {new}%.\n".format(old=TESTS_THRESHOLD, new=percentage),
color="red", attrs=["bold"]))
sys.exit(1)
# Announce flake8 run
sys.stdout.write(colored(text="\nStep 3: Checking for pep8 errors.\n\n", color="yellow", attrs=["bold"]))
print("pep8 errors:")
print("----------------------------------------------------------------------")
from subprocess import call
flake_result = call(["flake8", ".", "--count"])
if flake_result != 0:
print("pep8 errors detected.")
print(colored(text="\nYOUR CHANGES HAVE INTRODUCED PEP8 ERRORS!\n", color="red", attrs=["bold"]))
sys.exit(flake_result)
else:
print("None")
# Announce success
print(colored(text="\nTests completed successfully with no errors. Congrats!", color="green", attrs=["bold"]))
示例10: with_coverage
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def with_coverage(f, source, *, report=True, data=False):
cov = Coverage(source=[source])
cov.start()
try:
exit_code = f()
finally:
cov.stop()
if not exit_code:
if report:
print() # Print blank line.
cov.report(show_missing=False)
cov.html_report()
if data:
cov.save()
return exit_code
示例11: main
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def main():
cov = Coverage(
omit=[
"*passlib*",
"*test*",
"*tornado*",
"*backports_abc*",
"*singledispatch*",
"*six*",
"*certifi*",
"*daemon*",
"*funcsigs*",
"*mock*",
"*pbr*",
"*pkg_resources*",
"*tablib*",
]
)
cov.start()
from app_test import ApplicationTest
from database_test import DatabaseTest
from http_test import HTTPTestCase
from procinfo_test import ProcInfoTest
from user_test import UserTest
from token_test import TokenTest
from ws_test import WebSocketTestCase
from unittest import TestLoader, TextTestRunner, TestSuite
loader = TestLoader()
suite = TestSuite(
(
loader.loadTestsFromTestCase(ProcInfoTest),
loader.loadTestsFromTestCase(DatabaseTest),
loader.loadTestsFromTestCase(UserTest),
loader.loadTestsFromTestCase(TokenTest),
loader.loadTestsFromTestCase(HTTPTestCase),
loader.loadTestsFromTestCase(WebSocketTestCase),
loader.loadTestsFromTestCase(ApplicationTest),
)
)
runner = TextTestRunner(verbosity=2)
runner.run(suite)
cov.stop()
cov.save()
示例12: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage # avoid circular import
rcfile = os.environ[COVERAGE_RCFILE_ENV]
cov = Coverage(data_suffix=True, config_file=rcfile)
cov.start()
debug = cov.debug
try:
if debug.should("multiproc"):
debug.write("Calling multiprocessing bootstrap")
return original_bootstrap(self)
finally:
if debug.should("multiproc"):
debug.write("Finished multiprocessing bootstrap")
cov.stop()
cov.save()
if debug.should("multiproc"):
debug.write("Saved multiprocessing data")
示例13: _bootstrap
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
def _bootstrap(self):
"""Wrapper around _bootstrap to start coverage."""
from coverage import Coverage # avoid circular import
cov = Coverage(data_suffix=True)
cov._warn_preimported_source = False
cov.start()
debug = cov._debug
try:
if debug.should("multiproc"):
debug.write("Calling multiprocessing bootstrap")
return original_bootstrap(self)
finally:
if debug.should("multiproc"):
debug.write("Finished multiprocessing bootstrap")
cov.stop()
cov.save()
if debug.should("multiproc"):
debug.write("Saved multiprocessing data")
示例14: CodeCoverage
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
class CodeCoverage(object):
"""
Code Coverage radish extension
"""
OPTIONS = [
("--with-coverage", "enable code coverage"),
("--cover-packages=<cover_packages>", "specify source code package")
]
LOAD_IF = staticmethod(lambda config: config.with_coverage)
LOAD_PRIORITY = 70
def __init__(self):
before.all(self.coverage_start)
after.all(self.coverage_stop)
if world.config.cover_packages:
cover_packages = world.config.cover_packages.split(",")
else:
cover_packages = []
self.coverage = Coverage(source=cover_packages)
def coverage_start(self, features, marker):
"""
Start the coverage measurement
"""
self.coverage.load()
self.coverage.start()
def coverage_stop(self, features, marker):
"""
Stop the coverage measurement
and create report
"""
self.coverage.stop()
self.coverage.save()
self.coverage.report(file=sys.stdout)
示例15: Coverage
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import save [as 别名]
#!/usr/bin/env python
import os
import sys
from django.core import management
# Point to the correct settings for testing
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_settings'
if __name__ == "__main__":
testing = 'test' in sys.argv
if testing:
from coverage import Coverage
cov = Coverage()
cov.erase()
cov.start()
management.execute_from_command_line()
if testing:
cov.stop()
cov.save()
cov.report()