
    ިsg,                         d dl Z d dlZd dlmZmZ  G d d      Z G d d      Zd Z G d d	      Z	 G d
 d      Z
 G d d      Zy)    N)edges_equalnodes_equalc                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestReverseViewc                     t        j                  dt        j                               | _        t        j                  | j                        | _        y N	   create_using)nx
path_graphDiGraphGreverse_viewrvselfs    Y/var/www/html/venv/lib/python3.12/site-packages/networkx/classes/tests/test_graphviews.pysetup_methodzTestReverseView.setup_method
   s.    qrzz|<//$&&)    c                    dd l }| j                  }|j                  |j                  |d            }|j                  |j                  k(  sJ |j
                  |j
                  k(  sJ |j                  |j                  k(  sJ y Nr   pickler   loadsdumps_node_adjgraphr   r   r   prvs       r   test_picklezTestReverseView.test_pickle   i    WWll6<<B/0xx399$$$ww#(("""xx399$$$r   c                     d| j                   j                  v sJ d| j                   j                  vsJ d| j                  j                  vsJ d| j                  j                  v sJ y N)      )r(   r'   r   edgesr   r   s    r   test_containszTestReverseView.test_contains   sZ    %%%TVV\\)))TWW]]***&&&r   c                     t        d | j                  j                  D              }t        | j                  j                        |k(  sJ y )Nc              3   D   K   | ]  }t        t        |              y wN)tuplereversed).0es     r   	<genexpr>z,TestReverseView.test_iter.<locals>.<genexpr>   s     C%,Cs    sortedr   r*   r   r   expecteds     r   	test_iterzTestReverseView.test_iter   s5    CdffllCCdggmm$000r   c                     t        j                         }t        j                  t         j                  t         j
                  |       y r.   )r   GraphpytestraisesNetworkXNotImplementedr   r   r   s     r   test_exceptionszTestReverseView.test_exceptions!   s'    HHJb//!Dr   c                     G fddt         j                                }|j                  dd       t        j                  |      }t	        d|j
                         |j                         }t	        d|j
                         t	        |j                         |j                  dd      sJ |j                         dk(  sJ y )Nc                       e Zd Zd Z fdZy).TestReverseView.test_subclass.<locals>.MyGraphc                      yNme r   s    r   	my_methodz8TestReverseView.test_subclass.<locals>.MyGraph.my_method'       r   c                             S r.   rF   r   MyGraphs    r   to_directed_classz@TestReverseView.test_subclass.<locals>.MyGraph.to_directed_class*       y r   N__name__
__module____qualname__rG   rL   rK   s   r   rK   rB   &       !r   rK      r'   zRM classz	RMC classrE   )
r   r   add_edger   print	__class__copyr*   has_edgerG   )r   MRMRMCrK   s       @r   test_subclasszTestReverseView.test_subclass%   s    	!bjj 	! I	

1a__Qj",,'ggik3==)cii||Aq!!!}}$&&&r   N)	rO   rP   rQ   r   r#   r+   r8   r?   r]   rF   r   r   r   r   	   s!    *%'1E'r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestMultiReverseViewc                     t        j                  dt        j                               | _        | j                  j	                  dd       t        j
                  | j                        | _        y )Nr	   r
         )r   r   MultiDiGraphr   rU   r   r   r   s    r   r   z!TestMultiReverseView.setup_method9   sA    qr/@A1//$&&)r   c                    dd l }| j                  }|j                  |j                  |d            }|j                  |j                  k(  sJ |j
                  |j
                  k(  sJ |j                  |j                  k(  sJ y r   r   r!   s       r   r#   z TestMultiReverseView.test_pickle>   r$   r   c                 <   d| j                   j                  v sJ d| j                   j                  vsJ d| j                  j                  vsJ d| j                  j                  v sJ d| j                  j                  v sJ d| j                  j                  vsJ y )N)r'   r(   r   )r(   r'   r   )rb   ra   rT   )ra   rb   rT   r)   r   s    r   r+   z"TestMultiReverseView.test_containsG   s    DFFLL(((,,,---DGGMM)))DGGMM)))---r   c                     t        d | j                  j                  D              }t        | j                  j                        |k(  sJ y )Nc              3   .   K   | ]  \  }}}|||f  y wr.   rF   )r1   uvks       r   r3   z1TestMultiReverseView.test_iter.<locals>.<genexpr>P   s     @1a1a)@s   r4   r6   s     r   r8   zTestMultiReverseView.test_iterO   s5    @466<<@@dggmm$000r   c                     t        j                  | j                        }t        j                  t         j
                  t         j                  |       y r.   )r   
MultiGraphr   r;   r<   r=   r   )r   MGs     r   r?   z$TestMultiReverseView.test_exceptionsS   s.    ]]466"b//"Er   N)rO   rP   rQ   r   r#   r+   r8   r?   rF   r   r   r_   r_   8   s    *
%.1Fr   r_   c                     t         j                  } t        j                  dg      }t        j                  t         j
                        5  | j                  |t         j                         d d d        t        j                  dg      }t        j                  t         j
                        5  | j                  |t         j                         d d d        y # 1 sw Y   mxY w# 1 sw Y   y xY w)N)rT   r'   r
   )	r   
