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_sort.cpython-310.opt-1.pyc

o

0�i�5�@s�ddlmZddlZddlZddlmZejZdaddd�ZGdd�dej	�Z
Gdd	�d	ej	�ZGd
d�dej	�Zdd
�Z
Gdd�dej	�ZedkrPe��dSdS)�)�supportN��
cmp_to_keycCs�trtd|�|dd�}|r|jt|�d�n|��t|�t|�krEtd|�tdt|�t|��t|�t|�t|�td7adSt|�D]+\}}||}||urttd|�td|||�t|�t|�t|�td7adSqIdS)Nz    checking��keyzerror inzlength mismatch;�zout of order at index)�verbose�print�sortr�len�nerrors�	enumerate)�tagZexpected�rawZcompareZorig�iZgood�maybe�r�5/opt/alt/python310/lib64/python3.10/test/test_sort.py�check
s4


��rc@�eZdZdd�ZdS)�TestBasec
	s@dg}tdd�D]}d|}|�t|d|d��q|�gd��G�fdd�dt��Gdd	�d	t��|D]�}tt|��}trEtd
|�|dd�}td||�|dd�}|��td||�|dd�}t�	|�td
||�|dd�}|��|dd�}td||dd��tr�td�td�|dd�}|j
tdd��d�td||�t|�dkr�dd�}|dd�}|j
t|j
|d��fdd�|D�}|dd�}t�	|�d�_d}z|�
�Wnty�d}Ynw|r�d�_td||��fdd�t|�D�}dd�|D�}	|	�
�dd�|	D�}td ||�q6dS)!Nrr�
�)r�di�cs,eZdZdZdd�Z�fdd�Zdd�ZdS)	z+TestBase.testStressfully.<locals>.ComplainsTcSs
||_dS�N�r)�selfrrrr�__init__6�
z4TestBase.testStressfully.<locals>.Complains.__init__cs2�jrt��dkrtrtd||�t�|j|jkS)Ng����MbP?z        complaining at)�maybe_complain�randomrr	�RuntimeErrorr�r�other��	Complainsrr�__lt__9s
z2TestBase.testStressfully.<locals>.Complains.__lt__cSs
d|jS)Nz
Complains(%d)r�rrrr�__repr__@rz4TestBase.testStressfully.<locals>.Complains.__repr__N)�__name__�
__module__�__qualname__rrr&r(rr$rrr%3s
r%c@s$eZdZdd�Zdd�Zdd�ZdS)z(TestBase.testStressfully.<locals>.StablecSs||_||_dSr�r�index)rrrrrrrDs
z1TestBase.testStressfully.<locals>.Stable.__init__cSs|j|jkSrrr"rrrr&Hsz/TestBase.testStressfully.<locals>.Stable.__lt__cSsd|j|jfS)NzStable(%d, %d)r,r'rrrr(K�z1TestBase.testStressfully.<locals>.Stable.__repr__N)r)r*r+rr&r(rrrr�StableCsr/zTesting sizeZidentity�reversedzrandom permutationzreversed via functioncSs||k||kSrr��a�brrr�<lambda>asz*TestBase.testStressfully.<locals>.<lambda>z3    Checking against an insane comparison function.z?        If the implementation isn't careful, this may segfault.cSstt��d�dS)N�r)�intr r1rrrr4g�rz(an insane function left some permutationcS�t�r�r!��xrrr�bad_keyk�z)TestBase.testStressfully.<locals>.bad_keycsg|]}�|��qSrr��.0rr$rr�
<listcomp>pr7z,TestBase.testStressfully.<locals>.<listcomp>TFz+exception during sort left some permutationcsg|]
}�t�d�|��qS)r�r Z	randranger>)r/rrr@}�cSsg|]}||jf�qSr)r-)r?�errrr@~scSsg|]\}}|�qSrr)r?rCrrrrr@�r7Z	stability)�range�extend�object�listrr	r�reverser �shuffler
rr�assertRaisesr!r)
rZsizesZpower�nr;�s�yr<Z
it_complainedZ	augmentedr)r%r/r�testStressfully+sh


