diff options
author | toonn <toonn@toonn.io> | 2022-02-05 19:31:22 +0100 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2022-02-05 19:31:22 +0100 |
commit | 7a5f820e760c7ce2f93e2a5f0e91677b46252ea9 (patch) | |
tree | 6f4130ac9594adda5d6a1dd3fb97e87dc7fcc3ac /tests | |
parent | fcd0d50f8b952cc70f65639742cee5e194d84401 (diff) | |
parent | e3c90e2f758ebd94de8cd228d27ef5e1e4cda817 (diff) | |
download | ranger-7a5f820e760c7ce2f93e2a5f0e91677b46252ea9.tar.gz |
Merge branch 'pylint'
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/manpage_completion_test.py | 1 | ||||
-rw-r--r-- | tests/pylint/py2_compat.py | 8 | ||||
-rw-r--r-- | tests/pylint/test_py2_compat.py | 25 |
3 files changed, 34 insertions, 0 deletions
diff --git a/tests/manpage_completion_test.py b/tests/manpage_completion_test.py index 3b067b46..1a01f944 100755 --- a/tests/manpage_completion_test.py +++ b/tests/manpage_completion_test.py @@ -26,6 +26,7 @@ def get_path_of_man_page(): def read_manpage(): path = get_path_of_man_page() + # pylint: disable=unspecified-encoding with open(path, 'r') as man_page: return man_page.read() diff --git a/tests/pylint/py2_compat.py b/tests/pylint/py2_compat.py index 7e136148..e0353260 100644 --- a/tests/pylint/py2_compat.py +++ b/tests/pylint/py2_compat.py @@ -51,6 +51,9 @@ class Py2CompatibilityChecker(BaseChecker): "Python 2 subprocess.Popen objects were not contextmanagers," "popen23.Popen wraps them to enable use with" "with-statements."), + "E4240": ("Use format method", + "use-format-method", + "Python 2 (and <3.6) does not support f-strings."), } # This class variable declares the options # that are configurable by the user. @@ -121,6 +124,11 @@ class Py2CompatibilityChecker(BaseChecker): self.add_message("implicit-format-spec", node=node, confidence=HIGH) + def visit_joinedstr(self, node): + """Make sure we don't use f-strings""" + if isinstance(node, astroid.nodes.JoinedStr): + self.add_message("use-format-method", node=node, confidence=HIGH) + def visit_with(self, node): """Make sure subprocess.Popen objects aren't used in with-statements""" for (cm, _) in node.items: diff --git a/tests/pylint/test_py2_compat.py b/tests/pylint/test_py2_compat.py index 2eb51599..33fc5681 100644 --- a/tests/pylint/test_py2_compat.py +++ b/tests/pylint/test_py2_compat.py @@ -4,6 +4,7 @@ import py2_compat import astroid import pylint.testutils +from pylint.interfaces import HIGH from sys import version_info PY2 = version_info[0] < 3 @@ -25,6 +26,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): pylint.testutils.MessageTest( msg_id='old-style-class', node=oldstyle_class, + confidence=HIGH, ), ): self.checker.visit_classdef(oldstyle_class) @@ -56,6 +58,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): pylint.testutils.MessageTest( msg_id='print-without-import', node=print_function_call, + confidence=HIGH, ), ): self.checker.visit_call(print_function_call) @@ -95,6 +98,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): pylint.testutils.MessageTest( msg_id='print-without-import', node=early_print_function_call, + confidence=HIGH, ), ): self.checker.visit_call(early_print_function_call) @@ -111,6 +115,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): pylint.testutils.MessageTest( msg_id='implicit-format-spec', node=implicit_format_spec, + confidence=HIGH, ), ): self.checker.visit_call(implicit_format_spec) @@ -134,6 +139,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): pylint.testutils.MessageTest( msg_id='with-popen23', node=with_Popen, + confidence=HIGH, ), ): self.checker.visit_with(with_subprocess_Popen) @@ -141,6 +147,25 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): with self.assertNoMessages(): self.checker.visit_with(with_Popen23) + def test_use_format(self): + old_format, new_format, f_string = astroid.extract_node(""" + "2 + 2 is %s" % (2+2) #@ + "2 + 2 is {0}".format(2+2) #@ + f"2 + 2 is {2+2}" #@ + """) + + with self.assertAddsMessages( + pylint.testutils.MessageTest( + msg_id='use-format-method', + node=f_string, + confidence=HIGH, + ), + ): + self.checker.visit_joinedstr(f_string) + with self.assertNoMessages(): + self.checker.visit_joinedstr(old_format) + self.checker.visit_joinedstr(new_format) + # # These checks still exist as old-division and no-absolute-import # def test_division_without_import(self): # division = astroid.extract_node(""" |