diff options
author | Torsten Marek <shlomme@gmail.com> | 2014-07-24 19:04:47 +0200 |
---|---|---|
committer | Torsten Marek <shlomme@gmail.com> | 2014-07-24 19:04:47 +0200 |
commit | d76865583f0103915150ed901afeceba9f2eadba (patch) | |
tree | 13fdc313ec69358a16580f06b5e38d610ff65cb1 | |
parent | 328c824b73debaeee050f39043ba78b0b512ecc5 (diff) | |
download | pylint-d76865583f0103915150ed901afeceba9f2eadba.tar.gz |
Make pylint compatible with Python 2.5 again, and make all the tests pass (Closes: #278).
43 files changed, 263 insertions, 222 deletions
diff --git a/checkers/typecheck.py b/checkers/typecheck.py index 3bcb099..efc0909 100644 --- a/checkers/typecheck.py +++ b/checkers/typecheck.py @@ -386,7 +386,8 @@ accessed. Python regular expressions are accepted.'} if isinstance(arg, astroid.Keyword): keyword = arg.arg if keyword in keyword_args: - self.add_message('duplicate-keyword-arg', node=node, args=keyword) + self.add_message('duplicate-keyword-arg', node=node, + args=(keyword, 'function')) keyword_args.add(keyword) else: num_positional_args += 1 diff --git a/test/functional/abstract_abc_methods.args b/test/functional/abstract_abc_methods.args new file mode 100644 index 0000000..2b38575 --- /dev/null +++ b/test/functional/abstract_abc_methods.args @@ -0,0 +1,3 @@ +[testoptions] +min_pyver=2.6 + diff --git a/test/input/func_noerror_abstract_method.py b/test/functional/abstract_abc_methods.py index 18228c6..2e2bb13 100644 --- a/test/input/func_noerror_abstract_method.py +++ b/test/functional/abstract_abc_methods.py @@ -1,13 +1,10 @@ """ This should not warn about `prop` being abstract in Child """
-
# pylint: disable=too-few-public-methods,abstract-class-little-used
-__revision__ = None
-
import abc
class Parent(object):
- """ Class """
+ """Abstract Base Class """
__metaclass__ = abc.ABCMeta
@property
diff --git a/test/functional/anomalous_unicode_escape.args b/test/functional/anomalous_unicode_escape.args new file mode 100644 index 0000000..8bfa6c0 --- /dev/null +++ b/test/functional/anomalous_unicode_escape.args @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=2.6 diff --git a/test/input/func_raw_escapes.py b/test/functional/anomalous_unicode_escape.py index b08b6f1..19a6912 100644 --- a/test/input/func_raw_escapes.py +++ b/test/functional/anomalous_unicode_escape.py @@ -2,8 +2,9 @@ """Test for backslash escapes in byte vs unicode strings""" # Would be valid in Unicode, but probably not what you want otherwise -BAD_UNICODE = b'\u0042' -BAD_LONG_UNICODE = b'\U00000042' +BAD_UNICODE = b'\u0042' # [anomalous-unicode-escape-in-string] +BAD_LONG_UNICODE = b'\U00000042' # [anomalous-unicode-escape-in-string] +# +1:[anomalous-unicode-escape-in-string] BAD_NAMED_UNICODE = b'\N{GREEK SMALL LETTER ALPHA}' GOOD_UNICODE = u'\u0042' diff --git a/test/functional/anomalous_unicode_escape.txt b/test/functional/anomalous_unicode_escape.txt new file mode 100644 index 0000000..5c1acc7 --- /dev/null +++ b/test/functional/anomalous_unicode_escape.txt @@ -0,0 +1,3 @@ +anomalous-unicode-escape-in-string:5::Anomalous Unicode escape in byte string: '\u'. String constant might be missing an r or u prefix. +anomalous-unicode-escape-in-string:6::Anomalous Unicode escape in byte string: '\U'. String constant might be missing an r or u prefix. +anomalous-unicode-escape-in-string:8::Anomalous Unicode escape in byte string: '\N'. String constant might be missing an r or u prefix. diff --git a/test/functional/future_unicode_literals.args b/test/functional/future_unicode_literals.args new file mode 100644 index 0000000..d5fd0ce --- /dev/null +++ b/test/functional/future_unicode_literals.args @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=2.6
\ No newline at end of file diff --git a/test/input/func_unicode_literal.py b/test/functional/future_unicode_literals.py index fa47902..30c2bd6 100644 --- a/test/input/func_unicode_literal.py +++ b/test/functional/future_unicode_literals.py @@ -1,7 +1,6 @@ """Unicode literals in Python 2.*""" from __future__ import unicode_literals -__revision__ = 0 -BAD_STRING = b'\u1234' +BAD_STRING = b'\u1234' # >= 2.7.4:[anomalous-unicode-escape-in-string] GOOD_STRING = '\u1234' diff --git a/test/functional/future_unicode_literals.txt b/test/functional/future_unicode_literals.txt new file mode 100644 index 0000000..c490da5 --- /dev/null +++ b/test/functional/future_unicode_literals.txt @@ -0,0 +1 @@ +anomalous-unicode-escape-in-string:5::Anomalous Unicode escape in byte string: '\u'. String constant might be missing an r or u prefix. diff --git a/test/functional/name_styles.args b/test/functional/name_styles.args new file mode 100644 index 0000000..1a63e67 --- /dev/null +++ b/test/functional/name_styles.args @@ -0,0 +1,5 @@ +[testoptions] +min_pyver=2.6 + +[Messages Control] +disable=too-few-public-methods,abstract-class-not-used,global-statement diff --git a/test/functional/name_styles.py b/test/functional/name_styles.py new file mode 100644 index 0000000..be3e96d --- /dev/null +++ b/test/functional/name_styles.py @@ -0,0 +1,117 @@ +"""Test for the invalid-name warning.""" +import abc +import collections + +GOOD_CONST_NAME = '' +bad_const_name = 0 # [invalid-name] + + +def BADFUNCTION_name(): # [invalid-name] + """Bad function name.""" + BAD_LOCAL_VAR = 1 # [invalid-name] + print BAD_LOCAL_VAR + + +def func_bad_argname(NOT_GOOD): # [invalid-name] + """Function with a badly named argument.""" + return NOT_GOOD + + +def no_nested_args(arg1, arg21, arg22): + """Well-formed function.""" + print arg1, arg21, arg22 + + +class bad_class_name(object): # [invalid-name] + """Class with a bad name.""" + + +class CorrectClassName(object): + """Class with a good name.""" + + def __init__(self): + self._good_private_name = 10 + self.__good_real_private_name = 11 + self.good_attribute_name = 12 + self._Bad_AtTR_name = None # [invalid-name] + self.Bad_PUBLIC_name = None # [invalid-name] + + zz = 'Bad Class Attribute' # [invalid-name] + GOOD_CLASS_ATTR = 'Good Class Attribute' + + def BadMethodName(self): # [invalid-name] + """A Method with a bad name.""" + + def good_method_name(self): + """A method with a good name.""" + + def __DunDER_IS_not_free_for_all__(self): # [invalid-name] + """Another badly named method.""" + + +class DerivedFromCorrect(CorrectClassName): + """A derived class with an invalid inherited members. + + Derived attributes and methods with invalid names do not trigger warnings. + """ + zz = 'Now a good class attribute' + + def __init__(self): + super(DerivedFromCorrect, self).__init__() + self._Bad_AtTR_name = None # Ignored + + def BadMethodName(self): + """Ignored since the method is in the interface.""" + + +V = [WHAT_Ever_inListComp for WHAT_Ever_inListComp in GOOD_CONST_NAME] + +def class_builder(): + """Function returning a class object.""" + + class EmbeddedClass(object): + """Useless class.""" + + return EmbeddedClass + +# +1:[invalid-name] +BAD_NAME_FOR_CLASS = collections.namedtuple('Named', ['tuple']) +NEXT_BAD_NAME_FOR_CLASS = class_builder() # [invalid-name] + +GoodName = collections.namedtuple('Named', ['tuple']) +ToplevelClass = class_builder() + +# Aliases for classes have the same name constraints. +AlsoCorrect = CorrectClassName +NOT_CORRECT = CorrectClassName # [invalid-name] + + +def test_globals(): + """Names in global statements are also checked.""" + global NOT_CORRECT + global AlsoCorrect # [invalid-name] + NOT_CORRECT = 1 + AlsoCorrect = 2 + + +class FooClass(object): + """A test case for property names. + + Since by default, the regex for attributes is the same as the one + for method names, we check the warning messages to contain the + string 'attribute'. + """ + @property + def PROPERTY_NAME(self): # [invalid-name] + """Ignored.""" + pass + + @abc.abstractproperty + def ABSTRACT_PROPERTY_NAME(self): # [invalid-name] + """Ignored.""" + pass + + @PROPERTY_NAME.setter + def PROPERTY_NAME_SETTER(self): # [invalid-name] + """Ignored.""" + pass diff --git a/test/functional/name_styles.txt b/test/functional/name_styles.txt new file mode 100644 index 0000000..4f0ae53 --- /dev/null +++ b/test/functional/name_styles.txt @@ -0,0 +1,17 @@ +invalid-name:6::Invalid constant name "bad_const_name" +invalid-name:9:BADFUNCTION_name:Invalid function name "BADFUNCTION_name" +invalid-name:11:BADFUNCTION_name:Invalid variable name "BAD_LOCAL_VAR" +invalid-name:15:func_bad_argname:Invalid argument name "NOT_GOOD" +invalid-name:25:bad_class_name:Invalid class name "bad_class_name" +invalid-name:36:CorrectClassName.__init__:Invalid attribute name "_Bad_AtTR_name" +invalid-name:37:CorrectClassName.__init__:Invalid attribute name "Bad_PUBLIC_name" +invalid-name:39:CorrectClassName:Invalid class attribute name "zz" +invalid-name:42:CorrectClassName.BadMethodName:Invalid method name "BadMethodName" +invalid-name:48:CorrectClassName.__DunDER_IS_not_free_for_all__:Invalid method name "__DunDER_IS_not_free_for_all__" +invalid-name:78::Invalid class name "BAD_NAME_FOR_CLASS" +invalid-name:79::Invalid class name "NEXT_BAD_NAME_FOR_CLASS" +invalid-name:86::Invalid class name "NOT_CORRECT" +invalid-name:92:test_globals:Invalid constant name "AlsoCorrect" +invalid-name:105:FooClass.PROPERTY_NAME:Invalid attribute name "PROPERTY_NAME" +invalid-name:110:FooClass.ABSTRACT_PROPERTY_NAME:Invalid attribute name "ABSTRACT_PROPERTY_NAME" +invalid-name:115:FooClass.PROPERTY_NAME_SETTER:Invalid attribute name "PROPERTY_NAME_SETTER" diff --git a/test/functional/namedtuple_member_inference.args b/test/functional/namedtuple_member_inference.args new file mode 100644 index 0000000..8bfa6c0 --- /dev/null +++ b/test/functional/namedtuple_member_inference.args @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=2.6 diff --git a/test/functional/namedtuple_member_inference.py b/test/functional/namedtuple_member_inference.py new file mode 100644 index 0000000..675c3e2 --- /dev/null +++ b/test/functional/namedtuple_member_inference.py @@ -0,0 +1,21 @@ +"""Test namedtuple attributes. + +Regression test for: +https://bitbucket.org/logilab/pylint/issue/93/pylint-crashes-on-namedtuple-attribute +""" +__revision__ = None + +from collections import namedtuple +Thing = namedtuple('Thing', ()) + +Fantastic = namedtuple('Fantastic', ['foo']) + +def test(): + """Test member access in named tuples.""" + print Thing.x # [no-member] + fan = Fantastic(1) + print fan.foo + # Should not raise protected-access. + fan2 = fan._replace(foo=2) # [protected-access] + # This is a bug. + print fan2.foo # [no-member] diff --git a/test/functional/namedtuple_member_inference.txt b/test/functional/namedtuple_member_inference.txt new file mode 100644 index 0000000..87d9da4 --- /dev/null +++ b/test/functional/namedtuple_member_inference.txt @@ -0,0 +1,3 @@ +no-member:15:test:Class 'Thing' has no 'x' member +protected-access:19:test:Access to a protected member _replace of a client class +no-member:21:test:Instance of 'Fantastic' has no 'foo' member diff --git a/test/functional/suspicious_str_strip_call.args b/test/functional/suspicious_str_strip_call.args new file mode 100644 index 0000000..ecf5dcd --- /dev/null +++ b/test/functional/suspicious_str_strip_call.args @@ -0,0 +1,3 @@ +[testoptions] +min_pyver=2.6 +max_pyver=3.0 diff --git a/test/functional/suspicious_str_strip_call.py b/test/functional/suspicious_str_strip_call.py new file mode 100644 index 0000000..e859f25 --- /dev/null +++ b/test/functional/suspicious_str_strip_call.py @@ -0,0 +1,9 @@ +"""Suspicious str.strip calls.""" +__revision__ = 1 + +''.strip('yo') +''.strip() + +u''.strip('http://') # [bad-str-strip-call] +u''.lstrip('http://') # [bad-str-strip-call] +b''.rstrip('http://') # [bad-str-strip-call] diff --git a/test/functional/suspicious_str_strip_call.txt b/test/functional/suspicious_str_strip_call.txt new file mode 100644 index 0000000..ad714cc --- /dev/null +++ b/test/functional/suspicious_str_strip_call.txt @@ -0,0 +1,3 @@ +bad-str-strip-call:7::Suspicious argument in unicode.strip call +bad-str-strip-call:8::Suspicious argument in unicode.lstrip call +bad-str-strip-call:9::Suspicious argument in str.rstrip call diff --git a/test/functional/suspicious_str_strip_call_py3.args b/test/functional/suspicious_str_strip_call_py3.args new file mode 100644 index 0000000..c093be2 --- /dev/null +++ b/test/functional/suspicious_str_strip_call_py3.args @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.0 diff --git a/test/functional/suspicious_str_strip_call_py3.py b/test/functional/suspicious_str_strip_call_py3.py new file mode 100644 index 0000000..e859f25 --- /dev/null +++ b/test/functional/suspicious_str_strip_call_py3.py @@ -0,0 +1,9 @@ +"""Suspicious str.strip calls.""" +__revision__ = 1 + +''.strip('yo') +''.strip() + +u''.strip('http://') # [bad-str-strip-call] +u''.lstrip('http://') # [bad-str-strip-call] +b''.rstrip('http://') # [bad-str-strip-call] diff --git a/test/functional/suspicious_str_strip_call_py3.txt b/test/functional/suspicious_str_strip_call_py3.txt new file mode 100644 index 0000000..81f32cf --- /dev/null +++ b/test/functional/suspicious_str_strip_call_py3.txt @@ -0,0 +1,3 @@ +bad-str-strip-call:7::Suspicious argument in str.strip call +bad-str-strip-call:8::Suspicious argument in str.lstrip call +bad-str-strip-call:9::Suspicious argument in bytes.rstrip call diff --git a/test/input/func_bad_str_strip_call.py b/test/input/func_bad_str_strip_call.py deleted file mode 100644 index 2d94a6e..0000000 --- a/test/input/func_bad_str_strip_call.py +++ /dev/null @@ -1,9 +0,0 @@ -"""Suspicious str.strip calls.""" -__revision__ = 1 - -''.strip('yo') -''.strip() - -u''.strip('http://') -u''.lstrip('http://') -b''.rstrip('http://') diff --git a/test/input/func_ctor_arguments.py b/test/input/func_ctor_arguments.py index c708855..7bfc3a2 100644 --- a/test/input/func_ctor_arguments.py +++ b/test/input/func_ctor_arguments.py @@ -62,13 +62,16 @@ ClassNew(1, kwarg=1) ClassNew(1, 2, 3) ClassNew(one=2) -import abc + +class Metaclass(type): + pass + def with_metaclass(meta, base=object): """Create a new type that can be used as a metaclass.""" return meta("NewBase", (base, ), {}) -class ClassWithMeta(with_metaclass(abc.ABCMeta)): +class ClassWithMeta(with_metaclass(Metaclass)): pass ClassWithMeta() diff --git a/test/input/func_name_checking.py b/test/input/func_name_checking.py deleted file mode 100644 index d19d946..0000000 --- a/test/input/func_name_checking.py +++ /dev/null @@ -1,135 +0,0 @@ -# pylint: disable=R0903,R0201,R0921,W0603 -"""Test for the invalid-name (C0103) warning.""" - -__revision__ = 1 - -import collections - -def Run(): - """method without any good name""" - class B(object): - """nested class should not be tested has a variable""" - def __init__(self): - pass - bBb = 1 - return A, bBb, B - -def run(): - """anothrer method without only good name""" - class Aaa(object): - """nested class should not be tested has a variable""" - def __init__(self): - pass - bbb = 1 - return bbb, Aaa - -A = None - -def HOHOHOHO(): - """yo""" - HIHIHI = 1 - print HIHIHI - -class xyz(object): - """yo""" - - zz = 'Bad Class Attribute' - - def __init__(self): - pass - - def Youplapoum(self): - """bad method name""" - - -class Derived(xyz): - """Derived class.""" - zz = 'Not a bad class attribute' - - -def no_nested_args(arg1, arg21, arg22): - """a function which had nested arguments but no more""" - print arg1, arg21, arg22 - - -GOOD_CONST_NAME = '' -benpasceluila = 0 - -class Correct(object): - """yo""" - def __init__(self): - self.cava = 12 - self._Ca_va_Pas = None - - def BadMethodName(self): - """Ignored.""" - -V = [WHAT_Ever_inListComp for WHAT_Ever_inListComp in GOOD_CONST_NAME] - -def class_builder(): - """Function returning a class object.""" - - class EmbeddedClass(object): - """Useless class.""" - - return EmbeddedClass - -BAD_NAME_FOR_CLASS = collections.namedtuple('Named', ['tuple']) -NEXT_BAD_NAME_FOR_CLASS = class_builder() - -GoodName = collections.namedtuple('Named', ['tuple']) -ToplevelClass = class_builder() - -AlsoCorrect = Correct -NOT_CORRECT = Correct - - -def test_globals(): - """Names in global statements are also checked.""" - global NOT_CORRECT - global AlsoCorrect - NOT_CORRECT = 1 - AlsoCorrect = 2 - - -class DerivedFromCorrect(Correct): - """A derived class with an invalid inherited members. - - Derived attributes and methods with invalid names do not trigger warnings. - """ - - def __init__(self): - super(DerivedFromCorrect, self).__init__() - self._Ca_va_Pas = None - - def BadMethodName(self): - """Ignored.""" - -import abc - -class FooClass(object): - """A test case for property names. - - Since by default, the regex for attributes is the same as the one - for method names, we check the warning messages to contain the - string 'attribute'. - """ - @property - def PROPERTY_NAME(self): - """Ignored.""" - pass - - @abc.abstractproperty - def ABSTRACT_PROPERTY_NAME(self): - """Ignored.""" - pass - - @PROPERTY_NAME.setter - def PROPERTY_NAME_SETTER(self): - """Ignored.""" - pass - - -def func_bad_argname(NOT_GOOD): - """Function with a badly named argument.""" - return NOT_GOOD diff --git a/test/input/func_namedtuple.py b/test/input/func_namedtuple.py deleted file mode 100644 index 8cfd048..0000000 --- a/test/input/func_namedtuple.py +++ /dev/null @@ -1,10 +0,0 @@ -"""Test namedtuple attributes. - -Regression test for: -https://bitbucket.org/logilab/pylint/issue/93/pylint-crashes-on-namedtuple-attribute -""" -__revision__ = None - -from collections import namedtuple -Thing = namedtuple('Thing', ()) -print Thing.x diff --git a/test/input/func_noerror_abstract_method_py30.py b/test/input/func_noerror_abstract_method_py30.py deleted file mode 100644 index c237cb4..0000000 --- a/test/input/func_noerror_abstract_method_py30.py +++ /dev/null @@ -1,19 +0,0 @@ -""" This should not warn about `prop` being abstract in Child """
-
-# pylint: disable=too-few-public-methods,abstract-class-little-used,no-init,old-style-class
-
-__revision__ = None
-
-import abc
-
-class Parent(metaclass=abc.ABCMeta):
- """ Class """
-
- @property
- @abc.abstractmethod
- def prop(self):
- """ Abstract """
-
-class Child(Parent):
- """ No warning for the following. """
- prop = property(lambda self: 1)
diff --git a/test/input/func_w0404.py b/test/input/func_w0404.py index 0e2f727..f475a4d 100644 --- a/test/input/func_w0404.py +++ b/test/input/func_w0404.py @@ -7,8 +7,8 @@ import sys import xml.etree.ElementTree from xml.etree import ElementTree -from multiprocessing import pool -import multiprocessing.pool +from email import encoders +import email.encoders import sys @@ -24,4 +24,4 @@ def reimport(): del sys -del sys, ElementTree, xml.etree.ElementTree, pool, multiprocessing.pool +del sys, ElementTree, xml.etree.ElementTree, encoders, email.encoders diff --git a/test/messages/func_bad_str_strip_call.txt b/test/messages/func_bad_str_strip_call.txt deleted file mode 100644 index 44b8780..0000000 --- a/test/messages/func_bad_str_strip_call.txt +++ /dev/null @@ -1,3 +0,0 @@ -E: 7: Suspicious argument in unicode.strip call -E: 8: Suspicious argument in unicode.lstrip call -E: 9: Suspicious argument in str.rstrip call diff --git a/test/messages/func_bad_str_strip_call_py30.txt b/test/messages/func_bad_str_strip_call_py30.txt deleted file mode 100644 index 8ea0372..0000000 --- a/test/messages/func_bad_str_strip_call_py30.txt +++ /dev/null @@ -1,3 +0,0 @@ -E: 7: Suspicious argument in str.strip call -E: 8: Suspicious argument in str.lstrip call -E: 9: Suspicious argument in bytes.rstrip call diff --git a/test/messages/func_name_checking.txt b/test/messages/func_name_checking.txt deleted file mode 100644 index e8d0a73..0000000 --- a/test/messages/func_name_checking.txt +++ /dev/null @@ -1,18 +0,0 @@ -C: 10:Run.B: Invalid class name "B" -C: 14:Run: Invalid variable name "bBb" -C: 28:HOHOHOHO: Invalid function name "HOHOHOHO" -C: 30:HOHOHOHO: Invalid variable name "HIHIHI" -C: 33:xyz: Invalid class name "xyz" -C: 36:xyz: Invalid class attribute name "zz" -C: 41:xyz.Youplapoum: Invalid method name "Youplapoum" -C: 56: Invalid constant name "benpasceluila" -C: 62:Correct.__init__: Invalid attribute name "_Ca_va_Pas" -C: 64:Correct.BadMethodName: Invalid method name "BadMethodName" -C: 77: Invalid class name "BAD_NAME_FOR_CLASS" -C: 78: Invalid class name "NEXT_BAD_NAME_FOR_CLASS" -C: 84: Invalid class name "NOT_CORRECT" -C: 90:test_globals: Invalid constant name "AlsoCorrect" -C:118:FooClass.PROPERTY_NAME: Invalid attribute name "PROPERTY_NAME" -C:123:FooClass.ABSTRACT_PROPERTY_NAME: Invalid attribute name "ABSTRACT_PROPERTY_NAME" -C:128:FooClass.PROPERTY_NAME_SETTER: Invalid attribute name "PROPERTY_NAME_SETTER" -C:133:func_bad_argname: Invalid argument name "NOT_GOOD" diff --git a/test/messages/func_namedtuple.txt b/test/messages/func_namedtuple.txt deleted file mode 100644 index d1ef2b1..0000000 --- a/test/messages/func_namedtuple.txt +++ /dev/null @@ -1 +0,0 @@ -E: 10: Class 'Thing' has no 'x' member diff --git a/test/messages/func_w0404.txt b/test/messages/func_w0404.txt index 73d770f..cd7f3e2 100644 --- a/test/messages/func_w0404.txt +++ b/test/messages/func_w0404.txt @@ -1,5 +1,5 @@ W: 8: Reimport 'ElementTree' (imported line 7) -W: 11: Reimport 'multiprocessing.pool' (imported line 10) +W: 11: Reimport 'email.encoders' (imported line 10) W: 13: Reimport 'sys' (imported line 5) W: 23:reimport: Redefining name 'sys' from outer scope (line 5) W: 23:reimport: Reimport 'sys' (imported line 5) diff --git a/test/test_func.py b/test/test_func.py index d3fb9be..6a64ec2 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -44,7 +44,7 @@ class LintTestNonExistentModuleTC(LintTestUsingModule): class TestTests(testlib.TestCase): """check that all testable messages have been checked""" - PORTED = set(['I0001', 'I0010', 'W0712', 'E1001']) + PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310']) @testlib.tag('coverage') def test_exhaustivity(self): diff --git a/test/test_functional.py b/test/test_functional.py index ae12360..5c5cafa 100644 --- a/test/test_functional.py +++ b/test/test_functional.py @@ -1,4 +1,5 @@ """Functional full-module tests for PyLint.""" +from __future__ import with_statement import ConfigParser import cStringIO import operator @@ -88,15 +89,15 @@ class TestFile(object): @property def expected_output(self): - return self._file_type('.txt') + return self._file_type('.txt', check_exists=False) @property def source(self): return self._file_type('.py') - def _file_type(self, ext): + def _file_type(self, ext, check_exists=True): name = os.path.join(self._directory, self.base + ext) - if os.path.exists(name): + if not check_exists or os.path.exists(name): return name else: raise NoFileError @@ -171,12 +172,12 @@ class LintModuleTest(testlib.TestCase): self._linter = lint.PyLinter() self._linter.set_reporter(test_reporter) self._linter.config.persistent = 0 + checkers.initialize(self._linter) self._linter.disable('I') try: self._linter.load_file_configuration(test_file.option_file) except NoFileError: pass - checkers.initialize(self._linter) self._test_file = test_file def shortDescription(self): diff --git a/test/unittest_checker_base.py b/test/unittest_checker_base.py index 972c783..1ac14b9 100644 --- a/test/unittest_checker_base.py +++ b/test/unittest_checker_base.py @@ -1,6 +1,8 @@ """Unittest for the base checker.""" +from __future__ import with_statement import re +import sys from astroid import test_utils from pylint.checkers import base @@ -80,6 +82,8 @@ class NameCheckerTest(CheckerTestCase): @set_config(attr_rgx=re.compile('[A-Z]+')) def test_property_names(self): + if sys.version_info < (2, 6): + self.skip('abc module does not exist on 2.5') # 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. diff --git a/test/unittest_checker_classes.py b/test/unittest_checker_classes.py index 388a24a..b185322 100644 --- a/test/unittest_checker_classes.py +++ b/test/unittest_checker_classes.py @@ -1,4 +1,5 @@ """Unit tests for the variables checker.""" +from __future__ import with_statement from astroid import test_utils from pylint.checkers import classes diff --git a/test/unittest_checker_format.py b/test/unittest_checker_format.py index b9fba5c..82b079a 100644 --- a/test/unittest_checker_format.py +++ b/test/unittest_checker_format.py @@ -15,6 +15,7 @@ Check format checker helper functions """ +from __future__ import with_statement import sys import re diff --git a/test/unittest_checker_logging.py b/test/unittest_checker_logging.py index cbacada..c36aec9 100644 --- a/test/unittest_checker_logging.py +++ b/test/unittest_checker_logging.py @@ -2,6 +2,7 @@ """ Unittest for the logging checker. """ +from __future__ import with_statement from logilab.common.testlib import unittest_main from astroid import test_utils diff --git a/test/unittest_checker_misc.py b/test/unittest_checker_misc.py index 670d53c..a494b1a 100644 --- a/test/unittest_checker_misc.py +++ b/test/unittest_checker_misc.py @@ -15,6 +15,8 @@ """ Tests for the misc checker. """ +from __future__ import with_statement + import sys import tempfile import os diff --git a/test/unittest_checker_typecheck.py b/test/unittest_checker_typecheck.py index 0a8687b..93c73ea 100644 --- a/test/unittest_checker_typecheck.py +++ b/test/unittest_checker_typecheck.py @@ -1,4 +1,5 @@ """Unittest for the type checker.""" +from __future__ import with_statement from astroid import test_utils from pylint.checkers import typecheck diff --git a/test/unittest_checker_variables.py b/test/unittest_checker_variables.py index 20a0d9e..a3776d7 100644 --- a/test/unittest_checker_variables.py +++ b/test/unittest_checker_variables.py @@ -1,4 +1,5 @@ """Unit tests for the variables checker.""" +from __future__ import with_statement import sys import os diff --git a/test/unittest_checkers_utils.py b/test/unittest_checkers_utils.py index 72108d7..40186f5 100644 --- a/test/unittest_checkers_utils.py +++ b/test/unittest_checkers_utils.py @@ -15,6 +15,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """test the pylint.checkers.utils module """ +from __future__ import with_statement __revision__ = '$Id: unittest_checkers_utils.py,v 1.6 2005-11-02 09:22:07 syt Exp $' diff --git a/testutils.py b/testutils.py index daf7477..ef423c5 100644 --- a/testutils.py +++ b/testutils.py @@ -122,10 +122,30 @@ class TestReporter(BaseReporter): """ignore layouts""" -class Message(collections.namedtuple('Message', - ['msg_id', 'line', 'node', 'args'])): - def __new__(cls, msg_id, line=None, node=None, args=None): - return tuple.__new__(cls, (msg_id, line, node, args)) +if sys.version_info < (2, 6): + class Message(tuple): + def __new__(cls, msg_id, line=None, node=None, args=None): + return tuple.__new__(cls, (msg_id, line, node, args)) + + @property + def msg_id(self): + return self[0] + @property + def line(self): + return self[1] + @property + def node(self): + return self[2] + @property + def args(self): + return self[3] + + +else: + class Message(collections.namedtuple('Message', + ['msg_id', 'line', 'node', 'args'])): + def __new__(cls, msg_id, line=None, node=None, args=None): + return tuple.__new__(cls, (msg_id, line, node, args)) class UnittestLinter(object): |