
    0hhA!                         S SK r S SKrS SKrS SKJr   " S S\R
                  5      r\S:X  a  \R                  " 5         gg)    N)assert_python_okc                   z    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSrg)TestTopologicalSort   c                 p   S n[         R                  " U5      nU R                  [        U" U5      5      [        U5      5        [         R                  " U5      n[	        UR                  5       5      nU H9  nU Vs1 s H  n[        U5      iM     nnU R                  [        U5      U5        M;     g s  snf )Nc              3     #    U R                  5         U R                  5       (       aX  U R                  5       nU H  nU R                  U5        M     [	        [        U5      5      v   U R                  5       (       a  MW  g g 7fN)prepare	is_active	get_readydonetuplesorted)tsnodesnodes      ;/opt/python-3.13.8/usr/lib/python3.13/test/test_graphlib.pystatic_order_with_groupsATestTopologicalSort._test_graph.<locals>.static_order_with_groups	   sU     JJL,,..!DGGDM "F5M**	 ,,..s   A;B?B)graphlibTopologicalSorterassertEquallistiterstatic_ordernextset)	selfgraphexpectedr   r   itgroupelementtsgroups	            r   _test_graphTestTopologicalSort._test_graph   s    	+ ''.6r:;T(^L''. "//#$E/45uGtBxuG5SZ1 5s   <B3c                    [         R                  " 5       nUR                  5        H  u  pEUR                  " U/UQ76   M      UR	                  5         e ! [         R
                   ag  nUR                  u  pxU R                  SR                  [        [        U5      5      SR                  [        [        US-  5      5      5         S nAg S nAff = f)N    )r   r   itemsaddr
   
CycleErrorargsassertInjoinmapstr)	r   r   cycler   r   	dependsone_seqs	            r   _assert_cycle!TestTopologicalSort._assert_cycle   s    '')${{}ODFF4$)$  -	JJL
 	 "" 	RVVFAMM#((3sE?3SXXc#sQw>O5PQQ	Rs   A C(AC

Cc                 8   U R                  S1SS1SS1SS1SS1S./ SQ5        U R                  S0 0S	/5        U R                  [        S
5       Vs0 s H	  oUS-   1_M     sn[        S
SS5       Vs/ s H  o4PM     sn5        U R                  S1S1S1S1S1S1S1S1S./ SQ5        U R                  SS/S/SS/S/S/S/S/S/S// S.
/ SQ5        U R                  SS// S// S./ SQ5        U R                  SS// S// S/S// S./ SQ5        g s  snf s  snf )N         r      )r)   	   
   r:   r;   ))r<   r=   r   )r;   r:   )r)   r>   r?      r@   r?                  )r)   r<   rC   r=   r:   rD   rE   rF   ))r@   rG   )r=   rF   )rC   rE   )r<   rD   )r)   r:   r)      r>   )
r   r@   r)   r<   rC   r=   rH   r   r;   r>   ))r>   )rC   )r<   r;   )r@   r=   r   )rH   r)   r   )r   r@   r)   r<   ))r@   r<   rI   rJ   )r   r@   r)   r<   rC   r=   rH   ))r@   r<   rH   )r)   r=   )r   rC   )r%   range)r   xs     r   test_simple_cases%TestTopologicalSort.test_simple_cases)   sp   "ar1gAq6q!fE,	

 	!R4&)!&r+AQZ+E"b"<M-N<Mqd<M-N	
 	"B4bTPRtT9	

 	q63q6333333 >	
  	aVsr:<PQA21#"!!D'	
