2015-07-24 14:04:40 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2019-02-23 06:34:17 +01:00
|
|
|
# Copyright 2015-2019 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2015-07-24 14:04:40 +02:00
|
|
|
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""Enforce perfect coverage on some files."""
|
|
|
|
|
2015-08-12 06:41:41 +02:00
|
|
|
import os
|
2017-12-15 23:08:53 +01:00
|
|
|
import os.path
|
2015-07-24 14:04:40 +02:00
|
|
|
import sys
|
2015-10-04 20:35:24 +02:00
|
|
|
import enum
|
|
|
|
import subprocess
|
2015-07-24 14:42:18 +02:00
|
|
|
from xml.etree import ElementTree
|
2015-07-24 14:04:40 +02:00
|
|
|
|
2017-09-19 22:18:02 +02:00
|
|
|
import attr
|
|
|
|
|
2015-07-24 14:04:40 +02:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir,
|
|
|
|
os.pardir))
|
|
|
|
|
2017-09-20 10:39:39 +02:00
|
|
|
from scripts import utils as scriptutils
|
|
|
|
from qutebrowser.utils import utils
|
2015-07-24 14:04:40 +02:00
|
|
|
|
2017-09-19 22:18:02 +02:00
|
|
|
|
|
|
|
@attr.s
|
|
|
|
class Message:
|
|
|
|
|
|
|
|
"""A message shown by coverage.py."""
|
|
|
|
|
|
|
|
typ = attr.ib()
|
|
|
|
filename = attr.ib()
|
|
|
|
text = attr.ib()
|
|
|
|
|
|
|
|
|
2015-10-04 20:35:24 +02:00
|
|
|
MsgType = enum.Enum('MsgType', 'insufficent_coverage, perfect_file')
|
|
|
|
|
|
|
|
|
2015-10-04 19:36:26 +02:00
|
|
|
# A list of (test_file, tested_file) tuples. test_file can be None.
|
2015-07-24 14:04:40 +02:00
|
|
|
PERFECT_FILES = [
|
2015-10-04 19:36:26 +02:00
|
|
|
(None,
|
2017-12-15 19:08:15 +01:00
|
|
|
'commands/cmdexc.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/commands/test_argparser.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'commands/argparser.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
|
2018-12-03 08:49:10 +01:00
|
|
|
('tests/unit/api/test_cmdutils.py',
|
|
|
|
'api/cmdutils.py'),
|
|
|
|
(None,
|
|
|
|
'api/apitypes.py'),
|
|
|
|
(None,
|
|
|
|
'api/config.py'),
|
|
|
|
(None,
|
|
|
|
'api/message.py'),
|
|
|
|
|
2016-06-13 10:49:58 +02:00
|
|
|
('tests/unit/browser/webkit/test_cache.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/webkit/cache.py'),
|
2016-06-13 10:49:58 +02:00
|
|
|
('tests/unit/browser/webkit/test_cookies.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/webkit/cookies.py'),
|
2017-07-08 03:16:50 +02:00
|
|
|
('tests/unit/browser/test_history.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/history.py'),
|
2018-09-07 19:33:51 +02:00
|
|
|
('tests/unit/browser/test_pdfjs.py',
|
|
|
|
'browser/pdfjs.py'),
|
2016-06-13 10:49:58 +02:00
|
|
|
('tests/unit/browser/webkit/http/test_http.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/webkit/http.py'),
|
2016-06-13 10:49:58 +02:00
|
|
|
('tests/unit/browser/webkit/http/test_content_disposition.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/webkit/rfc6266.py'),
|
2017-02-12 02:26:46 +01:00
|
|
|
# ('tests/unit/browser/webkit/test_webkitelem.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
# 'browser/webkit/webkitelem.py'),
|
2017-02-03 23:46:44 +01:00
|
|
|
# ('tests/unit/browser/webkit/test_webkitelem.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
# 'browser/webelem.py'),
|
2016-06-13 10:49:58 +02:00
|
|
|
('tests/unit/browser/webkit/network/test_filescheme.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/webkit/network/filescheme.py'),
|
2016-06-13 10:49:58 +02:00
|
|
|
('tests/unit/browser/webkit/network/test_networkreply.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/webkit/network/networkreply.py'),
|
2016-06-13 10:49:58 +02:00
|
|
|
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/browser/test_signalfilter.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/signalfilter.py'),
|
2016-11-10 21:20:22 +01:00
|
|
|
(None,
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/webengine/certificateerror.py'),
|
2016-07-07 14:09:44 +02:00
|
|
|
# ('tests/unit/browser/test_tab.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
# 'browser/tab.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
|
|
|
|
('tests/unit/keyinput/test_basekeyparser.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'keyinput/basekeyparser.py'),
|
2018-03-04 19:12:24 +01:00
|
|
|
('tests/unit/keyinput/test_keyutils.py',
|
|
|
|
'keyinput/keyutils.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
|
|
|
|
('tests/unit/misc/test_autoupdate.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/autoupdate.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/misc/test_readline.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/readline.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/misc/test_split.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/split.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/misc/test_msgbox.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/msgbox.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/misc/test_checkpyver.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/checkpyver.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/misc/test_guiprocess.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/guiprocess.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/misc/test_editor.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/editor.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/misc/test_cmdhistory.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/cmdhistory.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/misc/test_ipc.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/ipc.py'),
|
2016-05-18 07:34:40 +02:00
|
|
|
('tests/unit/misc/test_keyhints.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/keyhintwidget.py'),
|
2016-06-13 10:49:58 +02:00
|
|
|
('tests/unit/misc/test_pastebin.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/pastebin.py'),
|
2018-11-29 19:04:14 +01:00
|
|
|
('tests/unit/misc/test_objects.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'misc/objects.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
|
|
|
|
(None,
|
2017-12-15 19:08:15 +01:00
|
|
|
'mainwindow/statusbar/keystring.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/mainwindow/statusbar/test_percentage.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'mainwindow/statusbar/percentage.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/mainwindow/statusbar/test_progress.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'mainwindow/statusbar/progress.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/mainwindow/statusbar/test_tabindex.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'mainwindow/statusbar/tabindex.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/mainwindow/statusbar/test_textbase.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'mainwindow/statusbar/textbase.py'),
|
2016-03-24 06:14:16 +01:00
|
|
|
('tests/unit/mainwindow/statusbar/test_url.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'mainwindow/statusbar/url.py'),
|
2017-06-18 15:04:14 +02:00
|
|
|
('tests/unit/mainwindow/statusbar/test_backforward.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'mainwindow/statusbar/backforward.py'),
|
2016-09-15 15:09:33 +02:00
|
|
|
('tests/unit/mainwindow/test_messageview.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'mainwindow/messageview.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
|
2017-07-03 14:00:42 +02:00
|
|
|
('tests/unit/config/test_config.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'config/config.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/config/test_configdata.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'config/configdata.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/config/test_configexc.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'config/configexc.py'),
|
2017-07-03 14:00:42 +02:00
|
|
|
('tests/unit/config/test_configfiles.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'config/configfiles.py'),
|
2017-07-03 14:00:42 +02:00
|
|
|
('tests/unit/config/test_configtypes.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'config/configtypes.py'),
|
2017-09-22 20:26:56 +02:00
|
|
|
('tests/unit/config/test_configinit.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'config/configinit.py'),
|
2017-10-02 07:06:05 +02:00
|
|
|
('tests/unit/config/test_configcommands.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'config/configcommands.py'),
|
2018-02-19 21:32:51 +01:00
|
|
|
('tests/unit/config/test_configutils.py',
|
|
|
|
'config/configutils.py'),
|
2018-09-02 23:57:55 +02:00
|
|
|
('tests/unit/config/test_configcache.py',
|
|
|
|
'config/configcache.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
|
|
|
|
('tests/unit/utils/test_qtutils.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/qtutils.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/utils/test_standarddir.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/standarddir.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/utils/test_urlutils.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/urlutils.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/utils/usertypes',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/usertypes.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/utils/test_utils.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/utils.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/utils/test_version.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/version.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/utils/test_debug.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/debug.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/utils/test_jinja.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/jinja.py'),
|
2015-10-04 19:36:26 +02:00
|
|
|
('tests/unit/utils/test_error.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/error.py'),
|
2016-08-04 17:53:13 +02:00
|
|
|
('tests/unit/utils/test_javascript.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'utils/javascript.py'),
|
2018-02-19 21:32:51 +01:00
|
|
|
('tests/unit/utils/test_urlmatch.py',
|
|
|
|
'utils/urlmatch.py'),
|
2016-08-04 17:53:13 +02:00
|
|
|
|
2017-09-13 12:19:18 +02:00
|
|
|
(None,
|
2017-12-15 19:08:15 +01:00
|
|
|
'completion/models/util.py'),
|
2016-06-27 04:12:11 +02:00
|
|
|
('tests/unit/completion/test_models.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'completion/models/urlmodel.py'),
|
2018-02-27 15:55:00 +01:00
|
|
|
('tests/unit/completion/test_models.py',
|
|
|
|
'completion/models/configmodel.py'),
|
2017-07-17 14:37:24 +02:00
|
|
|
('tests/unit/completion/test_histcategory.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'completion/models/histcategory.py'),
|
2017-07-21 13:59:22 +02:00
|
|
|
('tests/unit/completion/test_listcategory.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'completion/models/listcategory.py'),
|
2016-06-27 04:12:11 +02:00
|
|
|
|
2017-10-04 15:22:35 +02:00
|
|
|
('tests/unit/browser/webengine/test_spell.py',
|
2017-12-15 19:08:15 +01:00
|
|
|
'browser/webengine/spell.py'),
|
2017-10-04 15:22:35 +02:00
|
|
|
|
2015-07-24 14:04:40 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2016-05-29 18:20:00 +02:00
|
|
|
# 100% coverage because of end2end tests, but no perfect unit tests yet.
|
2016-11-10 06:54:02 +01:00
|
|
|
WHITELISTED_FILES = [
|
2017-05-09 06:13:35 +02:00
|
|
|
'browser/webkit/webkitinspector.py',
|
|
|
|
'keyinput/macros.py',
|
|
|
|
'browser/webkit/webkitelem.py',
|
2018-12-10 19:52:20 +01:00
|
|
|
'api/interceptor.py',
|
2016-11-10 06:54:02 +01:00
|
|
|
]
|
2016-01-10 23:22:44 +01:00
|
|
|
|
|
|
|
|
2015-08-26 20:08:40 +02:00
|
|
|
class Skipped(Exception):
|
|
|
|
|
|
|
|
"""Exception raised when skipping coverage checks."""
|
|
|
|
|
|
|
|
def __init__(self, reason):
|
|
|
|
self.reason = reason
|
|
|
|
super().__init__("Skipping coverage checks " + reason)
|
|
|
|
|
|
|
|
|
2015-11-11 22:23:43 +01:00
|
|
|
def _get_filename(filename):
|
|
|
|
"""Transform the absolute test filenames to relative ones."""
|
|
|
|
if os.path.isabs(filename):
|
|
|
|
basedir = os.path.abspath(
|
|
|
|
os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
|
|
common_path = os.path.commonprefix([basedir, filename])
|
|
|
|
if common_path:
|
|
|
|
filename = filename[len(common_path):].lstrip('/')
|
2017-05-09 06:13:35 +02:00
|
|
|
if filename.startswith('qutebrowser/'):
|
|
|
|
filename = filename.split('/', maxsplit=1)[1]
|
2015-11-11 22:23:43 +01:00
|
|
|
|
|
|
|
return filename
|
|
|
|
|
|
|
|
|
2015-08-26 20:08:40 +02:00
|
|
|
def check(fileobj, perfect_files):
|
2015-08-25 21:17:04 +02:00
|
|
|
"""Main entry point which parses/checks coverage.xml if applicable."""
|
2017-09-20 10:39:39 +02:00
|
|
|
if not utils.is_linux:
|
2015-08-26 20:08:40 +02:00
|
|
|
raise Skipped("on non-Linux system.")
|
2015-08-12 06:41:41 +02:00
|
|
|
elif '-k' in sys.argv[1:]:
|
2015-08-26 20:08:40 +02:00
|
|
|
raise Skipped("because -k is given.")
|
2015-08-12 06:41:41 +02:00
|
|
|
elif '-m' in sys.argv[1:]:
|
2015-08-26 20:08:40 +02:00
|
|
|
raise Skipped("because -m is given.")
|
2015-11-13 22:43:12 +01:00
|
|
|
elif '--lf' in sys.argv[1:]:
|
|
|
|
raise Skipped("because --lf is given.")
|
2015-08-08 21:11:38 +02:00
|
|
|
|
2015-10-04 19:36:26 +02:00
|
|
|
perfect_src_files = [e[1] for e in perfect_files]
|
|
|
|
|
|
|
|
filename_args = [arg for arg in sys.argv[1:]
|
|
|
|
if arg.startswith('tests' + os.sep)]
|
|
|
|
filtered_files = [tpl[1] for tpl in perfect_files if tpl[0] in
|
|
|
|
filename_args]
|
|
|
|
|
|
|
|
if filename_args and not filtered_files:
|
|
|
|
raise Skipped("because there is nothing to check.")
|
2015-07-24 14:04:40 +02:00
|
|
|
|
2015-08-26 20:08:40 +02:00
|
|
|
tree = ElementTree.parse(fileobj)
|
2015-07-24 14:42:18 +02:00
|
|
|
classes = tree.getroot().findall('./packages/package/classes/class')
|
2015-07-24 14:04:40 +02:00
|
|
|
|
2015-08-26 20:08:40 +02:00
|
|
|
messages = []
|
2015-07-24 14:04:40 +02:00
|
|
|
|
|
|
|
for klass in classes:
|
2015-11-11 22:23:43 +01:00
|
|
|
filename = _get_filename(klass.attrib['filename'])
|
2015-11-11 20:57:47 +01:00
|
|
|
|
2015-07-24 14:04:40 +02:00
|
|
|
line_cov = float(klass.attrib['line-rate']) * 100
|
|
|
|
branch_cov = float(klass.attrib['branch-rate']) * 100
|
|
|
|
|
2015-10-04 19:36:26 +02:00
|
|
|
if filtered_files and filename not in filtered_files:
|
|
|
|
continue
|
|
|
|
|
2015-07-24 14:04:40 +02:00
|
|
|
assert 0 <= line_cov <= 100, line_cov
|
|
|
|
assert 0 <= branch_cov <= 100, branch_cov
|
|
|
|
assert '\\' not in filename, filename
|
|
|
|
|
2015-09-21 07:42:10 +02:00
|
|
|
is_bad = line_cov < 100 or branch_cov < 100
|
2015-07-24 14:04:40 +02:00
|
|
|
|
2015-10-04 19:36:26 +02:00
|
|
|
if filename in perfect_src_files and is_bad:
|
2017-09-15 10:41:12 +02:00
|
|
|
text = "{} has {:.2f}% line and {:.2f}% branch coverage!".format(
|
2015-10-04 20:35:24 +02:00
|
|
|
filename, line_cov, branch_cov)
|
2016-09-26 08:12:18 +02:00
|
|
|
messages.append(Message(MsgType.insufficent_coverage, filename,
|
|
|
|
text))
|
2016-01-10 23:22:44 +01:00
|
|
|
elif (filename not in perfect_src_files and not is_bad and
|
2016-04-27 18:30:54 +02:00
|
|
|
filename not in WHITELISTED_FILES):
|
2015-10-04 20:35:24 +02:00
|
|
|
text = ("{} has 100% coverage but is not in "
|
|
|
|
"perfect_files!".format(filename))
|
2016-09-26 07:33:27 +02:00
|
|
|
messages.append(Message(MsgType.perfect_file, filename, text))
|
2015-07-24 14:04:40 +02:00
|
|
|
|
2015-08-26 20:08:40 +02:00
|
|
|
return messages
|
2015-08-08 22:55:37 +02:00
|
|
|
|
2015-08-25 17:59:10 +02:00
|
|
|
|
2015-10-04 20:35:24 +02:00
|
|
|
def main_check():
|
|
|
|
"""Check coverage after a test run."""
|
2015-08-26 20:08:40 +02:00
|
|
|
try:
|
2015-08-31 07:41:06 +02:00
|
|
|
with open('coverage.xml', encoding='utf-8') as f:
|
2015-08-26 20:08:40 +02:00
|
|
|
messages = check(f, PERFECT_FILES)
|
|
|
|
except Skipped as e:
|
|
|
|
print(e)
|
|
|
|
messages = []
|
|
|
|
|
2016-03-24 06:51:06 +01:00
|
|
|
if messages:
|
|
|
|
print()
|
|
|
|
print()
|
2017-09-20 10:39:39 +02:00
|
|
|
scriptutils.print_title("Coverage check failed")
|
2016-03-24 06:51:06 +01:00
|
|
|
for msg in messages:
|
|
|
|
print(msg.text)
|
|
|
|
print()
|
2017-05-15 11:32:41 +02:00
|
|
|
filters = ','.join('qutebrowser/' + msg.filename for msg in messages)
|
2017-10-23 11:22:56 +02:00
|
|
|
subprocess.run([sys.executable, '-m', 'coverage', 'report',
|
|
|
|
'--show-missing', '--include', filters], check=True)
|
2016-09-26 07:33:27 +02:00
|
|
|
print()
|
2017-09-10 01:14:52 +02:00
|
|
|
print("To debug this, run 'tox -e py36-pyqt59-cov' "
|
|
|
|
"(or py35-pyqt59-cov) locally and check htmlcov/index.html")
|
2017-02-05 00:14:50 +01:00
|
|
|
print("or check https://codecov.io/github/qutebrowser/qutebrowser")
|
2016-03-24 06:51:06 +01:00
|
|
|
print()
|
2015-08-26 20:08:40 +02:00
|
|
|
|
2015-10-23 08:10:15 +02:00
|
|
|
if 'CI' in os.environ:
|
|
|
|
print("Keeping coverage.xml on CI.")
|
|
|
|
else:
|
|
|
|
os.remove('coverage.xml')
|
2015-08-26 20:08:40 +02:00
|
|
|
return 1 if messages else 0
|
2015-07-24 14:04:40 +02:00
|
|
|
|
|
|
|
|
2015-10-04 20:35:24 +02:00
|
|
|
def main_check_all():
|
|
|
|
"""Check the coverage for all files individually.
|
|
|
|
|
|
|
|
This makes sure the files have 100% coverage without running unrelated
|
|
|
|
tests.
|
|
|
|
|
2016-08-22 07:41:10 +02:00
|
|
|
This runs pytest with the used executable, so check_coverage.py should be
|
2017-09-18 09:41:12 +02:00
|
|
|
called with something like ./.tox/py36/bin/python.
|
2015-10-04 20:35:24 +02:00
|
|
|
"""
|
|
|
|
for test_file, src_file in PERFECT_FILES:
|
|
|
|
if test_file is None:
|
|
|
|
continue
|
2017-10-23 11:22:56 +02:00
|
|
|
subprocess.run(
|
2016-08-22 07:41:10 +02:00
|
|
|
[sys.executable, '-m', 'pytest', '--cov', 'qutebrowser',
|
2017-10-23 11:22:56 +02:00
|
|
|
'--cov-report', 'xml', test_file], check=True)
|
2015-10-04 20:35:24 +02:00
|
|
|
with open('coverage.xml', encoding='utf-8') as f:
|
|
|
|
messages = check(f, [(test_file, src_file)])
|
|
|
|
os.remove('coverage.xml')
|
|
|
|
|
|
|
|
messages = [msg for msg in messages
|
|
|
|
if msg.typ == MsgType.insufficent_coverage]
|
|
|
|
if messages:
|
|
|
|
for msg in messages:
|
|
|
|
print(msg.text)
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
print("Check ok!")
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2017-09-20 10:39:39 +02:00
|
|
|
scriptutils.change_cwd()
|
2015-10-04 20:35:24 +02:00
|
|
|
if '--check-all' in sys.argv:
|
2015-11-09 20:07:08 +01:00
|
|
|
return main_check_all()
|
2015-10-04 20:35:24 +02:00
|
|
|
else:
|
2015-11-09 20:07:08 +01:00
|
|
|
return main_check()
|
2015-10-04 20:35:24 +02:00
|
|
|
|
|
|
|
|
2015-07-24 14:04:40 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|