graphviewsr   r;   r<   NetworkXErrorgeneric_graph_viewrl   rc   )nxgr   s     r   test_generic_multitypers   X   s    
--C


F8A	r''	( >qr}}=>
!A	r''	( ;qrzz:; ;> >; ;s   
"C-"C$C!$C-c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestToDirectedc                 $   t        j                  d      | _        t        j                  | j                        | _        t        j                  dt        j
                               | _        t        j                  | j                        | _        y r   )r   r   r   to_directeddvrl   rm   Mdvr   s    r   r   zTestToDirected.setup_methodc   sR    q!..(--@>>$''*r   c                 t    | j                   j                         rJ | j                  j                         sJ y r.   )r   is_directedrx   r   s    r   test_directedzTestToDirected.test_directedi   s.    66%%'''ww""$$$r   c                 0   t        j                  | j                        }t        j                  | j                        }t	        |j
                  | j                  j
                        sJ t	        |j
                  | j                  j
                        sJ y r.   )r   rw   rx   ry   r   r*   )r   ddMdds      r   test_already_directedz$TestToDirected.test_already_directedm   s^    ^^DGG$nnTXX&288TWW]]333399dhhnn555r   c                 >   dd l }| j                  }|j                  |j                  |d            }|j                  |j                  k(  sJ |j
                  |j
                  k(  sJ |j                  |j                  k(  sJ |j                  |j                  k(  sJ y r   )r   rx   r   r   r   _succ_predr    )r   r   rx   pdvs       r   r#   zTestToDirected.test_pickles   s    WWll6<<B/0xx399$$$xx399$$$xx399$$$xx399$$$r   c                     d| j                   j                  v sJ d| j                   j                  v sJ d| j                  j                  v sJ d| j                  j                  v sJ y r&   )r   r*   rx   r   s    r   r+   zTestToDirected.test_contains}   sZ    %%%%%%&&&&&&r   c                    | j                   j                  D cg c]  }t        t        |             }}t	        t        | j                   j                        |z         }t	        | j                  j                        |k(  sJ y c c}w r.   )r   r*   r/   r0   r5   listrx   )r   r2   revdr7   s       r   r8   zTestToDirected.test_iter   sb    ,0FFLL9qhqk"99$tvv||,t34dggmm$000 :s   BN	rO   rP   rQ   r   r|   r   r#   r+   r8   rF   r   r   ru   ru   b   s     +%6%'1r   ru   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestToUndirectedc                 L   t        j                  dt        j                               | _        t        j                  | j                        | _        t        j                  dt        j                               | _        t        j                  | j                        | _        y r   )	r   r   r   DGto_undirecteduvrc   MDGMuvr   s    r   r   zTestToUndirected.setup_method   s_    --

=""477+==1BC##DHH-r   c                 t    | j                   j                         sJ | j                  j                         rJ y r.   )r   r{   r   r   s    r   r|   zTestToUndirected.test_directed   s1    ww""$$$77&&((((r   c                 0   t        j                  | j                        }t        j                  | j                        }t	        |j
                  | j                  j
                        sJ t	        |j
                  | j                  j
                        sJ y r.   )r   r   r   r   r   r*   )r   uuMuus      r   r   z&TestToUndirected.test_already_directed   sb    dgg&txx(288TWW]]333399dhhnn555r   c                 $   dd l }| j                  }|j                  |j                  |d            }|j                  |j                  k(  sJ |j
                  |j
                  k(  sJ |j                  |j                  k(  sJ t        |d      sJ y )Nr   r   _graph)r   r   r   r   r   r   r    hasattr)r   r   r   puvs       r   r#   zTestToUndirected.test_pickle   sy    WWll6<<B/0xx399$$$ww#(("""xx399$$$r8$$$r   c                     d| j                   j                  v sJ d| j                   j                  vsJ d| j                  j                  v sJ d| j                  j                  v sJ y r&   )r   r*   r   r   s    r   r+   zTestToUndirected.test_contains   sZ    &&&TWW]]***&&&&&&r   c                     t        | j                  j                        }t        | j                  j                        |k(  sJ y r.   )r5   r   r*   r   r6   s     r   r8   zTestToUndirected.test_iter   s/    $''--(dggmm$000r   Nr   rF   r   r   r   r      s     .)6%'1r   r   c                   v    e Zd Zed        Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zy)TestChainsOfViewsc           
      :   t        j                  d      | _        t        j                  dt        j                               | _        t        j                  dt        j
                               | _        t        j                  dt        j                               | _        t        j                  | j                        | _
        t        j                  | j                        | _        t        j                  | j                        | _        t        j                  | j                        | _        | j                  j                         | _        | j                  j                         | _        | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                   | j"                  g
| _        | j$                  D ]%  }|j&                  |j(                  |j*                  f ' y r   )r   r   r   r   r   rl   rm   rc   r   r   Gvrw   DGvMGvMDGvreverseRvMRvgraphsr*   nodesdegree)clsr   s     r   setup_classzTestChainsOfViews.setup_class   sM   a qrzz|<qr}}?--0AB!!#&&)..'""377+>>#&&)!''//#EEFFFFGGFFGGGGHHFFGG

  	'AGGQWWahh&	'r   c                     dd l }| j                  D ]g  }|j                  |j                  |d            }t	        |j
                  |j
                        sJ t        |j                  |j                        rgJ  y r   )r   r   r   r   r   r*   r   r   )r   r   r   Hs       r   r#   zTestChainsOfViews.test_pickle   sa     	1AV\\!R01Aqww000qww000	1r   c                 @   t        j                  | j                  t        dd            }t        j                  | j                  t        dd            }t        j                  | j
                  t        dd            }t        j                  | j                  t        dd            }| j                  ||||gz   D ]`  }t        j                  |g d      }t        |      g dk(  sJ |j                  ddg      }t        |      dgk(  sJ |j                  |u r`J  y )Nr(      ra   rb      r   )r   subgraphr   ranger   rm   r   r   induced_subgraphr   r   )r   SGvSDGvSMGvSMDGvr   SGSSGs           r   test_subgraph_of_subgraphz+TestChainsOfViews.test_subgraph_of_subgraph   s    kk$&&%1+.{{477E!QK0{{477E!QK0DHHeAqk2T477 	#A$$Q	2B8y(((++q!f%C9###::?"?	#r   c                    g d}dg}t        j                  | j                  ||      }g d}t        j                  ||      }|j	                  |      }|j
                  | j                  u sJ |j
                  | j                  u sJ |j
                  |u sJ t        |j                  |j                        sJ | j                  j                         }|j                  |       |j                  |       t        |j                  |      |j                        sJ |j                  g d       t        |j                  |j                        sJ | j                  j	                  |      }t        j                  |||      }	|	j
                  | j                  usJ t        |	j                  |j                        sJ y)a&  Test subgraph chains that both restrict and show nodes/edges.

        A restricted_view subgraph should allow induced subgraphs using
        G.subgraph that automagically without a chain (meaning the result
        is a subgraph view of the original graph not a subgraph-of-subgraph.
        )r(   ra   rb   )r   r   )ra   rb   r   r      )r   rT   r'   r(   N)r   restricted_viewr   r   r   r   r   r*   rX   remove_nodes_fromremove_edges_from)
r   
hide_nodes
hide_edgesRGr   r   r   CGSSSGRSGs
             r   'test_restricted_induced_subgraph_chainsz9TestChainsOfViews.test_restricted_induced_subgraph_chains   sb    
X

J?  U+kk% yyDFF"""zzTVV###yyB288SYY///VV[[]
Z(
Z(288E?CII666
\*288SYY///vvu%  z:>zz'''399bhh///r   c                     | j                   D ]S  }t        j                  |      }|j                  g d      }|j	                         }t        |      t        |      k(  rSJ  y )Nr   )r   r   r:   r   rX   type)r   origGr   r   r   s        r   test_subgraph_copyz$TestChainsOfViews.test_subgraph_copy   sQ    [[ 	&EAI&B	A7d1g%%%		&r   c                     t        j                  | j                  g d      }|j                         }t	        |      g dk(  sJ t	        |j
                        g dk(  sJ y )Nr   )ra   rb   rb   ra   rb   r   )r   rb   )r   r   r   rw   r5   r*   r   r   r   s      r   test_subgraph_todirectedz*TestChainsOfViews.test_subgraph_todirected  sN      3nnc{i'''cii $DDDDr   c                     t        j                  | j                  g d      }|j                         }t	        |      g dk(  sJ t        |j                        ddgk(  sJ y )Nr   r   r   )r   r   r   r   r   r5   r*   r   s      r   test_subgraph_toundirectedz,TestChainsOfViews.test_subgraph_toundirected  sT      3 CyI%%%cii VV$4444r   c                     | j                   j                  d      }|j                  g d      }|j                         }t	        |      g dk(  sJ t        |j                        ddgk(  sJ y )NFrX   r   r   r   )r   r   r   r   r   r5   r*   )r   r   r   r   s       r   "test_reverse_subgraph_toundirectedz4TestChainsOfViews.test_reverse_subgraph_toundirected  s`    GGOOO'ZZ	" CyI%%%cii VV$4444r   c                    | j                   j                  d      }|j                  d      }|j                  | j                   j                  k(  sJ |j                  | j                   j                  k(  sJ | j                  j                  d      }|j                  d      }|j                  | j                  j                  k(  sJ |j                  | j                  j                  k(  sJ y )NFr   T)r   r   r   r*   r   )r   r   r   s      r   test_reverse_reverse_copyz+TestChainsOfViews.test_reverse_reverse_copy  s    GGOOO'II4I ww$''--'''ww$''--'''HH%(II4I ww$((..(((ww$((..(((r   c                     | j                   j                         }|j                  g d      }|j                  ddg      }|j	                         }t        |      ddgk(  sJ t        |j                        dgk(  sJ y )Nr   r   r   ra   rb   )r   rX   r   edge_subgraphr   r   r5   r*   )r   r   r   r   USSGs        r   'test_subgraph_edgesubgraph_toundirectedz9TestChainsOfViews.test_subgraph_edgesubgraph_toundirected"  sq    FFKKMZZ	"/0  "DzaV###djj!fX---r   c                     | j                   j                         }|j                  g d      }|j                  d      }|j                  d      }t        |d      sJ t        |d      rJ y Nr   Tas_viewFr   )r   rX   r   r   r   r   r   CSGDCSGs        r   test_copy_subgraphz$TestChainsOfViews.test_copy_subgraph*  sb    FFKKMZZ	"ggdg#wwuw%sH%%%4****r   c                     | j                   j                         }|j                  g d      }|j                  d      }|j                  d      }t        |d      sJ t        |d      rJ y r   )r   rX   r   r   r   s        r   test_copy_disubgraphz&TestChainsOfViews.test_copy_disubgraph2  b    GGLLNZZ	"ggdg#wwuw%sH%%%4****r   c                     | j                   j                         }|j                  g d      }|j                  d      }|j                  d      }t        |d      sJ t        |d      rJ y r   )r   rX   r   r   r   s        r   test_copy_multidisubgraphz+TestChainsOfViews.test_copy_multidisubgraph:  sb    HHMMOZZ	"ggdg#wwuw%sH%%%4****r   c                     | j                   j                         }|j                  g d      }|j                  d      }|j                  d      }t        |d      sJ t        |d      rJ y r   )rm   rX   r   r   r   s        r   test_copy_multisubgraphz)TestChainsOfViews.test_copy_multisubgraphB  r   r   c                     t        j                  | j                        }|j                  j                  dk(  sJ |j                  d      }|j                  j                  dk(  sJ y )Nrl   Tr   )r   rl   r   rW   rO   rX   r>   s     r   test_copy_of_viewz#TestChainsOfViews.test_copy_of_viewJ  sT    MM$((#{{##|333FF4F {{##|333r   c                     G fddt         j                        | j                  D ]b  } |      }|j                  g d      }|j	                         }|j                         dk(  sJ |j                         dk(  sJ d|vr]d|v rbJ  y )Nc                       e Zd Zd Z fdZy)0TestChainsOfViews.test_subclass.<locals>.MyGraphc                      yrD   rF   r   s    r   rG   z:TestChainsOfViews.test_subclass.<locals>.MyGraph.my_methodR  rH   r   c                             S r.   rF   rJ   s    r   rL   zBTestChainsOfViews.test_subclass.<locals>.MyGraph.to_directed_classU  rM   r   NrN   rR   s   r   rK   r   Q  rS   r   rK   r   rE   r(   )r   r   r   r   rX   rG   )r   r   r   r   r   rK   s        @r   r]   zTestChainsOfViews.test_subclassP  s    	!bjj 	! [[ 	)EAI&B	A<<>T)));;=D(((A:b((	)r   N)rO   rP   rQ   classmethodr   r#   r   r   r   r   r   r   r   r   r   r   r   r   r   r]   rF   r   r   r   r      s`    ' '41#0<&E55).++++4)r   r   )r;   networkxr   networkx.utilsr   r   r   r_   rs   ru   r   r   rF   r   r   <module>r      sM      3
,' ,'^F F@;$1 $1N#1 #1Lo) o)r   