diff options
-rw-r--r-- | test/unittest_checker_misc.py | 31 | ||||
-rw-r--r-- | testutils.py | 24 |
2 files changed, 28 insertions, 27 deletions
diff --git a/test/unittest_checker_misc.py b/test/unittest_checker_misc.py index 940b76d9d..03e3cc2dc 100644 --- a/test/unittest_checker_misc.py +++ b/test/unittest_checker_misc.py @@ -14,37 +14,15 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """Tests for the misc checker.""" -import contextlib -import os -import sys -import tempfile import unittest -from astroid import test_utils from pylint.checkers import misc -from pylint.testutils import CheckerTestCase, Message, set_config +from pylint.testutils import ( + CheckerTestCase, Message, + set_config, create_file_backed_module, +) -@contextlib.contextmanager -def create_file_backed_module(code): - # Can't use tempfile.NamedTemporaryFile here - # because on Windows the file must be closed before writing to it, - # see http://bugs.python.org/issue14243 - fd, tmp = tempfile.mkstemp() - if sys.version_info >= (3, 0): - # erff - os.write(fd, bytes(code, 'ascii')) - else: - os.write(fd, code) - - try: - module = test_utils.build_module(code) - module.file = tmp - yield module - finally: - os.close(fd) - os.remove(tmp) - class FixmeTest(CheckerTestCase): CHECKER_CLASS = misc.EncodingChecker @@ -66,5 +44,6 @@ class FixmeTest(CheckerTestCase): with self.assertNoMessages(): self.checker.process_module(module) + if __name__ == '__main__': unittest.main() diff --git a/testutils.py b/testutils.py index a89225830..c0334af0e 100644 --- a/testutils.py +++ b/testutils.py @@ -19,16 +19,18 @@ from __future__ import print_function import collections import contextlib import functools +import os import sys import re import unittest +import tempfile import tokenize from glob import glob from os import linesep, getcwd, sep from os.path import abspath, basename, dirname, isdir, join, splitext - +from astroid import test_utils from pylint import checkers from pylint.utils import PyLintASTWalker @@ -372,3 +374,23 @@ def make_tests(input_dir, msg_dir, filter_rgx, callbacks): def tokenize_str(code): return list(tokenize.generate_tokens(StringIO(code).readline)) + +@contextlib.contextmanager +def create_file_backed_module(code): + # Can't use tempfile.NamedTemporaryFile here + # because on Windows the file must be closed before writing to it, + # see http://bugs.python.org/issue14243 + fd, tmp = tempfile.mkstemp() + if sys.version_info >= (3, 0): + # erff + os.write(fd, bytes(code, 'ascii')) + else: + os.write(fd, code) + + try: + module = test_utils.build_module(code) + module.file = tmp + yield module + finally: + os.close(fd) + os.remove(tmp) |