��zTestBase.testStressfullyN)r)r*r+rNrrrrr*�rc@seZdZdd�Zdd�ZdS)�TestBugscs:G�fdd�d���fdd�td�D��|�t�j�dS)NcseZdZ�fdd�ZdS)z"TestBugs.test_bug453523.<locals>.Ccs0�r
t��dkr
���n��d�t��dkS)Ng�?r5g�?)r �pop�appendr"��Lrrr&�s

z)TestBugs.test_bug453523.<locals>.C.__lt__N�r)r*r+r&rrSrr�C�srVcsg|]}���qSrrr>)rVrrr@��z+TestBugs.test_bug453523.<locals>.<listcomp>�2)rDrJ�
ValueErrorr
r'r)rVrTr�test_bug453523�szTestBugs.test_bug453523cshg}td�D]+}�fdd�}ddg�|jt�jt|�d��fdd�}|jt�jt|�d�|g}qdS)N�cs"��d����||k||kS�Nr5)rRrQ�r;rMrSrr�mutating_cmp�s
z7TestBugs.test_undetected_mutation.<locals>.mutating_cmprrrcs$��d��dd�=||k||kSr\)rRr]rSrrr^�s

)rDrJrYr
r)rZmemorywasterrr^rrSr�test_undetected_mutation�s�z!TestBugs.test_undetected_mutationN)r)r*r+rZr_rrrrrP�srPc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestDecorateSortUndecoratecCsHd��}|dd�}t�|�|jtjd�dd�}|jt|�d�dS)N�,The quick Brown fox Jumped over The lazy DogrcSs"|��|��}}||k||kSr)�lower)r;rMZxlowerZylowerrrr�my_cmp��z9TestDecorateSortUndecorate.test_decorated.<locals>.my_cmp)�splitr rIr
�strrbr)r�data�copyrcrrr�test_decorated�s
z)TestDecorateSortUndecorate.test_decoratedcCs"d��}|jt|jdd�d�dS)NracSsdS�Nrrr]rrrr4�sz>TestDecorateSortUndecorate.test_baddecorator.<locals>.<lambda>r)rerJ�	TypeErrorr
�rrgrrr�test_baddecorator�sz,TestDecorateSortUndecorate.test_baddecoratorcCsFdd�td�D�}|dd�}|jdd�d�|��|�||�dS)NcS�g|]	}t�d�|f�qS�rrAr>rrrr@��z=TestDecorateSortUndecorate.test_stability.<locals>.<listcomp>��cS�|dSrjr)�trrrr4��z;TestDecorateSortUndecorate.test_stability.<locals>.<lambda>r)rDr
�assertEqual)rrgrhrrr�test_stability�s
z)TestDecorateSortUndecorate.test_stabilitycCs@ttdd��}|dd�}|jt|jdd�d�|�||�dS)N���rcSsd|S)Nrrr:rrrr4�rtzDTestDecorateSortUndecorate.test_key_with_exception.<locals>.<lambda>r)rGrDrJ�ZeroDivisionErrorr
ru)rrg�duprrr�test_key_with_exception�sz2TestDecorateSortUndecorate.test_key_with_exceptioncs.ttd����fdd�}|jt�j|d�dS)Nrcs�dd�=td��dd�<|S�Nr[�rDr:�rgrr�k�s
z<TestDecorateSortUndecorate.test_key_with_mutation.<locals>.kr)rGrDrJrYr
)rr~rr}r�test_key_with_mutation�sz1TestDecorateSortUndecorate.test_key_with_mutationc�6ttd���G�fdd�dt�}|jt�j|d�dS)Nrcs(eZdZdd�Z�fdd�Zdd�ZdS)zITestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKillercSsdSrr�rr;rrrr�r=zRTestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKiller.__init__cs�dd�=td��dd�<dSr{r|r'r}rr�__del__�s
zQTestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKiller.__del__cSst|�t|�kSr)�idr"rrrr&�r.zPTestDecorateSortUndecorate.test_key_with_mutating_del.<locals>.SortKiller.__lt__N)r)r*r+rr�r&rr}rr�
SortKiller�sr�r)rGrDrFrJrYr
�rr�rr}r�test_key_with_mutating_del�sz5TestDecorateSortUndecorate.test_key_with_mutating_delcr�)Nrcs eZdZdd�Z�fdd�ZdS)zWTestDecorateSortUndecorate.test_key_with_mutating_del_and_exception.<locals>.SortKillercSs|dkrt�dS)Nrr9r�rrrr�s�z`TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception.<locals>.SortKiller.__init__cs"�dd�=ttd���dd�<dSr{)rGrDr'r}rrr��s
z_TestDecorateSortUndecorate.test_key_with_mutating_del_and_exception.<locals>.SortKiller.__del__N)r)r*r+rr�rr}rrr��sr�r)rGrDrFrJr!r
r�rr}r�(test_key_with_mutating_del_and_exception�szCTestDecorateSortUndecorate.test_key_with_mutating_del_and_exceptioncCs>ttd��}t�|�|jdd�|�|ttddd���dS)NrT)rH�c���)rGrDr rIr
rurlrrr�test_reverse�s
z'TestDecorateSortUndecorate.test_reversecCs�dd�td�D�}|dd�}|dd�}dd�}dd�}|jt|�dd	�|jt|�d
�|�||�|jdd�dd	�|�||�dS)
NcSrnrorAr>rrrr@�rpzETestDecorateSortUndecorate.test_reverse_stability.<locals>.<listcomp>rqcSs"|d|d}}||k||kSrjr�r;rMZx0Zy0rrrrc�rdzATestDecorateSortUndecorate.test_reverse_stability.<locals>.my_cmpcSs"|d|d}}||k||kSrjrr�rrr�my_cmp_reversed�rdzJTestDecorateSortUndecorate.test_reverse_stability.<locals>.my_cmp_reversedT)rrHrcSrrrjrr:rrrr4rtzCTestDecorateSortUndecorate.test_reverse_stability.<locals>.<lambda>)rDr
rru)rrgZcopy1Zcopy2rcr�rrr�test_reverse_stability�sz1TestDecorateSortUndecorate.test_reverse_stabilityN)r)r*r+rirmrvrzrr�r�r�r�rrrrr`�s
r`c	Cs�t�d�t�|�|dd�}dd�|D�}dd�|D�}|||fD]$}t|�}dd�tdd�|D��D�}t||�D]
\}}|�||�q<q#dS)NrcS�g|]}|f�qSrr�r?r;rrrr@rWz:check_against_PyObject_RichCompareBool.<locals>.<listcomp>cS�g|]}|ff�qSrrr�rrrr@r7cSsg|]}|d�qS)rr)r?rMrrrr@r7cSsg|]}d|f�qS)rrr�rrrr@r7)r ZseedrI�sorted�zipZassertIs)	rrTZL_1ZL_2ZL_3Z	optimizedZ	reference�opt�refrrr�&check_against_PyObject_RichCompareBools

��r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�TestOptimizedComparescCs�ddgddgddgg}|D]!}|�t|j�|�tdd�|D�j�|�tdd�|D�j�q
dd	gd
d	gd	dgd	d
gg}|D]}t||�q?dS)Nr�foog)r�cSr�rrr�rrrr@*rWzBTestOptimizedCompares.test_safe_object_compare.<locals>.<listcomp>cSr�rrr�rrrr@+r7rg�������?�)rJrkr
r�)rZheterogeneous_listsrTZfloat_int_listsrrr�test_safe_object_compare$s ���z.TestOptimizedCompares.test_safe_object_comparecs�G��fdd�dt��Gdd�dt��Gdd�dt����fdd�td	�D�}|d
�|�t��|��Wd�n1s?wY��fdd�td	�D�}|d
�|�t��dd�|D���Wd�n1smwYGd
d�d�}|�|�g}|�t|j�|�tdd�|D�j�ttd��dgdd�td�D�dgdd�td�D�dd�td�D�g}|D]}t||�q�dS)NcseZdZ��fdd�ZdS)zITestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyComparatorcs��_t�||�Sr)�	__class__r6r&r"��
WackyList2�elemrrr&:szPTestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyComparator.__lt__NrUrr�rr�WackyComparator9sr�c@seZdZdS)zDTestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyList1N)r)r*r+rrrr�
WackyList1>sr�c@r)zDTestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyList2cSr8r)rYr"rrrr&Br=zKTestOptimizedCompares.test_unsafe_object_compare.<locals>.WackyList2.__lt__NrUrrrrr�ArOr�c�g|]
}��|�|g��qSrrr>�r�r�rrr@ErBzDTestOptimizedCompares.test_unsafe_object_compare.<locals>.<listcomp>rr�cr�rrr>r�rrr@JrBcSr�rrr�rrrr@MrWc@r)zMTestOptimizedCompares.test_unsafe_object_compare.<locals>.PointlessComparatorcSstSr)�NotImplementedr"rrrr&Rr=zTTestOptimizedCompares.test_unsafe_object_compare.<locals>.PointlessComparator.__lt__NrUrrrr�PointlessComparatorQrOr�cSr�rrr�rrrr@VrWrr�cS�g|]}t|��qSr�rfr�rrrr@[r7u￿cSr�r)�bytesr�rrrr@\r7cSsg|]
}tdd��|��qS)cSs||kSrrr]rrrr4]rtzMTestOptimizedCompares.test_unsafe_object_compare.<locals>.<listcomp>.<lambda>rr�rrrr@]rB)r6rGrDrJrYr
rkr�)rrTr�Zlistsr)r�r�r�r�r�test_unsafe_object_compare4s2
����z0TestOptimizedCompares.test_unsafe_object_comparecC�t|dd�td�D��dS)NcSr�rr�r�rrrr@b��zCTestOptimizedCompares.test_unsafe_latin_compare.<locals>.<listcomp>r�r�rDr'rrr�test_unsafe_latin_comparea�
�z/TestOptimizedCompares.test_unsafe_latin_comparecCr�)NcSsg|]}|�qSrrr�rrrr@fs�zBTestOptimizedCompares.test_unsafe_long_compare.<locals>.<listcomp>rr�r'rrr�test_unsafe_long_compareer�z.TestOptimizedCompares.test_unsafe_long_comparecCr�)NcSr�r��floatr�rrrr@jr�zCTestOptimizedCompares.test_unsafe_float_compare.<locals>.<listcomp>rr�r'rrr�test_unsafe_float_compareir�z/TestOptimizedCompares.test_unsafe_float_comparecCs0t|td�gd�t|dd�td�D��dS)N�nanrcSsg|]}td��qS)r�r�)r?�_rrrr@vr�zCTestOptimizedCompares.test_unsafe_tuple_compare.<locals>.<listcomp>)r�r�rDr'rrr�test_unsafe_tuple_comparems
�z/TestOptimizedCompares.test_unsafe_tuple_comparecCs:|�tgd�j�|�tddgj�|�tddgj�dS)N))��?r�)F�A�)r2r)rr2)rJrkr
r'rrr�test_not_all_tuplesysz)TestOptimizedCompares.test_not_all_tuplesN)
r)r*r+r�r�r�r�r�r�r�rrrrr�#s-r��__main__r)�testrr Zunittest�	functoolsrrrrZTestCaserrPr`r�r�r)�mainrrrr�<module>s
 [%]\