summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--scripts/dev/check_coverage.py89
-rw-r--r--tox.ini5
3 files changed, 94 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index a0f7adb30..fc3dd315d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@ __pycache__
/.venv
/.coverage
/htmlcov
+/coverage.xml
/.tox
/testresults.html
/.cache
diff --git a/scripts/dev/check_coverage.py b/scripts/dev/check_coverage.py
new file mode 100644
index 000000000..0b6ba9a01
--- /dev/null
+++ b/scripts/dev/check_coverage.py
@@ -0,0 +1,89 @@
+#!/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."""
+
+import sys
+import os.path
+
+from lxml import etree
+
+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',
+ 'qutebrowser/config/configtypes.py',
+ 'qutebrowser/misc/readline.py',
+
+ 'qutebrowser/utils/qtutils.py',
+ 'qutebrowser/utils/standarddir.py',
+ 'qutebrowser/utils/urlutils.py',
+ 'qutebrowser/utils/usertypes.py',
+ 'qutebrowser/utils/utils.py',
+ 'qutebrowser/utils/version.py',
+]
+
+
+def main():
+ """Main entry point.
+
+ Return:
+ The return code to return.
+ """
+ utils.change_cwd()
+
+ for path in PERFECT_FILES:
+ assert os.path.exists(os.path.join(*path.split('/'))), path
+
+ with open('coverage.xml', encoding='utf-8') as f:
+ tree = etree.parse(f) # pylint: disable=no-member
+ classes = tree.xpath('/coverage/packages/package/classes/class')
+
+ status = 0
+
+ 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
+
+ if branch_cov < 100 and klass.xpath('lines/line[@branch="true"]'):
+ # Files without any branches have 0% coverage
+ bad_branch_cov = True
+ else:
+ bad_branch_cov = False
+
+ if filename in PERFECT_FILES and (line_cov < 100 or bad_branch_cov):
+ status = 1
+ print("{} has {}% line and {}% branch coverage!".format(
+ filename, line_cov, branch_cov))
+
+ return status
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/tox.ini b/tox.ini
index 5137af0f4..2a14258d3 100644
--- a/tox.ini
+++ b/tox.ini
@@ -61,9 +61,11 @@ deps =
coverage==3.7.1
pytest-cov==1.8.1
cov-core==1.15.0
+ lxml==3.4.4
commands =
{envpython} scripts/link_pyqt.py --tox {envdir}
- {envpython} -m py.test --strict -rfEswx -v --cov qutebrowser --cov-report term --cov-report html {posargs:tests}
+ {envpython} -m py.test --strict -rfEswx -v --cov qutebrowser --cov-report term --cov-report html --cov-report xml {posargs:tests}
+ {envpython} scripts/dev/check_coverage.py
[testenv:misc]
commands =
@@ -81,6 +83,7 @@ deps =
pylint==1.4.4
logilab-common==1.0.2
six==1.9.0
+ lxml==3.4.4
commands =
{envpython} scripts/link_pyqt.py --tox {envdir}
{envpython} -m pylint scripts qutebrowser --rcfile=.pylintrc --output-format=colorized --reports=no --expected-line-ending-format=LF