summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2014-10-16 14:22:06 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2014-10-16 14:22:06 +0300
commit11ed19d3cfd4574dba17554e8ec27999a1578d05 (patch)
tree845c2f3b6a050548b6ece583eb6e03b21701c291
parent69672965cabf5f31d3f17c2095ba9685deafb0a8 (diff)
parent9851fe59dc2b3abb7e30af69f6d6c1d40419c7b9 (diff)
downloadpylint-11ed19d3cfd4574dba17554e8ec27999a1578d05.tar.gz
Fix a regression, where '{path}' was no longer accepted in '--msg-template'.
Patch by LCD47.
-rw-r--r--ChangeLog2
-rw-r--r--test/test_self.py2
-rw-r--r--test/unittest_reporting.py15
-rw-r--r--testutils.py3
-rw-r--r--utils.py17
5 files changed, 33 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 0b12ace..54f8a9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -131,6 +131,8 @@ ChangeLog for Pylint
* Don't emit 'assigning-non-slot' when the assignment is for a property.
Closes issue #359.
+ * Fix for regression: '{path}' was no longer accepted in '--msg-template'.
+
2014-07-26 -- 1.3.0
diff --git a/test/test_self.py b/test/test_self.py
index c9fa2f7..7a48ee0 100644
--- a/test/test_self.py
+++ b/test/test_self.py
@@ -12,6 +12,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import sys
+import os
from os.path import join, dirname, abspath
from cStringIO import StringIO
import tempfile
@@ -28,6 +29,7 @@ HERE = abspath(dirname(__file__))
class MultiReporter(BaseReporter):
def __init__(self, reporters):
self._reporters = reporters
+ self.path_strip_prefix = os.getcwd() + os.sep
def on_set_current_module(self, *args, **kwargs):
for rep in self._reporters:
diff --git a/test/unittest_reporting.py b/test/unittest_reporting.py
index 58fcf6b..07b0a24 100644
--- a/test/unittest_reporting.py
+++ b/test/unittest_reporting.py
@@ -47,6 +47,21 @@ class PyLinterTC(unittest.TestCase):
'C0301:001\n'
'C0301:002\n')
+ def test_parseable_output_regression(self):
+ output = cStringIO.StringIO()
+ linter = PyLinter(reporter=ParseableTextReporter())
+ checkers.initialize(linter)
+ linter.config.persistent = 0
+ linter.reporter.set_output(output)
+ linter.set_option('output-format', 'parseable')
+ linter.open()
+ linter.set_current_module('0123')
+ linter.add_message('line-too-long', line=1, args=(1, 2))
+ self.assertMultiLineEqual(output.getvalue(),
+ '************* Module 0123\n'
+ '0123:1: [C0301(line-too-long), ] '
+ 'Line too long (1/2)\n')
+
if __name__ == '__main__':
unittest.main()
diff --git a/testutils.py b/testutils.py
index 8ceac5f..0b1b967 100644
--- a/testutils.py
+++ b/testutils.py
@@ -24,7 +24,7 @@ import re
import unittest
from glob import glob
-from os import linesep
+from os import linesep, getcwd, sep
from os.path import abspath, basename, dirname, isdir, join, splitext
@@ -95,6 +95,7 @@ class TestReporter(BaseReporter):
def __init__(self):
self.message_ids = {}
self.reset()
+ self.path_strip_prefix = getcwd() + sep
def reset(self):
self.out = StringIO()
diff --git a/utils.py b/utils.py
index 36194b7..7c22b73 100644
--- a/utils.py
+++ b/utils.py
@@ -84,7 +84,7 @@ class WarningScope(object):
_MsgBase = collections.namedtuple(
'_MsgBase',
['msg_id', 'symbol', 'msg', 'C', 'category', 'confidence',
- 'abspath', 'module', 'obj', 'line', 'column'])
+ 'abspath', 'path', 'module', 'obj', 'line', 'column'])
class Message(_MsgBase):
@@ -95,7 +95,13 @@ class Message(_MsgBase):
confidence, *location)
def get_init_args(self):
- location = (self.abspath, self.module, self.obj, self.line, self.column)
+ location = (
+ self.abspath,
+ self.path,
+ self.module,
+ self.obj,
+ self.line,
+ self.column)
return (self.msg_id, self.symbol, location, self.msg, self.confidence)
def format(self, template):
@@ -395,14 +401,15 @@ class MessagesHandlerMixIn(object):
# get module and object
if node is None:
module, obj = self.current_name, ''
- path = self.current_file
+ abspath = self.current_file
else:
module, obj = get_module_and_frameid(node)
- path = node.root().file
+ abspath = node.root().file
+ path = abspath.replace(self.reporter.path_strip_prefix, '')
# add the message
self.reporter.handle_message(
Message(msgid, symbol,
- (path, module, obj, line or 1, col_offset or 0), msg, confidence))
+ (abspath, path, module, obj, line or 1, col_offset or 0), msg, confidence))
def print_full_documentation(self):
"""output a full documentation in ReST format"""