[Python-modules-commits] [pytest-pylint] 01/05: import pytest-pylint_0.5.0.orig.tar.gz

Ondrej Koblizek kobla-guest at moszumanska.debian.org
Fri May 27 14:41:26 UTC 2016


This is an automated email from the git hooks/post-receive script.

kobla-guest pushed a commit to branch master
in repository pytest-pylint.

commit 4255b62161c937e3b91a634994b230cf1ad1820c
Author: Ondrej Koblizek <ondrej.koblizek at firma.seznam.cz>
Date:   Fri May 27 16:26:46 2016 +0200

    import pytest-pylint_0.5.0.orig.tar.gz
---
 .coveragerc           |   5 ++
 .gitignore            |  57 +++++++++++++++++++
 .travis.yml           |  10 ++++
 LICENSE               |  22 ++++++++
 MANIFEST.in           |   2 +
 README.rst            |  37 +++++++++++++
 pylintrc              |   2 +
 pytest_pylint.py      | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++
 setup.py              |  31 +++++++++++
 test_pytest_pylint.py |  98 +++++++++++++++++++++++++++++++++
 tox.ini               |  18 ++++++
 11 files changed, 430 insertions(+)

diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..d6c6a84
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,5 @@
+[run]
+source = .
+omit =
+    .tox/*
+    setup.py
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ba74660
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,57 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..d8d2d3e
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,10 @@
+language: python
+python:
+  - "2.7"
+install:
+  - "pip install tox"
+  - "pip install coveralls"
+  - "pip install -e ."
+script: tox
+after_success:
+  "coveralls"
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..c3aff1a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Carson Gee
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..a5021c6
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,2 @@
+include README.rst
+include LICENSE
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..af610d5
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,37 @@
+pytest pylint
+-------------
+.. image:: https://img.shields.io/travis/carsongee/pytest-pylint.svg
+    :target: https://travis-ci.org/carsongee/orcoursetrion
+.. image:: https://img.shields.io/coveralls/carsongee/pytest-pylint.svg
+    :target: https://coveralls.io/r/carsongee/pytest-pylint
+.. image:: https://img.shields.io/pypi/v/pytest-pylint.svg
+    :target: https://pypi.python.org/pypi/pytest-pylint
+.. image:: https://img.shields.io/pypi/dm/pytest-pylint.svg
+    :target: https://pypi.python.org/pypi/pytest-pylint
+.. image:: https://img.shields.io/pypi/l/pytest-pylint.svg
+    :target: https://pypi.python.org/pypi/pytest-pylint
+
+Run pylint with pytest and have configurable rule types
+(i.e. Convention, Warn, and Error) fail the build.  You can also
+specify a pylintrc file.
+
+Sample Usage
+============
+.. code-block:: shell
+
+   py.test --pylint
+
+would be the most simple usage and would run pylint for all error messages.
+
+.. code-block:: shell
+
+   py.test --pylint --pylint-rcfile=/my/pyrc --pylint-error-types=EF
+
+This would use the pylintrc file at /my/pyrc and only error on pylint
+Errors and Failures.
+
+Acknowledgements
+================
+
+This code is heavily based on 
+`pytest-flakes <https://github.com/fschulze/pytest-flakes>`_
diff --git a/pylintrc b/pylintrc
new file mode 100644
index 0000000..9c4b7d0
--- /dev/null
+++ b/pylintrc
@@ -0,0 +1,2 @@
+[TYPECHECK]
+ignored-classes=pytest
\ No newline at end of file
diff --git a/pytest_pylint.py b/pytest_pylint.py
new file mode 100644
index 0000000..7f4fcc5
--- /dev/null
+++ b/pytest_pylint.py
@@ -0,0 +1,148 @@
+"""Pylint plugin for py.test"""
+from __future__ import unicode_literals
+from __future__ import absolute_import
+from os.path import exists, join, dirname
+from six.moves.configparser import (  # pylint: disable=import-error
+    ConfigParser,
+    NoSectionError,
+    NoOptionError
+)
+
+from pylint import lint
+from pylint.config import PYLINTRC
+from pylint.interfaces import IReporter
+from pylint.reporters import BaseReporter
+import pytest
+
+
+class ProgrammaticReporter(BaseReporter):
+    """Reporter that replaces output with storage in list of dictionaries"""
+
+    __implements__ = IReporter
+    extension = 'prog'
+
+    def __init__(self, output=None):
+        BaseReporter.__init__(self, output)
+        self.current_module = None
+        self.data = []
+
+    def add_message(self, msg_id, location, msg):
+        """Deprecated, but required"""
+        raise NotImplementedError
+
+    def handle_message(self, msg):
+        """Get message and append to our data structure"""
+        self.data.append(msg)
+
+    def _display(self, layout):
+        """launch layouts display"""
+
+
+def pytest_addoption(parser):
+    """Add all our command line options"""
+    group = parser.getgroup("general")
+    group.addoption(
+        "--pylint",
+        action="store_true", default=False,
+        help="run pylint on all"
+    )
+    group.addoption(
+        '--pylint-rcfile',
+        default=None,
+        help='Location of RC file if not pylintrc'
+    )
+    group.addoption(
+        '--pylint-error-types',
+        default='CRWEF',
+        help='The types of pylint errors to consider failures by letter'
+        ', default is all of them (CRWEF).'
+    )
+
+
+def pytest_collect_file(path, parent):
+    """Handle running pylint on files discovered"""
+    config = parent.config
+    if not config.option.pylint:
+        return
+    if path.ext != ".py":
+        return
+
+    # Find pylintrc to check ignore list
+    pylintrc_file = config.option.pylint_rcfile or PYLINTRC
+
+    if pylintrc_file and not exists(pylintrc_file):
+        # The directory of pytest.ini got a chance
+        pylintrc_file = join(dirname(str(config.inifile)), pylintrc_file)
+
+    if not pylintrc_file or not exists(pylintrc_file):
+        # No pylintrc, therefore no ignores, so return the item.
+        return PyLintItem(path, parent)
+
+    pylintrc = ConfigParser()
+    pylintrc.read(pylintrc_file)
+    ignore_list = []
+    try:
+        ignore_string = pylintrc.get('MASTER', 'ignore')
+        if len(ignore_string) > 0:
+            ignore_list = ignore_string.split(',')
+    except (NoSectionError, NoOptionError):
+        pass
+    msg_template = None
+    try:
+        msg_template = pylintrc.get('REPORTS', 'msg-template')
+    except (NoSectionError, NoOptionError):
+        pass
+    rel_path = path.strpath.replace(parent.fspath.strpath, '', 1)[1:]
+    if not any(basename in rel_path for basename in ignore_list):
+        return PyLintItem(path, parent, msg_template, pylintrc_file)
+
+
+class PyLintException(Exception):
+    """Exception to raise if a file has a specified pylint error"""
+    pass
+
+
+class PyLintItem(pytest.Item, pytest.File):
+    """pylint test running class."""
+    # pylint doesn't deal well with dynamic modules and there isn't an
+    # astng plugin for pylint in pypi yet, so we'll have to disable
+    # the checks.
+    # pylint: disable=no-member,super-on-old-class
+    def __init__(self, fspath, parent, msg_format=None, pylintrc_file=None):
+        super(PyLintItem, self).__init__(fspath, parent)
+
+        if msg_format is None:
+            self._msg_format = '{C}:{line:3d},{column:2d}: {msg} ({symbol})'
+        else:
+            self._msg_format = msg_format
+
+        self.pylintrc_file = pylintrc_file
+
+    def runtest(self):
+        """Setup and run pylint for the given test file."""
+        reporter = ProgrammaticReporter()
+        # Build argument list for pylint
+        args_list = [str(self.fspath)]
+        if self.pylintrc_file:
+            args_list.append('--rcfile={0}'.format(
+                self.pylintrc_file
+            ))
+        lint.Run(args_list, reporter=reporter, exit=False)
+        reported_errors = []
+        for error in reporter.data:
+            if error.C in self.config.option.pylint_error_types:
+                reported_errors.append(
+                    error.format(self._msg_format)
+                )
+        if reported_errors:
+            raise PyLintException('\n'.join(reported_errors))
+
+    def repr_failure(self, excinfo):
+        """Handle any test failures by checkint that they were ours."""
+        if excinfo.errisinstance(PyLintException):
+            return excinfo.value.args[0]
+        return super(PyLintItem, self).repr_failure(excinfo)
+
+    def reportinfo(self):
+        """Generate our test report"""
+        return self.fspath, None, "[pylint] {0}".format(self.name)
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..37d622e
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+"""
+pytest-pylint
+=============
+
+Plugin for py.test for doing pylint tests
+"""
+
+from setuptools import setup
+
+setup(
+    name='pytest-pylint',
+    description='pytest plugin to check source code with pylint',
+    long_description=open("README.rst").read(),
+    license="MIT",
+    version='0.5.0',
+    author='Carson Gee',
+    author_email='x at carsongee.com',
+    url='https://github.com/carsongee/pytest-pylint',
+    py_modules=['pytest_pylint'],
+    entry_points={'pytest11': ['pylint = pytest_pylint']},
+    install_requires=['pytest>=2.4', 'pylint>=1.4.5', 'six'],
+    classifiers=[
+        'Development Status :: 5 - Production/Stable',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: MIT License',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: 3.4',
+    ],
+)
diff --git a/test_pytest_pylint.py b/test_pytest_pylint.py
new file mode 100644
index 0000000..4c8baac
--- /dev/null
+++ b/test_pytest_pylint.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+"""
+Unit testing module for pytest-pylti plugin
+"""
+
+pytest_plugins = 'pytester',  # pylint: disable=invalid-name
+
+
+def test_basic(testdir):
+    """Verify basic pylint checks"""
+    testdir.makepyfile("""import sys""")
+    result = testdir.runpytest('--pylint')
+    assert 'Missing module docstring' in result.stdout.str()
+    assert 'Unused import sys' in result.stdout.str()
+    assert 'Final newline missing' in result.stdout.str()
+    assert 'passed' not in result.stdout.str()
+
+
+def test_error_control(testdir):
+    """Verify that error types are configurable"""
+    testdir.makepyfile("""import sys""")
+    result = testdir.runpytest('--pylint', '--pylint-error-types=EF')
+    assert '1 passed' in result.stdout.str()
+
+
+def test_pylintrc_file(testdir):
+    """Verify that a specified pylint rc file will work."""
+    rcfile = testdir.makefile('rc', """
+[FORMAT]
+
+max-line-length=3
+""")
+    testdir.makepyfile("""import sys""")
+    result = testdir.runpytest(
+        '--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
+    )
+    assert 'Line too long (10/3)' in result.stdout.str()
+
+
+def test_pylintrc_file_beside_ini(testdir):
+    """
+    Verify that a specified pylint rc file will work what placed into pytest
+    ini dir.
+    """
+    non_cwd_dir = testdir.mkdir('non_cwd_dir')
+
+    rcfile = non_cwd_dir.join('foo.rc')
+    rcfile.write("""
+[FORMAT]
+
+max-line-length=3
+""")
+
+    inifile = non_cwd_dir.join('foo.ini')
+    inifile.write("""
+[pytest]
+addopts = --pylint --pylint-rcfile={0}
+""".format(rcfile.basename))
+
+    pyfile = testdir.makepyfile("""import sys""")
+
+    result = testdir.runpytest(
+        pyfile.strpath
+    )
+    assert 'Line too long (10/3)' not in result.stdout.str()
+
+    result = testdir.runpytest(
+        '-c', inifile.strpath, pyfile.strpath
+    )
+    assert 'Line too long (10/3)' in result.stdout.str()
+
+
+def test_pylintrc_ignore(testdir):
+    """Verify that a pylintrc file with ignores will work."""
+    rcfile = testdir.makefile('rc', """
+[MASTER]
+
+ignore = test_pylintrc_ignore.py
+""")
+    testdir.makepyfile("""import sys""")
+    result = testdir.runpytest(
+        '--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
+    )
+    assert 'collected 0 items' in result.stdout.str()
+
+
+def test_pylintrc_msg_template(testdir):
+    """Verify that msg-template from pylintrc file is handled."""
+    rcfile = testdir.makefile('rc', """
+[REPORTS]
+
+msg-template=start {msg_id} end
+""")
+    testdir.makepyfile("""import sys""")
+    result = testdir.runpytest(
+        '--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
+    )
+    assert 'start W0611 end' in result.stdout.str()
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..562e09a
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,18 @@
+[tox]
+envlist = py27,py33,py34
+skip_missing_interpreters =
+    true
+[testenv]
+usedevelop = true
+deps =
+    pytest
+    pytest-pep8
+    coverage
+commands =
+    coverage erase
+    coverage run -m py.test {posargs}
+    coverage report
+    coverage html -d htmlcov
+
+[pytest]
+addopts = --pylint --pep8

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pytest-pylint.git



More information about the Python-modules-commits mailing list