diff options
| author | Torsten Marek <shlomme@gmail.com> | 2014-07-26 17:11:14 +0200 |
|---|---|---|
| committer | Torsten Marek <shlomme@gmail.com> | 2014-07-26 17:11:14 +0200 |
| commit | 97006fcc02e1035c6b5c680e4f07b7e58fb14a12 (patch) | |
| tree | 773da6bbbd64430a127fd3d79ba5e2835ac2be1e | |
| parent | fc7f9b8e0526f4ca9eb525479180843cc612bd1d (diff) | |
| download | pylint-git-97006fcc02e1035c6b5c680e4f07b7e58fb14a12.tar.gz | |
Remove dependency on logilab.testlib in the test suite (also removes Python 2.5 compatibility).
| -rwxr-xr-x | test/fulltest.sh | 19 | ||||
| -rw-r--r-- | test/test_func.py | 15 | ||||
| -rw-r--r-- | test/test_functional.py | 63 | ||||
| -rw-r--r-- | test/test_import_graph.py | 8 | ||||
| -rw-r--r-- | test/test_regr.py | 8 | ||||
| -rw-r--r-- | test/test_self.py (renamed from test/smoketest.py) | 19 | ||||
| -rw-r--r-- | test/unittest_checker_base.py | 5 | ||||
| -rw-r--r-- | test/unittest_checker_classes.py | 5 | ||||
| -rw-r--r-- | test/unittest_checker_format.py | 15 | ||||
| -rw-r--r-- | test/unittest_checker_logging.py | 9 | ||||
| -rw-r--r-- | test/unittest_checker_misc.py | 13 | ||||
| -rw-r--r-- | test/unittest_checker_similar.py | 21 | ||||
| -rw-r--r-- | test/unittest_checker_typecheck.py | 5 | ||||
| -rw-r--r-- | test/unittest_checker_variables.py | 5 | ||||
| -rw-r--r-- | test/unittest_checkers_utils.py | 12 | ||||
| -rw-r--r-- | test/unittest_lint.py | 56 | ||||
| -rw-r--r-- | test/unittest_pyreverse_writer.py | 13 | ||||
| -rw-r--r-- | test/unittest_reporting.py | 11 | ||||
| -rw-r--r-- | test/unittest_utils.py | 7 | ||||
| -rw-r--r-- | testutils.py | 41 | ||||
| -rw-r--r-- | tox.ini | 6 |
21 files changed, 164 insertions, 192 deletions
diff --git a/test/fulltest.sh b/test/fulltest.sh deleted file mode 100755 index 95d784f48..000000000 --- a/test/fulltest.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -if [ $@ ] ; then - PYVERSIONS=$@ -else - PYVERSIONS=`pyversions -iv` -fi - -cd `dirname $0` - -for ver in $PYVERSIONS; do - echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" - echo `python$ver -V` - echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" - python$ver `which pytest` - echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" - echo `python$ver -V` -OO - python$ver -OO `which pytest` -done diff --git a/test/test_func.py b/test/test_func.py index f11eeaab0..2c05d09c4 100644 --- a/test/test_func.py +++ b/test/test_func.py @@ -22,8 +22,6 @@ import re from os import getcwd from os.path import abspath, dirname, join -from logilab.common import testlib - from pylint.testutils import (make_tests, LintTestUsingModule, LintTestUsingFile, LintTestUpdate, cb_test_gen, linter, test_reporter) @@ -40,9 +38,9 @@ quote = "'" if sys.version_info >= (3, 3) else '' class LintTestNonExistentModuleTC(LintTestUsingModule): module = 'nonexistent' _get_expected = lambda self: 'F: 1: No module named %snonexistent%s\n' % (quote, quote) - tags = testlib.Tags(('generated','pylint_input_%s' % module)) -class TestTests(testlib.TestCase): + +class TestTests(unittest.TestCase): """check that all testable messages have been checked""" PORTED = set(['I0001', 'I0010', 'W0712', 'E1001', 'W1402', 'E1310', 'E0202', 'W0711', 'W0108', 'E0603', 'W0710', 'E0710', 'E0711', 'W1001', @@ -51,7 +49,6 @@ class TestTests(testlib.TestCase): 'W0109', 'E1004', 'W0604', 'W0601', 'W0602', 'C0112', 'C0330', 'C0325', 'E0211', 'W1501']) - @testlib.tag('coverage') def test_exhaustivity(self): # skip fatal messages not_tested = set(msg.msgid for msg in linter.msgs_store.messages @@ -104,10 +101,14 @@ FILTER_RGX = None UPDATE = False def suite(): - return testlib.TestSuite([unittest.makeSuite(test, suiteClass=testlib.TestSuite) + return unittest.TestSuite([unittest.makeSuite(test, suiteClass=unittest.TestSuite) for test in gen_tests(FILTER_RGX)]) +def load_tests(loader, tests, pattern): + return suite() + + if __name__=='__main__': if '-u' in sys.argv: UPDATE = True @@ -116,4 +117,4 @@ if __name__=='__main__': if len(sys.argv) > 1: FILTER_RGX = sys.argv[1] del sys.argv[1] - testlib.unittest_main(defaultTest='suite') + unittest.main(defaultTest='suite') diff --git a/test/test_functional.py b/test/test_functional.py index ad844b408..fb495e0c7 100644 --- a/test/test_functional.py +++ b/test/test_functional.py @@ -1,30 +1,35 @@ """Functional full-module tests for PyLint.""" -from __future__ import with_statement +from __future__ import unicode_literals +import collections import ConfigParser -import contextlib -import cStringIO +import io import operator import os import re import sys - -from logilab.common import testlib +import unittest from pylint import lint from pylint import reporters from pylint import checkers + class NoFileError(Exception): pass # TODOs -# - use a namedtuple for expected lines # - implement exhaustivity tests -# - call skipTests in setUp when not using logilab.testlib any more. # If message files should be updated instead of checked. UPDATE = False +class OutputLine(collections.namedtuple('OutputLine', + ['symbol', 'lineno', 'object', 'msg'])): + @classmethod + def from_msg(cls, msg): + return cls(msg.symbol, msg.line, msg.obj or '', msg.msg + '\n') + + # Common sub-expressions. _MESSAGE = {'msg': r'[a-z][a-z\-]+'} # Matches a #, @@ -123,10 +128,10 @@ def parse_expected_output(stream): parts = line.split(':', 3) if len(parts) != 4: symbol, lineno, obj, msg = lines.pop() - lines.append((symbol, lineno, obj, msg + line)) + lines.append(OutputLine(symbol, lineno, obj, msg + line)) else: linenum = int(parts[1]) - lines.append((parts[0], linenum, parts[2], parts[3])) + lines.append(OutputLine(parts[0], linenum, parts[2], parts[3])) return lines @@ -136,7 +141,7 @@ def get_expected_messages(stream): :param stream: File-like input stream. :returns: A dict mapping line,msg-symbol tuples to the count on this line. """ - messages = {} + messages = collections.Counter() for i, line in enumerate(stream): match = _EXPECTED_RE.search(line) if match is None: @@ -157,7 +162,6 @@ def get_expected_messages(stream): continue for msg_id in match.group('msgs').split(','): - messages.setdefault((line, msg_id.strip()), 0) messages[line, msg_id.strip()] += 1 return messages @@ -173,21 +177,19 @@ def multiset_difference(left_op, right_op): :returns: The two multisets of missing and unexpected messages. """ missing = left_op.copy() + missing.subtract(right_op) unexpected = {} - for key, value in right_op.iteritems(): - missing.setdefault(key, 0) - missing[key] -= value - if missing[key] == 0: - del missing[key] - elif missing[key] < 0: - unexpected.setdefault(key, 0) - unexpected[key] = -missing.pop(key) + for key, value in missing.items(): + if value <= 0: + missing.pop(key) + if value < 0: + unexpected[key] = -value return missing, unexpected -class LintModuleTest(testlib.TestCase): +class LintModuleTest(unittest.TestCase): def __init__(self, test_file): - super(LintModuleTest, self).__init__() + super(LintModuleTest, self).__init__('_runTest') test_reporter = TestReporter() self._linter = lint.PyLinter() self._linter.set_reporter(test_reporter) @@ -200,7 +202,7 @@ class LintModuleTest(testlib.TestCase): pass self._test_file = test_file - def check_test(self): + def setUp(self): if (sys.version_info < self._test_file.options['min_pyver'] or sys.version_info >= self._test_file.options['max_pyver']): self.skipTest( @@ -235,17 +237,14 @@ class LintModuleTest(testlib.TestCase): def _get_received(self): messages = self._linter.reporter.messages messages.sort(key=lambda m: (m.line, m.symbol, m.msg)) - received_msgs = {} + received_msgs = collections.Counter() received_output_lines = [] for msg in messages: - received_msgs.setdefault((msg.line, msg.symbol), 0) received_msgs[msg.line, msg.symbol] += 1 - received_output_lines.append( - (msg.symbol, msg.line, msg.obj or '', msg.msg + '\n')) + received_output_lines.append(OutputLine.from_msg(msg)) return received_msgs, received_output_lines - def runTest(self): - self.check_test() + def _runTest(self): self._linter.check([self._test_file.module]) expected_messages, expected_text = self._get_expected() @@ -303,7 +302,7 @@ class LintModuleOutputUpdate(LintModuleTest): def suite(): input_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'functional') - suite = testlib.TestSuite() + suite = unittest.TestSuite() for fname in os.listdir(input_dir): if fname != '__init__.py' and fname.endswith('.py'): test_file = TestFile(input_dir, fname) @@ -314,8 +313,12 @@ def suite(): return suite +def load_tests(loader, tests, pattern): + return suite() + + if __name__=='__main__': if '-u' in sys.argv: UPDATE = True sys.argv.remove('-u') - testlib.unittest_main(defaultTest='suite') + unittest.main(defaultTest='suite') diff --git a/test/test_import_graph.py b/test/test_import_graph.py index a1dfdc80e..54e58cf2b 100644 --- a/test/test_import_graph.py +++ b/test/test_import_graph.py @@ -1,15 +1,15 @@ import sys import os -from logilab.common.testlib import unittest_main, TestCase from os.path import exists from cStringIO import StringIO +import unittest from pylint.checkers import initialize, imports from pylint.lint import PyLinter from pylint.testutils import TestReporter -class DependenciesGraphTC(TestCase): +class DependenciesGraphTC(unittest.TestCase): """test the imports graph function""" dest = 'dependencies_graph.dot' @@ -34,7 +34,7 @@ URL="." node[shape="box"] } '''.strip()) -class ImportCheckerTC(TestCase): +class ImportCheckerTC(unittest.TestCase): def setUp(self): self.linter = l = PyLinter(reporter=TestReporter()) initialize(l) @@ -62,4 +62,4 @@ class ImportCheckerTC(TestCase): pass if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/test_regr.py b/test/test_regr.py index 8d76e2b7d..6fb0fc52f 100644 --- a/test/test_regr.py +++ b/test/test_regr.py @@ -20,8 +20,7 @@ to be incorporated in the automatic functional test framework import sys import os from os.path import abspath, dirname, join - -from logilab.common.testlib import TestCase, unittest_main +import unittest from pylint.testutils import TestReporter from pylint.lint import PyLinter @@ -37,7 +36,7 @@ checkers.initialize(linter) REGR_DATA = join(dirname(abspath(__file__)), 'regrtest_data') sys.path.insert(1, REGR_DATA) -class NonRegrTC(TestCase): +class NonRegrTC(unittest.TestCase): def setUp(self): """call reporter.finalize() to cleanup pending messages if a test finished badly @@ -138,5 +137,6 @@ class NonRegrTC(TestCase): got = linter.reporter.finalize().strip() self.assertEqual(got, "") + if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/smoketest.py b/test/test_self.py index 26e2c9ae0..e5c91c3ca 100644 --- a/test/smoketest.py +++ b/test/test_self.py @@ -15,8 +15,7 @@ import sys from os.path import join, dirname, abspath from cStringIO import StringIO import tempfile - -from logilab.common.testlib import TestCase, unittest_main, tag +import unittest from pylint.lint import Run from pylint.reporters.text import * @@ -24,7 +23,7 @@ from pylint.reporters.html import HTMLReporter HERE = abspath(dirname(__file__)) -class RunTC(TestCase): +class RunTC(unittest.TestCase): def _runtest(self, args, reporter=None, out=None, code=28): if out is None: @@ -55,63 +54,51 @@ class RunTC(TestCase): sys.stderr = sys.__stderr__ sys.stdout = sys.__stdout__ - @tag('smoke') def test0(self): """make pylint checking itself""" self._runtest(['pylint.__pkginfo__'], reporter=TextReporter(StringIO()), code=0) - @tag('smoke') def test1(self): """make pylint checking itself""" self._runtest(['pylint.lint'], reporter=TextReporter(StringIO())) - @tag('smoke') def test2(self): """make pylint checking itself""" self._runtest(['pylint.lint'], reporter=HTMLReporter(StringIO())) - @tag('smoke') def test3(self): """make pylint checking itself""" self._runtest(['pylint.lint'], reporter=ColorizedTextReporter(StringIO())) - @tag('smoke') def test_no_ext_file(self): self._runtest([join(HERE, 'input', 'noext')], code=0) - @tag('smoke') 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']) - @tag('smoke') def test_w0704_ignored(self): self._runtest([join(HERE, 'input', 'ignore_except_pass_by_default.py')], code=0) - @tag('smoke', 'help', 'config') def test_generate_config_option(self): """make pylint checking itself""" self._runtest(['--generate-rcfile'], reporter=HTMLReporter(StringIO()), code=0) - @tag('smoke', 'help') def test_help_message_option(self): """make pylint checking itself""" self._runtest(['--help-msg', 'W0101'], reporter=HTMLReporter(StringIO()), code=0) - @tag('smoke', 'help') def test_error_help_message_option(self): self._runtest(['--help-msg', 'WX101'], reporter=HTMLReporter(StringIO()), code=0) - @tag('smoke', 'usage') def test_error_missing_arguments(self): self._runtest([], reporter=HTMLReporter(StringIO()), code=32) - @tag('smoke', 'encoding') def test_no_out_encoding(self): """test redirection of stdout with non ascii caracters """ @@ -128,4 +115,4 @@ class RunTC(TestCase): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_checker_base.py b/test/unittest_checker_base.py index 1ac14b97f..fe0dbca8e 100644 --- a/test/unittest_checker_base.py +++ b/test/unittest_checker_base.py @@ -1,8 +1,8 @@ """Unittest for the base checker.""" -from __future__ import with_statement import re import sys +import unittest from astroid import test_utils from pylint.checkers import base @@ -223,5 +223,4 @@ class MultiNamingStyleTest(CheckerTestCase): if __name__ == '__main__': - from logilab.common.testlib import unittest_main - unittest_main() + unittest.main() diff --git a/test/unittest_checker_classes.py b/test/unittest_checker_classes.py index b185322ac..fd7fa4086 100644 --- a/test/unittest_checker_classes.py +++ b/test/unittest_checker_classes.py @@ -1,5 +1,5 @@ """Unit tests for the variables checker.""" -from __future__ import with_statement +import unittest from astroid import test_utils from pylint.checkers import classes @@ -20,3 +20,6 @@ class VariablesCheckerTC(CheckerTestCase): with self.assertAddsMessages(Message('access-member-before-definition', node=n1.target, args=('first', n2.lineno))): self.walk(n1.root()) + +if __name__ == '__main__': + unittest.main() diff --git a/test/unittest_checker_format.py b/test/unittest_checker_format.py index 82b079a55..1f31e28cc 100644 --- a/test/unittest_checker_format.py +++ b/test/unittest_checker_format.py @@ -15,15 +15,14 @@ Check format checker helper functions """ -from __future__ import with_statement - -import sys -import re +from __future__ import unicode_literals +import io from os import linesep +import re +import sys import tokenize -import StringIO -from logilab.common.testlib import TestCase, unittest_main + from astroid import test_utils from pylint.checkers.format import * @@ -32,7 +31,7 @@ from pylint.testutils import CheckerTestCase, Message, set_config def tokenize_str(code): - return list(tokenize.generate_tokens(StringIO.StringIO(code).readline)) + return list(tokenize.generate_tokens(io.StringIO(code).readline)) class MultiStatementLineTest(CheckerTestCase): @@ -255,4 +254,4 @@ class CheckSpaceTest(CheckerTestCase): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_checker_logging.py b/test/unittest_checker_logging.py index c36aec974..e25daac68 100644 --- a/test/unittest_checker_logging.py +++ b/test/unittest_checker_logging.py @@ -1,9 +1,6 @@ # Copyright 2014 Google Inc. All Rights Reserved. -""" -Unittest for the logging checker. -""" -from __future__ import with_statement -from logilab.common.testlib import unittest_main +"""Unittest for the logging checker.""" +import unittest from astroid import test_utils from pylint.checkers import logging @@ -47,4 +44,4 @@ class LoggingModuleDetectionTest(CheckerTestCase): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_checker_misc.py b/test/unittest_checker_misc.py index a494b1a6a..940b76d9d 100644 --- a/test/unittest_checker_misc.py +++ b/test/unittest_checker_misc.py @@ -12,15 +12,13 @@ # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -""" -Tests for the misc checker. -""" -from __future__ import with_statement +"""Tests for the misc checker.""" +import contextlib +import os import sys import tempfile -import os -import contextlib +import unittest from astroid import test_utils from pylint.checkers import misc @@ -69,5 +67,4 @@ class FixmeTest(CheckerTestCase): self.checker.process_module(module) if __name__ == '__main__': - from logilab.common.testlib import unittest_main - unittest_main() + unittest.main() diff --git a/test/unittest_checker_similar.py b/test/unittest_checker_similar.py index d797a5f46..8d68b81af 100644 --- a/test/unittest_checker_similar.py +++ b/test/unittest_checker_similar.py @@ -1,19 +1,18 @@ +import cStringIO import sys -from logilab.common.testlib import TestCase, unittest_main - -from cStringIO import StringIO from os.path import join, dirname, abspath +import unittest from pylint.checkers import similar SIMILAR1 = join(dirname(abspath(__file__)), 'input', 'similar1') SIMILAR2 = join(dirname(abspath(__file__)), 'input', 'similar2') -class SimilarTC(TestCase): +class SimilarTC(unittest.TestCase): """test the similar command line utility""" def test_ignore_comments(self): - sys.stdout = StringIO() + sys.stdout = cStringIO.StringIO() try: similar.Run(['--ignore-comments', SIMILAR1, SIMILAR2]) except SystemExit, ex: @@ -42,7 +41,7 @@ TOTAL lines=44 duplicates=10 percent=22.73 def test_ignore_docsrings(self): - sys.stdout = StringIO() + sys.stdout = cStringIO.StringIO() try: similar.Run(['--ignore-docstrings', SIMILAR1, SIMILAR2]) except SystemExit, ex: @@ -78,7 +77,7 @@ TOTAL lines=44 duplicates=13 percent=29.55 def test_ignore_imports(self): - sys.stdout = StringIO() + sys.stdout = cStringIO.StringIO() try: similar.Run(['--ignore-imports', SIMILAR1, SIMILAR2]) except SystemExit, ex: @@ -94,7 +93,7 @@ TOTAL lines=44 duplicates=0 percent=0.00 def test_ignore_nothing(self): - sys.stdout = StringIO() + sys.stdout = cStringIO.StringIO() try: similar.Run([SIMILAR1, SIMILAR2]) except SystemExit, ex: @@ -117,7 +116,7 @@ TOTAL lines=44 duplicates=5 percent=11.36 """ % (SIMILAR1, SIMILAR2)).strip()) def test_help(self): - sys.stdout = StringIO() + sys.stdout = cStringIO.StringIO() try: similar.Run(['--help']) except SystemExit, ex: @@ -128,7 +127,7 @@ TOTAL lines=44 duplicates=5 percent=11.36 sys.stdout = sys.__stdout__ def test_no_args(self): - sys.stdout = StringIO() + sys.stdout = cStringIO.StringIO() try: similar.Run([]) except SystemExit, ex: @@ -139,4 +138,4 @@ TOTAL lines=44 duplicates=5 percent=11.36 sys.stdout = sys.__stdout__ if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_checker_typecheck.py b/test/unittest_checker_typecheck.py index 93c73eadf..33efe5da5 100644 --- a/test/unittest_checker_typecheck.py +++ b/test/unittest_checker_typecheck.py @@ -1,5 +1,5 @@ """Unittest for the type checker.""" -from __future__ import with_statement +import unittest from astroid import test_utils from pylint.checkers import typecheck @@ -39,5 +39,4 @@ class TypeCheckerTest(CheckerTestCase): if __name__ == '__main__': - from logilab.common.testlib import unittest_main - unittest_main() + unittest.main() diff --git a/test/unittest_checker_variables.py b/test/unittest_checker_variables.py index a3776d7a6..fa012b7b1 100644 --- a/test/unittest_checker_variables.py +++ b/test/unittest_checker_variables.py @@ -1,7 +1,7 @@ """Unit tests for the variables checker.""" -from __future__ import with_statement import sys import os +import unittest from astroid import test_utils from pylint.checkers import variables @@ -53,5 +53,4 @@ class MissingSubmoduleTest(CheckerTestCase): sys.path.pop(0) if __name__ == '__main__': - from logilab.common.testlib import unittest_main - unittest_main() + unittest.main() diff --git a/test/unittest_checkers_utils.py b/test/unittest_checkers_utils.py index 40186f53b..5909cd734 100644 --- a/test/unittest_checkers_utils.py +++ b/test/unittest_checkers_utils.py @@ -13,16 +13,12 @@ # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 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 $' +"""Tests for the pylint.checkers.utils module.""" import sys +import unittest from astroid import test_utils -from logilab.common.testlib import TestCase, unittest_main from pylint.checkers import utils try: @@ -30,7 +26,7 @@ try: except AttributeError: __builtins__['mybuiltin'] = 2 -class UtilsTC(TestCase): +class UtilsTC(unittest.TestCase): ## def test_is_native_builtin(self): ## self.assertEqual(utils.is_native_builtin('min'), True) @@ -71,5 +67,5 @@ class UtilsTC(TestCase): self.assertEqual(name.name, 'a') if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_lint.py b/test/unittest_lint.py index d9185f697..b2022ccf7 100644 --- a/test/unittest_lint.py +++ b/test/unittest_lint.py @@ -12,15 +12,15 @@ # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +import cStringIO import sys import os import tempfile from shutil import rmtree from os import getcwd, chdir from os.path import join, basename, dirname, isdir, abspath -from cStringIO import StringIO +import unittest -from logilab.common.testlib import TestCase, unittest_main, create_files from logilab.common.compat import reload from pylint import config @@ -38,7 +38,7 @@ if sys.platform == 'win32': else: HOME = 'HOME' -class GetNoteMessageTC(TestCase): +class GetNoteMessageTC(unittest.TestCase): def test(self): msg = None for note in range(-1, 11): @@ -50,8 +50,44 @@ class GetNoteMessageTC(TestCase): HERE = abspath(dirname(__file__)) INPUTDIR = join(HERE, 'input') +def create_files(paths, chroot): + """Creates directories and files found in <path>. + + :param paths: list of relative paths to files or directories + :param chroot: the root directory in which paths will be created + + >>> from os.path import isdir, isfile + >>> isdir('/tmp/a') + False + >>> create_files(['a/b/foo.py', 'a/b/c/', 'a/b/c/d/e.py'], '/tmp') + >>> isdir('/tmp/a') + True + >>> isdir('/tmp/a/b/c') + True + >>> isfile('/tmp/a/b/c/d/e.py') + True + >>> isfile('/tmp/a/b/foo.py') + True + """ + dirs, files = set(), set() + for path in paths: + path = join(chroot, path) + filename = basename(path) + # path is a directory path + if filename == '': + dirs.add(path) + # path is a filename path + else: + dirs.add(dirname(path)) + files.add(path) + for dirpath in dirs: + if not isdir(dirpath): + os.makedirs(dirpath) + for filepath in files: + open(filepath, 'w').close() + -class PyLinterTC(TestCase): +class PyLinterTC(unittest.TestCase): def setUp(self): self.linter = PyLinter() @@ -318,13 +354,13 @@ class PyLinterTC(TestCase): def test_analyze_explicit_script(self): self.linter.set_reporter(TestReporter()) - self.linter.check(self.datapath('ascript')) + self.linter.check(os.path.join(os.path.dirname(__file__), 'data', 'ascript')) self.assertEqual( ['C: 2: Line too long (175/80)'], self.linter.reporter.messages) -class ConfigTC(TestCase): +class ConfigTC(unittest.TestCase): def setUp(self): os.environ.pop('PYLINTRC', None) @@ -431,7 +467,7 @@ class ConfigTC(TestCase): rmtree(chroot) -class PreprocessOptionsTC(TestCase): +class PreprocessOptionsTC(unittest.TestCase): def _callback(self, name, value): self.args.append((name, value)) @@ -470,7 +506,7 @@ class PreprocessOptionsTC(TestCase): {'bar' : (None, False)}) -class MessagesStoreTC(TestCase): +class MessagesStoreTC(unittest.TestCase): def setUp(self): self.store = MessagesStore() class Checker(object): @@ -528,7 +564,7 @@ class MessagesStoreTC(TestCase): msg, checkerref=False) def test_list_messages(self): - sys.stdout = StringIO() + sys.stdout = cStringIO.StringIO() try: self.store.list_messages() output = sys.stdout.getvalue() @@ -552,4 +588,4 @@ class MessagesStoreTC(TestCase): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_pyreverse_writer.py b/test/unittest_pyreverse_writer.py index 19d94ab42..43465b464 100644 --- a/test/unittest_pyreverse_writer.py +++ b/test/unittest_pyreverse_writer.py @@ -23,8 +23,7 @@ import sys import codecs from os.path import join, dirname, abspath from difflib import unified_diff - -from logilab.common.testlib import TestCase, unittest_main +import unittest from astroid import MANAGER from astroid.inspector import Linker @@ -67,11 +66,11 @@ def get_project(module, name=None): CONFIG = Config() -class DotWriterTC(TestCase): +class DotWriterTC(unittest.TestCase): @classmethod def setUpClass(cls): - project = get_project(cls.datadir) + project = get_project(os.path.join(os.path.dirname(__file__), 'data')) linker = Linker(project) handler = DiadefsHandler(CONFIG) dd = DefaultDiadefGenerator(linker, handler).visit(project) @@ -89,7 +88,7 @@ class DotWriterTC(TestCase): continue def _test_same_file(self, generated_file): - expected_file = self.datapath(generated_file) + expected_file = os.path.join(os.path.dirname(__file__), 'data', generated_file) generated = _file_lines(generated_file) expected = _file_lines(expected_file) generated = '\n'.join(generated) @@ -109,7 +108,7 @@ class DotWriterTC(TestCase): -class GetVisibilityTC(TestCase): +class GetVisibilityTC(unittest.TestCase): def test_special(self): for name in ["__reduce_ex__", "__setattr__"]: @@ -133,4 +132,4 @@ class GetVisibilityTC(TestCase): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_reporting.py b/test/unittest_reporting.py index e1cf1617c..58fcf6b4f 100644 --- a/test/unittest_reporting.py +++ b/test/unittest_reporting.py @@ -11,12 +11,11 @@ # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - +import cStringIO import os from os.path import join, dirname, abspath -from cStringIO import StringIO +import unittest -from logilab.common.testlib import TestCase, unittest_main from pylint.lint import PyLinter from pylint import checkers @@ -25,7 +24,7 @@ from pylint.reporters.text import TextReporter HERE = abspath(dirname(__file__)) INPUTDIR = join(HERE, 'input') -class PyLinterTC(TestCase): +class PyLinterTC(unittest.TestCase): def setUp(self): self.linter = PyLinter(reporter=TextReporter()) @@ -36,7 +35,7 @@ class PyLinterTC(TestCase): os.environ.pop('PYLINTRC', None) def test_template_option(self): - output = StringIO() + output = cStringIO.StringIO() self.linter.reporter.set_output(output) self.linter.set_option('msg-template', '{msg_id}:{line:03d}') self.linter.open() @@ -50,4 +49,4 @@ class PyLinterTC(TestCase): if __name__ == '__main__': - unittest_main() + unittest.main() diff --git a/test/unittest_utils.py b/test/unittest_utils.py index d8c4c67f0..ef0cda235 100644 --- a/test/unittest_utils.py +++ b/test/unittest_utils.py @@ -11,14 +11,14 @@ # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from logilab.common.testlib import TestCase +import unittest from astroid import test_utils from pylint import utils from pylint.checkers.utils import check_messages -class PyLintASTWalkerTest(TestCase): +class PyLintASTWalkerTest(unittest.TestCase): class MockLinter(object): def __init__(self, msgs): self._msgs = msgs @@ -58,6 +58,5 @@ class PyLintASTWalkerTest(TestCase): if __name__ == '__main__': - from logilab.common.testlib import unittest_main - unittest_main() + unittest.main() diff --git a/testutils.py b/testutils.py index 1dd083fe7..ef212113a 100644 --- a/testutils.py +++ b/testutils.py @@ -14,20 +14,20 @@ # this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """functional/non regression tests for pylint""" -from __future__ import with_statement import collections import contextlib import functools +import cStringIO import sys import re +import unittest from glob import glob from os import linesep from os.path import abspath, basename, dirname, isdir, join, splitext -from cStringIO import StringIO -from logilab.common import testlib + from pylint import checkers from pylint.utils import PyLintASTWalker @@ -94,7 +94,7 @@ class TestReporter(BaseReporter): self.reset() def reset(self): - self.out = StringIO() + self.out = cStringIO.StringIO() self.messages = [] def add_message(self, msg_id, location, msg): @@ -122,30 +122,10 @@ class TestReporter(BaseReporter): """ignore layouts""" -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 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): @@ -192,7 +172,7 @@ def set_config(**kwargs): return _Wrapper -class CheckerTestCase(testlib.TestCase): +class CheckerTestCase(unittest.TestCase): """A base testcase class for unittesting individual checker classes.""" CHECKER_CLASS = None CONFIG = {} @@ -256,7 +236,7 @@ def exception_str(self, ex): # Test classes -class LintTestUsingModule(testlib.TestCase): +class LintTestUsingModule(unittest.TestCase): INPUT_DIR = None DEFAULT_PACKAGE = 'input' package = DEFAULT_PACKAGE @@ -351,7 +331,6 @@ def cb_test_gen(base_class): module = module_file.replace('.py', '') output = messages_file depends = dependencies or None - tags = testlib.Tags(('generated', 'pylint_input_%s' % module)) INPUT_DIR = input_dir MSG_DIR = msg_dir return LintTC @@ -1,10 +1,10 @@ [tox] # official list is -#envlist = py25, py26, py27, py32, py33 -# though 2.5 support is known to be broken... +#envlist = py27, py32, py33, py34 envlist = py27, py33 [testenv] deps = logilab-common hg+https://bitbucket.org/logilab/astroid/ -commands = pytest -t {envsitepackagesdir}/pylint/test/ +commands = python -Wi -m unittest discover -s {envsitepackagesdir}/pylint/test/ -p *test_*.py +changedir = {toxworkdir} |
