Add coverage.py support to run_checks.py

This commit is contained in:
Florian Bruhin 2015-03-04 21:39:14 +01:00
parent ebae77e8c5
commit 4fa5872733
3 changed files with 20 additions and 5 deletions

2
.gitignore vendored
View File

@ -14,3 +14,5 @@ __pycache__
/README.html
/qutebrowser/html/doc/
/.venv
/.coverage
/covhtml

View File

@ -79,7 +79,7 @@ def get_dev_packages(short=False):
short: Remove the version specification.
"""
packages = ['colorlog', 'flake8', 'astroid', 'pylint', 'pep257',
'colorama', 'beautifulsoup4']
'colorama', 'beautifulsoup4', 'coverage']
if short:
packages = [re.split(r'[<>=]', p)[0] for p in packages]
return packages

View File

@ -44,7 +44,7 @@ import contextlib
import traceback
import pep257
import coverage
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir))
@ -151,10 +151,21 @@ def check_init(target):
return ok
def check_unittest():
"""Run the unittest checker."""
def check_unittest(run_coverage):
"""Run the unittest checker.
Args:
run_coverage: Whether to also run coverage.py.
"""
if run_coverage:
cov = coverage.coverage(branch=True, source=['qutebrowser'])
cov.erase()
cov.start()
suite = unittest.TestLoader().discover('.')
result = unittest.TextTestRunner().run(suite)
if run_coverage:
cov.stop()
cov.html_report()
print()
return result.wasSuccessful()
@ -268,7 +279,7 @@ def _get_checkers(args):
# "Static" checkers
checkers = collections.OrderedDict([
('global', collections.OrderedDict([
('unittest', check_unittest),
('unittest', functools.partial(check_unittest, args.coverage)),
('git', check_git),
])),
('setup', collections.OrderedDict([
@ -303,6 +314,8 @@ def _checker_enabled(args, group, name):
def _parse_args():
"""Parse commandline args via argparse."""
parser = argparse.ArgumentParser(description='Run various checkers.')
parser.add_argument('-c', '--coverage', help="Also run coverage.py and "
"generate a HTML report.", action='store_true')
parser.add_argument('-s', '--setup', help="Run additional setup checks",
action='store_true')
parser.add_argument('-q', '--quiet',