Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_syntax.cpython-311.opt-2.pyc
�

�KeN���	ddlZddlZddlZddlmZGd�dej��Zd�Zedkrej	��dSdS)�N)�supportc�N�eZdZ		d'd�Zd�Zd�Zd�Zd�Zd	�Zd
�Z	d�Z
d�Zd
�Zd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zejd���Zd�Zd�Zd�Zd�Zd�Z d �Z!d!�Z"d"�Z#d#�Z$ejd$���Z%ejd%���Z&ejd&���Z'dS)(�SyntaxTestCase�
<testcase>�execNc
��		t|||��|�d��dS#t$�r}
|r-t|
|��s|�d|jz��tj|t|
����}|�|�d|����|�|
j	|��|�|�|
j
|��|�|�|
j|��|�|�|
j|��|	�!|�|
j
|	��Yd}
~
dSYd}
~
dSd}
~
wwxYw)Nz#compile() did not raise SyntaxErrorzSyntaxError is not a %szSyntaxError did not contain )�compile�fail�SyntaxError�
isinstance�__name__�re�search�str�assertEqual�filename�lineno�offset�
end_lineno�
end_offset)�self�code�errtextr�mode�subclassrrrr�err�mos            �:/usr/local/apps/python3/lib/python3.11/test/test_syntax.py�_check_errorzSyntaxTestCase._check_errors{��	�	=��D�(�D�)�)�)�$
�I�I�;�<�<�<�<�<��#�	=�	=�	=��
I�
�3�� 9� 9�
I��	�	�3�h�6G�G�H�H�H���7�C��H�H�-�-�B��z��	�	�	�g�g�G�H�H�H����S�\�8�4�4�4��!�� � ���V�4�4�4��!�� � ���V�4�4�4��%�� � ����<�<�<��%�� � ����<�<�<�<�<�<�<�<�<�&�%�%�%�%�%�����	=���s�+�E�C:D<�<Ec�6�|�ddd���dS)Nzprint(end1 + end2 = ' ')z=expression cannot contain assignment, perhaps you meant "=="?�)r�r�rs r�test_expression_with_assignmentz.SyntaxTestCase.test_expression_with_assignment6s2�����&�K��	�	
�	
�	
�	
�	
�c�6�|�ddd���dS)Nzf{}�invalid syntax�single�rr"r#s r�1test_curly_brace_after_primary_raises_immediatelyz@SyntaxTestCase.test_curly_brace_after_primary_raises_immediately=s$�����%�!1���A�A�A�A�Ar%c�2�|�dd��dS)Nzf() = 1�assignr"r#s r�test_assign_callzSyntaxTestCase.test_assign_call@s�����)�X�.�.�.�.�.r%c��|�dd��|�dd��|�dd��|�dd��|�dd	��|�d
d��|�dd	��|�d
d	��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�d d��|�d!d��|�d"d#��|�d$d��dS)%Nzdel (,)r'zdel 1zcannot delete literalz
del (1, 2)zdel Nonezcannot delete Nonezdel *xzcannot delete starredzdel (*x)zcannot use starred expressionz	del (*x,)z	del [*x,]zdel f()zcannot delete function callzdel f(a, b)z	del o.f()z
del a[0]()z
del x, f()z
del f(), xzdel [a, b, ((c), (d,), e.f())]zdel (a if True else b)zcannot delete conditionalzdel +azcannot delete expressionz	del a, +bz	del a + bzdel (a + b, c)zdel (c[0], a + b)z
del a.b.c + 2zdel a.b.c[0] + 2zdel (a, b, (c, d.e.f + 2))zdel [a, b, (c, d.e.f[0] + 2)]zdel (a := 5)zcannot delete named expressionz
del a += br"r#s r�test_assign_delzSyntaxTestCase.test_assign_delCs~�����)�%5�6�6�6����'�#:�;�;�;����,�(?�@�@�@����*�&:�;�;�;����(�$;�<�<�<����*�&E�F�F�F����+�'>�?�?�?����+�'>�?�?�?����)�%B�C�C�C����-�)F�G�G�G����+�'D�E�E�E����,�(E�F�F�F����,�(E�F�F�F����,�(E�F�F�F����:�<Y�Z�Z�Z����2�4O�P�P�P����(�$>�?�?�?����+�'A�B�B�B����+�'A�B�B�B����*�,F�G�G�G����-�/I�J�J�J����/�+E�F�F�F����,�.H�I�I�I����6�8R�S�S�S����9�;U�V�V�V����.�*J�K�K�K�	
���,�(8�9�9�9�9�9r%c�:�d}|�|dd���dS)Nz�if 1:
            def error(a):
                global a  # SyntaxError
            def error2():
                b = 1
                global b  # SyntaxError
            zparameter and global��rr"�r�sources  r�test_global_param_err_firstz*SyntaxTestCase.test_global_param_err_firstbs-����	
