B
    u9aX                 @   sH   d dl Z d dlZd dlmZ G dd dejZdd ZedkrDe  dS )    N)supportc               @   sn   e Zd ZdddZdd Zdd	 Zd
d Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )SyntaxTestCase
<testcase>execNc       
   
   C   s   yt ||| W n tk
r } z|r@t||s@| d|j  t|t|}	|	d krh| d|f  | |j	| |d k	r| |j
| |d k	r| |j| W d d }~X Y nX | d d S )NzSyntaxError is not a %sz SyntaxError did not contain '%r'z#compile() did not raise SyntaxError)compileSyntaxError
isinstanceZfail__name__researchstrZassertEqualfilenamelinenooffset)
selfcodeZerrtextr   modesubclassr   r   errmo r   !/usr/lib/python3.7/test_syntax.py_check_errorX  s     zSyntaxTestCase._check_errorc             C   s   |  dd d S )Nzf() = 1Zassign)r   )r   r   r   r   test_assign_callp  s    zSyntaxTestCase.test_assign_callc             C   s   |  dd d S )Nzdel f()delete)r   )r   r   r   r   test_assign_dels  s    zSyntaxTestCase.test_assign_delc             C   s   d}| j |ddd d S )Nzif 1:
            def error(a):
                global a  # SyntaxError
            def error2():
                b = 1
                global b  # SyntaxError
            zparameter and global   )r   )r   )r   sourcer   r   r   test_global_param_err_firstv  s    z*SyntaxTestCase.test_global_param_err_firstc             C   s   d}| j |ddd d S )Nzif 1:
            def error(a):
                nonlocal a  # SyntaxError
            def error2():
                b = 1
                global b  # SyntaxError
            zparameter and nonlocalr   )r   )r   )r   r   r   r   r   test_nonlocal_param_err_first  s    z,SyntaxTestCase.test_nonlocal_param_err_firstc             C   s   |  dd d S )Nbreakzoutside loop)r   )r   r   r   r   test_break_outside_loop  s    z&SyntaxTestCase.test_break_outside_loopc             C   s   | j ddtd d S )Nzfoo()
 bar()
zunexpected indent)r   )r   IndentationError)r   r   r   r   test_unexpected_indent  s    z%SyntaxTestCase.test_unexpected_indentc             C   s   | j ddtd d S )Nzif 1:
foo()zexpected an indented block)r   )r   r"   )r   r   r   r   test_no_indent  s    zSyntaxTestCase.test_no_indentc             C   s   | j ddtd d S )Nzif 1:
  foo()
 bar()z unindent does not match .* level)r   )r   r"   )r   r   r   r   test_bad_outdent  s    zSyntaxTestCase.test_bad_outdentc             C   s   |  dd d S )Nzint(base=10, '2')z,positional argument follows keyword argument)r   )r   r   r   r   test_kwargs_last  s    zSyntaxTestCase.test_kwargs_lastc             C   s   |  dd d S )Nzint(**{'base': 10}, '2')z6positional argument follows keyword argument unpacking)r   )r   r   r   r   test_kwargs_last2  s    z SyntaxTestCase.test_kwargs_last2c             C   s   |  dd d S )Nzint(**{'base': 10}, *['2'])z>iterable argument unpacking follows keyword argument unpacking)r   )r   r   r   r   test_kwargs_last3  s    z SyntaxTestCase.test_kwargs_last3)r   r   NNN)r	   
__module____qualname__r   r   r   r   r   r!   r#   r$   r%   r&   r'   r(   r   r   r   r   r   V  s   


r   c              C   s(   t t ddlm}  t j| dd d S )Nr   )test_syntaxT)	verbosity)r   Zrun_unittestr   testr+   Zrun_doctest)r+   r   r   r   	test_main  s    
r.   __main__)r
   Zunittestr-   r   ZTestCaser   r.   r	   r   r   r   r   <module>Q  s   R