
    ިsgm                        d Z ddlmZ ddlZddlZddlmZ  ej                  d      Z	 G d d      Z
d Zej                  j                  d	ej                  ej                  ej                   ej"                  g      d
        Zd Zy)z'Unit tests for pydot drawing functions.    )StringION)graphs_equalpydotc                       e Zd Zej                  j                  d ej                          ej                         f      ej                  j                  dd      d               Z	d Z
y)	TestPydotGprog)neatodotc                    d|j                   d<   |j                  g d       |j                  d       t        j                  j                  ||      }t        |t              sJ t        j                  j                  |      }|j                  t        j                  j                  |            }t        ||      sJ |dz  }|j                  |       t        j                  |d      }t        |      d	k(  sJ |d
   }	t!        d |j#                         D              }
t!        d |	j#                         D              }|
|k(  sJ t!        d |j%                         D              }t!        d |	j%                         D              }||k(  sJ t        j                  j'                  |      }|j                  |      }t        ||      sJ y)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              3   <   K   | ]  }|j                           y wNget_name.0ps     T/var/www/html/venv/lib/python3.12/site-packages/networkx/drawing/tests/test_pydot.py	<genexpr>z'TestPydot.test_pydot.<locals>.<genexpr>:   s     <QAJJL<   c              3   <   K   | ]  }|j                           y wr   r   r   s     r    r!   z'TestPydot.test_pydot.<locals>.<genexpr>=   s     >QAJJL>r"   c              3   \   K   | ]$  }|j                         |j                         f & y wr   
get_sourceget_destinationr   es     r    r!   z'TestPydot.test_pydot.<locals>.<genexpr>C   s$     UaQ\\^Q%6%6%89U   *,c              3   \   K   | ]$  }|j                         |j                         f & y wr   r%   r(   s     r    r!   z'TestPydot.test_pydot.<locals>.<genexpr>F   s$     WaQ\\^Q%6%6%89Wr*   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Hins                  r    
test_pydotzTestPydot.test_pydot   s     	
IJ	

3 {{///=,--- KK  # [[//23 Ar"""9$ 	
E ,,%',J 8}!!! qk <!//*;<< >#*;*;*=>> Rxx U1??CTUU W3CTCTCVWW Rxx kk""5)kk# As###    c                 B   t        j                         }d|j                  d<   |j                  ddd       t	               }t         j
                  j                  ||       |j                  d       t         j
                  j                  |      }t        ||      sJ y )Nr   r   120)keyr   )
r/   
MultiGraphr,   add_edger   r0   	write_dotseekr=   r   )r>   r   fhHs       r    test_read_writezTestPydot.test_read_writeR   sv    MMO	

3
%Z
a$

KK  $Aq!!!rL   N)__name__
__module____qualname__pytestmarkparametrizer/   GraphDiGraphrK   rX    rL   r    r   r      s\    [[S8288:zrzz|"<=[[V%56@$ 7 >@$D"rL   r   c                 v   t        j                         }|j                  g d       t         j                  j	                  |d      }t        |t              sJ t         j                  j                  |      }t        j                  t         j                  j                  |            }t        ||      sJ y)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   )rc   r   r   r   r   N)
r/   r_   r-   r0   r1   r2   r3   r4   r6   r   )r?   r   r@   rA   rB   s        r    test_pydot_issue_7581rd   ]   s     	
AMN;;++AE+:LlD))) 	QA	"++((+	,B2rL   
graph_typec           	          |        }|j                  dt        dg      dd       |j                  dddd	t        d
g             |j                  ddd       dddddddddigt        j                  j	                  t        j                  j                  |            j                  j                         D cg c]  \  }}}|
 c}}k(  sJ |j                         D ch c]  }t        |       c}t        t        j                  j	                  t        j                  j                  |            j                        k(  sJ y c c}}w c c}w )N5r   z"Example:A"F)tlrN      T)node1rk   )wrh   ri   node)   rn   string)rl   FalseTruez
('node1',)zfrozenset({'node1'})rl   )rS   	frozensetr/   r0   r6   r4   edgesdatanodesstrset)re   r   _attris        r    test_hashable_pydotr{   p   s0   
 	AJJsIqcNmuJ=JJsAy'/CJDJJvvJ* '*<.DE	h ++001E1Ea1HIOOTTV
Aq$ 	
	   GGI&qCF&#
r{{33A67==+   

 's   ?E&Ec                      t        j                         } | j                  ddg       t         j                  j	                  | d      }t        |t              sJ d|vsJ d|v sJ d|vsJ d|v sJ d	|v sJ d
|v sJ y )Nr   )r   r   r   r   rP   r   rN   r   r   r   )r/   r_   r-   r0   r1   r2   r3   )r   r@   s     r    test_pydot_numerical_namer}      s    

Aj&)*;;++AE+:LlD)))l"""l""",,rL   )__doc__ior   r\   networkxr/   networkx.utilsr   importorskipr   r   rd   r]   r^   r_   r`   rR   MultiDiGraphr{   r}   ra   rL   r    <module>r      s~    -    'G$M" M"`& 288RZZH*
rL   