5 ,-Ns   D2D
c                     U R                  S1S1S1S.SS/5        U R                  [        5       [        5       [        5       S.S/5        g )Nr)   rC   rH   )r@   r<   r=   )r)   rC   rH   )r%   r   r   s    r   test_no_dependencies(TestTopologicalSort.test_no_dependenciesQ   sC    aSaSaS1Iy3IJSUsu7)E    c                    U R                  S1S1/ SQS.SS/5        [        R                  " 5       nUR                  SS5        UR                  SS5        UR                  SS5        U R	                  / UR                  5       QSS/5        g )Nr)   rC   )r)   rC   rC   rC   rC   rC   )r@   r<   r   )r)   rC   )r   r@   r<   r@   )r%   r   r   r+   r   r   r   r   s     r   test_the_node_multiple_times0TestTopologicalSort.test_the_node_multiple_timesV   s{    aSaS-?@69BUV '')
q!
q!
q!-2??,-1v6rS   c                     S [        S5       5       n[        R                  " SU05      nU R                  [	        UR                  5       5      / SQ5        g )Nc              3   2   #    U  H  nS U-  S-   v   M     g7f)r)   r@   N ).0rL   s     r   	<genexpr>@TestTopologicalSort.test_graph_with_iterables.<locals>.<genexpr>b   s     11QUQYs   r=   r   )r@   r<   r=   r   r>   r   )rK   r   r   r   r   r   )r   r3   r   s      r   test_graph_with_iterables-TestTopologicalSort.test_graph_with_iterablesa   sA    1a1	''I7boo/02DErS   c                 V   [         R                  " 5       nUR                  SS5        UR                  SS5        UR                  SS5        UR                  SS5        [         R                  " S1 Sk05      nU R                  / UR	                  5       Q/ UR	                  5       Q5        g )Nr@   r)   r<   rC   r=   >   r)   r<   rC   r=   )r   r   r+   r   r   )r   r   ts2s      r   1test_add_dependencies_for_same_node_incrementallyETestTopologicalSort.test_add_dependencies_for_same_node_incrementallyf   s    '')
q!
q!
q!
q!((!\):;-2??,-/D1A1A1C/DErS   c                 (    U R                  0 / 5        g r	   )r%   rP   s    r   
test_emptyTestTopologicalSort.test_emptyq   s    R rS   c           	      V   U R                  SS10SS/5        U R                  S1S1S./ SQ5        U R                  S1S1S1S./ SQ5        U R                  S1S1S1S1S	1S
./ SQ5        U R                  S1S1S1S1S1S	1S./ SQ5        U R                  S1S1SS1S1S.SS/5        g )Nr@   r)   )r@   r)   )r@   r)   r@   r<   )r@   r)   r<   )r@   r<   r)   r@   rC   rH   )r@   r)   r<   r=   rC   r=   r   )r@   r)   r<   rC   rH   r   )r@   r)   r<   rC   )r7   rP   s    r   
test_cycleTestTopologicalSort.test_cyclet   s    As8aV,ss+Y7sss3\BsssssC\RssssssKYWss1v1#>AGrS   c                    [         R                  " 5       nU R                  [        S5         UR	                  5         S S S 5        U R                  [        S5         UR                  S5        S S S 5        U R                  [        S5         UR                  5         S S S 5        g ! , (       d  f       Nn= f! , (       d  f       NO= f! , (       d  f       g = f)Nz prepare\(\) must be called firstr<   )r   r   assertRaisesRegex
ValueErrorr   r   r   rU   s     r   test_calls_before_prepare-TestTopologicalSort.test_calls_before_prepare   s    '')##J0STLLN U##J0STGGAJ U##J0STLLN UT	 UTTTTTs#   B%B6C%
B36
C
Cc                     [         R                  " 5       nUR                  5         U R                  [        S5         UR                  5         S S S 5        g ! , (       d  f       g = f)Nz!cannot prepare\(\) more than once)r   r   r
   rk   rl   rU   s     r   test_prepare_multiple_times/TestTopologicalSort.test_prepare_multiple_times   s@    '')


##J0TUJJL VUUs   A
A$c                    [         R                  " 5       nUR                  SSSS5        UR                  SSS5        UR                  5         UR	                  5         U R                  [        S5         UR                  S5        S S S 5        U R                  [        S5         UR                  S5        S S S 5        g ! , (       d  f       N?= f! , (       d  f       g = f)Nr@   r)   r<   rC   znode 2 was not passed outz#node 24 was not added using add\(\)   )r   r   r+   r
   r   rk   rl   r   rU   s     r   test_invalid_nodes_in_done.TestTopologicalSort.test_invalid_nodes_in_done   s    '')
q!Q
q!Q



