summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTorsten Marek <shlomme@gmail.com>2014-11-09 10:33:29 +0100
committerTorsten Marek <shlomme@gmail.com>2014-11-09 10:33:29 +0100
commit0ed61a71b1756e204cd57d3711c7f4d0b90ebef2 (patch)
treecc704a4444b0686293e860ce785b8f8f9008efeb /test
parent052955e6b48af4ac80448fbb87ca2e6702f9a8e4 (diff)
downloadpylint-git-0ed61a71b1756e204cd57d3711c7f4d0b90ebef2.tar.gz
Make most tests run unmodified under Python 3.4.
Diffstat (limited to 'test')
-rw-r--r--test/test_functional.py8
-rw-r--r--test/test_import_graph.py3
-rw-r--r--test/test_self.py15
-rw-r--r--test/unittest_checker_similar.py27
-rw-r--r--test/unittest_lint.py7
-rw-r--r--test/unittest_pyreverse_diadefs.py4
-rw-r--r--test/unittest_reporting.py6
7 files changed, 39 insertions, 31 deletions
diff --git a/test/test_functional.py b/test/test_functional.py
index ead8f586d..f9e33fa1c 100644
--- a/test/test_functional.py
+++ b/test/test_functional.py
@@ -2,7 +2,6 @@
from __future__ import unicode_literals
import csv
import collections
-import ConfigParser
import io
import operator
import os
@@ -11,6 +10,9 @@ import sys
import platform
import unittest
+import six
+from six.moves import configparser
+
from pylint import checkers
from pylint import interfaces
from pylint import lint
@@ -113,7 +115,7 @@ class TestFile(object):
self._parse_options()
def _parse_options(self):
- cp = ConfigParser.ConfigParser()
+ cp = configparser.ConfigParser()
cp.add_section('testoptions')
try:
cp.read(self.option_file)
@@ -204,7 +206,7 @@ def multiset_difference(left_op, right_op):
missing = left_op.copy()
missing.subtract(right_op)
unexpected = {}
- for key, value in missing.items():
+ for key, value in list(six.iteritems(missing)):
if value <= 0:
missing.pop(key)
if value < 0:
diff --git a/test/test_import_graph.py b/test/test_import_graph.py
index 2948dd10c..2b41536b1 100644
--- a/test/test_import_graph.py
+++ b/test/test_import_graph.py
@@ -1,9 +1,10 @@
import sys
import os
from os.path import exists
-from cStringIO import StringIO
import unittest
+import six
+
from pylint.checkers import initialize, imports
from pylint.lint import PyLinter
diff --git a/test/test_self.py b/test/test_self.py
index 7a48ee0cd..ef5de96c5 100644
--- a/test/test_self.py
+++ b/test/test_self.py
@@ -14,10 +14,11 @@
import sys
import os
from os.path import join, dirname, abspath
-from cStringIO import StringIO
import tempfile
import unittest
+import six
+
from pylint.lint import Run
from pylint.reporters import BaseReporter
from pylint.reporters.text import *
@@ -61,7 +62,7 @@ class RunTC(unittest.TestCase):
def _runtest(self, args, reporter=None, out=None, code=28):
if out is None:
- out = StringIO()
+ out = six.StringIO()
try:
sys.stderr = sys.stdout = out
try:
@@ -85,15 +86,15 @@ class RunTC(unittest.TestCase):
def test_pkginfo(self):
"""Make pylint check itself."""
- self._runtest(['pylint.__pkginfo__'], reporter=TextReporter(StringIO()),
+ self._runtest(['pylint.__pkginfo__'], reporter=TextReporter(six.StringIO()),
code=0)
def test_all(self):
"""Make pylint check itself."""
reporters = [
- TextReporter(StringIO()),
- HTMLReporter(StringIO()),
- ColorizedTextReporter(StringIO())
+ TextReporter(six.StringIO()),
+ HTMLReporter(six.StringIO()),
+ ColorizedTextReporter(six.StringIO())
]
self._runtest(['pylint/test/functional/arguments.py'],
reporter=MultiReporter(reporters), code=1)
@@ -125,7 +126,7 @@ class RunTC(unittest.TestCase):
if sys.version_info < (3, 0):
strio = tempfile.TemporaryFile()
else:
- strio = StringIO()
+ strio = six.StringIO()
assert strio.encoding is None
self._runtest([join(HERE, 'regrtest_data/no_stdout_encoding.py')],
out=strio)
diff --git a/test/unittest_checker_similar.py b/test/unittest_checker_similar.py
index 8d68b81af..4cd48cc41 100644
--- a/test/unittest_checker_similar.py
+++ b/test/unittest_checker_similar.py
@@ -1,8 +1,9 @@
-import cStringIO
import sys
from os.path import join, dirname, abspath
import unittest
+import six
+
from pylint.checkers import similar
SIMILAR1 = join(dirname(abspath(__file__)), 'input', 'similar1')
@@ -12,10 +13,10 @@ class SimilarTC(unittest.TestCase):
"""test the similar command line utility"""
def test_ignore_comments(self):
- sys.stdout = cStringIO.StringIO()
+ sys.stdout = six.StringIO()
try:
similar.Run(['--ignore-comments', SIMILAR1, SIMILAR2])
- except SystemExit, ex:
+ except SystemExit as ex:
self.assertEqual(ex.code, 0)
output = sys.stdout.getvalue()
else:
@@ -41,10 +42,10 @@ TOTAL lines=44 duplicates=10 percent=22.73
def test_ignore_docsrings(self):
- sys.stdout = cStringIO.StringIO()
+ sys.stdout = six.StringIO()
try:
similar.Run(['--ignore-docstrings', SIMILAR1, SIMILAR2])
- except SystemExit, ex:
+ except SystemExit as ex:
self.assertEqual(ex.code, 0)
output = sys.stdout.getvalue()
else:
@@ -77,10 +78,10 @@ TOTAL lines=44 duplicates=13 percent=29.55
def test_ignore_imports(self):
- sys.stdout = cStringIO.StringIO()
+ sys.stdout = six.StringIO()
try:
similar.Run(['--ignore-imports', SIMILAR1, SIMILAR2])
- except SystemExit, ex:
+ except SystemExit as ex:
self.assertEqual(ex.code, 0)
output = sys.stdout.getvalue()
else:
@@ -93,10 +94,10 @@ TOTAL lines=44 duplicates=0 percent=0.00
def test_ignore_nothing(self):
- sys.stdout = cStringIO.StringIO()
+ sys.stdout = six.StringIO()
try:
similar.Run([SIMILAR1, SIMILAR2])
- except SystemExit, ex:
+ except SystemExit as ex:
self.assertEqual(ex.code, 0)
output = sys.stdout.getvalue()
else:
@@ -116,10 +117,10 @@ TOTAL lines=44 duplicates=5 percent=11.36
""" % (SIMILAR1, SIMILAR2)).strip())
def test_help(self):
- sys.stdout = cStringIO.StringIO()
+ sys.stdout = six.StringIO()
try:
similar.Run(['--help'])
- except SystemExit, ex:
+ except SystemExit as ex:
self.assertEqual(ex.code, 0)
else:
self.fail('not system exit')
@@ -127,10 +128,10 @@ TOTAL lines=44 duplicates=5 percent=11.36
sys.stdout = sys.__stdout__
def test_no_args(self):
- sys.stdout = cStringIO.StringIO()
+ sys.stdout = six.StringIO()
try:
similar.Run([])
- except SystemExit, ex:
+ except SystemExit as ex:
self.assertEqual(ex.code, 1)
else:
self.fail('not system exit')
diff --git a/test/unittest_lint.py b/test/unittest_lint.py
index c0064062e..c96dcf70e 100644
--- a/test/unittest_lint.py
+++ b/test/unittest_lint.py
@@ -13,7 +13,6 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from contextlib import contextmanager
-import cStringIO
import sys
import os
import tempfile
@@ -22,6 +21,8 @@ from os import getcwd, chdir
from os.path import join, basename, dirname, isdir, abspath, sep
import unittest
+import six
+
from logilab.common.compat import reload
from pylint import config, lint
@@ -468,7 +469,7 @@ class PyLinterTC(unittest.TestCase):
self.linter.reporter.messages)
def test_html_reporter_missing_files(self):
- output = cStringIO.StringIO()
+ output = six.StringIO()
self.linter.set_reporter(html.HTMLReporter(output))
self.linter.set_option('output-format', 'html')
self.linter.check('troppoptop.py')
@@ -661,7 +662,7 @@ class MessagesStoreTC(unittest.TestCase):
msg, checkerref=False)
def test_list_messages(self):
- sys.stdout = cStringIO.StringIO()
+ sys.stdout = six.StringIO()
try:
self.store.list_messages()
output = sys.stdout.getvalue()
diff --git a/test/unittest_pyreverse_diadefs.py b/test/unittest_pyreverse_diadefs.py
index 0f67e36c4..5f775aa22 100644
--- a/test/unittest_pyreverse_diadefs.py
+++ b/test/unittest_pyreverse_diadefs.py
@@ -20,6 +20,8 @@ unittest for the extensions.diadefslib modules
import unittest
import sys
+import six
+
import astroid
from astroid import MANAGER
from astroid.inspector import Linker
@@ -38,7 +40,7 @@ def _process_classes(classes):
def _process_relations(relations):
"""extract relation indices from a relation list"""
result = []
- for rel_type, rels in relations.iteritems():
+ for rel_type, rels in six.iteritems(relations):
for rel in rels:
result.append( (rel_type, rel.from_object.title,
rel.to_object.title) )
diff --git a/test/unittest_reporting.py b/test/unittest_reporting.py
index 88fb288de..ef1de0c64 100644
--- a/test/unittest_reporting.py
+++ b/test/unittest_reporting.py
@@ -11,11 +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
import unittest
+import six
from pylint.lint import PyLinter
from pylint import checkers
@@ -35,7 +35,7 @@ class PyLinterTC(unittest.TestCase):
os.environ.pop('PYLINTRC', None)
def test_template_option(self):
- output = cStringIO.StringIO()
+ output = six.StringIO()
self.linter.reporter.set_output(output)
self.linter.set_option('msg-template', '{msg_id}:{line:03d}')
self.linter.open()
@@ -48,7 +48,7 @@ class PyLinterTC(unittest.TestCase):
'C0301:002\n')
def test_parseable_output_regression(self):
- output = cStringIO.StringIO()
+ output = six.StringIO()
linter = PyLinter(reporter=ParseableTextReporter())
checkers.initialize(linter)
linter.config.persistent = 0