o
    ˷ea                     @   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   sT  d|j d< |g d |d tjj||d}t|ts J tj|}|	tj
|}t||s6J t \}}|| tj|dd}t|dksPJ |d	 }	td
d | D }
tdd |	 D }|
|kspJ tdd | D }tdd |	 D }||ksJ tj|}|	|}t||sJ 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       | ]}|  V  qd S Nget_name.0p r   X/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/drawing/tests/test_pydot.py	<genexpr>:       z)TestPydot.pydot_checks.<locals>.<genexpr>c                 s   r   r   r   r   r   r   r   r   =   r   c                 s        | ]}|  | fV  qd S r   
get_sourceget_destinationr   er   r   r   r   C       c                 s   r   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mkstemp	write_rawr   graph_from_dot_filelensortedget_node_listget_edge_listread_dotoscloseunlink)selfr   r   graph_layoutPG2fdfnamePin_listPinn1n2e1e2Hinr   r   r   pydot_checks   s0   




zTestPydot.pydot_checksc                 C      | j t dd d S )Nneator   )rI   r(   Graphr<   r   r   r   test_undirectedU      zTestPydot.test_undirectedc                 C   rJ   )Ndotr   )rI   r(   DiGraphrM   r   r   r   test_directedX   rO   zTestPydot.test_directedc                 C   s^   t  }d|jd< |jdddd t }t j|| |d t j|}t	||s-J d S )Nr   r   120)keyr   )
r(   
MultiGraphr%   add_edger   r)   	write_dotseekr8   r   )r<   r   fhHr   r   r   test_read_write[   s   

zTestPydot.test_read_writeN)__name__
__module____qualname__rI   rN   rR   r]   r   r   r   r   r      s
    Er   c                  C   s8  t dg} tt t j|  W d    n1 sw   Y  tt t j|  W d    n1 s7w   Y  t  } | jdddd tt t j|  W d    n1 s^w   Y  | 	d | jdddd | j
 t jt j| j
 ksJ t  } | jddd	d
 tt t j|  W d    n1 sw   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 sw   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s/J t  } | dd d| d d d< tt t j|  W d    n	1 sXw   Y  t  } | dd d| d d d< | d d t jt j| d d ksJ t dg} t j| }t|tsJ d S )N)z	Example:Ar   z1.2filledz
red:yellow)style	fillcolorz"red:yellow"rS   rT   zbar:1)fooz"bar:1"zb:1zfoo:foo)barz"b:1"z	"foo:foo"c                 S      g | ]\}}}|qS r   r   r   _attrr   r   r   
<listcomp>   s    z(test_pydot_issue_258.<locals>.<listcomp>re   zf:ooz"f:oo")"Example:A"r   )r(   rL   pytestraises
ValueErrorr)   r-   r*   r'   remove_nodenodesdatar/   rQ   rX   rW   edgesr+   r,   )r   layoutr   r   r   test_pydot_issue_258f   s`   
(,.rt   
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sFJ dd | D t	tjtj|jks^J d S )N5r   rk   F)tlrS      T)node1rz   )wrw   rx   node)   r}   string)r{   FalseTruez
('node1',)zfrozenset({'node1'})r{   c                 S   rf   r   r   rg   r   r   r   rj      s    z'test_hashable_pydot.<locals>.<listcomp>c                 S   s   h | ]}t |qS r   )str)r   ir   r   r   	<setcomp>   s    z&test_hashable_pydot.<locals>.<setcomp>)
rX   	frozensetr(   r)   r/   r-   rr   rq   rp   set)ru   r   r   r   r   test_hashable_pydot   s   
	r   c                  C   s   t  } | ddg t jj| dd}t|tsJ d|vs J d|v s&J d|vs,J d|v s2J d	|v s8J d
|v s>J d S )Nr   )r   r   rP   r   rU   r   rS   r   r	   r
   )r(   rL   r&   r)   r*   r+   r,   )r   r=   r   r   r   test_pydot_numrical_name   s   r   )__doc__r9   r0   ior   rl   networkxr(   networkx.utilsr   importorskipr   markxfailr   rt   parametrizerL   rQ   rW   MultiDiGraphr   r   r   r   r   r   <module>   s     
W6
