Changeset 391 for python/trunk/Lib/test/test_syntax.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_syntax.py
r2 r391 28 28 Errors from set_context(): 29 29 30 TODO(jhylton): "assignment to None" is inconsistent with other messages31 32 30 >>> obj.None = 1 33 31 Traceback (most recent call last): 34 SyntaxError: assignment to None (<doctest test.test_syntax[1]>, line 1) 32 File "<doctest test.test_syntax[1]>", line 1 33 SyntaxError: cannot assign to None 35 34 36 35 >>> None = 1 37 36 Traceback (most recent call last): 38 SyntaxError: assignment to None (<doctest test.test_syntax[2]>, line 1) 37 File "<doctest test.test_syntax[2]>", line 1 38 SyntaxError: cannot assign to None 39 39 40 40 It's a syntax error to assign to the empty tuple. Why isn't it an … … 44 44 >>> () = 1 45 45 Traceback (most recent call last): 46 SyntaxError: can't assign to () (<doctest test.test_syntax[3]>, line 1) 46 File "<doctest test.test_syntax[3]>", line 1 47 SyntaxError: can't assign to () 47 48 48 49 >>> f() = 1 49 50 Traceback (most recent call last): 50 SyntaxError: can't assign to function call (<doctest test.test_syntax[4]>, line 1) 51 File "<doctest test.test_syntax[4]>", line 1 52 SyntaxError: can't assign to function call 51 53 52 54 >>> del f() 53 55 Traceback (most recent call last): 54 SyntaxError: can't delete function call (<doctest test.test_syntax[5]>, line 1) 56 File "<doctest test.test_syntax[5]>", line 1 57 SyntaxError: can't delete function call 55 58 56 59 >>> a + 1 = 2 57 60 Traceback (most recent call last): 58 SyntaxError: can't assign to operator (<doctest test.test_syntax[6]>, line 1) 61 File "<doctest test.test_syntax[6]>", line 1 62 SyntaxError: can't assign to operator 59 63 60 64 >>> (x for x in x) = 1 61 65 Traceback (most recent call last): 62 SyntaxError: can't assign to generator expression (<doctest test.test_syntax[7]>, line 1) 66 File "<doctest test.test_syntax[7]>", line 1 67 SyntaxError: can't assign to generator expression 63 68 64 69 >>> 1 = 1 65 70 Traceback (most recent call last): 66 SyntaxError: can't assign to literal (<doctest test.test_syntax[8]>, line 1) 71 File "<doctest test.test_syntax[8]>", line 1 72 SyntaxError: can't assign to literal 67 73 68 74 >>> "abc" = 1 69 75 Traceback (most recent call last): 70 SyntaxError: can't assign to literal (<doctest test.test_syntax[9]>, line 1) 76 File "<doctest test.test_syntax[8]>", line 1 77 SyntaxError: can't assign to literal 71 78 72 79 >>> `1` = 1 73 80 Traceback (most recent call last): 74 SyntaxError: can't assign to repr (<doctest test.test_syntax[10]>, line 1) 81 File "<doctest test.test_syntax[10]>", line 1 82 SyntaxError: can't assign to repr 75 83 76 84 If the left-hand side of an assignment is a list or tuple, an illegal … … 81 89 >>> (a, "b", c) = (1, 2, 3) 82 90 Traceback (most recent call last): 83 SyntaxError: can't assign to literal (<doctest test.test_syntax[11]>, line 1) 91 File "<doctest test.test_syntax[11]>", line 1 92 SyntaxError: can't assign to literal 84 93 85 94 >>> [a, b, c + 1] = [1, 2, 3] 86 95 Traceback (most recent call last): 87 SyntaxError: can't assign to operator (<doctest test.test_syntax[12]>, line 1) 96 File "<doctest test.test_syntax[12]>", line 1 97 SyntaxError: can't assign to operator 88 98 89 99 >>> a if 1 else b = 1 90 100 Traceback (most recent call last): 91 SyntaxError: can't assign to conditional expression (<doctest test.test_syntax[13]>, line 1) 101 File "<doctest test.test_syntax[13]>", line 1 102 SyntaxError: can't assign to conditional expression 92 103 93 104 From compiler_complex_args(): … … 96 107 ... pass 97 108 Traceback (most recent call last): 98 SyntaxError: assignment to None (<doctest test.test_syntax[14]>, line 1) 109 File "<doctest test.test_syntax[14]>", line 1 110 SyntaxError: cannot assign to None 99 111 100 112 … … 104 116 ... pass 105 117 Traceback (most recent call last): 106 SyntaxError: non-default argument follows default argument (<doctest test.test_syntax[15]>, line 1) 118 File "<doctest test.test_syntax[15]>", line 1 119 SyntaxError: non-default argument follows default argument 107 120 108 121 >>> def f(x, None): 109 122 ... pass 110 123 Traceback (most recent call last): 111 SyntaxError: assignment to None (<doctest test.test_syntax[16]>, line 1) 124 File "<doctest test.test_syntax[16]>", line 1 125 SyntaxError: cannot assign to None 112 126 113 127 >>> def f(*None): 114 128 ... pass 115 129 Traceback (most recent call last): 116 SyntaxError: assignment to None (<doctest test.test_syntax[17]>, line 1) 130 File "<doctest test.test_syntax[17]>", line 1 131 SyntaxError: cannot assign to None 117 132 118 133 >>> def f(**None): 119 134 ... pass 120 135 Traceback (most recent call last): 121 SyntaxError: assignment to None (<doctest test.test_syntax[18]>, line 1) 136 File "<doctest test.test_syntax[18]>", line 1 137 SyntaxError: cannot assign to None 122 138 123 139 … … 127 143 ... pass 128 144 Traceback (most recent call last): 129 SyntaxError: assignment to None (<doctest test.test_syntax[19]>, line 1) 145 File "<doctest test.test_syntax[19]>", line 1 146 SyntaxError: cannot assign to None 130 147 131 148 … … 139 156 >>> f(x for x in L, 1) 140 157 Traceback (most recent call last): 141 SyntaxError: Generator expression must be parenthesized if not sole argument (<doctest test.test_syntax[23]>, line 1) 158 File "<doctest test.test_syntax[23]>", line 1 159 SyntaxError: Generator expression must be parenthesized if not sole argument 142 160 >>> f((x for x in L), 1) 143 161 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] … … 171 189 ... i253, i254, i255) 172 190 Traceback (most recent call last): 173 SyntaxError: more than 255 arguments (<doctest test.test_syntax[25]>, line 1) 191 File "<doctest test.test_syntax[25]>", line 1 192 SyntaxError: more than 255 arguments 174 193 175 194 The actual error cases counts positional arguments, keyword arguments, … … 205 224 ... i252=1, i253=1, i254=1, i255=1) 206 225 Traceback (most recent call last): 207 SyntaxError: more than 255 arguments (<doctest test.test_syntax[26]>, line 1) 226 File "<doctest test.test_syntax[26]>", line 1 227 SyntaxError: more than 255 arguments 208 228 209 229 >>> f(lambda x: x[0] = 3) 210 230 Traceback (most recent call last): 211 SyntaxError: lambda cannot contain assignment (<doctest test.test_syntax[27]>, line 1) 231 File "<doctest test.test_syntax[27]>", line 1 232 SyntaxError: lambda cannot contain assignment 212 233 213 234 The grammar accepts any test (basically, any expression) in the … … 216 237 >>> f(x()=2) 217 238 Traceback (most recent call last): 218 SyntaxError: keyword can't be an expression (<doctest test.test_syntax[28]>, line 1) 239 File "<doctest test.test_syntax[28]>", line 1 240 SyntaxError: keyword can't be an expression 219 241 >>> f(a or b=1) 220 242 Traceback (most recent call last): 221 SyntaxError: keyword can't be an expression (<doctest test.test_syntax[29]>, line 1) 243 File "<doctest test.test_syntax[29]>", line 1 244 SyntaxError: keyword can't be an expression 222 245 >>> f(x.y=1) 223 246 Traceback (most recent call last): 224 SyntaxError: keyword can't be an expression (<doctest test.test_syntax[30]>, line 1) 225 226 227 From ast_for_expr_stmt(): 247 File "<doctest test.test_syntax[30]>", line 1 248 SyntaxError: keyword can't be an expression 249 250 251 More set_context(): 228 252 229 253 >>> (x for x in x) += 1 230 254 Traceback (most recent call last): 231 SyntaxError: augmented assignment to generator expression not possible (<doctest test.test_syntax[31]>, line 1) 255 File "<doctest test.test_syntax[31]>", line 1 256 SyntaxError: can't assign to generator expression 232 257 >>> None += 1 233 258 Traceback (most recent call last): 234 SyntaxError: assignment to None (<doctest test.test_syntax[32]>, line 1) 259 File "<doctest test.test_syntax[32]>", line 1 260 SyntaxError: cannot assign to None 235 261 >>> f() += 1 236 262 Traceback (most recent call last): 237 SyntaxError: illegal expression for augmented assignment (<doctest test.test_syntax[33]>, line 1) 263 File "<doctest test.test_syntax[33]>", line 1 264 SyntaxError: can't assign to function call 238 265 239 266 240 267 Test continue in finally in weird combinations. 241 268 242 continue in for loop under finally shou uld be ok.269 continue in for loop under finally should be ok. 243 270 244 271 >>> def test(): … … 262 289 Traceback (most recent call last): 263 290 ... 264 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[36]>, line 6) 291 File "<doctest test.test_syntax[36]>", line 6 292 SyntaxError: 'continue' not supported inside 'finally' clause 265 293 266 294 This is essentially a continue in a finally which should not be allowed. … … 277 305 Traceback (most recent call last): 278 306 ... 279 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[37]>, line 7) 307 File "<doctest test.test_syntax[37]>", line 6 308 SyntaxError: 'continue' not supported inside 'finally' clause 280 309 281 310 >>> def foo(): … … 286 315 Traceback (most recent call last): 287 316 ... 288 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[38]>, line 5) 317 File "<doctest test.test_syntax[38]>", line 5 318 SyntaxError: 'continue' not supported inside 'finally' clause 289 319 290 320 >>> def foo(): … … 296 326 Traceback (most recent call last): 297 327 ... 298 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[39]>, line 6) 328 File "<doctest test.test_syntax[39]>", line 6 329 SyntaxError: 'continue' not supported inside 'finally' clause 299 330 300 331 >>> def foo(): … … 309 340 Traceback (most recent call last): 310 341 ... 311 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[40]>, line 7) 342 File "<doctest test.test_syntax[40]>", line 7 343 SyntaxError: 'continue' not supported inside 'finally' clause 312 344 313 345 >>> def foo(): … … 321 353 Traceback (most recent call last): 322 354 ... 323 SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[41]>, line 8) 355 File "<doctest test.test_syntax[41]>", line 8 356 SyntaxError: 'continue' not supported inside 'finally' clause 324 357 325 358 There is one test for a break that is not in a loop. The compiler … … 336 369 Traceback (most recent call last): 337 370 ... 338 SyntaxError: 'break' outside loop (<doctest test.test_syntax[42]>, line 3) 371 File "<doctest test.test_syntax[42]>", line 3 372 SyntaxError: 'break' outside loop 339 373 340 374 This should probably raise a better error than a SystemError (or none at all). … … 378 412 Traceback (most recent call last): 379 413 ... 380 SyntaxError: can't assign to function call (<doctest test.test_syntax[44]>, line 2) 414 File "<doctest test.test_syntax[44]>", line 2 415 SyntaxError: can't assign to function call 381 416 382 417 >>> if 1: … … 386 421 Traceback (most recent call last): 387 422 ... 388 SyntaxError: can't assign to function call (<doctest test.test_syntax[45]>, line 4) 423 File "<doctest test.test_syntax[45]>", line 4 424 SyntaxError: can't assign to function call 389 425 390 426 >>> if 1: … … 396 432 Traceback (most recent call last): 397 433 ... 398 SyntaxError: can't assign to function call (<doctest test.test_syntax[46]>, line 2) 434 File "<doctest test.test_syntax[46]>", line 2 435 SyntaxError: can't assign to function call 399 436 400 437 >>> if 1: … … 406 443 Traceback (most recent call last): 407 444 ... 408 SyntaxError: can't assign to function call (<doctest test.test_syntax[47]>, line 4) 445 File "<doctest test.test_syntax[47]>", line 4 446 SyntaxError: can't assign to function call 409 447 410 448 >>> if 1: … … 416 454 Traceback (most recent call last): 417 455 ... 418 SyntaxError: can't assign to function call (<doctest test.test_syntax[48]>, line 6) 456 File "<doctest test.test_syntax[48]>", line 6 457 SyntaxError: can't assign to function call 419 458 420 459 >>> f(a=23, a=234) 421 460 Traceback (most recent call last): 422 461 ... 423 SyntaxError: keyword argument repeated (<doctest test.test_syntax[49]>, line 1) 462 File "<doctest test.test_syntax[49]>", line 1 463 SyntaxError: keyword argument repeated 464 465 >>> del () 466 Traceback (most recent call last): 467 ... 468 File "<doctest test.test_syntax[50]>", line 1 469 SyntaxError: can't delete () 470 471 >>> {1, 2, 3} = 42 472 Traceback (most recent call last): 473 ... 474 File "<doctest test.test_syntax[50]>", line 1 475 SyntaxError: can't assign to literal 476 477 Corner-case that used to crash: 478 479 >>> def f(*xx, **__debug__): pass 480 Traceback (most recent call last): 481 SyntaxError: cannot assign to __debug__ 424 482 425 483 """ … … 507 565 test_support.run_unittest(SyntaxTestCase) 508 566 from test import test_syntax 509 test_support.run_doctest(test_syntax, verbosity=True) 567 with test_support.check_py3k_warnings(("backquote not supported", 568 SyntaxWarning)): 569 test_support.run_doctest(test_syntax, verbosity=True) 510 570 511 571 if __name__ == "__main__":
Note:
See TracChangeset
for help on using the changeset viewer.