a
    na&                      @  s  d Z ddlmZ ddlZeeZddlZddlm	Z	 ddl
mZmZmZmZmZmZmZmZmZ ddlmZmZ ddlZddlmZ dZejd	d
Zeeeddf Z G dd dZ!G dd dZ"ed Z#d"dddddddddd	ddZ$dddddZ%ddddd d!Z&dS )#z4 Provide support modules for testing Bokeh itself.

    )annotationsN)	b64decode)	basenamedirnameexistsisdirjoinnormpathpardirrelpathsplitext)ListUnion)Literal)add_examplescollect_examplesExampleFlagsZGITHUB_ACTIONZlocalzos.PathLike[str]zos.PathLike[bytes]c                   @  s(   e Zd ZdZdZdZdZdZdZdZ	dS )	r                   @      N)
__name__
__module____qualname__fileservernotebookslowskipxfailno_js r%   r%   ;lib/python3.9/site-packages/bokeh/_testing/util/examples.pyr   >   s   r   c                   @  s   e Zd Zg fddddddddZddd	d
ZeZeddddZeddddZeddddZ	eddddZ
eddddZeddddZeddddZeddddZeddddZeddddZeddd d!Zeddd"d#Zddd$d%d&Zd'S )(r   strintz	List[str]None)pathflagsexamples_dir
extensionsreturnc                 C  s2   t || _|| _|| _|| _d | _d| _d | _d S Nr   )r	   r*   r+   r,   r-   Z	_diff_refZpixelsZ_has_ref)selfr*   r+   r,   r-   r%   r%   r&   __init__I   s    
zExample.__init__)r.   c                 C  sv   | j r
dnd| jrdnd| jr"dnd| jr.dnd| jr:dnd| jrFdnd| jrRdndg}d	| jd
dd |D f S )Nr    r   r    r!   r"   r#   r$   zExample(%r, %s)|c                 s  s   | ]}|r|V  qd S Nr%   ).0fr%   r%   r&   	<genexpr>]       z"Example.__str__.<locals>.<genexpr>)	is_file	is_serveris_notebookis_slowis_skipis_xfailr$   r   r   )r0   r+   r%   r%   r&   __str__R   s    
zExample.__str__c                 C  s
   t | jS r4   )r   path_no_extr0   r%   r%   r&   namea   s    zExample.namec                 C  s
   t | jS r4   )r   r*   rA   r%   r%   r&   base_dire   s    zExample.base_dirc                 C  s   t | j| jS r4   )r   r*   r,   rA   r%   r%   r&   r   i   s    zExample.relpathc                 C  s   t | jd S r/   )r   r*   rA   r%   r%   r&   r@   m   s    zExample.path_no_extc                 C  s
   | j d S )Nz.png)r@   rA   r%   r%   r&   img_pathq   s    zExample.img_pathboolc                 C  s   t | jtj@ S r4   )rE   r+   r   r   rA   r%   r%   r&   r9   u   s    zExample.is_filec                 C  s   t | jtj@ S r4   )rE   r+   r   r   rA   r%   r%   r&   r:   y   s    zExample.is_serverc                 C  s   t | jtj@ S r4   )rE   r+   r   r    rA   r%   r%   r&   r;   }   s    zExample.is_notebookc                 C  s   t | jtj@ S r4   )rE   r+   r   r!   rA   r%   r%   r&   r<      s    zExample.is_slowc                 C  s   t | jtj@ S r4   )rE   r+   r   r"   rA   r%   r%   r&   r=      s    zExample.is_skipc                 C  s   t | jtj@ S r4   )rE   r+   r   r#   rA   r%   r%   r&   r>      s    zExample.is_xfailc                 C  s   t | jtj@ S r4   )rE   r+   r   r$   rA   r%   r%   r&   r$      s    zExample.no_js)img_datar.   c                 C  s   t | jt| d S r4   )_store_binaryrD   r   )r0   rF   r%   r%   r&   	store_img   s    zExample.store_imgN)r   r   r   r1   r?   __repr__propertyrB   rC   r   r@   rD   r9   r:   r;   r<   r=   r>   r$   rH   r%   r%   r%   r&   r   H   s8   	r   allzList[Example]r'   z
int | NonezList[str] | All | Noner)   )	list_of_examplesr*   r,   example_typer!   r"   r#   r$   r.   c              
   C  sh  | drft||d d }tt|D ]6}	tt||	r*t| t|d d |	|||||| q*d S tt||}
tt|
D ]}	d}g }|	}|	drqn|	 dr||r|nt	j
O }n|	 dr|t	jO }ntt|
|	rtt|
|	|	d r t|	|	d }	||r|nt	j
O }n(tt|
|	dr||r<|nt	jO }nqd}tt|
||rp|t|
| n>tt|
|D ],}t|
||}tt||r|| qnq|d ur||v r|t	jO }|d ur|d	ks||v r|t	jO }|d ur |d	ks||v r |t	jO }|d urH|d	ks>||v rH|t	jO }| tt|
|	||| qd S )
N*r   )_.z.pyz.ipynbzmain.pyzbokeh.ext.jsonrK   )endswithr   sortedoslistdirr   r   r	   
startswithr   r   r    r   r   appendr!   r"   r#   r$   r   )rL   r*   r,   rM   r!   r"   r#   r$   Z	star_pathrB   Zexample_pathr+   r-   Z	orig_nameZext_fileZdir_nameZdir_pathr%   r%   r&   r      sR    
&






r   )config_pathr.   c                 C  s   t t| t}g }t| d}t| }W d    n1 s@0    Y  |D ]n}|d }|dd urxtt	|d }nd }|d}|d}	|d}
|d}t
||||||	|
|d qN|S )	Nrr*   typer!   r"   r#   r$   )rM   r!   r"   r#   r$   )r   r   r
   openyamlZ	safe_loadreadgetgetattrr   r   )rX   r,   rL   r6   ZexamplesZexampler*   rM   Zslow_statusZskip_statusZxfail_statusZno_js_statusr%   r%   r&   r      s"    ,




r   PathLikebytes)r*   datar.   c                 C  sR   t | }t|st| t| d}|| W d    n1 sD0    Y  d S )Nwb)r   r   rT   makedirsr[   write)r*   rb   Z	directoryr6   r%   r%   r&   rG      s
    
rG   )NNNNN)'__doc__Z
__future__r   ZloggingZ	getLoggerr   logrT   base64r   os.pathr   r   r   r   r   r	   r
   r   r   typingr   r   r\   Ztyping_extensionsr   __all__environr^   ZJOB_IDr'   ra   r`   r   r   ZAllr   r   rG   r%   r%   r%   r&   <module>   s*   
,
L    = 