
    Gda                     $   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j
        d          Zej        j         G d d                      Zd Zej                            d	ej        ej        ej        ej        g          d
             Zd ZdS )z'Unit tests for pydot drawing functions.    N)StringIO)graphs_equalpydotc                   &    e Zd Zd Zd Zd Zd ZdS )	TestPydotc                    d|j         d<   |                    g d           |                    d           t          j                            ||          }t          |t                    sJ t          j                            |          }|	                    t          j        
                    |                    }t          ||          sJ t          j                    \  }}|                    |           t                              |d          }t#          |          dk    sJ |d	         }	t%          d
 |                                D                       }
t%          d |	                                D                       }|
|k    sJ t%          d |                                D                       }t%          d |	                                D                       }||k    sJ t          j                            |          }|	                    |          }t          ||          sJ t-          j        |           t-          j        |           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              3   >   K   | ]}|                                 V  d S Nget_name.0ps     Alib/python3.11/site-packages/networkx/drawing/tests/test_pydot.py	<genexpr>z)TestPydot.pydot_checks.<locals>.<genexpr>:   s*      <<QAJJLL<<<<<<    c              3   >   K   | ]}|                                 V  d S r   r   r   s     r   r   z)TestPydot.pydot_checks.<locals>.<genexpr>=   s*      >>QAJJLL>>>>>>r   c              3   f   K   | ],}|                                 |                                fV  -d S r   
get_sourceget_destinationr   es     r   r   z)TestPydot.pydot_checks.<locals>.<genexpr>C   s;      UUaQ\\^^Q%6%6%8%89UUUUUUr   c              3   f   K   | ],}|                                 |                                fV  -d S r   r"   r%   s     r   r   z)TestPydot.pydot_checks.<locals>.<genexpr>F   s;      WWaQ\\^^Q%6%6%8%89WWWWWWr   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Hins                  r   pydot_checkszTestPydot.pydot_checks   sH     	
IIIJJJ	

3 {///==,----- K  ## [[//2233 Ar"""""$&&	E 	
E ,,%',JJ 8}}!!!! qk <<!//*;*;<<<<< >>#*;*;*=*=>>>>> Rxxxx UU1??CTCTUUUUU WW3CTCTCVCVWWWWW Rxxxx k""5))kk# As#####

	%r   c                 V    |                      t          j                    d           d S )Nneator   )rL   r+   Graphr?   s    r   test_undirectedzTestPydot.test_undirectedU   s'    "(**733333r   c                 V    |                      t          j                    d           d S )Ndotr   )rL   r+   DiGraphrP   s    r   test_directedzTestPydot.test_directedX   s'    "*,,U33333r   c                 X   t          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seekr;   r   )r?   r	   fhHs       r   test_read_writezTestPydot.test_read_write[   s    MOO	

3
%%%ZZ
a$$$



K  $$Aq!!!!!!!r   N)__name__
__module____qualname__rL   rQ   rU   ra    r   r   r   r      sT        C C CJ4 4 44 4 4" " " " "r   r   c                  &   t          j        dg          } t          j        t                    5  t           j                            |            d d d            n# 1 swxY w Y   t          j        t                    5  t           j                            |            d d d            n# 1 swxY w Y   t          j                    } |                     ddd           t          j        t                    5  t           j                            |            d d d            n# 1 swxY w Y   | 	                    d           |                     ddd           | j
                                        t           j                            t           j                            |                     j
                                        k    sJ t          j                    } |                     ddd	
           t          j        t                    5  t           j                            |            d d d            n# 1 swxY w Y   t          j                    } |                     ddd
           | d         d         t           j                            t           j                            |                     d         d         k    sJ t          j                    } |                     ddd
           |                     ddd           t          j        t                    5  t           j                            |            d d d            n# 1 swxY w Y   t          j                    } |                     ddd
           |                     ddd           d | j                                        D             d t           j                            t           j                            |                     j                                        D             k    sJ t          j                    } |                     dd           d| d         d         d<   t          j        t                    5  t           j                            |            d d d            n# 1 swxY w Y   t          j                    } |                     dd           d| d         d         d<   | d         d         t           j                            t           j                            |                     d         d         k    sJ t          j        dg          } t           j                            |           }t#          |t$                    sJ d S )N)z	Example:Ar   z1.2filledz
