Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_graphlib.cpython-310.opt-2.pyc

o

0�i_!�@sZddlmZddlZddlZddlZddlmZGdd�dej�Ze	dkr+e�
�dSdS)�)�chainN)�assert_python_okc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�TestTopologicalSortcspdd�}t�|�}|�t||��t|��t�|�}t|����|D]}�fdd�|D�}|�t|�|�q"dS)NcssL�|��|��r$|��}|D]}|�|�qtt|��V|��s	dSdS�N)�prepare�	is_active�	get_ready�done�tuple�sorted)�ts�nodes�node�r�9/opt/alt/python310/lib64/python3.10/test/test_graphlib.py�static_order_with_groups
s��zATestTopologicalSort._test_graph.<locals>.static_order_with_groupscsh|]}t���qSr)�next)�.0Zelement��itrr�	<setcomp>sz2TestTopologicalSort._test_graph.<locals>.<setcomp>)�graphlib�TopologicalSorter�assertEqual�list�iter�static_order�set)�self�graphZexpectedrr�groupZtsgrouprrr�_test_graph	s

�zTestTopologicalSort._test_graphc	Cs�t��}|��D]
\}}|j|g|�R�qz|��W�tjyI}z |j\}}|�d�t	t
|��d�t	t
|d���WYd}~dSd}~ww)N� �)rr�items�addrZ
CycleError�argsZassertIn�join�map�str)	rr�cyclerr�	dependson�e�msg�seqrrr�
_assert_cycles
�
6��z!TestTopologicalSort._assert_cyclec
Cs(|�dhddhddhddhddhd�gd��|�diid	g�|�d
d�td�D�d
d�tddd�D��|�dhdhdhdhdhdhdhdhd�gd��|�ddgdgddgdgdgdgdgdgdggd�
gd��|�ddggdggd�gd��|�ddggdggdgdggd�gd��dS) N�����)r#�	�
r0r1))r2r4r3)r1r0)r#r5r6��r7cSsi|]}||dh�qSr8r�r�xrrr�
<dictcomp>3sz9TestTopologicalSort.test_simple_cases.<locals>.<dictcomp>r6cSsg|]}|f�qSrrr9rrr�
<listcomp>3sz9TestTopologicalSort.test_simple_cases.<locals>.<listcomp>������
��)r#r2r>r4r0r?r@rA))r7rB)r4rA)r>r@)r2r?)r#r0r#�r5)
rr7r#r2r>r4rCr3r1r5))r5)r>)r2r1)r7r4r3)rC�r#�r)rr7r#r2))r7r2rDrE)rr7r#r2r>r4rC))r7r2rC)r#r4)rr>)r!�range�rrrr�test_simple_cases*s> �$�$��� �z%TestTopologicalSort.test_simple_casescCs>|�dhdhdhd�ddg�|�t�t�t�d�dg�dS)Nr#r>rC)r7r2r4)r#r>rC)r!rrGrrr�test_no_dependenciesRs z(TestTopologicalSort.test_no_dependenciescCsh|�dhdhgd�d�ddg�t��}|�dd�|�dd�|�dd�|�g|���ddg�dS)Nr#r>)r#r>r>r>r>r>)r7r2r)r#r>)rr7r2r7)r!rrr%rr�rrrrr�test_the_node_multiple_timesWs z0TestTopologicalSort.test_the_node_multiple_timescCs<dd�td�D�}t�d|i�}|�t|���gd��dS)Ncss�|]	}d|dVqdS)r#r7Nrr9rrr�	<genexpr>cs�z@TestTopologicalSort.test_graph_with_iterables.<locals>.<genexpr>r4r)r7r2r4r3r5r)rFrrrrr)rr+rrrr�test_graph_with_iterablesbsz-TestTopologicalSort.test_graph_with_iterablescCsjt��}|�dd�|�dd�|�dd�|�dd�t�dhd�i�}|�g|���g|����dS)Nr7r#r2r>r4>r#r2r>r4)rrr%rr)rr�ts2rrr�1test_add_dependencies_for_same_node_incrementallygs zETestTopologicalSort.test_add_dependencies_for_same_node_incrementallycCs|�ig�dSr)r!rGrrr�
test_emptyrszTestTopologicalSort.test_emptyc	Cs�|�ddhiddg�|�dhdhd�gd��|�dhdhdhd�gd��|�dhdhdhdhd	hd
�gd��|�dhdhdhdhdhd	hd
�gd��|�dhdhddhdhd�ddg�dS)Nr7r#)r7r#)r7r#r7r2)r7r#r2)r7r2r#r7r>rC)r7r#r2r4r>r4r3)r7r#r2r>rCr3)r7r#r2r>)r/rGrrr�
test_cycleus&*(zTestTopologicalSort.test_cyclecCs�t��}|�td��|��Wd�n1swY|�td��
|�d�Wd�n1s4wY|�td��
|��Wd�dS1sOwYdS)Nz prepare\(\) must be called firstr2)rr�assertRaisesRegex�
ValueErrorrr	rrJrrr�test_calls_before_prepare�s
��
"�z-TestTopologicalSort.test_calls_before_preparecCsJt��}|��|�td��
|��Wd�dS1swYdS)Nz!cannot prepare\(\) more than once)rrrrRrSrJrrr�test_prepare_multiple_times�s

