a
    da                     @   s   d Z ddlZddlZddlmZ ddlZddlZddlm	Z	 e
dZejjG dd dZdd	 Zejd
ejejejejgdd Zdd ZdS )z'Unit tests for pydot drawing functions.    N)StringIO)graphs_equalpydotc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	TestPydotc                 C   sX  d|j d< |g d |d tjj||d}t|ts@J tj|}|	tj
|}t||slJ t \}}|| tj|dd}t|dksJ |d	 }	td
d | D }
tdd |	 D }|
|ksJ tdd | D }tdd |	 D }||ksJ tj|}|	|}t||s@J t| t| dS )z
        Validate :mod:`pydot`-based usage of the passed NetworkX graph with the
        passed basename of an external GraphViz command (e.g., `dot`, `neato`).
        Gname)AB)r	   C)r
   r   )r	   DEprogzutf-8)pathencoding   r   c                 s   s   | ]}|  V  qd S Nget_name.0p r   j/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/networkx/drawing/tests/test_pydot.py	<genexpr>:       z)TestPydot.pydot_checks.<locals>.<genexpr>c                 s   s   | ]}|  V  qd S r   r   r   r   r   r   r   =   r   c                 s   s   | ]}|  | fV  qd S r   
get_sourceZget_destinationr   er   r   r   r   C   r   c                 s   s   | ]}|  | fV  qd S r   r   r   r   r   r   r   F   r   N)graphadd_edges_fromadd_nodenxnx_pydotpydot_layout
isinstancedictto_pydot	__class__
from_pydotr   tempfilemkstempZ	write_rawr   Zgraph_from_dot_filelensortedZget_node_listZget_edge_listread_dotoscloseunlink)selfr   r   graph_layoutPZG2fdfnameZPin_listZPinZn1Zn2e1e2ZHinr   r   r   pydot_checks   s0    




zTestPydot.pydot_checksc                 C   s   | j t dd d S )NZneator   )r;   r$   Graphr4   r   r   r   test_undirectedU   s    zTestPydot.test_undirectedc                 C   s   | j t dd d S )Ndotr   )r;   r$   DiGraphr=   r   r   r   test_directedX   s    zTestPydot.test_directedc                 C   s^   t  }d|jd< |jdddd t }t j|| |d t j|}t	||sZJ d S )Nr   r   120)keyr   )
r$   
MultiGraphr!   add_edger   r%   Z	write_dotseekr0   r   )r4   r   fhHr   r   r   test_read_write[   s    

zTestPydot.test_read_writeN)__name__
__module____qualname__r;   r>   rA   rK   r   r   r   r   r      s   Er   c                  C   s@  t dg} tt t j|  W d    n1 s80    Y  tt t j|  W d    n1 sn0    Y  t  } | jdddd tt t j|  W d    n1 s0    Y  | 	d | jdddd | j
 t jt j| j
 ks
J t  } | jddd	d
 tt t j|  W d    n1 sP0    Y  t  } | jdddd
 | d d t jt j| d d ksJ t  } | jdddd
 | jdddd tt t j|  W d    n1 s0    Y  t  } | jdddd
 | jdddd dd | j D dd t jt j| j D ksfJ t  } | dd d| d d d< tt t j|  W d    n1 s0    Y  t  } | dd d| d d d< | d d t jt j| d d ksJ t dg} t j| }t|ts<J d S )N)z	Example:Ar   z1.2Zfilledz
red:yellow)styleZ	fillcolorz"red:yellow"rB   rC   zbar:1)Zfooz"bar:1"zb:1zfoo:foo)barz"b:1"z	"foo:foo"c                 S   s   g | ]\}}}|qS r   r   r   _attrr   r   r   
<listcomp>   r   z(test_pydot_issue_258.<locals>.<listcomp>rP   zf:ooz"f:oo")"Example:A"r   )r$   r<   pytestZraises
ValueErrorr%   r)   r&   r#   remove_nodenodesdatar+   r@   rG   rF   edgesr'   r(   )r   Zlayoutr   r   r   test_pydot_issue_258f   sV    ***
",.,,.r\   
graph_typec                 C   s   |  }|j dtdgddd |j dddd	td
gd |j dddd dddddddddigdd tjtj|j D ksJ dd | D t	tjtj|jksJ d S )N5r   rU   F)tlrB      T)node1rb   )wr_   r`   node)   re   string)rc   FalseTruez
('node1',)zfrozenset({'node1'})rc   c                 S   s   g | ]\}}}|qS r   r   rQ   r   r   r   rT      s   z'test_hashable_pydot.<locals>.<listcomp>c                 S   s   h | ]}t |qS r   )str)r   ir   r   r   	<setcomp>   r   z&test_hashable_pydot.<locals>.<setcomp>)
rG   	frozensetr$   r%   r+   r)   r[   rZ   rY   set)r]   r   r   r   r   test_hashable_pydot   s    
	rn   c                  C   s   t  } | ddg t jj| dd}t|ts4J d|vs@J d|v sLJ d|vsXJ d|v sdJ d	|v spJ d
|v s|J d S )Nr   )r   r   r?   r   rD   r   rB   r   r	   r
   )r$   r<   r"   r%   r&   r'   r(   )r   r5   r   r   r   test_pydot_numrical_name   s    ro   )__doc__r1   r,   ior   rV   Znetworkxr$   Znetworkx.utilsr   Zimportorskipr   markZxfailr   r\   Zparametrizer<   r@   rF   ZMultiDiGraphrn   ro   r   r   r   r   <module>   s   
W6
