Add regex whitelist to pylint

This commit is contained in:
Stefano Rivera 2010-12-27 13:39:43 +02:00
parent 8b659d8fc3
commit 76ba39d60b
2 changed files with 31 additions and 6 deletions

View File

@ -2,7 +2,7 @@
# List of classes names for which member attributes should not be checked # List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set). # (useful for classes with attributes dynamically set).
ignored-classes=Launchpad,BaseWrapper,PersonTeam,Distribution,Consumer ignored-classes=Launchpad,BaseWrapper,PersonTeam,Distribution,Consumer,Credentials
[FORMAT] [FORMAT]

View File

@ -14,12 +14,19 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE. # PERFORMANCE OF THIS SOFTWARE.
import os import re
import subprocess import subprocess
import setup import setup
from ubuntutools.test import unittest from ubuntutools.test import unittest
WHITELIST = [re.compile(': %s$' % x) for x in (
# Wildcard import:
r"No name '\w+Error' in module 'launchpadlib\.errors'",
# http://www.logilab.org/ticket/51250:
r"Module 'hashlib' has no '(md5|sha(1|224|256|384|512))' member",
)]
class PylintTestCase(unittest.TestCase): class PylintTestCase(unittest.TestCase):
def test_pylint(self): def test_pylint(self):
"Test: Run pylint on Python source code" "Test: Run pylint on Python source code"
@ -30,11 +37,29 @@ class PylintTestCase(unittest.TestCase):
files.append(script) files.append(script)
f.close() f.close()
p = subprocess.Popen(['pylint', '--rcfile=ubuntutools/test/pylint.conf', p = subprocess.Popen(['pylint', '--rcfile=ubuntutools/test/pylint.conf',
'-E', '--'] + files, '-E', '--include-ids=y', '--'] + files,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
close_fds=True) close_fds=True)
out, err = p.communicate() out, err = p.communicate()
self.assertEqual(p.wait(), 0, self.assertEqual(err, '')
"pylint returned non-zero.\n"
"Output:\n" + out + err) filtered_out = []
detected_in = ''
# pylint: disable=E1103
for line in out.splitlines():
# pylint: enable=E1103
if line.startswith('************* '):
detected_in = line
continue
for r in WHITELIST:
if r.search(line):
break
else:
filtered_out.append(detected_in)
filtered_out.append(line)
self.assertEqual(filtered_out, [],
"pylint found errors.\n"
"Filtered Output:\n" + '\n'.join(filtered_out))