o
    hm                     @   s~   d Z ddlmZ ddlZddlZddlmZ edZ	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.    )StringION)graphs_equalpydotc                   @   sD   e Zd Zejde e fejdddd Z	dd Z
dS )		TestPydotGprog)neatodotc                 C   s<  d|j d< |g d |d tjj||d}t|ts J tj|}|	tj
|}t||s6J |d }|| tj|dd}t|d	ksNJ |d
 }	tdd | D }
tdd |	 D }|
|ksnJ tdd | D }tdd |	 D }||ksJ tj|}|	|}t||sJ 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`).
        r   name)AB)r   Cr   r   )r   DEr   zout.dotzutf-8)pathencoding   r   c                 s       | ]}|  V  qd S Nget_name.0p r   U/var/www/vscode/kcb/lib/python3.10/site-packages/networkx/drawing/tests/test_pydot.py	<genexpr>:       z'TestPydot.test_pydot.<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   	write_rawr   graph_from_dot_filelensortedget_node_listget_edge_listread_dot)selfr   r   tmp_pathgraph_layoutPG2fnamePin_listPinn1n2e1e2Hinr   r   r   
test_pydot   s,   




zTestPydot.test_pydotc                 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seekr9   r   )r:   r   fhHr   r   r   test_read_writeR   s   

zTestPydot.test_read_writeN)__name__
__module____qualname__pytestmarkparametrizer+   GraphDiGraphrG   rR   r   r   r   r   r      s
    Br   c                 C   sd   t  }|g d t jj|dd}t|tsJ t j|}t t j|}t	||s0J dS )zValidate that `nx_pydot.pydot_layout` handles nodes
    with characters like "
", " ".

    Those characters cause `pydot` to escape and quote them on output,
    which caused #7581.
    ))
A
big testr   )r[   r   r   r	   r   N)
r+   rY   r)   r,   r-   r.   r/   r0   r2   r   )r;   r   r<   r=   r>   r   r   r   test_pydot_issue_7581]   s   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sFJ dd | D t	tjtj|jks^J d S )N5r   z"Example:A"F)tlrH      T)node1rb   )wr_   r`   node)   re   string)rc   FalseTruez
('node1',)zfrozenset({'node1'})rc   c                 S   s   g | ]\}}}|qS r   r   )r   _attrr   r   r   
<listcomp>~   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>)
rM   	frozensetr+   r,   r2   r0   edgesdatanodesset)r]   r   r   r   r   test_hashable_pydotp   s   
	rt   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   r	   r   rJ   r   rH   r   r   r   )r+   rY   r)   r,   r-   r.   r/   )r   r<   r   r   r   test_pydot_numerical_name   s   ru   )__doc__ior   rV   networkxr+   networkx.utilsr   importorskipr   r   r\   rW   rX   rY   rZ   rL   MultiDiGraphrt   ru   r   r   r   r   <module>   s    
P
