U
    luf                     @   s   d Z ddlZddlZddlmZmZmZ ddlZddlZe	d ej
ejZdd ZedZedZd	d
 Zej
erdd eeD Zejjej
e ddejdedd Zej
erdd eeD Zejdedd ZdS )z
Test our typing with mypy
    N)PIPESTDOUTPopenmypyc                 C   s*   t jt jt| }t j|s&| }|S )zResolve a dir in the repo

    Resolved relative to zmq dir

    fallback on CWD (e.g. test run from repo, zmq installed, not -e)
    )ospathjoindirnamezmq_direxists)r   resolved_path r   7/tmp/pip-unpacked-wheel-h6ekxre8/zmq/tests/test_mypy.pyresolve_repo_dir   s    r   examples
mypy_testsc                  G   sT   t tjddgt|  ttd}| \}}|dd}t| |j	dksPt
|dS )zFRun mypy for a path

    Captures output and reports it on errors
    z-mr   )stdoutstderrutf8replacer   N)r   sys
executablelistr   r   communicatedecodeprint
returncodeAssertionError)Z	mypy_argspo_outr   r   r   run_mypy$   s      r"   c                 C   s&   g | ]}t jt jt|r|qS r   )r   r   isdirr   examples_dir).0dr   r   r   
<listcomp>3   s   r'   z!only test from examples directory)reasonexamplec                 C   s   t jt| }td| d S Nz--disallow-untyped-calls)r   r   r   r$   r"   )r)   Zexample_dirr   r   r   test_mypy_example:   s    r+   c                 C   s   g | ]}| d r|qS )z.py)endswith)r%   r   r   r   r   r'   D   s     
 filenamec                 C   s   t dtjt|  d S r*   )r"   r   r   r   mypy_dir)r-   r   r   r   	test_mypyG   s    r/   )__doc__r   r   
subprocessr   r   r   ZpytestZzmqZimportorskipr   r	   __file__r
   r   r$   r.   r"   r   listdirr   markZskipifZparametrizer+   r   r/   r   r   r   r   <module>   s2   
 