Skip to content

Commit

Permalink
Merge pull request #29 from carsongee/rc/0.7.1
Browse files Browse the repository at this point in the history
Rc/0.7.1
  • Loading branch information
carsongee committed Apr 16, 2017
2 parents bca432b + 7bebfa4 commit 07518ba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .travis.yml
@@ -1,9 +1,12 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
install:
- "pip install tox"
- "pip install coveralls"
- "pip install tox-travis tox coveralls"
- "pip install -e ."
script: tox
after_success:
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Expand Up @@ -47,6 +47,11 @@ This code is heavily based on
Releases
========

0.7.1
~~~~~

- Corrected path issue reported by `Kargathia <https://github.com/Kargathia>`_

0.7.0
~~~~~

Expand Down
31 changes: 21 additions & 10 deletions pytest_pylint.py
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import print_function
from os import sep
from os.path import exists, join, dirname
from six.moves.configparser import ( # pylint: disable=import-error
ConfigParser,
Expand All @@ -16,6 +17,11 @@
import pytest


class PyLintException(Exception):
"""Exception to raise if a file has a specified pylint error"""
pass


class ProgrammaticReporter(BaseReporter):
"""Reporter that replaces output with storage in list of dictionaries"""

Expand All @@ -39,6 +45,18 @@ def _display(self, layout):
"""launch layouts display"""


def get_rel_path(path, parent_path):
"""
Give the path to object relative to ``parent_path``.
"""
replaced_path = path.replace(parent_path, '', 1)
if replaced_path[0] == sep:
rel_path = replaced_path[1:]
else:
rel_path = replaced_path
return rel_path


def pytest_addoption(parser):
"""Add all our command line options"""
group = parser.getgroup("general")
Expand Down Expand Up @@ -83,7 +101,7 @@ def pytest_sessionstart(session):
session.pylint_config.read(pylintrc_file)
try:
ignore_string = session.pylint_config.get('MASTER', 'ignore')
if len(ignore_string) > 0:
if ignore_string:
session.pylint_ignore = ignore_string.split(',')
except (NoSectionError, NoOptionError):
pass
Expand All @@ -102,7 +120,7 @@ def pytest_collect_file(path, parent):
return
if path.ext != ".py":
return
rel_path = path.strpath.replace(parent.fspath.strpath, '', 1)[1:]
rel_path = get_rel_path(path.strpath, parent.fspath.strpath)
if parent.pylint_config is None:
parent.pylint_files.add(rel_path)
# No pylintrc, therefore no ignores, so return the item.
Expand Down Expand Up @@ -139,11 +157,6 @@ def pytest_collection_finish(session):
print('-' * 65)


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
Expand All @@ -154,9 +167,7 @@ def __init__(self, fspath, parent, msg_format=None, pylintrc_file=None):
super(PyLintItem, self).__init__(fspath, parent)

self.add_marker("pylint")
self.rel_path = fspath.strpath.replace(
parent.fspath.strpath, '', 1
)[1:]
self.rel_path = get_rel_path(fspath.strpath, parent.fspath.strpath)

if msg_format is None:
self._msg_format = '{C}:{line:3d},{column:2d}: {msg} ({symbol})'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -13,7 +13,7 @@
description='pytest plugin to check source code with pylint',
long_description=open("README.rst").read(),
license="MIT",
version='0.7.0',
version='0.7.1',
author='Carson Gee',
author_email='x@carsongee.com',
url='https://github.com/carsongee/pytest-pylint',
Expand Down
16 changes: 15 additions & 1 deletion test_pytest_pylint.py
Expand Up @@ -3,7 +3,7 @@
Unit testing module for pytest-pylti plugin
"""

pytest_plugins = 'pytester', # pylint: disable=invalid-name
pytest_plugins = ('pytester',) # pylint: disable=invalid-name


def test_basic(testdir):
Expand Down Expand Up @@ -96,3 +96,17 @@ def test_pylintrc_msg_template(testdir):
'--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
)
assert 'start W0611 end' in result.stdout.str()


def test_get_rel_path():
"""
Verify our relative path function.
"""
from pytest_pylint import get_rel_path
correct_rel_path = 'How/Are/You/blah.py'
path = '/Hi/How/Are/You/blah.py'
parent_path = '/Hi/'
assert get_rel_path(path, parent_path) == correct_rel_path

parent_path = '/Hi'
assert get_rel_path(path, parent_path) == correct_rel_path
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py33,py34,py35
envlist = py27,py33,py34,py35,py36
skip_missing_interpreters =
true
[testenv]
Expand Down

0 comments on commit 07518ba

Please sign in to comment.