���&�"8���C�C�C�C�Cr%c�:�d}|�|dd���dS)Nz�if 1:
            def error(a):
                nonlocal a  # SyntaxError
            def error2():
                b = 1
                global b  # SyntaxError
            zparameter and nonlocalr1r2r"r3s  r�test_nonlocal_param_err_firstz,SyntaxTestCase.test_nonlocal_param_err_firstls-����	
���&�":�1��E�E�E�E�Er%c��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�d	d��|�d
d��dS)Nzif 0: yield�outside functionzif 0: yield
else:  x=1zif 1: pass
else: yieldzwhile 0: yieldzwhile 0: yield
else:  x=1zclass C:
  if 0: yieldz#class C:
  if 1: pass
  else: yieldzclass C:
  while 0: yieldz(class C:
  while 0: yield
  else:  x = 1r"r#s r�test_yield_outside_functionz*SyntaxTestCase.test_yield_outside_functionvs������-�8J�K�K�K����3�8J�K�K�K����3�8J�K�K�K����*�8J�K�K�K����6�8J�K�K�K����3�8J�K�K�K����A�,�	.�	.�	.����6�8J�K�K�K����F�,�	.�	.�	.�	.�	.r%c��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�dd��|�d	d��|�d
d��dS)Nzif 0: returnr9zif 0: return
else:  x=1zif 1: pass
else: returnzwhile 0: returnzclass C:
  if 0: returnzclass C:
  while 0: returnz'class C:
  while 0: return
  else:  x=1z$class C:
  if 0: return
  else: x= 1z$class C:
  if 1: pass
  else: returnr"r#s r�test_return_outside_functionz+SyntaxTestCase.test_return_outside_function�s������.�9K�L�L�L����4�9K�L�L�L����4�9K�L�L�L����+�9K�L�L�L����4�9K�L�L�L����7�9K�L�L�L����E�,�	.�	.�	.����B�,�	.�	.�	.����B�,�	.�	.�	.�	.�	.r%c�Z�d}|�d|d���|�d|d���|�d|d���|�d|d���|�d	|d���|�d
|d���|�d|d���dS)
Nzoutside loop�break�r2zif 0: breakzif 0: break
else:  x=1zif 1: pass
else: break�zclass C:
  if 0: breakz#class C:
  if 1: pass
  else: breakr1zwith object() as obj:
 breakr"�r�msgs  r�test_break_outside_loopz&SyntaxTestCase.test_break_outside_loop�s��������'�3�q��1�1�1����-��Q��7�7�7����3�S���C�C�C����3�S���C�C�C����3�S���C�C�C����A��a�	�	)�	)�	)����9��a�	�	)�	)�	)�	)�	)r%c�*�d}|�d|d���|�d|d���|�d|d���|�d|d���|�d	|d
