summaryrefslogtreecommitdiff
path: root/tests/checkers/unittest_format.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/checkers/unittest_format.py')
-rw-r--r--tests/checkers/unittest_format.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/checkers/unittest_format.py b/tests/checkers/unittest_format.py
index 7c07ac9ed..562649eb9 100644
--- a/tests/checkers/unittest_format.py
+++ b/tests/checkers/unittest_format.py
@@ -184,6 +184,27 @@ class TestSuperfluousParentheses(CheckerTestCase):
with self.assertAddsMessages(msg):
self.checker._check_keyword_parentheses(_tokenize_str(code), offset)
+ def testNoSuperfluousParensWalrusOperatorIf(self):
+ """Parenthesis change the meaning of assignment in the walrus operator
+ and so are not superfluous:"""
+ code = "if (odd := is_odd(i))"
+ offset = 0
+ with self.assertNoMessages():
+ self.checker._check_keyword_parentheses(_tokenize_str(code), offset)
+
+ def testPositiveSuperfluousParensWalrusOperatorIf(self):
+ """Test positive superfluous parens with the walrus operator"""
+ code = "if ((odd := is_odd(i))):"
+ msg = Message("superfluous-parens", line=1, args="if")
+ with self.assertAddsMessages(msg):
+ self.checker._check_keyword_parentheses(_tokenize_str(code), 0)
+
+ def testNoSuperfluousParensWalrusOperatorNot(self):
+ """Test superfluous-parens with the not operator"""
+ code = "not (foo := 5)"
+ with self.assertNoMessages():
+ self.checker._check_keyword_parentheses(_tokenize_str(code), 0)
+
def testCheckIfArgsAreNotUnicode(self):
cases = [("if (foo):", 0), ("assert (1 == 1)", 0)]