##J0KLGGAJ M##J0VWGGBK XW MLWWs   3B>#C>
C
Cc                     [         R                  " 5       nUR                  SSSS5        UR                  SS5        UR                  5         U R	                  UR                  5       S5        U R	                  UR                  5       S5        UR                  S5        U R	                  UR                  5       S5        U R	                  UR                  5       S5        UR                  S5        UR                  S5        U R	                  UR                  5       S5        U R	                  UR                  5       S5        UR                  S5        U R	                  UR                  5       S5        U R                  UR                  5       5        g )	Nr@   r)   r<   rC   )r<   rC   rZ   rI   rA   )	r   r   r+   r
   r   r   r   assertFalser   rU   s     r   	test_doneTestTopologicalSort.test_done   s   '')
q!Q
q!


0,

.,



.,

,(rS   c                 l   [         R                  " 5       nUR                  SS5        UR                  5         U R	                  UR                  5       5        U R                  UR                  5       S5        U R	                  UR                  5       5        UR                  S5        U R	                  UR                  5       5        U R                  UR                  5       S5        U R	                  UR                  5       5        UR                  S5        U R                  UR                  5       5        g )Nr@   r)   rI   rA   )
r   r   r+   r
   
assertTruer   r   r   r   rw   rU   s     r   test_is_active"TestTopologicalSort.test_is_active   s    '')
q!


'.'

'.'

(rS   c                 :   [         R                  " 5       nU R                  [        UR                  [        5       S5        U R                  [        UR                  S[        5       5        U R                  [        UR                  [        5       [        5       5        g )Nr@   )r   r   assertRaises	TypeErrorr+   dictrU   s     r   test_not_hashable_nodes+TestTopologicalSort.test_not_hashable_nodes   s`    ''))RVVTVQ7)RVVQ7)RVVTVTV<rS   c                 *   S n[         R                  " 5       nUR                  SSS5        UR                  SS5        UR                  SS5        UR                  SS	5        UR                  SS	5        [         R                  " 5       nUR                  SS5        UR                  SSS5        UR                  SS	5        UR                  SS	5        UR                  SS5        U R                  [	        U" U5      5      [	        U" U5      5      5        g )
Nc              3      #    U R                  5         U R                  5       (       aD  U R                  5       nU R                  " U6   [	        U5      v   U R                  5       (       a  MC  g g 7fr	   )r
   r   r   r   r   )r   r   s     r   
get_groups^TestTopologicalSort.test_order_of_insertion_does_not_matter_between_groups.<locals>.get_groups   sF     JJL,,..%j  ,,..s   A'A-+A-r<   r)   r@   r   rC   r=   rH   r   )r   r   r+   r   r   )r   r   r   ra   s       r   6test_order_of_insertion_does_not_matter_between_groupsJTestTopologicalSort.test_order_of_insertion_does_not_matter_between_groups   s    	! '')
q!Q
q!
q!
q!
q!((*11a111jn-tJsO/DErS   c                     S nU" S5      nU" S5      nU R                  US5        U R                  US5        U R                  X#5        g )Nc                     Sn[         R                  R                  5       nSUS'   [        U 5      US'   [	        SU40 UD6nU$ )Nax  if 1:
                import graphlib
                ts = graphlib.TopologicalSorter()
                ts.add('blech', 'bluch', 'hola')
                ts.add('abcd', 'blech', 'bluch', 'a', 'b')
                ts.add('a', 'a string', 'something', 'b')
                ts.add('bluch', 'hola', 'abcde', 'a', 'b')
                print(list(ts.static_order()))
                T
__cleanenvPYTHONHASHSEEDz-c)osenvironcopyr1   r   )seedcodeenvouts       r   check_order_with_hash_seedlTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seed.<locals>.check_order_with_hash_seed   sL    D **//#C !%C$'IC !"455CJrS   i  iz   )assertNotEqualr   )r   r   run1run2s       r   4test_static_order_does_not_change_with_the_hash_seedHTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seed   sK    	$ *$/)%0D"%D"%$rS   rZ   N)__name__
__module____qualname____firstlineno__r%   r7   rM   rQ   rV   r^   rb   re   rh   rm   rp   rt   rx   r|   r   r   r   __static_attributes__rZ   rS   r   r   r      s]    2*
&
PF
	7F
	F!H
),)=F0%rS   r   __main__)	r   r   unittesttest.support.script_helperr   TestCaser   r   mainrZ   rS   r   <module>r      s>     	  7r%(++ r%h zMMO rS   