Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_graphlib.cpython-311.pyc
�

�KeA!��~�ddlZddlZddlZddlmZGd�dej��Zedkrej��dSdS)�N)�assert_python_okc�t�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�ZdS)�TestTopologicalSortc�~��d�}tj|��}|�t||����t|����tj|��}t	|������|D]3}�fd�|D��}|�t
|��|���4dS)Nc3�K�|���|���rb|���}|D]}|�|���t	t|����V�|����`dSdS�N)�prepare�	is_active�	get_ready�done�tuple�sorted)�ts�nodes�nodes   �</usr/local/apps/python3/lib/python3.11/test/test_graphlib.py�static_order_with_groupszATestTopologicalSort._test_graph.<locals>.static_order_with_groups	s������J�J�L�L�L��,�,�.�.�
+�������!�"�"�D��G�G�D�M�M�M�M��F�5�M�M�*�*�*�*�*�	�,�,�.�.�
+�
+�
+�
+�
+�c�.��h|]}t�����S�)�next)�.0�element�its  �r�	<setcomp>z2TestTopologicalSort._test_graph.<locals>.<setcomp>s���5�5�5�G�t�B�x�x�5�5�5r)�graphlib�TopologicalSorter�assertEqual�list�iter�static_order�set)�self�graph�expectedrr�group�tsgrouprs       @r�_test_graphzTestTopologicalSort._test_graphs����	+�	+�	+��
'��
.�
.������6�6�r�:�:�;�;�T�(�^�^�L�L�L�
�
'��
.�
.���"�/�/�#�#�
$�
$���	2�	2�E�5�5�5�5�u�5�5�5�G����S��Z�Z��1�1�1�1�	2�	2rc��tj��}|���D]\}}|j|g|�R��	|����#tj$rz}|j\}}|�d�tt|����d�tt|dz������Yd}~dSd}~wwxYw)N� �)rr�items�addr	�
CycleError�args�assertIn�join�map�str)	r#r$�cyclerr�	dependson�e�_�seqs	         r�
_assert_cyclez!TestTopologicalSort._assert_cycles���
�
'�
)�
)��$�{�{�}�}�	%�	%�O�D�)��B�F�4�$�)�$�$�$�$�$�	��J�J�L�L�L�

��	�"�	R�	R�	R��V�F�A�s��M�M�#�(�(�3�s�E�?�?�3�3�S�X�X�c�#�s�Q�w�>O�>O�5P�5P�Q�Q�Q�Q�Q�Q�Q�Q�Q�����	R���s�A�C�!A/C�Cc
�J�|�dhddhddhddhddhd�gd���|�diid	g��|�d
�td��D��d�tdd
d
��D����|�dhdhdhdhdhdhdhdhd�gd���|�ddgdgddgdgdgdgdgdgdggd�
gd���|�ddggdggd�gd���|�ddggdggdgdggd�gd���dS)N�����)r+�	�
r;r<))r=r?r>)r<r;)r+r@rA��rBc��i|]	}||dzh��
SrCr�r�xs  r�
<dictcomp>z9TestTopologicalSort.test_simple_cases.<locals>.<dictcomp>2s ��+�+�+�A�Q��Q���+�+�+rrAc��g|]}|f��SrrrEs  r�
<listcomp>z9TestTopologicalSort.test_simple_cases.<locals>.<listcomp>2s��-N�-N�-N�q�q�d�-N�-N�-Nr������
��)r+r=rKr?r;rLrMrN))rBrO)r?rN)rKrM)r=rL)r+r;r+�r@)
rrBr+r=rKr?rPr>r<r@))r@)rK)r=r<)rBr?r>)rP�r+�r)rrBr+r=))rBr=rQrR)rrBr+r=rKr?rP))rBr=rP)r+r?)rrK)r(�range�r#s r�test_simple_casesz%TestTopologicalSort.test_simple_cases)s��������"�a��r�1�g�A�q�6�q�!�f�E�E�,�,�,�	
�	
�	
�
	
���!�R��4�&�)�)�)����+�+��r���+�+�+�-N�-N�E�"�b�"�<M�<M�-N�-N�-N�	
�	
�	
�	
�����������"��B�4�b�T�PR�t�T�T�9�9�9�	
�	
�	
�
	
����q�6��3��q�6��3��3��3��3��3��3��
�
�
>�=�=�	
�	
�	
� 	
���a��V���s�r�:�:�<P�<P�<P�Q�Q�Q�����A��2�1�#�"�!��!���D�D�'�'�'�	
�	
�	
�	
�	
rc���|�dhdhdhd�ddg��|�t��t��t��d�dg��dS)Nr+rKrP)rBr=r?)r+rKrP)r(r"rTs r�test_no_dependenciesz(TestTopologicalSort.test_no_dependenciesQsa�����a�S�a�S�a�S�1�1�I�y�3I�J�J�J����S�U�U�s�u�u����7�7�)��E�E�E�E�Erc�H�|�dhdhgd�d�ddg��tj��}|�dd��|�dd��|�dd��|�g|����ddg��dS)Nr+rK)r+rKrKrKrKrK)rBr=r)r+rK)rrBr=rB)r(rrr-rr!�r#rs  r�test_the_node_multiple_timesz0TestTopologicalSort.test_the_node_multiple_timesVs������a�S�a�S�-?�-?�-?�@�@�6�9�BU�V�V�V��
'�
)�
)��
���q�!����
���q�!����
���q�!�������-�2�?�?�,�,�-��1�v�6�6�6�6�6rc���d�td��D��}tjd|i��}|�t	|�����gd���dS)Nc3�&K�|]}d|zdzV��
dS)r+rBNrrEs  r�	<genexpr>z@TestTopologicalSort.test_graph_with_iterables.<locals>.<genexpr>bs*����1�1�1�Q��U�Q�Y�1�1�1�1�1�1rr?r)rBr=r?r>r@r)rSrrrrr!)r#r5rs   r�test_graph_with_iterablesz-TestTopologicalSort.test_graph_with_iterablesasd��1�1��a���1�1�1�	�
�
'��I��
7�
7������b�o�o�/�/�0�0�2D�2D�2D�E�E�E�E�Erc��tj��}|�dd��|�dd��|�dd��|�dd��tjdhd�i��}|�g|����g|������dS)NrBr+r=rKr?>r+r=rKr?)rrr-rr!)r#r�ts2s   r�1test_add_dependencies_for_same_node_incrementallyzETestTopologicalSort.test_add_dependencies_for_same_node_incrementallyfs���
�
'�
)�
)��
���q�!����
���q�!����
���q�!����
���q�!�����(�!�\�\�\�):�;�;�����-�2�?�?�,�,�-�/D��1A�1A�1C�1C�/D�E�E�E�E�Erc�2�|�ig��dSr)r(rTs r�
test_emptyzTestTopologicalSort.test_emptyqs������R� � � � � rc	��|�ddhiddg��|�dhdhd�gd���|�dhdhdhd�gd���|�dhdhdhdhd	hd
�gd���|�dhdhdhdhdhd	hd
�gd���|�dhdhddhdhd�ddg��dS)NrBr+)rBr+)rBr+rBr=)rBr+r=)rBr=r+rBrKrP)rBr+r=r?rKr?r>)rBr+r=rKrPr>)rBr+r=rK)r9rTs r�
test_cyclezTestTopologicalSort.test_cyclets�����A��s�8�a��V�,�,�,�����s��s�+�+�Y�Y�Y�7�7�7�����s��s��s�3�3�\�\�\�B�B�B�����s��s��s��s��s�C�C�\�\�\�R�R�R�����s��s��s��s��s��s�K�K�Y�Y�Y�W�W�W�����s��s��1�v�1�#�>�>��A��G�G�G�G�Grc���tj��}|�td��5|���ddd��n#1swxYwY|�td��5|�d��ddd��n#1swxYwY|�td��5|���ddd��dS#1swxYwYdS)Nz prepare\(\) must be called firstr=)rr�assertRaisesRegex�
ValueErrorrrr
rYs  r�test_calls_before_preparez-TestTopologicalSort.test_calls_before_prepare�s���
�
'�
)�
)��
�
#�
#�J�0S�
T�
T�	�	��L�L�N�N�N�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�
#�
#�J�0S�
T�
T�	�	��G�G�A�J�J�J�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�
#�
#�J�0S�
T�
T�	�	��L�L�N�N�N�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s5�A�A�A�6B�B�B�>C � C$�'C$c���tj��}|���|�td��5|���ddd��dS#1swxYwYdS)Nz!cannot prepare\(\) more than once)rrr	rgrhrYs  r�test_prepare_multiple_timesz/TestTopologicalSort.test_prepare_multiple_times�s���
�
'�
)�
)��
�
�
����
�
#�
#�J�0T�
U�
U�	�	��J�J�L�L�L�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�A%�%A)�,A)c��tj��}|�dddd��|�ddd��|���|���|�td��5|�d��ddd��n#1swxYwY|�td��5|�d��ddd��dS#1swxYwYdS)NrBr+r=rKznode 2 was not passed outz#node 24 was not added using add\(\)�)rrr-r	rrgrhrrYs  r�test_invalid_nodes_in_donez.TestTopologicalSort.test_invalid_nodes_in_done�sZ��
�
'�
)�
)��
���q�!�Q�����
���q�!�Q����
�
�
����
������
�
#�
#�J�0K�
L�
L�	�	��G�G�A�J�J�J�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�
#�
#�J�0V�
W�
W�	�	��G�G�B�K�K�K�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s$�B(�(B,�/B,�C1�1C5�8C5c���tj��}|�dddd��|�dd��|���|�|���d��|�|���d��|�d��|�|���d��|�|���d��|�d��|�d��|�|���d��|�|���d��|�d��|�|���d��|�|�����dS)	NrBr+r=rK)r=rKrrQrC)	rrr-r	rrr�assertFalser
rYs  r�	test_donezTestTopologicalSort.test_done�sv��
�
'�
)�
)��
���q�!�Q�����
���q�!����
�
�
�������������0�0�0����������,�,�,�
����
�
�
����������.�.�.����������,�,�,�
����
�
�
�
����
�
�
����������.�.�.����������,�,�,�
����
�
�
����������,�,�,���������(�(�(�(�(rc��tj��}|�dd��|���|�|�����|�|���d��|�|�����|�d��|�|�����|�|���d��|�|�����|�d��|�	|�����dS)NrBr+rQrC)
rrr-r	�
assertTruer
rrrrprYs  r�test_is_activez"TestTopologicalSort.test_is_active�s��
�
'�
)�
)��
���q�!����
�
�
������������'�'�'����������.�.�.���������'�'�'�
����
�
�
���������'�'�'����������.�.�.���������'�'�'�
����
�
�
���������(�(�(�(�(rc�X�tj��}|�t|jt��d��|�t|jdt����|�t|jt��t����dS)NrB)rr�assertRaises�	TypeErrorr-�dictrYs  r�test_not_hashable_nodesz+TestTopologicalSort.test_not_hashable_nodes�sz��
�
'�
)�
)�����)�R�V�T�V�V�Q�7�7�7����)�R�V�Q����7�7�7����)�R�V�T�V�V�T�V�V�<�<�<�<�<rc��d�}tj��}|�ddd��|�dd��|�dd��|�dd	��|�dd	��tj��}|�dd��|�ddd��|�dd	��|�dd	��|�dd��|�t	||����t	||������dS)
Nc3��K�|���|���rE|���}|j|�t	|��V�|����CdSdSr)r	r
rrr")rrs  r�
get_groupsz^TestTopologicalSort.test_order_of_insertion_does_not_matter_between_groups.<locals>.get_groups�su�����J�J�L�L�L��,�,�.�.�
!��������������%�j�j� � � ��,�,�.�.�
!�
!�
!�
!�
!rr=r+rBrrKr?rPr>)rrr-rr)r#r|rr`s    r�6test_order_of_insertion_does_not_matter_between_groupszJTestTopologicalSort.test_order_of_insertion_does_not_matter_between_groups�s��	!�	!�	!��
'�
)�
)��
���q�!�Q����
���q�!����
���q�!����
���q�!����
���q�!�����(�*�*������1�
�
�
�����1�a��������1�
�
�
�����1�
�
�
�����1�
�
�
�����j�j��n�n�-�-�t�J�J�s�O�O�/D�/D�E�E�E�E�Erc��d�}|d��}|d��}|�|d��|�|d��|�||��dS)Nc��d}tj���}d|d<t|��|d<t	d|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()))
                T�
