summaryrefslogtreecommitdiff
path: root/pylint/test/test_self.py
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-02-28 19:13:33 +0200
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-02-28 19:13:33 +0200
commit37e6b5c9c2dba47d2845d5f69557fabaee2e9e55 (patch)
tree53e5c5b3f7553c5e1a2f12dfba0b27e72bdf628a /pylint/test/test_self.py
parentf9f9efa32bd9bca116cea8163409a2d5f44818b5 (diff)
downloadpylint-git-37e6b5c9c2dba47d2845d5f69557fabaee2e9e55.tar.gz
Make the --py3k flag commutative with the -E flag.
Also, this patch fixes the leaks of error messages from the Python 3 checker when the errors mode was activated. Closes issue #437.
Diffstat (limited to 'pylint/test/test_self.py')
-rw-r--r--pylint/test/test_self.py50
1 files changed, 49 insertions, 1 deletions
diff --git a/pylint/test/test_self.py b/pylint/test/test_self.py
index 173488946..9c296b8ab 100644
--- a/pylint/test/test_self.py
+++ b/pylint/test/test_self.py
@@ -11,10 +11,12 @@
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+import contextlib
import sys
import os
from os.path import join, dirname, abspath
import tempfile
+import textwrap
import unittest
import six
@@ -28,6 +30,17 @@ from pylint.reporters.json import JSONReporter
HERE = abspath(dirname(__file__))
+
+@contextlib.contextmanager
+def _patch_streams(out):
+ sys.stderr = sys.stdout = out
+ try:
+ yield
+ finally:
+ sys.stderr = sys.__stderr__
+ sys.stdout = sys.__stdout__
+
+
class MultiReporter(BaseReporter):
def __init__(self, reporters):
self._reporters = reporters
@@ -85,6 +98,15 @@ class RunTC(unittest.TestCase):
sys.stderr = sys.__stderr__
sys.stdout = sys.__stdout__
+ def _test_output(self, args, expected_output):
+ out = six.StringIO()
+ with _patch_streams(out):
+ with self.assertRaises(SystemExit):
+ Run(args)
+
+ actual_output = out.getvalue()
+ self.assertEqual(expected_output.strip(), actual_output.strip())
+
def test_pkginfo(self):
"""Make pylint check itself."""
self._runtest(['pylint.__pkginfo__'], reporter=TextReporter(six.StringIO()),
@@ -151,7 +173,33 @@ class RunTC(unittest.TestCase):
rc_code = 2 if six.PY2 else 0
self._runtest([join(HERE, 'functional', 'unpacked_exceptions.py'),
'--py3k', '-j 2'],
- code=rc_code)
+ code=rc_code)
+
+ @unittest.skipIf(sys.version_info[0] > 2, "Requires the --py3k flag.")
+ def test_py3k_commutative_with_errors_only(self):
+
+ # Test what gets emitted with -E only
+ module = join(HERE, 'regrtest_data', 'py3k_error_flag.py')
+ expected = textwrap.dedent("""
+ No config file found, using default configuration
+ ************* Module py3k_error_flag
+ Explicit return in __init__
+ """)
+ self._test_output([module, "-E", "--msg-template='{msg}'"],
+ expected_output=expected)
+
+ # Test what gets emitted with -E --py3k
+ expected = textwrap.dedent("""
+ No config file found, using default configuration
+ ************* Module py3k_error_flag
+ Use raise ErrorClass(args) instead of raise ErrorClass, args.
+ """)
+ self._test_output([module, "-E", "--py3k", "--msg-template='{msg}'"],
+ expected_output=expected)
+
+ # Test what gets emitted with --py3k -E
+ self._test_output([module, "--py3k", "-E", "--msg-template='{msg}'"],
+ expected_output=expected)
if __name__ == '__main__':