B
    wZÚ[×  ã               @   sL   d Z ddlZddlmZmZ ddlmZ dd„ Zdd	„ Zd
d„ Z	dd„ Z
dS )zj
This plugin provides command-line options for controlling whether and how tests
make use of online data.
é    Né   )Úturn_off_internetÚturn_on_internet)ÚStrictVersionc             C   s*   | j dddddd | jddd	d
d d S )Nz--remote-dataú?ÚanyÚnonezrun tests with online data)ÚnargsZconstÚdefaultÚhelpÚremote_data_strictzrIf 'True', tests will fail if they attempt to access the internet but are not explicitly marked with 'remote_data'ÚboolF)Útyper
   )Z	addoptionZaddini)Úparser© r   ú7lib/python3.7/site-packages/pytest_remotedata/plugin.pyÚpytest_addoption   s    r   c             C   sŽ   |   d¡ d¡ |   d¡ d¡ t|   d¡ƒ}|  d¡}|dkrPt d |¡¡‚|rŠ|dkrnt| jj	d	d
 n|dkrŠt| jj	|dkd d S )NZmarkerszAremote_data: Apply to tests that require data from remote serverszTinternet_off: Apply to tests that should only run when network access is deactivatedr   Úremote_data)Úastropyr   Úgithubr   z*'{}' is not a valid source for remote datar   T)ÚverboseZallow_github_datar   r   )r   Zallow_astropy_data)
ZgetiniÚappendr   Z	getoptionÚpytestZ
UsageErrorÚformatr   Zoptionr   )ÚconfigZstrict_checkr   r   r   r   Úpytest_configure   s"    


r   c               C   s
   t ƒ  dS )z
    Cleanup post-testing
    N)r   r   r   r   r   Úpytest_unconfigure5   s    r   c             C   s  t tjƒt dƒk r(|  d¡}|  d¡}n|  d¡}|  d¡}| j d¡}|d k	r`|d k	r`tdƒ‚|d k	rêt|j	ƒdkr‚|j	d }n|j
 dd¡}|dkr td	ƒ‚|d
kr´t d¡ n6|dkrÐ|dkrêt d¡ n|dkrê|dkrêt d¡ |d k	r|d
krt d¡ d S )Nz3.6r   Úinternet_offz/remote_data and internet_off are not compatibler   Úsourcer   )r   r   r   z.source should be 'astropy', 'any', or 'github'r   z need --remote-data option to runr   )r   r   z9need --remote-data or --remote-data=astropy option to runr   z2run this test only when network access is disabled)r   r   Ú__version__Z
get_markerZget_closest_markerr   ÚgetvalueÚ
ValueErrorÚlenÚargsÚkwargsÚgetÚskip)Úitemr   r   Zremote_data_configr   r   r   r   Úpytest_runtest_setup?   s2    





r(   )Ú__doc__r   Zdisable_internetr   r   Zdistutils.versionr   r   r   r   r(   r   r   r   r   Ú<module>   s   