���|�d|d���dS)Nznot properly in loopzif 0: continuer?r2zif 0: continue
else:  x=1zif 1: pass
else: continuer@zclass C:
  if 0: continuez&class C:
  if 1: pass
  else: continuer1z"with object() as obj:
    continuer"rAs  r�test_continue_outside_loopz)SyntaxTestCase.test_continue_outside_loop�s���$�����*�C���:�:�:����6��A��F�F�F����6��A��F�F�F����6��A��F�F�F����D��a�	�	)�	)�	)����?��a�	�	)�	)�	)�	)�	)r%c�@�|�ddt���dS)Nz
foo()
 bar()
zunexpected indent�r�r�IndentationErrorr#s r�test_unexpected_indentz%SyntaxTestCase.test_unexpected_indent�s2�����+�-@�#3�	�	5�	5�	5�	5�	5r%c�@�|�ddt���dS)Nzif 1:
foo()zexpected an indented blockrGrHr#s r�test_no_indentzSyntaxTestCase.test_no_indent�s1�����.�*F�#3�	�	5�	5�	5�	5�	5r%c�@�|�ddt���dS)Nzif 1:
  foo()
 bar()z unindent does not match .* levelrGrHr#s r�test_bad_outdentzSyntaxTestCase.test_bad_outdent�s2�����2�<�#3�	�	5�	5�	5�	5�	5r%c�2�|�dd��dS)Nzint(base=10, '2')z,positional argument follows keyword argumentr"r#s r�test_kwargs_lastzSyntaxTestCase.test_kwargs_last�s/�����-�H�	J�	J�	J�	J�	Jr%c�2�|�dd��dS)Nzint(**{'base': 10}, '2')z6positional argument follows keyword argument unpackingr"r#s r�test_kwargs_last2z SyntaxTestCase.test_kwargs_last2�s,�����4�7�	8�	8�	8�	8�	8r%c�2�|�dd��dS)Nzint(**{'base': 10}, *['2'])z>iterable argument unpacking follows keyword argument unpackingr"r#s r�test_kwargs_last3z SyntaxTestCase.test_kwargs_last3�s,�����7�7�	8�	8�	8�	8�	8r%c�<�|�dddddd���dS)Nz<foo(x,    y for y in range(3) for z in range(2) if z    , p)z*Generator expression must be parenthesizedr?��5�rrrrr"r#s r�test_generator_in_function_callz.SyntaxTestCase.test_generator_in_function_call�s=�����X�F�!"�q���	�	L�	L�	L�	L�	Lr%c�<�|�dddddd���dS)Nz9try: pass
except ValueError: pass
except* TypeError: pass�:cannot have both 'except' and 'except\*' on the same 'try'r1r?�rXr"r#s r�test_except_then_except_starz+SyntaxTestCase.test_except_then_except_star��=�����W�W�!"�q��q�	�	J�	J�	J�	J�	Jr%c�<�|�dddddd���dS)Nz9try: pass
except* ValueError: pass
except TypeError: passr[r1r?r!rXr"r#s r�test_except_star_then_exceptz+SyntaxTestCase.test_except_star_then_except�r^r%c��d}	t|dd��n%#t$r|�d��YnwxYwd}d}	t|dd��t|dd��dS#t$r|�d��YdSwxYw)Nz\
pass
        \

pass
�<string>rz8Empty line after a line continuation character is valid.zN\
def fib(n):
    \
'''Print a Fibonacci series up to n.'''
    \
a, b = 0, 1
zJ\
def fib(n):
    '''Print a Fibonacci series up to n.'''
    a, b = 0, 1
z/Indented statement over multiple lines is valid)r	rr
)r�s�s1�s2s    r�test_empty_line_after_linecontz-SyntaxTestCase.test_empty_line_after_linecont�s���
��	R��A�z�6�*�*�*�*���	R�	R�	R��I�I�P�Q�Q�Q�Q�Q�	R��������
	I��B�
