diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2017-07-21 12:20:17 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2017-07-21 12:20:17 +0200 |
commit | 73bf9ba0dee713749b6c4f26a07ebc0f7eb426eb (patch) | |
tree | 3f5f7ac6d0f0b90b5ef1ab6a386a6d162c4eaefb /pylint/test/unittest_checker_python3.py | |
parent | 38608a6d165dced47939fbd612419fd64eacca63 (diff) | |
download | pylint-git-73bf9ba0dee713749b6c4f26a07ebc0f7eb426eb.tar.gz |
Added a couple of new Python 3 checks for accessing dict methods in non-iterable context. Part of #377
Diffstat (limited to 'pylint/test/unittest_checker_python3.py')
-rw-r--r-- | pylint/test/unittest_checker_python3.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py index 73732cdef..910a6b71e 100644 --- a/pylint/test/unittest_checker_python3.py +++ b/pylint/test/unittest_checker_python3.py @@ -167,6 +167,38 @@ class TestPython3Checker(testutils.CheckerTestCase): self.as_argument_to_callable_constructor_test(fxn, func) @python2_only + def test_dict_methods_in_iterating_context(self): + iterating_code = [ + 'for x in {}: pass', + '(x for x in {})', + '[x for x in {}]', + 'func({})', + 'a, b = {}' + ] + non_iterating_code = [ + 'x = __({}())', + '__({}())[0]' + ] + + for method in ('keys', 'items', 'values'): + dict_method = '{{}}.{}'.format(method) + + for code in iterating_code: + with_value = code.format(dict_method) + module = astroid.parse(with_value) + with self.assertNoMessages(): + self.walk(module) + + for code in non_iterating_code: + with_value = code.format(dict_method) + node = astroid.extract_node(with_value) + + checker = 'dict-{}-not-iterating'.format(method) + message = testutils.Message(checker, node=node) + with self.assertAddsMessages(message): + self.checker.visit_call(node) + + @python2_only def test_map_in_iterating_context(self): self.iterating_context_tests('map') |