66
77class NamedExpressionInvalidTest (unittest .TestCase ):
88
9+ # Test modified to accept syntax error with deviating message
910 def test_named_expression_invalid_01 (self ):
1011 code = """x := 0"""
1112
12- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
13- with self .assertRaises (SyntaxError ): # TODO RustPython
13+ with self .assertRaises (SyntaxError ):
1414 exec (code , {}, {})
1515
16+ # Test modified to accept syntax error with deviating message
1617 def test_named_expression_invalid_02 (self ):
1718 code = """x = y := 0"""
1819
19- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
20- with self .assertRaises (SyntaxError ): # TODO RustPython
20+ with self .assertRaises (SyntaxError ):
2121 exec (code , {}, {})
2222
23+ # Test modified to accept syntax error with deviating message
2324 def test_named_expression_invalid_03 (self ):
2425 code = """y := f(x)"""
2526
26- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
27- with self .assertRaises (SyntaxError ): # TODO RustPython
27+ with self .assertRaises (SyntaxError ):
2828 exec (code , {}, {})
2929
30+ # Test modified to accept syntax error with deviating message
3031 def test_named_expression_invalid_04 (self ):
3132 code = """y0 = y1 := f(x)"""
3233
33- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
34- with self .assertRaises (SyntaxError ): # TODO RustPython
34+ with self .assertRaises (SyntaxError ):
3535 exec (code , {}, {})
3636
37+ # Test modified to accept syntax error with deviating message
3738 def test_named_expression_invalid_06 (self ):
3839 code = """((a, b) := (1, 2))"""
3940
40- #with self.assertRaisesRegex(SyntaxError, "cannot use assignment expressions with tuple"):
41- with self .assertRaises (SyntaxError ): # TODO RustPython
41+ with self .assertRaises (SyntaxError ):
4242 exec (code , {}, {})
4343
44+ # Test modified to accept syntax error with deviating message
4445 def test_named_expression_invalid_07 (self ):
4546 code = """def spam(a = b := 42): pass"""
4647
47- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
48- with self .assertRaises (SyntaxError ): # TODO RustPython
48+ with self .assertRaises (SyntaxError ):
4949 exec (code , {}, {})
5050
51+ # Test modified to accept syntax error with deviating message
5152 def test_named_expression_invalid_08 (self ):
5253 code = """def spam(a: b := 42 = 5): pass"""
5354
54- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
55- with self .assertRaises (SyntaxError ): # TODO RustPython
55+ with self .assertRaises (SyntaxError ):
5656 exec (code , {}, {})
5757
58+ # Test modified to accept syntax error with deviating message
5859 def test_named_expression_invalid_09 (self ):
5960 code = """spam(a=b := 'c')"""
6061
61- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
62- with self .assertRaises (SyntaxError ): # TODO RustPython
62+ with self .assertRaises (SyntaxError ):
6363 exec (code , {}, {})
6464
65+ # Test modified to accept syntax error with deviating message
6566 def test_named_expression_invalid_10 (self ):
6667 code = """spam(x = y := f(x))"""
6768
68- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
69- with self .assertRaises (SyntaxError ): # TODO RustPython
69+ with self .assertRaises (SyntaxError ):
7070 exec (code , {}, {})
7171
72+ # Test modified to accept syntax error with deviating message
7273 def test_named_expression_invalid_11 (self ):
7374 code = """spam(a=1, b := 2)"""
7475
75- #with self.assertRaisesRegex(SyntaxError,
76- # "positional argument follows keyword argument"):
77- with self .assertRaises (SyntaxError ): # TODO RustPython
76+ with self .assertRaises (SyntaxError ):
7877 exec (code , {}, {})
7978
79+ # Test modified to accept syntax error with deviating message
8080 def test_named_expression_invalid_12 (self ):
8181 code = """spam(a=1, (b := 2))"""
8282
83- #with self.assertRaisesRegex(SyntaxError,
84- # "positional argument follows keyword argument"):
85- with self .assertRaises (SyntaxError ): # TODO RustPython
83+ with self .assertRaises (SyntaxError ):
8684 exec (code , {}, {})
8785
86+ # Test modified to accept syntax error with deviating message
8887 def test_named_expression_invalid_13 (self ):
8988 code = """spam(a=1, (b := 2))"""
9089
91- #with self.assertRaisesRegex(SyntaxError,
92- # "positional argument follows keyword argument"):
93- with self .assertRaises (SyntaxError ): # TODO RustPython
90+ with self .assertRaises (SyntaxError ):
9491 exec (code , {}, {})
9592
93+ # Test modified to accept syntax error with deviating message
9694 def test_named_expression_invalid_14 (self ):
9795 code = """(x := lambda: y := 1)"""
9896
99- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
100- with self .assertRaises (SyntaxError ): # TODO RustPython
97+ with self .assertRaises (SyntaxError ):
10198 exec (code , {}, {})
10299
100+ # Test modified to accept syntax error with deviating message
103101 def test_named_expression_invalid_15 (self ):
104102 code = """(lambda: x := 1)"""
105103
106- #with self.assertRaisesRegex(SyntaxError,
107- # "cannot use assignment expressions with lambda"):
108- with self .assertRaises (SyntaxError ): # TODO RustPython
104+ with self .assertRaises (SyntaxError ):
109105 exec (code , {}, {})
110106
107+ # Test modified to accept syntax error with deviating message
111108 def test_named_expression_invalid_16 (self ):
112109 code = "[i + 1 for i in i := [1,2]]"
113110
114- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
115- with self .assertRaises (SyntaxError ): # TODO RustPython
111+ with self .assertRaises (SyntaxError ):
116112 exec (code , {}, {})
117113
114+ # Test modified to accept syntax error with deviating message
118115 def test_named_expression_invalid_17 (self ):
119116 code = "[i := 0, j := 1 for i, j in [(1, 2), (3, 4)]]"
120117
121- #with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
122- with self .assertRaises (SyntaxError ): # TODO RustPython
118+ with self .assertRaises (SyntaxError ):
123119 exec (code , {}, {})
124120
125121 def test_named_expression_invalid_in_class_body (self ):
@@ -131,6 +127,7 @@ def test_named_expression_invalid_in_class_body(self):
131127 "assignment expression within a comprehension cannot be used in a class body" ):
132128 exec (code , {}, {})
133129
130+ # Test modified to accept syntax error with deviating message
134131 def test_named_expression_invalid_rebinding_comprehension_iteration_variable (self ):
135132 cases = [
136133 ("Local reuse" , 'i' , "[i := 0 for i in range(5)]" ),
@@ -143,18 +140,17 @@ def test_named_expression_invalid_rebinding_comprehension_iteration_variable(sel
143140 "[(i, j) for i in range(5) for j in range(5) if True or (i:=10)]" ),
144141 ]
145142 for case , target , code in cases :
146- msg = f"assignment expression cannot rebind comprehension iteration variable '{ target } '"
147143 with self .subTest (case = case ):
148144 with self .assertRaises (SyntaxError ):
149145 exec (code , {}, {})
150146
147+ # Test modified to accept syntax error with deviating message
151148 def test_named_expression_invalid_rebinding_comprehension_inner_loop (self ):
152149 cases = [
153150 ("Inner reuse" , 'j' , "[i for i in range(5) if (j := 0) for j in range(5)]" ),
154151 ("Inner unpacking reuse" , 'j' , "[i for i in range(5) if (j := 0) for j, k in [(0, 1)]]" ),
155152 ]
156153 for case , target , code in cases :
157- #msg = f"comprehension inner loop cannot rebind assignment expression target '{target}'"
158154 with self .subTest (case = case ):
159155 with self .assertRaises (SyntaxError ):
160156 exec (code , {}) # Module scope
@@ -163,6 +159,7 @@ def test_named_expression_invalid_rebinding_comprehension_inner_loop(self):
163159 with self .assertRaises (SyntaxError ):
164160 exec (f"lambda: { code } " , {}) # Function scope
165161
162+ # Test modified to accept syntax error with deviating message
166163 def test_named_expression_invalid_comprehension_iterable_expression (self ):
167164 cases = [
168165 ("Top level" , "[i for i in (i := range(5))]" ),
@@ -175,7 +172,6 @@ def test_named_expression_invalid_comprehension_iterable_expression(self):
175172 ("Nested comprehension condition" , "[i for i in [j for j in range(5) if (j := True)]]" ),
176173 ("Nested comprehension body" , "[i for i in [(j := True) for j in range(5)]]" ),
177174 ]
178- #msg = "assignment expression cannot be used in a comprehension iterable expression"
179175 for case , code in cases :
180176 with self .subTest (case = case ):
181177 with self .assertRaises (SyntaxError ):
@@ -339,10 +335,10 @@ def spam(a):
339335 self .assertEqual (res , [(1 , 1 , 1.0 ), (2 , 2 , 1.0 ), (3 , 3 , 1.0 )])
340336 self .assertEqual (y , 3 )
341337
342- # TODO RustPython,
343- @unittest .expectedFailure # TODO RustPython
338+ # TODO RustPython, added test_named_expression_scope_06_rp_modified as
339+ # minimaly modified variant of this test.
340+ @unittest .expectedFailure
344341 def test_named_expression_scope_06 (self ):
345- #spam=1000
346342 res = [[spam := i for i in range (3 )] for j in range (2 )]
347343
348344 self .assertEqual (res , [[0 , 1 , 2 ], [0 , 1 , 2 ]])
@@ -388,7 +384,7 @@ def eggs(b):
388384 self .assertEqual (res , [0 , 2 ])
389385 self .assertEqual (a , 2 )
390386
391- # TODO RustPython,
387+ # TODO RustPython, added test_named_expression_scope_10_rp_modified
392388 @unittest .expectedFailure
393389 def test_named_expression_scope_10 (self ):
394390 res = [b := [a := 1 for i in range (2 )] for j in range (2 )]
0 commit comments