U
    9vfa  ã                   @   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   s\  d|j d< | ddddg¡ | d¡ tjj||d}t|tƒsDt‚tj 	|¡}| 
tj |¡¡}t||ƒspt‚t ¡ \}}| |¡ tj|d	d
}t|ƒdks¤t‚|d }	tdd„ | ¡ D ƒƒ}
tdd„ |	 ¡ D ƒƒ}|
|ksät‚tdd„ | ¡ D ƒƒ}tdd„ |	 ¡ D ƒƒ}||kst‚tj |¡}| 
|¡}t||ƒsDt‚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   úE/tmp/pip-unpacked-wheel-_lngutwb/networkx/drawing/tests/test_pydot.pyÚ	<genexpr>:   s     z)TestPydot.pydot_checks.<locals>.<genexpr>c                 s   s   | ]}|  ¡ V  qd S r   r   r   r   r   r   r   =   s     c                 s   s   | ]}|  ¡ | ¡ fV  qd S r   ©Ú
get_sourceZget_destination©r   Úer   r   r   r   C   s     c                 s   s   | ]}|  ¡ | ¡ fV  qd S r   r   r   r   r   r   r   F   s     N)ÚgraphÚadd_edges_fromÚadd_nodeÚnxÚnx_pydotÚpydot_layoutÚ
isinstanceÚdictÚAssertionErrorÚ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	||ƒsZt
‚d S )Nr   r   Ú1Ú2Ú0)Úkeyr   )r#   Ú
MultiGraphr    Úadd_edger   r$   Z	write_dotÚseekr0   r   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 5 Q R X t t¡ t j | ¡ W 5 Q R X t  ¡ } | jdddd t t¡ t j | ¡ W 5 Q R X |  	d¡ | jdddd | j
 ¡ t j t j | ¡¡j
 ¡ ksÌt‚t  ¡ } | jddd	d
 t t¡ t j | ¡ W 5 Q R X t  ¡ } | jdddd
 | d d t j t j | ¡¡d d ksLt‚t  ¡ } | jdddd
 | jdddd t t¡ t j | ¡ W 5 Q R X 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üt‚t  ¡ } |  dd¡ d| d d d< t t¡ t j | ¡ W 5 Q R X t  ¡ } |  dd¡ d| d d d< | d d t j t j | ¡¡d d ks”t‚t  dg¡} t j | ¡}t|tƒs¼t‚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>ˆ   s     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(   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Œt‚dd„ | 	¡ D ƒt
tj tj |¡¡j	ƒks¼t‚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>¯   s     z&test_hashable_pydot.<locals>.<setcomp>)rG   Ú	frozensetr#   r$   r+   r)   r[   rZ   r(   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ƒs4t‚d|ks@t‚d|ksLt‚d|ksXt‚d|ksdt‚d	|kspt‚d
|ks|t‚d S )Nr   )r   r   r?   r   rD   r   rB   r   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 ÿ
