U
    Zf                     @   s  d dl Z ddlmZ G dd dZzLd dlmZmZmZmZm	Z	 d dl
mZ d dlmZmZmZ d dlZd	ZW n< ek
r   eZeZeZ	eZeZeZeZeZeZd
ZY nX dd Ze jjdd Ze jd	d	ddd Ze jedddZe jedddZe je	dddZe jedddZe jedddZe jedddZe jeddd Z e jedd!d"Z!e jedd#d$Z"e jedd%d&Z#e jd'd( Z$dS ))    N   )SELENIUM_GRID_DEFAULTc                   @   s   e Zd Zdd ZdS )MissingDashTestingc                 K   s   t dd S )NzQdash[testing] was not installed. Please install to use the dash testing fixtures.)	Exception)selfkwargs r   7/tmp/pip-unpacked-wheel-47crqvv_/dash/testing/plugin.py__init__   s    zMissingDashTesting.__init__N)__name__
__module____qualname__r
   r   r   r   r	   r      s   r   )ThreadedRunnerProcessRunnerRRunnerJuliaRunnerMultiProcessRunner)Browser)DashCompositeDashRCompositeDashJuliaCompositeTFc                 C   s   t sd S | dd}|jddddd |jdd	d
d |jddtdd |jdd	dd |jddddd |jdddd |jdd	dd d S )NZDashzDash Integration Testsz--webdriver)ChromeZFirefoxr   z"Name of the selenium driver to use)choicesdefaulthelpz--remote
store_truez$instruct pytest to use selenium grid)actionr   z--remote-urlstorez>set a different selenium grid remote url if other than default)r   r   r   z
--headlessz%set this flag to run in headless modez--percy-assetsztests/assetsz3configure how Percy will discover your app's assetsz--nopercyfinalizestore_falsez3set this flag to control percy finalize at CI levelz--pausezGpause using pdb after opening the test app, so you can interact with it)
_installedZgetgroupZ	addoptionr   )parserZdashr   r   r	   pytest_addoption,   sR        r!   c                 C   s:   t sd S ddlm} t| dd }|d kr.| j}|| d S )Nr   )newhooksZadd_hookspecs)r   Zdash.testingr"   getattrZaddhooks)Zpluginmanagerr"   methodr   r   r	   pytest_addhooks\   s    r%   )tryfirstZhookwrapperc                 c   s   d V }t sd S | }|jdkr|jrt| dr| j D ]L\}}z|dkrX|| j W q: t	k
r } zt
| W 5 d }~X Y q:X q:d S )Ncallfuncargs>   dashjldashrdash_duodash_br)r   Z
get_resultwhenfailedhasattrr(   itemsZtake_snapshotnamer   print)itemr'   Zoutcomerepr1   fixtureer   r   r	   pytest_runtest_makereportj   s    r7   )returnc               	   c   s   t  } | V  W 5 Q R X dS )z*Start a local dash server in a new thread.N)r   Zstarterr   r   r	   dash_thread_server   s    r:   c               	   c   s   t  } | V  W 5 Q R X dS )z=Start a Dash server with subprocess.Popen and waitress-serve.N)r   r9   r   r   r	   dash_process_server   s    r;   c               	   c   s   t  } | V  W 5 Q R X d S N)r   r9   r   r   r	   dash_multi_process_server   s    r=   c               	   c   s   t  } | V  W 5 Q R X d S r<   )r   r9   r   r   r	   dashr_server   s    r>   c               	   c   s   t  } | V  W 5 Q R X d S r<   )r   r9   r   r   r	   dashjl_server   s    r?   c                 c   sx   t | jd| jd| jd| jd| jj |dj| jd| jd| jdd		}|V  W 5 Q R X d S 
NZ	webdriverremote
remote_urlheadlessdownloadZpercy_assetsZnopercyfinalizepause)	browserrA   rB   rC   optionsdownload_pathZpercy_assets_rootZpercy_finalizerE   )r   config	getoptionhookpytest_setup_optionsmkdirstrpath)requesttmpdirrF   r   r   r	   r,      s    









r,   c                 c   sz   t || jd| jd| jd| jd| jj |dj| jd| jd| jdd	
}|V  W 5 Q R X d S r@   r   rI   rJ   rK   rL   rM   rN   )rO   r:   rP   dcr   r   r	   r+      s    








r+   c                 c   sz   t || jd| jd| jd| jd| jj |dj| jd| jd| jdd	
}|V  W 5 Q R X d S r@   rQ   )rO   r=   rP   rR   r   r   r	   dash_duo_mp   s    








rS   c                 c   sz   t || jd| jd| jd| jd| jj |dj| jd| jd| jdd	
}|V  W 5 Q R X d S r@   )r   rI   rJ   rK   rL   rM   rN   )rO   r>   rP   rR   r   r   r	   r*      s    








r*   c                 c   sz   t || jd| jd| jd| jd| jj |dj| jd| jd| jdd	
}|V  W 5 Q R X d S r@   )r   rI   rJ   rK   rL   rM   rN   )rO   r?   rP   rR   r   r   r	   r)      s    








r)   c                  C   s   ddl m}  |  S )Nr   DiskcacheLongCallbackManager)Zdash.long_callbackrU   rT   r   r   r	   diskcache_manager   s    rV   )%ZpytestZconstsr   r   Z dash.testing.application_runnersr   r   r   r   r   Zdash.testing.browserr   Zdash.testing.compositer   r   r   Zdash_testing_stubr   ImportErrorr!   markr&   r%   Zhookimplr7   r5   r:   r;   r=   r>   r?   r,   r+   rS   r*   r)   rV   r   r   r   r	   <module>   s\   
0