red:yellow)style	fillcolorz"red:yellow"rW   rX   zbar:1)fooz"bar:1"zb:1zfoo:foo)barz"b:1"z	"foo:foo"c                     g | ]\  }}}|	S re   re   r   _attrs      r   
<listcomp>z(test_pydot_issue_258.<locals>.<listcomp>   s    222ZQ4D222r   c                     g | ]\  }}}|	S re   re   rm   s      r   rp   z(test_pydot_issue_258.<locals>.<listcomp>   s.     7 7 7Aq$ 	7 7 7r   rk   zf:ooz"f:oo")"Example:A"r   )r+   rO   pytestraises
ValueErrorr,   r0   r-   r*   remove_nodenodesdatar2   rT   r\   r[   edgesr.   r/   )r	   layouts     r   test_pydot_issue_258r{   f   s   
"#$$A	z	"	"    
Q                             	z	"	" $ $
  ###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 	

AJJuHJ===	z	"	"    
Q                             MM%JJuHJ???	"+001E1Ea1H1HIIOTTVVVVVV 	
AJJsCWJ%%%	z	"	"    
Q                             

AJJsCYJ'''S6#;"+001E1Ea1H1HII#NsSSSSS
AJJsCUJ###JJsCYJ'''	z	"	"    
Q                             
AJJsCWJ%%%JJsC[J)))2217<<>>222 7 7+001E1Ea1H1HIIOTTVV7 7 7    
 	

AJJsCAcF3K	z	"	"    
Q                             


AJJsC!AcF3KS6#;"+001E1Ea1H1HII#NsSSSSS
$%&&A[%%a((Ffd#######sk    AA"A? B++B/2B/: D&&D*-D* H>>II* MMM; R''R+.R+
graph_typec           	          |             }|                     dt          dg          dd           |                     dddd	t          d
g                     |                     ddd           dddddddddigd t          j                            t          j                            |                    j                                        D             k    sJ d |                                D             t          t          j                            t          j                            |                    j                  k    sJ d S )N5r   rr   F)tlrW      T)node1r   )wr   r   node)   r   string)r   FalseTruez
('node1',)zfrozenset({'node1'})r   c                     g | ]\  }}}|	S re   re   rm   s      r   rp   z'test_hashable_pydot.<locals>.<listcomp>   s.     
 
 
Aq$ 	
 
 
r   c                 ,    h | ]}t          |          S re   )str)r   is     r   	<setcomp>z&test_hashable_pydot.<locals>.<setcomp>   s    &&&qCFF&&&r   )
r\   	frozensetr+   r,   r2   r0   ry   rx   rw   set)r|   r	   s     r   test_hashable_pydotr      s`   
 	
AJJsIqcNNmuJ===JJsAy'/C/CJDDDJJvvJ*** '**<.DEE	h
 
+001E1Ea1H1HIIOTTVV
 
 
	    '&AGGII&&&#
r{33A6677=+ +      r   c                     t          j                    } |                     ddg           t           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 d S )Nr   )r   r   rS   r   rY   r   rW   r   r   r   )r+   rO   r)   r,   r-   r.   r/   )r	   r@   s     r   test_pydot_numrical_namer      s    


Aj&)***;++AE+::LlD)))))l""""l"""",,r   )__doc__r<   r3   ior   rs   networkxr+   networkx.utilsr   importorskipr   markxfailr   r{   parametrizerO   rT   r[   MultiDiGraphr   r   re   r   r   <module>r      s   - - 				             ' ' ' ' ' 'G$$ T" T" T" T" T" T" T" T"n3$ 3$ 3$l 28RZH   *
 
 
 
 
r   