__cleanenv�PYTHONHASHSEEDz-c)�os�environ�copyr3r)�seed�code�env�outs    r�check_order_with_hash_seedzlTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seed.<locals>.check_order_with_hash_seed�sU���D��*�/�/�#�#�C�!%�C���$'��I�I�C� �!�"�4��5�5��5�5�C��Jri�i�z�)�assertNotEqualr)r#r��run1�run2s    r�4test_static_order_does_not_change_with_the_hash_seedzHTestTopologicalSort.test_static_order_does_not_change_with_the_hash_seed�s{��	�	�	�$*�)�$�/�/��)�)�%�0�0�����D�"�%�%�%����D�"�%�%�%�����t�$�$�$�$�$rN)�__name__�
__module__�__qualname__r(r9rUrWrZr^rarcrerirkrnrqrtryr}r�rrrrrs#������2�2�2�*
�
�
�&
�&
�&
�PF�F�F�
	7�	7�	7�F�F�F�
	F�	F�	F�!�!�!�H�H�H�������
�
�
�)�)�)�,
)�
)�
)�=�=�=�F�F�F�0%�%�%�%�%rr�__main__)	rr��unittest�test.support.script_helperr�TestCaserr��mainrrr�<module>r�s�������	�	�	�	�����7�7�7�7�7�7�r%�r%�r%�r%�r%�(�+�r%�r%�r%�h�z����H�M�O�O�O�O�O��r