From: Benjamin Peterson Date: Tue, 7 Apr 2009 15:15:04 +0000 (+0000) Subject: fix syntax tests after formatting change X-Git-Tag: v2.7a1~1537 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=52b9620c1941643dc6f834857bf6d76e8bbfc478;p=python fix syntax tests after formatting change --- diff --git a/Lib/test/test_genexps.py b/Lib/test/test_genexps.py index a86f12f03e..17ad78a033 100644 --- a/Lib/test/test_genexps.py +++ b/Lib/test/test_genexps.py @@ -137,12 +137,14 @@ Verify that syntax error's are raised for genexps used as lvalues >>> (y for y in (1,2)) = 10 Traceback (most recent call last): ... - SyntaxError: can't assign to generator expression (, line 1) + File "", line 1 + SyntaxError: can't assign to generator expression >>> (y for y in (1,2)) += 10 Traceback (most recent call last): ... - SyntaxError: augmented assignment to generator expression not possible (, line 1) + File "", line 1 + SyntaxError: augmented assignment to generator expression not possible ########### Tests borrowed from or inspired by test_generators.py ############ diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 794564a7c1..896ee81255 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -29,11 +29,13 @@ Errors from set_context(): >>> obj.None = 1 Traceback (most recent call last): -SyntaxError: cannot assign to None (, line 1) + File "", line 1 +SyntaxError: cannot assign to None >>> None = 1 Traceback (most recent call last): -SyntaxError: cannot assign to None (, line 1) + File "", line 1 +SyntaxError: cannot assign to None It's a syntax error to assign to the empty tuple. Why isn't it an error to assign to the empty list? It will always raise some error at @@ -41,35 +43,43 @@ runtime. >>> () = 1 Traceback (most recent call last): -SyntaxError: can't assign to () (, line 1) + File "", line 1 +SyntaxError: can't assign to () >>> f() = 1 Traceback (most recent call last): -SyntaxError: can't assign to function call (, line 1) + File "", line 1 +SyntaxError: can't assign to function call >>> del f() Traceback (most recent call last): -SyntaxError: can't delete function call (, line 1) + File "", line 1 +SyntaxError: can't delete function call >>> a + 1 = 2 Traceback (most recent call last): -SyntaxError: can't assign to operator (, line 1) + File "", line 1 +SyntaxError: can't assign to operator >>> (x for x in x) = 1 Traceback (most recent call last): -SyntaxError: can't assign to generator expression (, line 1) + File "", line 1 +SyntaxError: can't assign to generator expression >>> 1 = 1 Traceback (most recent call last): -SyntaxError: can't assign to literal (, line 1) + File "", line 1 +SyntaxError: can't assign to literal >>> "abc" = 1 Traceback (most recent call last): -SyntaxError: can't assign to literal (, line 1) + File "", line 1 +SyntaxError: can't assign to literal >>> `1` = 1 Traceback (most recent call last): -SyntaxError: can't assign to repr (, line 1) + File "", line 1 +SyntaxError: can't assign to repr If the left-hand side of an assignment is a list or tuple, an illegal expression inside that contain should still cause a syntax error. @@ -78,22 +88,26 @@ them. >>> (a, "b", c) = (1, 2, 3) Traceback (most recent call last): -SyntaxError: can't assign to literal (, line 1) + File "", line 1 +SyntaxError: can't assign to literal >>> [a, b, c + 1] = [1, 2, 3] Traceback (most recent call last): -SyntaxError: can't assign to operator (, line 1) + File "", line 1 +SyntaxError: can't assign to operator >>> a if 1 else b = 1 Traceback (most recent call last): -SyntaxError: can't assign to conditional expression (, line 1) + File "", line 1 +SyntaxError: can't assign to conditional expression From compiler_complex_args(): >>> def f(None=1): ... pass Traceback (most recent call last): -SyntaxError: cannot assign to None (, line 1) + File "", line 1 +SyntaxError: cannot assign to None From ast_for_arguments(): @@ -101,22 +115,26 @@ From ast_for_arguments(): >>> def f(x, y=1, z): ... pass Traceback (most recent call last): -SyntaxError: non-default argument follows default argument (, line 1) + File "", line 1 +SyntaxError: non-default argument follows default argument >>> def f(x, None): ... pass Traceback (most recent call last): -SyntaxError: cannot assign to None (, line 1) + File "", line 1 +SyntaxError: cannot assign to None >>> def f(*None): ... pass Traceback (most recent call last): -SyntaxError: cannot assign to None (, line 1) + File "", line 1 +SyntaxError: cannot assign to None >>> def f(**None): ... pass Traceback (most recent call last): -SyntaxError: cannot assign to None (, line 1) + File "", line 1 +SyntaxError: cannot assign to None From ast_for_funcdef(): @@ -124,7 +142,8 @@ From ast_for_funcdef(): >>> def None(x): ... pass Traceback (most recent call last): -SyntaxError: cannot assign to None (, line 1) + File "", line 1 +SyntaxError: cannot assign to None From ast_for_call(): @@ -136,7 +155,8 @@ From ast_for_call(): [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> f(x for x in L, 1) Traceback (most recent call last): -SyntaxError: Generator expression must be parenthesized if not sole argument (, line 1) + File "", line 1 +SyntaxError: Generator expression must be parenthesized if not sole argument >>> f((x for x in L), 1) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] @@ -168,7 +188,8 @@ SyntaxError: Generator expression must be parenthesized if not sole argument (, line 1) + File "", line 1 +SyntaxError: more than 255 arguments The actual error cases counts positional arguments, keyword arguments, and generator expression arguments separately. This test combines the @@ -202,37 +223,45 @@ three. ... (x for x in i244), i245, i246, i247, i248, i249, i250, i251, ... i252=1, i253=1, i254=1, i255=1) Traceback (most recent call last): -SyntaxError: more than 255 arguments (, line 1) + File "", line 1 +SyntaxError: more than 255 arguments >>> f(lambda x: x[0] = 3) Traceback (most recent call last): -SyntaxError: lambda cannot contain assignment (, line 1) + File "", line 1 +SyntaxError: lambda cannot contain assignment The grammar accepts any test (basically, any expression) in the keyword slot of a call site. Test a few different options. >>> f(x()=2) Traceback (most recent call last): -SyntaxError: keyword can't be an expression (, line 1) + File "", line 1 +SyntaxError: keyword can't be an expression >>> f(a or b=1) Traceback (most recent call last): -SyntaxError: keyword can't be an expression (, line 1) + File "", line 1 +SyntaxError: keyword can't be an expression >>> f(x.y=1) Traceback (most recent call last): -SyntaxError: keyword can't be an expression (, line 1) + File "", line 1 +SyntaxError: keyword can't be an expression From ast_for_expr_stmt(): >>> (x for x in x) += 1 Traceback (most recent call last): -SyntaxError: augmented assignment to generator expression not possible (, line 1) + File "", line 1 +SyntaxError: augmented assignment to generator expression not possible >>> None += 1 Traceback (most recent call last): -SyntaxError: cannot assign to None (, line 1) + File "", line 1 +SyntaxError: cannot assign to None >>> f() += 1 Traceback (most recent call last): -SyntaxError: illegal expression for augmented assignment (, line 1) + File "", line 1 +SyntaxError: illegal expression for augmented assignment Test continue in finally in weird combinations. @@ -259,7 +288,8 @@ Start simple, a continue in a finally should not be allowed. ... continue Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 6) + File "", line 6 + SyntaxError: 'continue' not supported inside 'finally' clause This is essentially a continue in a finally which should not be allowed. @@ -274,7 +304,8 @@ This is essentially a continue in a finally which should not be allowed. ... pass Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 7) + File "", line 6 + SyntaxError: 'continue' not supported inside 'finally' clause >>> def foo(): ... try: @@ -283,7 +314,8 @@ This is essentially a continue in a finally which should not be allowed. ... continue Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 5) + File "", line 5 + SyntaxError: 'continue' not supported inside 'finally' clause >>> def foo(): ... for a in (): @@ -293,7 +325,8 @@ This is essentially a continue in a finally which should not be allowed. ... continue Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 6) + File "", line 6 + SyntaxError: 'continue' not supported inside 'finally' clause >>> def foo(): ... for a in (): @@ -306,7 +339,8 @@ This is essentially a continue in a finally which should not be allowed. ... pass Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 7) + File "", line 7 + SyntaxError: 'continue' not supported inside 'finally' clause >>> def foo(): ... for a in (): @@ -318,7 +352,8 @@ This is essentially a continue in a finally which should not be allowed. ... continue Traceback (most recent call last): ... - SyntaxError: 'continue' not supported inside 'finally' clause (, line 8) + File "", line 8 + SyntaxError: 'continue' not supported inside 'finally' clause There is one test for a break that is not in a loop. The compiler uses a single data structure to keep track of try-finally and loops, @@ -333,7 +368,8 @@ isn't, there should be a syntax error. ... print 3 Traceback (most recent call last): ... - SyntaxError: 'break' outside loop (, line 3) + File "", line 3 + SyntaxError: 'break' outside loop This should probably raise a better error than a SystemError (or none at all). In 2.5 there was a missing exception and an assert was triggered in a debug @@ -375,7 +411,8 @@ leading to spurious errors. ... pass Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 2) + File "", line 2 + SyntaxError: can't assign to function call >>> if 1: ... pass @@ -383,7 +420,8 @@ leading to spurious errors. ... x() = 1 Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 4) + File "", line 4 + SyntaxError: can't assign to function call >>> if 1: ... x() = 1 @@ -393,7 +431,8 @@ leading to spurious errors. ... pass Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 2) + File "", line 2 + SyntaxError: can't assign to function call >>> if 1: ... pass @@ -403,7 +442,8 @@ leading to spurious errors. ... pass Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 4) + File "", line 4 + SyntaxError: can't assign to function call >>> if 1: ... pass @@ -413,12 +453,14 @@ leading to spurious errors. ... x() = 1 Traceback (most recent call last): ... - SyntaxError: can't assign to function call (, line 6) + File "", line 6 + SyntaxError: can't assign to function call >>> f(a=23, a=234) Traceback (most recent call last): ... -SyntaxError: keyword argument repeated (, line 1) + File "", line 1 +SyntaxError: keyword argument repeated """