diff options
author | cpopa <devnull@localhost> | 2013-09-05 10:30:44 +0300 |
---|---|---|
committer | cpopa <devnull@localhost> | 2013-09-05 10:30:44 +0300 |
commit | e794dcc35b0e39c1a86305d383e75d183cd8164a (patch) | |
tree | f432d4b6b4892d623f5d75695ac7a77c60b5bdf2 | |
parent | ecf4bee82c43e9c222d22574a60f3f2d3409faa8 (diff) | |
download | pylint-e794dcc35b0e39c1a86305d383e75d183cd8164a.tar.gz |
Fixing various tests for other platforms (Windows).
-rw-r--r-- | test/input/func_noerror_defined_and_used_on_same_line_py27.py | 2 | ||||
-rw-r--r-- | test/test_misc.py | 46 | ||||
-rw-r--r-- | test/unittest_lint.py | 23 |
3 files changed, 41 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..b903161 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -17,44 +17,48 @@ 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): + fd, tmp = tempfile.mkstemp() + os.close(fd) + with open(tmp, 'w') as stream: + stream.write(code) + + try: + module = test_utils.build_module(code) + module.file = tmp + yield module + finally: + 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 a65eb01..cec1551 100644 --- a/test/unittest_lint.py +++ b/test/unittest_lint.py @@ -32,6 +32,11 @@ from pylint.testutils import TestReporter from pylint.reporters import text from pylint import checkers +if sys.platform == 'win32': + HOME = 'USERPROFILE' +else: + HOME = 'HOME' + class SortMessagesTC(TestCase): def test(self): @@ -369,9 +374,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) @@ -379,7 +384,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) @@ -397,12 +402,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'), @@ -427,8 +432,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) @@ -442,7 +447,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) |