B
    S\	                 @   sV   d Z ddlZddlZddlZddlZddlmZ d
ddZdddZej	dd	 Z
dS )z@Utility functions for test code that uses astroid ASTs as input.    N)nodesc                s   ddd fdd}|S )zY Compare version of python interpreter to the given one. Skip the test
    if older.
    Nc          
   S   sZ   | p|} yt dd | dD S  tk
rT } ztdj| d|W d d }~X Y nX d S )Nc             s   s   | ]}t |V  qd S )N)int).0v r   1lib/python3.7/site-packages/astroid/test_utils.py	<genexpr>   s    z1require_version.<locals>.parse.<locals>.<genexpr>.z6{string} is not a correct version : should be X.Y[.Z].)string)tuplesplit
ValueErrorformat)r
   defaultexcr   r   r   parse   s    zrequire_version.<locals>.parsec                sj   t jd d }d|  k r.dkr6n n| S ddd t jD  t|  fdd}|S )	N   04r	   c             s   s   | ]}t |V  qd S )N)str)r   r   r   r   r   r   )   s    zArequire_version.<locals>.check_require_version.<locals>.<genexpr>c                s:   d k	r|  df  n d k	r6|  d f  d S )Nz)Needs Python > %s. Current version is %s.z*Needs Python <= %s. Current version is %s.)ZskipTest)selfargskwargs)maxverminverstr_versionr   r   new_f+   s    z=require_version.<locals>.check_require_version.<locals>.new_f)sysversion_infojoin	functoolswraps)fZcurrentr   )r   r   r   )r   r   check_require_version$   s    $z.require_version.<locals>.check_require_version)Nr   )r   r   r#   r   )r   r   r   r   require_version   s    
r$   c                s    fdd|  tjD | S )Nc                s   g | ]}|j  kr|qS r   )name)r   n)r%   r   r   
<listcomp><   s    z!get_name_node.<locals>.<listcomp>)Znodes_of_classr   Name)Z
start_fromr%   indexr   )r%   r   get_name_node;   s    r*   c          
   c   s*   t d|  z
d V  W d t d|  X d S )Nalwaysr   )warningssimplefilter)Zwarningr   r   r   enable_warning?   s    
r.   )NN)r   )__doc__
contextlibr    r   r,   Zastroidr   r$   r*   contextmanagerr.   r   r   r   r   <module>   s   
'
