a
    º”hb  ã                   @   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s J ‚|d	 }	td
d„ | ¡ D ƒƒ}
tdd„ |	 ¡ D ƒƒ}|
|ksàJ ‚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   úO/var/www/auris/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 s¼0    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s J ‚t  ¡ } | jdddd
 | jdddd t t¡ t j | ¡ W d   ƒ n1 sö0    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 s¸0    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sŒJ ‚dd„ | ¡ D ƒt	tj tj |¡¡jƒks¼J ‚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_numerical_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ÿ
