diff options
author | Roy Williams <roy.williams.iii@gmail.com> | 2016-12-05 10:37:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-05 10:37:00 -0800 |
commit | 1c29c5156e954ec43be210b9521b92f987bf48fa (patch) | |
tree | 99c84527e24e6aa5aab07d96d49ccd42c1329401 /pylint/test/unittest_checker_python3.py | |
parent | 230bebb08fe92b7d537ba2e64f8fcb045361d210 (diff) | |
download | pylint-git-1c29c5156e954ec43be210b9521b92f987bf48fa.tar.gz |
Add a Python 3 checker for finding deprecated calls to `str.translate`. (#1188)
* Add a Python 3 checker for finding deprecated calls to `str.translate`.
This checker could possibly have some false positives, but after checking our codebase
and several other large codebases using this implementation, I did not find any false
positives.
* Add filter for types proven not to be strings
Diffstat (limited to 'pylint/test/unittest_checker_python3.py')
-rw-r--r-- | pylint/test/unittest_checker_python3.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py index 922bc4939..28a6d8052 100644 --- a/pylint/test/unittest_checker_python3.py +++ b/pylint/test/unittest_checker_python3.py @@ -647,6 +647,50 @@ class Python3CheckerTest(testutils.CheckerTestCase): with self.assertAddsMessages(absolute_import_message): self.checker.visit_importfrom(node) + @python2_only + def test_bad_str_translate_call_string_literal(self): + node = astroid.extract_node(''' + foobar.translate(None, 'abc123') #@ + ''') + message = testutils.Message('deprecated-str-translate-call', node=node) + with self.assertAddsMessages(message): + self.checker.visit_call(node) + + @python2_only + def test_bad_str_translate_call_variable(self): + node = astroid.extract_node(''' + foobar.translate(None, foobar) #@ + ''') + message = testutils.Message('deprecated-str-translate-call', node=node) + with self.assertAddsMessages(message): + self.checker.visit_call(node) + + @python2_only + def test_ok_str_translate_call_integer(self): + node = astroid.extract_node(''' + foobar.translate(None, 33) #@ + ''') + with self.assertNoMessages(): + self.checker.visit_call(node) + + @python2_only + def test_ok_str_translate_call_keyword(self): + node = astroid.extract_node(''' + foobar.translate(None, 'foobar', raz=33) #@ + ''') + with self.assertNoMessages(): + self.checker.visit_call(node) + + @python2_only + def test_ok_str_translate_call_not_str(self): + node = astroid.extract_node(''' + foobar = {} + foobar.translate(None, 'foobar') #@ + ''') + with self.assertNoMessages(): + self.checker.visit_call(node) + + @python2_only class Python3TokenCheckerTest(testutils.CheckerTestCase): |