summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Marek <shlomme@gmail.com>2014-03-30 14:19:33 -0700
committerTorsten Marek <shlomme@gmail.com>2014-03-30 14:19:33 -0700
commit66a922f1b008ef9bb8e574ae5430584caaaa43c6 (patch)
tree59e81d5ca3699c8a5e400b7c0f7e4b501a345445
parentb332c37c1fd90e54fcdeb716676950884d443661 (diff)
downloadpylint-66a922f1b008ef9bb8e574ae5430584caaaa43c6.tar.gz
Add a new decorator that can be used to declaratively set options on the checker instance for CheckerTestCase.
-rw-r--r--test/test_base.py10
-rw-r--r--test/test_format.py4
-rw-r--r--test/test_logging.py5
-rw-r--r--test/test_misc.py4
-rw-r--r--testutils.py14
5 files changed, 25 insertions, 12 deletions
diff --git a/test/test_base.py b/test/test_base.py
index 9bd3aa5..f35dfae 100644
--- a/test/test_base.py
+++ b/test/test_base.py
@@ -4,7 +4,7 @@ import re
from astroid import test_utils
from pylint.checkers import base
-from pylint.testutils import CheckerTestCase, Message
+from pylint.testutils import CheckerTestCase, Message, set_config
class DocstringTest(CheckerTestCase):
@@ -27,16 +27,16 @@ class DocstringTest(CheckerTestCase):
with self.assertAddsMessages(Message('missing-docstring', node=func, args=('function',))):
self.checker.visit_function(func)
+ @set_config(docstring_min_length=2)
def testShortFunctionNoDocstring(self):
- self.checker.config.docstring_min_length = 2
func = test_utils.extract_node("""
def func(tion):
pass""")
with self.assertNoMessages():
self.checker.visit_function(func)
+ @set_config(docstring_min_length=2)
def testFunctionNoDocstringByName(self):
- self.checker.config.docstring_min_length = 2
func = test_utils.extract_node("""
def __fun__(tion):
pass""")
@@ -57,11 +57,11 @@ class NameCheckerTest(CheckerTestCase):
'bad_names': set(),
}
+ @set_config(attr_rgx=re.compile('[A-Z]+'))
def testPropertyNames(self):
# If a method is annotated with @property, it's name should
# match the attr regex. Since by default the attribute regex is the same
# as the method regex, we override it here.
- self.checker.config.attr_rgx = re.compile('[A-Z]+')
methods = test_utils.extract_node("""
import abc
@@ -85,8 +85,8 @@ class NameCheckerTest(CheckerTestCase):
args=('attribute', 'bar'))):
self.checker.visit_function(methods[1])
+ @set_config(attr_rgx=re.compile('[A-Z]+'))
def testPropertySetters(self):
- self.checker.config.attr_rgx = re.compile('[A-Z]+')
method = test_utils.extract_node("""
class FooClass(object):
@property
diff --git a/test/test_format.py b/test/test_format.py
index 866fc29..9494f75 100644
--- a/test/test_format.py
+++ b/test/test_format.py
@@ -27,7 +27,7 @@ from astroid import test_utils
from pylint.checkers.format import *
-from pylint.testutils import CheckerTestCase, Message
+from pylint.testutils import CheckerTestCase, Message, set_config
def tokenize_str(code):
@@ -171,8 +171,8 @@ class CheckSpaceTest(CheckerTestCase):
with self.assertNoMessages():
self.checker.process_tokens(tokenize_str('(a,)\n'))
+ @set_config(no_space_check=[])
def testTrailingCommaBad(self):
- self.checker.config.no_space_check = []
with self.assertAddsMessages(
Message('C0326', line=1,
args=('No', 'allowed', 'before', 'bracket', '(a, )\n ^'))):
diff --git a/test/test_logging.py b/test/test_logging.py
index 85d3c82..fe7e638 100644
--- a/test/test_logging.py
+++ b/test/test_logging.py
@@ -7,7 +7,7 @@ from astroid import test_utils
from pylint.checkers import logging
-from pylint.testutils import CheckerTestCase, Message
+from pylint.testutils import CheckerTestCase, Message, set_config
class LoggingModuleDetectionTest(CheckerTestCase):
@@ -33,9 +33,8 @@ class LoggingModuleDetectionTest(CheckerTestCase):
with self.assertAddsMessages(Message('W1201', node=stmts[1])):
self.checker.visit_callfunc(stmts[1])
+ @set_config(logging_modules=['logging', 'my.logging'])
def test_nonstandard_logging_module(self):
- self.checker.config.logging_modules = (
- 'logging', 'my.logging')
stmts = test_utils.extract_node("""
from my import logging as blogging #@
blogging.warn('%s' % '%s') #@
diff --git a/test/test_misc.py b/test/test_misc.py
index 5b40394..5a10936 100644
--- a/test/test_misc.py
+++ b/test/test_misc.py
@@ -23,7 +23,7 @@ import contextlib
from logilab.common.testlib import unittest_main
from astroid import test_utils
from pylint.checkers import misc, variables
-from pylint.testutils import CheckerTestCase, Message, linter
+from pylint.testutils import CheckerTestCase, Message, linter, set_config
@contextlib.contextmanager
@@ -58,8 +58,8 @@ class FixmeTest(CheckerTestCase):
Message(msg_id='W0511', line=2, args=u'FIXME')):
self.checker.process_module(module)
+ @set_config(notes=[])
def test_empty_fixme_regex(self):
- self.checker.config.notes = []
with create_file_backed_module(
"""a = 1
# fixme
diff --git a/testutils.py b/testutils.py
index 818a576..668bd6d 100644
--- a/testutils.py
+++ b/testutils.py
@@ -18,6 +18,7 @@ from __future__ import with_statement
import collections
import contextlib
+import functools
import sys
import re
@@ -149,6 +150,19 @@ class UnittestLinter(object):
self.stats[name] = value
+def set_config(**kwargs):
+ """Decorator for setting config values on a checker."""
+ def _Wrapper(fun):
+ functools.wraps(fun)
+ def _Forward(self):
+ for key, value in kwargs.iteritems():
+ setattr(self.checker.config, key, value)
+ fun(self)
+
+ return _Forward
+ return _Wrapper
+
+
class CheckerTestCase(testlib.TestCase):
"""A base testcase class for unittesting individual checker classes."""
CHECKER_CLASS = None