summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2014-11-16 16:12:07 +0200
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2014-11-16 16:12:07 +0200
commite2ad67904f2e3a8fabf15630f00a72586b3168b1 (patch)
treea296858d7c579a178493b12b1edb06ef8a519f84
parent637718a2f73787fc02b8a769a763049bb0f241eb (diff)
downloadpylint-git-e2ad67904f2e3a8fabf15630f00a72586b3168b1.tar.gz
Move create_file_backed_module to testutils.
-rw-r--r--test/unittest_checker_misc.py31
-rw-r--r--testutils.py24
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)