
    \Mh                     <    d Z ddlZddlmZmZ  G d d          ZdS )z
Pajek tests
    N)edges_equalnodes_equalc                   T    e Zd Zed             Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
S )	TestPajekc                     d| _         t          j                    | _        | j                            g d           | j                            g d           d| j        j        d<   d S )Na`  *network Tralala
*vertices 4
   1 "A1"         0.0938 0.0896   ellipse x_fact 1 y_fact 1
   2 "Bb"         0.8188 0.2458   ellipse x_fact 1 y_fact 1
   3 "C"          0.3688 0.7792   ellipse x_fact 1
   4 "D2"         0.9583 0.8563   ellipse x_fact 1
*arcs
1 1 1  h2 0 w 3 c Blue s 3 a1 -130 k1 0.6 a2 -130 k2 0.6 ap 0.5 l "Bezier loop" lc BlueViolet fos 20 lr 58 lp 0.3 la 360
2 1 1  h2 0 a1 120 k1 1.3 a2 -120 k2 0.3 ap 25 l "Bezier arc" lphi 270 la 180 lr 19 lp 0.5
1 2 1  h2 0 a1 40 k1 2.8 a2 30 k2 0.8 ap 25 l "Bezier arc" lphi 90 la 0 lp 0.65
4 2 -1  h2 0 w 1 k1 -2 k2 250 ap 25 l "Circular arc" c Red lc OrangeRed
3 4 1  p Dashed h2 0 w 2 c OliveGreen ap 25 l "Straight arc" lc PineGreen
1 3 1  p Dashed h2 0 w 5 k1 -1 k2 -20 ap 25 l "Oval arc" c Brown lc Black
3 3 -1  h1 6 w 1 h2 12 k1 -2 k2 -15 ap 0.5 l "Circular loop" c Red lc OrangeRed lphi 270 la 180A1BbCD2)r	   r	   )r	   r
   )r	   r   )r
   r	   )r   r   )r   r   )r   r
   Tralalaname)datanxMultiDiGraphGadd_nodes_fromadd_edges_fromgraph)clss    c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/networkx/readwrite/tests/test_pajek.pysetup_classzTestPajek.setup_class
   sw     G!!444555  
	
 
	
 
	
 (F    c                     d}t          j        |          }t          |                                          ddgk    sJ t	          |                                ddg          sJ d S )Nz&*Vertices 2
1 "1"
2 "2"
*Edges
1 2
2 112)r   r   )r   parse_pajeksortednodesr   edgesselfr   r   s      r   test_parse_pajek_simplez!TestPajek.test_parse_pajek_simple   sd    @N4  aggii  S#J....17799z:&>???????r   c                     t          j        | j                  }t          |                                          g dk    sJ t          |                                g d          sJ d S )Nr   r   )r   r   r   r   r    r   r!   )r#   r   s     r   test_parse_pajekzTestPajek.test_parse_pajek$   s{    N49%%aggii  $;$;$;;;;;GGII  
 
 	
 	
 	
 	
 	
r   c                    d}t          j        |          }t          |                                          h dk    sJ |j        d         ddik    sJ t	          t          |                                          h d          sJ d S )Nz@*Vertices 3
1 "one"
2 "two"
3 "three"
*Matrix
1 1 0
0 1 0
0 1 0
>   onetwothreer)   idr   >   r(   r(   r)   r)   r)   r(   r)   r*   )r   r   setr    r   r!   r"   s      r   test_parse_pajet_matzTestPajek.test_parse_pajet_mat4   s    ]N4  17799~~!8!8!88888wu~$,,,,		NNNNN
 
 	
 	
 	
 	
 	
r   c                    t          j        | j                  }|dz  }t          |d          5 }|                    | j                            d                     d d d            n# 1 swxY w Y   t          j        |          }t          |                                          t          |                                          k    sJ t          |
                                |
                                          sJ | j        j        |j        k    sJ |D ] }|j        |         |j        |         k    sJ !d S )Nztest.pjkwbzUTF-8)r   r   r   openwriteencode
read_pajekr   r    r   r!   r   r   )r#   tmp_pathr   fnamefhGinns          r   test_read_pajekzTestPajek.test_read_pajek>   sY   N49%%:%% 	0"HHTY%%g..///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 mE""aggii  F399;;$7$7777717799ciikk22222v|sy(((( 	. 	.A71:1-----	. 	.s   .A))A-0A-c                    dd l }t          j        | j                  }|                                }t          j        ||           |                    d           t          j        |          }t          t          |          t          |                    sJ t          t          |                                          t          |                                                    sJ d S )Nr   )ior   r   r   BytesIOwrite_pajekseekr7   r   listr   r!   )r#   r?   r   r:   Hs        r   test_write_pajekzTestPajek.test_write_pajekL   s    			N49%%ZZ\\
q"



M"477DGG,,,,,4		??DOO<<<<<<<r   c                    dd l }t          j                    }|                                }|                    dd           |                    dd           |                    ddd           |                    ddd           dd l}|                    d	          5 }t          j        ||           t          |          d
k    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr      )int_attr   z  )
empty_attr   T)record   )
r?   r   Graphr@   add_nodeadd_edgewarningscatch_warningsrA   len)r#   r?   r   r:   rQ   ws         r   test_ignored_attributez TestPajek.test_ignored_attributeY   s'   			HJJZZ\\	

1q
!!!	

1
&&&	

1a!
$$$	

1aD
)))$$D$11 	QN1b!!!q66Q;;;;;	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   $+CC!$C!c                     d}| j                             d          dd          }|d                    |          z   }t          j        |          }d S )Nz	*network

rG   )r   splitjoinr   r   )r#   lineother_linesr   r   s        r   test_nonamezTestPajek.test_nonamei   sN     iood++ABB/dii,,,N4  r   c                    dd l }t          j                    }t          d          t          d          z   t          d          z   }t          d          t          d          z   t          d          z   }|                    |d|	           |                                }t          j        ||           |                    d           t          j        |          }t          t          |          t          |                    sJ t          t          |                                          t          |                                                    sJ |j        |j        k    sJ d S )
Nr   i(	  {   i  i  i  iD  	Radiohead)foo)r?   r   rN   chrrP   r@   rA   rB   r7   r   rC   r   r!   r   )r#   r?   r   name1name2r:   rD   s          r   test_unicodezTestPajek.test_unicodeq   s   			HJJD		CHH$s4yy0D		CII%C0	

5+5
111ZZ\\
q"



M"477DGG,,,,,4		??DOO<<<<<w!'!!!!!!r   N)__name__
__module____qualname__classmethodr   r$   r&   r1   r=   rE   rU   r\   rd    r   r   r   r   	   s        ( ( [($@ @ @
 
 
 
 
 
. . .	= 	= 	=   ! ! !" " " " "r   r   )__doc__networkxr   networkx.utilsr   r   r   ri   r   r   <module>rm      sq         3 3 3 3 3 3 3 3u" u" u" u" u" u" u" u" u" u"r   