Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_syntax.py

    r2 r391  
    2828Errors from set_context():
    2929
    30 TODO(jhylton): "assignment to None" is inconsistent with other messages
    31 
    3230>>> obj.None = 1
    3331Traceback (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
     33SyntaxError: cannot assign to None
    3534
    3635>>> None = 1
    3736Traceback (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
     38SyntaxError: cannot assign to None
    3939
    4040It's a syntax error to assign to the empty tuple.  Why isn't it an
     
    4444>>> () = 1
    4545Traceback (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
     47SyntaxError: can't assign to ()
    4748
    4849>>> f() = 1
    4950Traceback (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
     52SyntaxError: can't assign to function call
    5153
    5254>>> del f()
    5355Traceback (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
     57SyntaxError: can't delete function call
    5558
    5659>>> a + 1 = 2
    5760Traceback (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
     62SyntaxError: can't assign to operator
    5963
    6064>>> (x for x in x) = 1
    6165Traceback (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
     67SyntaxError: can't assign to generator expression
    6368
    6469>>> 1 = 1
    6570Traceback (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
     72SyntaxError: can't assign to literal
    6773
    6874>>> "abc" = 1
    6975Traceback (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
     77SyntaxError: can't assign to literal
    7178
    7279>>> `1` = 1
    7380Traceback (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
     82SyntaxError: can't assign to repr
    7583
    7684If the left-hand side of an assignment is a list or tuple, an illegal
     
    8189>>> (a, "b", c) = (1, 2, 3)
    8290Traceback (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
     92SyntaxError: can't assign to literal
    8493
    8594>>> [a, b, c + 1] = [1, 2, 3]
    8695Traceback (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
     97SyntaxError: can't assign to operator
    8898
    8999>>> a if 1 else b = 1
    90100Traceback (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
     102SyntaxError: can't assign to conditional expression
    92103
    93104From compiler_complex_args():
     
    96107...     pass
    97108Traceback (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
     110SyntaxError: cannot assign to None
    99111
    100112
     
    104116...     pass
    105117Traceback (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
     119SyntaxError: non-default argument follows default argument
    107120
    108121>>> def f(x, None):
    109122...     pass
    110123Traceback (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
     125SyntaxError: cannot assign to None
    112126
    113127>>> def f(*None):
    114128...     pass
    115129Traceback (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
     131SyntaxError: cannot assign to None
    117132
    118133>>> def f(**None):
    119134...     pass
    120135Traceback (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
     137SyntaxError: cannot assign to None
    122138
    123139
     
    127143...     pass
    128144Traceback (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
     146SyntaxError: cannot assign to None
    130147
    131148
     
    139156>>> f(x for x in L, 1)
    140157Traceback (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
     159SyntaxError: Generator expression must be parenthesized if not sole argument
    142160>>> f((x for x in L), 1)
    143161[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
     
    171189...   i253,  i254,  i255)
    172190Traceback (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
     192SyntaxError: more than 255 arguments
    174193
    175194The actual error cases counts positional arguments, keyword arguments,
     
    205224...    i252=1, i253=1,  i254=1,  i255=1)
    206225Traceback (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
     227SyntaxError: more than 255 arguments
    208228
    209229>>> f(lambda x: x[0] = 3)
    210230Traceback (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
     232SyntaxError: lambda cannot contain assignment
    212233
    213234The grammar accepts any test (basically, any expression) in the
     
    216237>>> f(x()=2)
    217238Traceback (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
     240SyntaxError: keyword can't be an expression
    219241>>> f(a or b=1)
    220242Traceback (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
     244SyntaxError: keyword can't be an expression
    222245>>> f(x.y=1)
    223246Traceback (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
     248SyntaxError: keyword can't be an expression
     249
     250
     251More set_context():
    228252
    229253>>> (x for x in x) += 1
    230254Traceback (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
     256SyntaxError: can't assign to generator expression
    232257>>> None += 1
    233258Traceback (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
     260SyntaxError: cannot assign to None
    235261>>> f() += 1
    236262Traceback (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
     264SyntaxError: can't assign to function call
    238265
    239266
    240267Test continue in finally in weird combinations.
    241268
    242 continue in for loop under finally shouuld be ok.
     269continue in for loop under finally should be ok.
    243270
    244271    >>> def test():
     
    262289    Traceback (most recent call last):
    263290      ...
    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
    265293
    266294This is essentially a continue in a finally which should not be allowed.
     
    277305    Traceback (most recent call last):
    278306      ...
    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
    280309
    281310    >>> def foo():
     
    286315    Traceback (most recent call last):
    287316      ...
    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
    289319
    290320    >>> def foo():
     
    296326    Traceback (most recent call last):
    297327      ...
    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
    299330
    300331    >>> def foo():
     
    309340    Traceback (most recent call last):
    310341      ...
    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
    312344
    313345    >>> def foo():
     
    321353    Traceback (most recent call last):
    322354      ...
    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
    324357
    325358There is one test for a break that is not in a loop.  The compiler
     
    336369   Traceback (most recent call last):
    337370     ...
    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
    339373
    340374This should probably raise a better error than a SystemError (or none at all).
     
    378412   Traceback (most recent call last):
    379413     ...
    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
    381416
    382417   >>> if 1:
     
    386421   Traceback (most recent call last):
    387422     ...
    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
    389425
    390426   >>> if 1:
     
    396432   Traceback (most recent call last):
    397433     ...
    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
    399436
    400437   >>> if 1:
     
    406443   Traceback (most recent call last):
    407444     ...
    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
    409447
    410448   >>> if 1:
     
    416454   Traceback (most recent call last):
    417455     ...
    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
    419458
    420459>>> f(a=23, a=234)
    421460Traceback (most recent call last):
    422461   ...
    423 SyntaxError: keyword argument repeated (<doctest test.test_syntax[49]>, line 1)
     462  File "<doctest test.test_syntax[49]>", line 1
     463SyntaxError: keyword argument repeated
     464
     465>>> del ()
     466Traceback (most recent call last):
     467   ...
     468  File "<doctest test.test_syntax[50]>", line 1
     469SyntaxError: can't delete ()
     470
     471>>> {1, 2, 3} = 42
     472Traceback (most recent call last):
     473   ...
     474   File "<doctest test.test_syntax[50]>", line 1
     475SyntaxError: can't assign to literal
     476
     477Corner-case that used to crash:
     478
     479    >>> def f(*xx, **__debug__): pass
     480    Traceback (most recent call last):
     481    SyntaxError: cannot assign to __debug__
    424482
    425483"""
     
    507565    test_support.run_unittest(SyntaxTestCase)
    508566    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)
    510570
    511571if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.