�F�+�+�+��B�
�F�+�+�+�+�+���	I�	I�	I��I�I�G�H�H�H�H�H�H�	I���s��8�8�"A$�$B�Bc�L�d}|�tt|��dS)Nz(\
if x:
    y = 1
  \
  foo = 1
        )�assertRaisesrIr�rrs  r�!test_continuation_bad_indentationz0SyntaxTestCase.test_continuation_bad_indentation�s*����	
���*�D�$�7�7�7�7�7r%c��d}td��D]&}|d|z�d�z
}|d|dzz�d�z
}|d|z�d�z
}�'|d�d	�z
}|�|d
��dS)N��z    ztry:
r?zraise Exception
zexcept Exception as e:
z0                                                �pass�!too many statically nested blocks)�ranger)rr�is   r�test_nested_named_except_blocksz.SyntaxTestCase.test_nested_named_except_blocks�s������r���	:�	:�A��v�a�x�'�'�'�'�D��v�q��s�|�6�6�6�6�D��v�a�x�9�9�9�9�D�D��8�!�!�!�!�����$� C�D�D�D�D�Dr%c�6�d}|�|d��dS)Nzw
def func1():
    if a != b:
        raise ValueError

def func2():
    try
        return 1
    finally:
        pass
zexpected ':'r"ris  r�&test_barry_as_flufl_with_syntax_errorsz5SyntaxTestCase.test_barry_as_flufl_with_syntax_errorss'��
��	
���$��/�/�/�/�/r%c��|�dddd���|�dddd���|�ddd	d���dS)
Nz	a = 3 \ 4�6unexpected character after line continuation characterr?r\)rrz1,\#
2�z
fgdfgf
1,\#
2
r1r"r#s r�-test_invalid_line_continuation_error_positionz<SyntaxTestCase.test_invalid_line_continuation_error_positions������,�R�!"�1�	�	.�	.�	.�	
���*�R�!"�1�	�	.�	.�	.�	
���0�R�!"�1�	�	.�	.�	.�	.�	.r%c�^�|�dd��|�dd��dS)NuA.Ɗ\ rvuA.μ\
zunexpected EOF while parsingr"r#s r�-test_invalid_line_continuation_left_recursivez<SyntaxTestCase.test_invalid_line_continuation_left_recursive$sK��	
���-�R�	T�	T�	T����.�8�	:�	:�	:�	:�	:r%c��dD]}|�|dzd|�d���� dD] }|�d|�d�d|�d����!dD]}|�|dzd|�d	���� d
}|�|d��dS)Nz([{z1 + 2�\z' was never closedza = z 1, 2, 3
b=3z)]}zunmatched '\�'zFfunc(
    a=["unclosed], # Need a quote in this comment: "
    b=2,
)
z8parenthesis '\)' does not match opening parenthesis '\['r")r�parenrs   r�test_error_parenthesisz%SyntaxTestCase.test_error_parenthesis,s����	O�	O�E����e�g�o�/M�E�/M�/M�/M�N�N�N�N��	[�	[�E����9�U�9�9�9�;Y��;Y�;Y�;Y�Z�Z�Z�Z��	I�	I�E����e�g�o�/G�u�/G�/G�/G�H�H�H�H���	
���$� \�]�]�]�]�]r%c��|�dd��|�dd��|�dd��|�dd��dS)Nz'blechzunterminated string literalz"blechz'''blechz)unterminated triple-quoted string literalz"""blechr"r#s r�test_error_string_literalz(SyntaxTestCase.test_error_string_literal?sd�����(�$A�B�B�B����(�$A�B�B�B����*�&Q�R�R�R����*�&Q�R�R�R�R�Rr%c�2�|�dd��dS)Nzprint("Hello")zinvalid non-printable characterr"r#s r�test_invisible_charactersz(SyntaxTestCase.test_invisible_charactersFs �����.�0Q�R�R�R�R�Rr%c�,�d}t|dd��dS)Nz)
def match(x):
    return 1+1

match(34)
rbr�r	ris  r�+test_match_call_does_not_raise_syntax_errorz:SyntaxTestCase.test_match_call_does_not_raise_syntax_errorI�#����	��j�&�)�)�)�)�)r%c�,�d}t|dd��dS)Nz'
def case(x):
    return 1+1

case(34)
rbrr�ris  r�*test_case_call_does_not_raise_syntax_errorz9SyntaxTestCase.test_case_call_does_not_raise_syntax_errorRr�r%c�6�|�ddd���dS)Nzcall(
a=1,
a=1
)zkeyword argument repeatedr1r2r"r#s r�/test_multiline_compiler_error_points_to_the_endz>SyntaxTestCase.test_multiline_compiler_error_points_to_the_end[s2�����!�'��	�	
�	
�	
�	
�	
r%c�6�d}|�|d��dS)Na�
while 1:
 while 2:
  while 3:
   while 4:
    while 5:
     while 6:
      while 8:
       while 9:
        while 10:
         while 11:
          while 12:
           while 13:
            while 14:
             while 15:
              while 16:
               while 17:
                while 18:
                 while 19:
                  while 20:
                   while 21:
                    while 22:
                     break
ror"r3s  r�)test_syntax_error_on_deeply_nested_blocksz8SyntaxTestCase.test_syntax_error_on_deeply_nested_blocksbs(����0	
���&�"E�F�F�F�F�Fr%c��ddzdz}dD]s}|�|���5|�t��5t|d|��ddd��n#1swxYwYddd��n#1swxYwY�tdS)N�-i���4)r�evalr(r)rb)�subTestrh�MemoryErrorr	)rr4rs   r�#test_error_on_parser_stack_overflowz2SyntaxTestCase.test_error_on_parser_stack_overflow�s���v���#��.�	6�	6�D����4��(�(�
6�
6��&�&�{�3�3�6�6��F�J��5�5�5�6�6�6�6�6�6�6�6�6�6�6����6�6�6�6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6����
6�
6�
6�
6��	6�	6s4�A3�A�A3�A � A3�#A �$A3�3A7	�:A7	c��d}|�t��5t|dd��ddd��dS#1swxYwYdS)Nz,d{{{{{{{{{{{{{{{{{{{{{{{{{```{{{{{{{ef f():yrbr)rhrr	r3s  r�test_deep_invalid_rulez%SyntaxTestCase.test_deep_invalid_rule�s���@��
�
�
�{�
+�
+�	0�	0��F�J��/�/�/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0s�<�A�A)rrNNNNN)(r
�
__module__�__qualname__rr$r*r-r/r5r7r:r<rCrErJrLrNrPrRrTrYr]r`rfrjr�cpython_onlyrrrtrxrzrr�r�r�r�r�r�r�r��r%rrrs�������CG�KO�=�=�=�=�<
�
�
�B�B�B�/�/�/�:�:�:�>D�D�D�F�F�F�.�.�.�.�.�.�
)�
)�
)�	)�	)�	)�5�5�5�5�5�5�5�5�5�
J�J�J�8�8�8�
8�8�8�
L�L�L�
J�J�J�
J�J�J�
I�I�I�@
8�
8�
8�
��E�E���E�0�0�0�"	.�	.�	.�:�:�:�^�^�^�&S�S�S�S�S�S�*�*�*�*�*�*�
�
�
�
�� G� G��� G�D
��6�6���6�
��0�0���0�0�0r%rc�R�|�tj����|S)N)�addTest�doctest�DocTestSuite)�loader�tests�patterns   r�
load_testsr��s"��	�M�M�'�&�(�(�)�)�)��Lr%�__main__)
rr��unittest�testr�TestCaserr�r
�mainr�r%r�<module>r�s���M�^8
�	�	�	���������������}0�}0�}0�}0�}0�X�&�}0�}0�}0�@���
�z����H�M�O�O�O�O�O��r%