"�z/TestTopologicalSort.test_prepare_multiple_timescCs�t��}|�dddd�|�ddd�|��|��|�td��
|�d�Wd�n1s1wY|�td��|�d�Wd�dS1sMwYdS)Nr7r#r2r>znode 2 was not passed outz#node 24 was not added using add\(\)�)rrr%rrrRrSr	rJrrr�test_invalid_nodes_in_done�s�"�z.TestTopologicalSort.test_invalid_nodes_in_donecCs�t��}|�dddd�|�dd�|��|�|��d�|�|��d�|�d�|�|��d�|�|��d�|�d�|�d�|�|��d�|�|��d�|�d�|�|��d�|�|���dS)	Nr7r#r2r>)r2r>rrDr8)	rrr%rrrr	�assertFalserrJrrr�	test_done�s 



zTestTopologicalSort.test_donecCs�t��}|�dd�|��|�|���|�|��d�|�|���|�d�|�|���|�|��d�|�|���|�d�|�	|���dS)Nr7r#rDr8)
rrr%rZ
assertTruerrrr	rXrJrrr�test_is_active�s

z"TestTopologicalSort.test_is_activecCsJt��}|�t|jt�d�|�t|jdt��|�t|jt�t��dS)Nr7)rrZassertRaises�	TypeErrorr%�dictrJrrr�test_not_hashable_nodes�sz+TestTopologicalSort.test_not_hashable_nodescCs�dd�}t��}|�ddd�|�dd�|�dd�|�d	d
�|�dd
�t��}|�dd�|�ddd�|�dd
�|�d	d
�|�dd�|�t||��t||���dS)Ncss>�|��|��r|��}|j|�t|�V|��s	dSdSr)rrrr	r)rr
rrr�
get_groups�s�

�z^TestTopologicalSort.test_order_of_insertion_does_not_matter_between_groups.<locals>.get_groupsr2r#r7rr>r4rCr3)rrr%rr)rr^rrNrrr�6test_order_of_insertion_does_not_matter_between_groups�s zJTestTopologicalSort.test_order_of_insertion_does_not_matter_between_groupscCs@dd�}|d�}|d�}|�|d�|�|d�|�||�dS)NcSs8d}tj��}d|d<t|�|d<td|fi|��}|S)Naxif 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()))
                TZ
__cleanenvZPYTHONHASHSEEDz-c)�os�environ�copyr)r)Zseed�code�env�outrrr�check_order_with_hash_seed�s
	zlTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seed.<locals>.check_order_with_hash_seedi�i�z�)ZassertNotEqualr)rrfZrun1Zrun2rrr�4test_static_order_does_not_change_with_the_hash_seed�szHTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seedN)�__name__�
__module__�__qualname__r!r/rHrIrKrMrOrPrQrTrUrWrYrZr]r_rhrrrrrs$(
r�__main__)�	itertoolsrrr`ZunittestZtest.support.script_helperrZTestCaserri�mainrrrr�<module>su