From d3a92d505cb94c6df4db6139d1cb943ab7caf68c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 5 Apr 2015 18:44:01 +0200 Subject: [PATCH] Make lints run with adjusted test folder location. For pylint we need a custom script; see https://bitbucket.org/logilab/pylint/issue/512/ --- scripts/run_pylint_on_tests.py | 60 ++++++++++++++++++++++++++++++++++ tox.ini | 9 ++--- 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 scripts/run_pylint_on_tests.py diff --git a/scripts/run_pylint_on_tests.py b/scripts/run_pylint_on_tests.py new file mode 100644 index 000000000..94ba89c7d --- /dev/null +++ b/scripts/run_pylint_on_tests.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2014-2015 Florian Bruhin (The Compiler) + +# 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 . + +"""Run pylint on tests. + +This is needed because pylint can't check a folder which isn't a package: +https://bitbucket.org/logilab/pylint/issue/512/ +""" + +import os +import sys +import os.path +import subprocess + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) + +from scripts import utils + + +def main(): + """Main entry point. + + Return: + The pylint exit status. + """ + utils.change_cwd() + files = [] + for dirpath, _dirnames, filenames in os.walk('tests'): + for fn in filenames: + if os.path.splitext(fn)[1] == '.py': + files.append(os.path.join(dirpath, fn)) + disabled = ['attribute-defined-outside-init', 'redefined-outer-name', + 'unused-argument'] + no_docstring_rgx = ['^__.*__$', '^setup$'] + args = (['--disable={}'.format(','.join(disabled)), + '--no-docstring-rgx=({})'.format('|'.join(no_docstring_rgx))] + + sys.argv[1:] + files) + ret = subprocess.call(['pylint'] + args) + return ret + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tox.ini b/tox.ini index 8b65b42a2..7bbe8ff7b 100644 --- a/tox.ini +++ b/tox.ini @@ -44,8 +44,8 @@ commands = [testenv:misc] commands = {envpython} scripts/misc_checks.py git - {envpython} scripts/misc_checks.py vcs qutebrowser scripts - {envpython} scripts/misc_checks.py spelling qutebrowser scripts + {envpython} scripts/misc_checks.py vcs qutebrowser scripts tests + {envpython} scripts/misc_checks.py spelling qutebrowser scripts tests [testenv:pylint] skip_install = true @@ -60,6 +60,7 @@ deps = commands = {[testenv:mkvenv]commands} {envdir}/bin/pylint scripts qutebrowser --rcfile=.pylintrc --output-format=colorized --reports=no + {envpython} scripts/run_pylint_on_tests.py --rcfile=.pylintrc --output-format=colorized --reports=no [testenv:pep257] skip_install = true @@ -68,7 +69,7 @@ deps = pep257==0.5.0 # D102: Docstring missing, will be handled by others # D209: Blank line before closing """ (removed from PEP257) # D402: First line should not be function's signature (false-positives) -commands = {envpython} -m pep257 scripts qutebrowser --ignore=D102,D209,D402 '--match=(?!resources|test_content_disposition).*\.py' +commands = {envpython} -m pep257 scripts tests qutebrowser --ignore=D102,D209,D402 '--match=(?!resources|test_content_disposition).*\.py' [testenv:flake8] skip_install = true @@ -79,7 +80,7 @@ deps = flake8==2.4.0 commands = {[testenv:mkvenv]commands} - {envdir}/bin/flake8 scripts qutebrowser --config=.flake8 + {envdir}/bin/flake8 scripts tests qutebrowser --config=.flake8 [testenv:pyroma] skip_install = true