Skip to content

Commit

Permalink
Simplify and speed up the selftest by only linting pylint.lint once i…
Browse files Browse the repository at this point in the history
…nstead of 4 times.
  • Loading branch information
torstenmarek committed Jul 29, 2014
1 parent 97006fc commit 7255b51
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 33 deletions.
7 changes: 7 additions & 0 deletions test/functional/generated_members.py
Original file line number Diff line number Diff line change
@@ -0,0 1,7 @@
"""Test the generated-members config option."""

class Klass(object):
"""A class with a generated member."""

print Klass().DoesNotExist
print Klass().aBC_set1
5 changes: 5 additions & 0 deletions test/functional/generated_members.rc
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@
[Messages Control]
disable=too-few-public-methods

[typecheck]
generated-members=DoesNotExist,"[a-zA-Z] _set{1,2}""
80 changes: 47 additions & 33 deletions test/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 18,53 @@
import unittest

from pylint.lint import Run
from pylint.reporters import BaseReporter
from pylint.reporters.text import *
from pylint.reporters.html import HTMLReporter

HERE = abspath(dirname(__file__))


class MultiReporter(BaseReporter):
def __init__(self, reporters):
self._reporters = reporters

def on_set_current_module(self, *args, **kwargs):
for rep in self._reporters:
rep.on_set_current_module(*args, **kwargs)

def add_message(self, *args, **kwargs):
for rep in self._reporters:
rep.add_message(*args, **kwargs)

def display_results(self, layout):
pass

@property
def out(self):
return self._reporters[0].out

@property
def linter(self):
return self._linter

@linter.setter
def linter(self, value):
self._linter = value
for rep in self._reporters:
rep.linter = value


class RunTC(unittest.TestCase):

def _runtest(self, args, reporter=None, out=None, code=28):
if out is None:
out = StringIO()
if args and args[-1].startswith('pylint.lint'):
try:
import cProfile, pstats
except ImportError:
code = 1
try:
sys.stderr = sys.stdout = out
try:
Run(args, reporter=reporter)
except SystemExit, ex:
except SystemExit as ex:
if reporter:
output = reporter.out.getvalue()
elif hasattr(out, 'getvalue'):
Expand All @@ -54,50 81,37 @@ def _runtest(self, args, reporter=None, out=None, code=28):
sys.stderr = sys.__stderr__
sys.stdout = sys.__stdout__

def test0(self):
"""make pylint checking itself"""
def test_pkginfo(self):
"""Make pylint check itself."""
self._runtest(['pylint.__pkginfo__'], reporter=TextReporter(StringIO()),
code=0)

def test1(self):
"""make pylint checking itself"""
self._runtest(['pylint.lint'], reporter=TextReporter(StringIO()))

def test2(self):
"""make pylint checking itself"""
self._runtest(['pylint.lint'], reporter=HTMLReporter(StringIO()))

def test3(self):
"""make pylint checking itself"""
self._runtest(['pylint.lint'], reporter=ColorizedTextReporter(StringIO()))
def test_all(self):
"""Make pylint check itself."""
reporters = [
TextReporter(StringIO()),
HTMLReporter(StringIO()),
ColorizedTextReporter(StringIO())
]
self._runtest(['pylint.lint'], reporter=MultiReporter(reporters))

def test_no_ext_file(self):
self._runtest([join(HERE, 'input', 'noext')], code=0)

def test_generated_members(self):
# XXX dual end quotation since optparse buggily remove one...
self._runtest(['--generated-members=objects,DoesNotExist,delay,retry,"[a-zA-Z] _set{1,2}""', 'pylint.lint'])

def test_w0704_ignored(self):
self._runtest([join(HERE, 'input', 'ignore_except_pass_by_default.py')], code=0)

def test_generate_config_option(self):
"""make pylint checking itself"""
self._runtest(['--generate-rcfile'], reporter=HTMLReporter(StringIO()),
code=0)
self._runtest(['--generate-rcfile'], code=0)

def test_help_message_option(self):
"""make pylint checking itself"""
self._runtest(['--help-msg', 'W0101'], reporter=HTMLReporter(StringIO()),
code=0)
self._runtest(['--help-msg', 'W0101'], code=0)

def test_error_help_message_option(self):
self._runtest(['--help-msg', 'WX101'], reporter=HTMLReporter(StringIO()),
code=0)
self._runtest(['--help-msg', 'WX101'], code=0)

def test_error_missing_arguments(self):
self._runtest([], reporter=HTMLReporter(StringIO()),
code=32)
self._runtest([], code=32)

def test_no_out_encoding(self):
"""test redirection of stdout with non ascii caracters
Expand Down

0 comments on commit 7255b51

Please sign in to comment.