本文整理汇总了Python中coverage.Coverage.erase方法的典型用法代码示例。如果您正苦于以下问题:Python Coverage.erase方法的具体用法?Python Coverage.erase怎么用?Python Coverage.erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类coverage.Coverage
的用法示例。
在下文中一共展示了Coverage.erase方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import erase [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)))
示例2: run_test_suite
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import erase [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"]))
示例3: main
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import erase [as 别名]
def main():
""" The main function, mainly functioning to do the main functional work
(thanks pylint)
"""
if len(sys.argv) > 1 and sys.argv[1] == 'cover':
# FIXME - there are enough args now to need an arg parser
cover = Coverage(branch=True, auto_data=True)
min_percent = 0
if len(sys.argv) > 2:
min_percent = float(sys.argv[2])
else:
cover = False
loader = unittest.defaultTestLoader
runner = unittest.TextTestRunner(verbosity=2)
if cover:
cover.erase()
cover.start()
tests = loader.discover('.')
tests_lib = loader.discover('lib', top_level_dir='lib')
tests.addTests(tests_lib)
result = runner.run(tests)
if cover:
cover.stop()
# the debian coverage package didnt include jquery.debounce.min.js
# (and additionally, that thing is not packaged for debian elsewhere)
try:
cover.html_report()
except:
pass
percent = cover.report(show_missing=True)
if min_percent > percent:
print("The coverage ({:.1f}% reached) fails to reach the "
"minimum required ({}%)\n".format(percent, min_percent))
exit(1)
if not result.wasSuccessful():
exit(1)
示例4: Coverage
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import erase [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()
示例5: run_test_suite
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import erase [as 别名]
def run_test_suite(args):
skip_utc = args.skip_utc
enable_coverage = not args.no_coverage
enable_pep8 = not args.no_pep8
if enable_coverage:
cov = Coverage(config_file=True)
cov.erase()
cov.start()
settings.configure(
DJSTRIPE_TESTS_SKIP_UTC=skip_utc,
TIME_ZONE='America/Los_Angeles',
DEBUG=True,
USE_TZ=True,
DATABASES={
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "djstripe",
"USER": "",
"PASSWORD": "",
"HOST": "",
"PORT": "",
},
},
ROOT_URLCONF="tests.test_urls",
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"jsonfield",
"djstripe",
"tests",
"tests.apps.testapp"
],
MIDDLEWARE_CLASSES=(
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware"
),
SITE_ID=1,
STRIPE_PUBLIC_KEY=os.environ.get("STRIPE_PUBLIC_KEY", ""),
STRIPE_SECRET_KEY=os.environ.get("STRIPE_SECRET_KEY", ""),
DJSTRIPE_PLANS={
"test0": {
"stripe_plan_id": "test_id_0",
"name": "Test Plan 0",
"description": "A test plan",
"price": 1000, # $10.00
"currency": "usd",
"interval": "month"
},
"test": {
"stripe_plan_id": "test_id",
"name": "Test Plan 1",
"description": "Another test plan",
"price": 2500, # $25.00
"currency": "usd",
"interval": "month"
},
"test2": {
"stripe_plan_id": "test_id_2",
"name": "Test Plan 2",
"description": "Yet Another test plan",
"price": 5000, # $50.00
"currency": "usd",
"interval": "month"
},
"test_deletion": {
"stripe_plan_id": "test_id_3",
"name": "Test Plan 3",
"description": "Test plan for deletion.",
"price": 5000, # $50.00
"currency": "usd",
"interval": "month"
},
"test_trial": {
"stripe_plan_id": "test_id_4",
"name": "Test Plan 4",
"description": "Test plan for trails.",
"price": 7000, # $70.00
"currency": "usd",
"interval": "month",
"trial_period_days": 7
},
"unidentified_test_plan": {
"name": "Unidentified Test Plan",
"description": "A test plan with no ID.",
"price": 2500, # $25.00
"currency": "usd",
"interval": "month"
}
},
DJSTRIPE_PLAN_HIERARCHY = {
"bronze": {
"level": 1,
"plans": [
"test0",
#.........这里部分代码省略.........
示例6: run_test_suite
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import erase [as 别名]
def run_test_suite(args):
enable_coverage = not args.no_coverage
tests = args.tests
if enable_coverage:
cov = Coverage(config_file=True)
cov.erase()
cov.start()
settings.configure(
DEBUG=True,
USE_TZ=True,
TIME_ZONE="UTC",
SITE_ID=1,
DATABASES={
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "djstripe",
"USER": "postgres",
"PASSWORD": "",
"HOST": "localhost",
"PORT": "",
},
},
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
],
},
},
],
ROOT_URLCONF="tests.test_urls",
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"jsonfield",
"djstripe",
"tests",
"tests.apps.testapp"
],
MIDDLEWARE=(
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware"
),
STRIPE_PUBLIC_KEY=os.environ.get("STRIPE_PUBLIC_KEY", ""),
STRIPE_SECRET_KEY=os.environ.get("STRIPE_SECRET_KEY", ""),
DJSTRIPE_PLANS={
"test0": {
"stripe_plan_id": "test_id_0",
"name": "Test Plan 0",
"description": "A test plan",
"price": 1000, # $10.00
"currency": "usd",
"interval": "month"
},
"test": {
"stripe_plan_id": "test_id",
"name": "Test Plan 1",
"description": "Another test plan",
"price": 2500, # $25.00
"currency": "usd",
"interval": "month"
},
"test2": {
"stripe_plan_id": "test_id_2",
"name": "Test Plan 2",
"description": "Yet Another test plan",
"price": 5000, # $50.00
"currency": "usd",
"interval": "month"
},
"test_deletion": {
"stripe_plan_id": "test_id_3",
"name": "Test Plan 3",
"description": "Test plan for deletion.",
"price": 5000, # $50.00
"currency": "usd",
"interval": "month"
},
"test_trial": {
"stripe_plan_id": "test_id_4",
"name": "Test Plan 4",
"description": "Test plan for trails.",
"price": 7000, # $70.00
"currency": "usd",
"interval": "month",
"trial_period_days": 7
},
"unidentified_test_plan": {
"name": "Unidentified Test Plan",
"description": "A test plan with no ID.",
#.........这里部分代码省略.........
示例7: CoverageScript
# 需要导入模块: from coverage import Coverage [as 别名]
# 或者: from coverage.Coverage import erase [as 别名]
class CoverageScript(object):
"""The command-line interface to coverage.py."""
def __init__(self):
self.global_option = False
self.coverage = None
def command_line(self, argv):
"""The bulk of the command line interface to coverage.py.
`argv` is the argument list to process.
Returns 0 if all is well, 1 if something went wrong.
"""
# Collect the command-line options.
if not argv:
show_help(topic='minimum_help')
return OK
# The command syntax we parse depends on the first argument. Global
# switch syntax always starts with an option.
self.global_option = argv[0].startswith('-')
if self.global_option:
parser = GlobalOptionParser()
else:
parser = CMDS.get(argv[0])
if not parser:
show_help("Unknown command: '%s'" % argv[0])
return ERR
argv = argv[1:]
ok, options, args = parser.parse_args_ok(argv)
if not ok:
return ERR
# Handle help and version.
if self.do_help(options, args, parser):
return OK
# Listify the list options.
source = unshell_list(options.source)
omit = unshell_list(options.omit)
include = unshell_list(options.include)
debug = unshell_list(options.debug)
# Do something.
self.coverage = Coverage(
data_suffix=options.parallel_mode,
cover_pylib=options.pylib,
timid=options.timid,
branch=options.branch,
config_file=options.rcfile,
source=source,
omit=omit,
include=include,
debug=debug,
concurrency=options.concurrency,
check_preimported=True,
context=options.context,
)
if options.action == "debug":
return self.do_debug(args)
elif options.action == "erase":
self.coverage.erase()
return OK
elif options.action == "run":
return self.do_run(options, args)
elif options.action == "combine":
if options.append:
self.coverage.load()
data_dirs = args or None
self.coverage.combine(data_dirs, strict=True)
self.coverage.save()
return OK
# Remaining actions are reporting, with some common options.
report_args = dict(
morfs=unglob_args(args),
ignore_errors=options.ignore_errors,
omit=omit,
include=include,
)
# We need to be able to import from the current directory, because
# plugins may try to, for example, to read Django settings.
sys.path.insert(0, '')
self.coverage.load()
total = None
if options.action == "report":
total = self.coverage.report(
show_missing=options.show_missing,
skip_covered=options.skip_covered,
**report_args
#.........这里部分代码省略.........