summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSylvain Th?nault <thenault@gmail.com>2013-10-03 16:56:18 +0200
committerSylvain Th?nault <thenault@gmail.com>2013-10-03 16:56:18 +0200
commit3df202b61fdb89dee09fe8bf9180587496831958 (patch)
tree16a4e918cecaa168dc4f30bfd174de6f475c28b8 /test
parent95647d4da1d098e0d143fbec57062c7e4fd193b2 (diff)
parent0a53cc2d8e60ade303893d19ff1b0d2e8be70ad4 (diff)
downloadpylint-3df202b61fdb89dee09fe8bf9180587496831958.tar.gz
Merged in PCManticore/pylint/exit_context (pull request #61)
Check that __exit__ accepts the right number of arguments
Diffstat (limited to 'test')
-rw-r--r--test/input/func_noerror_defined_and_used_on_same_line_py27.py2
-rw-r--r--test/test_misc.py48
-rw-r--r--test/unittest_lint.py22
3 files changed, 42 insertions, 30 deletions
diff --git a/test/input/func_noerror_defined_and_used_on_same_line_py27.py b/test/input/func_noerror_defined_and_used_on_same_line_py27.py
index 5a75722..11b1a2d 100644
--- a/test/input/func_noerror_defined_and_used_on_same_line_py27.py
+++ b/test/input/func_noerror_defined_and_used_on_same_line_py27.py
@@ -1,5 +1,7 @@
#pylint: disable=C0111,C0321
"""pylint complains about 'index' being used before definition"""
+__revision__ = 1
+
with open('f') as f, open(f.read()) as g:
print g.read()
diff --git a/test/test_misc.py b/test/test_misc.py
index 68f3e4a..d2c03c0 100644
--- a/test/test_misc.py
+++ b/test/test_misc.py
@@ -17,44 +17,50 @@ Tests for the misc checker.
"""
import tempfile
+import os
+import contextlib
from logilab.common.testlib import unittest_main
from astroid import test_utils
from pylint.checkers import misc
from pylint.testutils import CheckerTestCase, Message
+@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()
+ 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
- def create_file_backed_module(self, code):
- tmp = tempfile.NamedTemporaryFile()
- tmp.write(code)
- tmp.flush()
- module = test_utils.build_module(code)
- module.file = tmp.name
- # Just make sure to keep a reference to the file
- # so it isn't deleted.
- module._tmpfile = tmp
- return module
-
def test_fixme(self):
- module = self.create_file_backed_module(
+ with create_file_backed_module(
"""a = 1
- # FIXME
- """)
- with self.assertAddsMessages(
- Message(msg_id='W0511', line=2, args=u'FIXME')):
- self.checker.process_module(module)
+ # FIXME """) as module:
+ with self.assertAddsMessages(
+ Message(msg_id='W0511', line=2, args=u'FIXME')):
+ self.checker.process_module(module)
def test_emtpy_fixme_regex(self):
self.checker.config.notes = []
- module = self.create_file_backed_module(
+ with create_file_backed_module(
"""a = 1
# fixme
- """)
- with self.assertNoMessages():
- self.checker.process_module(module)
+ """) as module:
+ with self.assertNoMessages():
+ self.checker.process_module(module)
if __name__ == '__main__':
diff --git a/test/unittest_lint.py b/test/unittest_lint.py
index 0b847c2..7612ef4 100644
--- a/test/unittest_lint.py
+++ b/test/unittest_lint.py
@@ -32,6 +32,10 @@ from pylint.testutils import TestReporter
from pylint.reporters import text
from pylint import checkers
+if sys.platform == 'win32':
+ HOME = 'USERPROFILE'
+else:
+ HOME = 'HOME'
class GetNoteMessageTC(TestCase):
def test(self):
@@ -388,9 +392,9 @@ class ConfigTC(TestCase):
def test_pylintrc(self):
fake_home = tempfile.mkdtemp('fake-home')
- home = os.environ['HOME']
+ home = os.environ[HOME]
try:
- os.environ['HOME'] = fake_home
+ os.environ[HOME] = fake_home
self.assertEqual(config.find_pylintrc(), None)
os.environ['PYLINTRC'] = join(tempfile.gettempdir(), '.pylintrc')
self.assertEqual(config.find_pylintrc(), None)
@@ -398,7 +402,7 @@ class ConfigTC(TestCase):
self.assertEqual(config.find_pylintrc(), None)
finally:
os.environ.pop('PYLINTRC', '')
- os.environ['HOME'] = home
+ os.environ[HOME] = home
rmtree(fake_home, ignore_errors=True)
reload(config)
@@ -416,12 +420,12 @@ class ConfigTC(TestCase):
'a/b/c/__init__.py', 'a/b/c/d/__init__.py'], chroot)
os.chdir(chroot)
fake_home = tempfile.mkdtemp('fake-home')
- home = os.environ['HOME']
+ home = os.environ[HOME]
try:
- os.environ['HOME'] = fake_home
+ os.environ[HOME] = fake_home
self.assertEqual(config.find_pylintrc(), None)
finally:
- os.environ['HOME'] = home
+ os.environ[HOME] = home
os.rmdir(fake_home)
results = {'a' : join(chroot, 'a', 'pylintrc'),
'a/b' : join(chroot, 'a', 'b', 'pylintrc'),
@@ -446,8 +450,8 @@ class ConfigTC(TestCase):
chdir(cdir)
fake_home = tempfile.mkdtemp('fake-home')
- home = os.environ['HOME']
- os.environ['HOME'] = fake_home
+ home = os.environ[HOME]
+ os.environ[HOME] = fake_home
try:
create_files(['a/pylintrc', 'a/b/pylintrc', 'a/b/c/d/__init__.py'], chroot)
os.chdir(chroot)
@@ -461,7 +465,7 @@ class ConfigTC(TestCase):
os.chdir(join(chroot, basedir))
self.assertEqual(config.find_pylintrc(), expected)
finally:
- os.environ['HOME'] = home
+ os.environ[HOME] = home
rmtree(fake_home, ignore_errors=True)
os.chdir(HERE)
rmtree(chroot)