2015-07-24 14:04:40 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
|
|
|
# Copyright 2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
|
|
|
|
|
|
|
# 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
|
2015-07-24 14:04:40 +02:00
|
|
|
import sys
|
|
|
|
import os.path
|
|
|
|
|
2015-07-24 14:42:18 +02:00
|
|
|
from xml.etree import ElementTree
|
2015-07-24 14:04:40 +02:00
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir,
|
|
|
|
os.pardir))
|
|
|
|
|
|
|
|
from scripts import utils
|
|
|
|
|
|
|
|
|
|
|
|
PERFECT_FILES = [
|
|
|
|
'qutebrowser/commands/cmdexc.py',
|
2015-08-17 21:13:13 +02:00
|
|
|
'qutebrowser/commands/cmdutils.py',
|
2015-08-20 07:09:49 +02:00
|
|
|
'qutebrowser/commands/argparser.py',
|
2015-08-02 19:52:43 +02:00
|
|
|
|
2015-08-02 00:34:04 +02:00
|
|
|
'qutebrowser/browser/tabhistory.py',
|
2015-08-02 19:52:43 +02:00
|
|
|
'qutebrowser/browser/http.py',
|
|
|
|
'qutebrowser/browser/rfc6266.py',
|
2015-08-10 19:37:16 +02:00
|
|
|
'qutebrowser/browser/webelem.py',
|
2015-08-12 06:53:32 +02:00
|
|
|
'qutebrowser/browser/network/schemehandler.py',
|
2015-08-13 21:55:36 +02:00
|
|
|
'qutebrowser/browser/network/filescheme.py',
|
2015-08-17 07:16:33 +02:00
|
|
|
'qutebrowser/browser/network/networkreply.py',
|
2015-08-16 23:16:13 +02:00
|
|
|
'qutebrowser/browser/signalfilter.py',
|
2015-08-02 01:49:33 +02:00
|
|
|
|
2015-08-26 20:38:56 +02:00
|
|
|
'qutebrowser/keyinput/basekeyparser.py',
|
|
|
|
|
2015-08-31 01:25:42 +02:00
|
|
|
'qutebrowser/misc/autoupdate.py',
|
2015-08-02 13:42:01 +02:00
|
|
|
'qutebrowser/misc/readline.py',
|
|
|
|
'qutebrowser/misc/split.py',
|
2015-08-17 23:18:52 +02:00
|
|
|
'qutebrowser/misc/msgbox.py',
|
2015-08-19 00:04:01 +02:00
|
|
|
'qutebrowser/misc/checkpyver.py',
|
2015-08-19 07:57:02 +02:00
|
|
|
'qutebrowser/misc/guiprocess.py',
|
2015-08-19 09:34:44 +02:00
|
|
|
'qutebrowser/misc/editor.py',
|
2015-08-26 12:07:47 +02:00
|
|
|
'qutebrowser/misc/cmdhistory.py',
|
2015-09-04 06:57:08 +02:00
|
|
|
'qutebrowser/misc/ipc.py',
|
2015-08-02 13:42:01 +02:00
|
|
|
|
2015-08-02 01:34:40 +02:00
|
|
|
'qutebrowser/mainwindow/statusbar/keystring.py',
|
2015-08-02 01:45:19 +02:00
|
|
|
'qutebrowser/mainwindow/statusbar/percentage.py',
|
2015-08-02 01:49:33 +02:00
|
|
|
'qutebrowser/mainwindow/statusbar/progress.py',
|
2015-08-02 20:34:37 +02:00
|
|
|
'qutebrowser/mainwindow/statusbar/tabindex.py',
|
2015-08-12 07:37:00 +02:00
|
|
|
'qutebrowser/mainwindow/statusbar/textbase.py',
|
2015-07-24 14:04:40 +02:00
|
|
|
|
2015-08-02 01:31:43 +02:00
|
|
|
'qutebrowser/config/configtypes.py',
|
|
|
|
'qutebrowser/config/configdata.py',
|
|
|
|
'qutebrowser/config/configexc.py',
|
2015-08-12 07:00:04 +02:00
|
|
|
'qutebrowser/config/textwrapper.py',
|
2015-08-19 20:43:06 +02:00
|
|
|
'qutebrowser/config/style.py',
|
2015-08-02 01:31:43 +02:00
|
|
|
|
2015-07-24 14:04:40 +02:00
|
|
|
'qutebrowser/utils/qtutils.py',
|
|
|
|
'qutebrowser/utils/standarddir.py',
|
|
|
|
'qutebrowser/utils/urlutils.py',
|
|
|
|
'qutebrowser/utils/usertypes.py',
|
|
|
|
'qutebrowser/utils/utils.py',
|
|
|
|
'qutebrowser/utils/version.py',
|
2015-08-11 17:11:00 +02:00
|
|
|
'qutebrowser/utils/debug.py',
|
2015-08-12 06:25:05 +02:00
|
|
|
'qutebrowser/utils/jinja.py',
|
2015-08-17 22:48:05 +02:00
|
|
|
'qutebrowser/utils/error.py',
|
2015-07-24 14:04:40 +02: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)
|
|
|
|
|
|
|
|
|
|
|
|
def check(fileobj, perfect_files):
|
2015-08-25 21:17:04 +02:00
|
|
|
"""Main entry point which parses/checks coverage.xml if applicable."""
|
2015-08-08 21:11:38 +02:00
|
|
|
if sys.platform != '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-08-12 06:41:41 +02:00
|
|
|
elif any(arg.startswith('tests' + os.sep) for arg in sys.argv[1:]):
|
2015-08-26 20:08:40 +02:00
|
|
|
raise Skipped("because a filename is given.")
|
2015-08-08 21:11:38 +02:00
|
|
|
|
2015-08-26 20:08:40 +02:00
|
|
|
for path in perfect_files:
|
|
|
|
assert os.path.exists(path)
|
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:
|
|
|
|
filename = klass.attrib['filename']
|
|
|
|
line_cov = float(klass.attrib['line-rate']) * 100
|
|
|
|
branch_cov = float(klass.attrib['branch-rate']) * 100
|
|
|
|
|
|
|
|
assert 0 <= line_cov <= 100, line_cov
|
|
|
|
assert 0 <= branch_cov <= 100, branch_cov
|
|
|
|
assert '\\' not in filename, filename
|
|
|
|
|
2015-08-02 20:39:40 +02:00
|
|
|
# Files without any branches have 0% coverage
|
2015-08-26 17:51:51 +02:00
|
|
|
has_branches = klass.find('./lines/line[@branch="true"]') is not None
|
|
|
|
if branch_cov < 100 and has_branches:
|
2015-08-02 20:39:40 +02:00
|
|
|
is_bad = True
|
2015-07-24 14:04:40 +02:00
|
|
|
else:
|
2015-08-02 20:39:40 +02:00
|
|
|
is_bad = line_cov < 100
|
2015-07-24 14:04:40 +02:00
|
|
|
|
2015-08-26 20:08:40 +02:00
|
|
|
if filename in perfect_files and is_bad:
|
|
|
|
messages.append(("{} has {}% line and {}% branch coverage!".format(
|
|
|
|
filename, line_cov, branch_cov)))
|
|
|
|
elif filename not in perfect_files and not is_bad:
|
|
|
|
messages.append("{} has 100% coverage but is not in "
|
|
|
|
"perfect_files!".format(filename))
|
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
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Main entry point.
|
|
|
|
|
|
|
|
Return:
|
|
|
|
The return code to return.
|
|
|
|
"""
|
|
|
|
utils.change_cwd()
|
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 = []
|
|
|
|
|
|
|
|
for msg in messages:
|
|
|
|
print(msg)
|
|
|
|
|
2015-08-31 07:41:06 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|