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

o

0�i�A�@s�dZddlZddlZddlZddlmZddlmZddlmZm	Z	ddl
mZejddgd	�Z
ejddgd
�Zgd�ZGdd
�d
e�Zdd�ZGdd�d�ZGdd�dee�Ze	ed�Gdd�dee��ZGdd�d�ZGdd�d�Zdd�ZGdd�d�ZGdd �d �ZGd!d"�d"�ZGd#d$�d$�ZGd%d&�d&�ZGd'd(�d(�ZGd)d*�d*�Zdd+lm Z d,d-�Z!Gd.d/�d/�Z"Gd0d1�d1�Z#Gd2d3�d3e#e�Z$e	ed�Gd4d5�d5e#e��Z%e&d6kr�e�'�dSdS)7zUnittests for heapq.�N)�support)�
import_helper)�TestCase�
skipUnless)�
itemgetter�heapq�_heapq)Zblocked)Zfresh)�heapify�heappop�heappush�heappushpop�heapreplace�_heappop_maxZ_heapreplace_maxZ_heapify_maxc@s&eZdZdd�Zeed�dd��ZdS)�TestModulescC�"tD]}|�tt|�jd�qdS)Nr)�
func_names�assertEqual�getattr�py_heapq�
__module__��selfZfname�r�6/opt/alt/python310/lib64/python3.10/test/test_heapq.py�test_py_functionss�zTestModules.test_py_functions�requires _heapqcCr)Nr)rrr�c_heapqrrrrr�test_c_functionss�zTestModules.test_c_functionsN)�__name__r�__qualname__rrrrrrrrrsrcCs(Gdd�d�}|�tjt|�d��|S)Nc@seZdZdd�ZdS)z+load_tests.<locals>.HeapqMergeDocTestFinderc_st��}|�tj�S�N)�doctestZ
DocTestFinder�findr�merge)r�args�kwargsZdtfrrrr"(sz0load_tests.<locals>.HeapqMergeDocTestFinder.findN)rrrr"rrrr�HeapqMergeDocTestFinder'sr&)Ztest_finder)ZaddTestsr!ZDocTestSuiter)�loaderZtests�ignorer&rrr�
load_testss

�r)c@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)$�TestHeapcCs�g}g}|�|�td�D]}t��}|�|�|j�||�|�|�q
g}|r;|j�|�}|�|�|�|�|s)|dd�}|��|�||�|�|�|�	t
|jjg�z|�	t
|jjdd�|�	t
|jjd�WdStyyYdSw)N�)�check_invariant�range�random�append�modulerr
�sortr�assertRaises�	TypeError�AttributeError)r�heap�data�i�itemZresultsZdata_sortedrrr�
test_push_pop2s2



�
�zTestHeap.test_push_popcCs8t|�D]\}}|r|dd?}|�|||k�qdS�N�)�	enumerateZ
assertTrue)rr5�posr8Z	parentposrrrr,Ns��zTestHeap.check_invariantcCsVttd��dgD]}dd�t|�D�}|j�|�|�|�q	|�t|jjd�dS)N�� NcS�g|]}t���qSr�r.)�.0Zdummyrrr�
<listcomp>W�z)TestHeap.test_heapify.<locals>.<listcomp>)�listr-r0r	r,r2r3)r�sizer5rrr�test_heapifyUs
zTestHeap.test_heapifycCsjdd�td�D�}g}|D]}|j�||�t|�dkr"|j�|�q
|��|�|t|�dd��dS)NcS�g|]}t�d��qS����r.�	randrange�rBr7rrrrC^�z-TestHeap.test_naive_nbest.<locals>.<listcomp>���
���)r-r0r�lenr
r1r�sorted�rr6r5r8rrr�test_naive_nbest]s�zTestHeap.test_naive_nbestccs*�z		|j�|�VqtyYdSwr )r0r
�
IndexError)rr5rrr�heapitergs���zTestHeap.heapitercCs�dd�td�D�}|dd�}|j�|�|dd�D]}||dkr*|j�||�q|�t|�|��t|�dd��|�t	|jjd�|�t	|jjdd�|�t
|jjgd�dS)NcSrHrIrKrMrrrrCurNz'TestHeap.test_nbest.<locals>.<listcomp>rOrPrrQ)r-r0r	r
rrErWrSr2r3rVrTrrr�
test_nbestos�"zTestHeap.test_nbestcCs�dd�td�D�}|dd�}|j�|�|dd�D]	}|j�||�q|�t|�|��t|�dd��|�|j�gd�d�dS)NcSrHrIrKrMrrrrC�rNz4TestHeap.test_nbest_with_pushpop.<locals>.<listcomp>rOrPrQ�x)r-r0r	rrrErWrSrTrrr�test_nbest_with_pushpop�s"z TestHeap.test_nbest_with_pushpopcCs�g}|j�|d�}|�||fgdf�dg}|j�|d�}|�||fdgdf�|�t|d�t�|�t|�t�dg}|j�|d�}|�||fdgdf�dg}|j�|d�}|�||fdgdf�dS)NrPg$@r�	�)r0rr�type�int�float)r�hrYrrr�test_heappushpop�szTestHeap.test_heappushpopcCs4ddg}|�|j�|�d�|�|j�|�d�dS)N��)rr0r)rr`rrr�test_heappop_max�szTestHeap.test_heappop_maxcs�td�D]C}t�d�}dd�t|�D�}|d@r%|dd���j���ng�|D]	}�j��|�q)��fdd�t|�D�}��|t|��qdS)N�d�2cSrH)�rKrMrrrrC�rNz*TestHeap.test_heapsort.<locals>.<listcomp>r;csg|]}�j����qSr)r0r
rM�r5rrrrC�s)r-r.rLr0r	rrrS)rZtrialrFr6r8Zheap_sortedrrhr�
test_heapsort�s
�zTestHeap.test_heapsortc
Cs�g}tt�d��D]#}g}tt�d��D]}t�d�t�dd�f}|�|�q|�|�q	dtd�td�tdd�fD]:}dD]5}g}|D]}	|�t|	||d	��qD|�tt|�||d	�t	|j
j|||d	����|�t	|j
���g�q>q:dS)
Nrgre�ABCi�����rr;)FT��key�reverse)r-r.rLZchoicer/rrSr�chainrEr0r#)
r�inputsr7�row�j�tuprmrnZseqs�seqrrr�
test_merge�s$���zTestHeap.test_mergecCs@|�t|j�gg��g�|�t|jjggdd�d��g�dS)NcS�dS)N�rrrrr�<lambda>��z,TestHeap.test_empty_merges.<locals>.<lambda>�rm)rrEr0r#�rrrr�test_empty_merges�s&zTestHeap.test_empty_mergescCsNdd�}|�t��t|j�|�|���Wd�dS1s wYdS)Ncss*�ttd��}td�D]}||VqdS)NrP�)rEr-)�sr7rrr�iterable�s
��zCTestHeap.test_merge_does_not_suppress_index_error.<locals>.iterable)r2rVrEr0r#)rrrrr�(test_merge_does_not_suppress_index_error�s"�z1TestHeap.test_merge_does_not_suppress_index_errorcCs�Gdd�dt�}ggggg}td�D]}t�d�}t�d�}||�}||f|_||�|�q|D]}|��q1dd�|jj|�D�}|�	|t
|��dS)Nc@seZdZdS)z*TestHeap.test_merge_stability.<locals>.IntN)rrrrrrr�Int�sr�r?�rkcSsg|]}|j�qSr)�pairrMrrrrC�sz1TestHeap.test_merge_stability.<locals>.<listcomp>)r^r-r.rLr�r/r1r0r#rrS)rr�rpr7�streamrY�obj�resultrrr�test_merge_stability�s



zTestHeap.test_merge_stabilityc
Cs�dd�td�D�}ddd�fD]1}dD],}|�t|j�||��t|�d|��|�t|jj|||d��t||d�d|��qqdS)NcS�g|]	}t�d�|f�qSrIrKrMrrrrC��z+TestHeap.test_nsmallest.<locals>.<listcomp>rOcS�|dddS�Nri#rJr�rYrrrrx��z)TestHeap.test_nsmallest.<locals>.<lambda>�	rr;rcrPrei�i�rOiLrz)r-rrEr0�	nsmallestrS�rr6�f�nrrr�test_nsmallest�s����zTestHeap.test_nsmallestc
Cs�dd�td�D�}ddd�fD]4}dD]/}|�t|j�||��t|dd�d|��|�t|jj|||d	��t||dd
�d|��qqdS)NcSr�rIrKrMrrrrC�r�z*TestHeap.test_nlargest.<locals>.<listcomp>rOcSr�r�rr�rrrrx�r�z(TestHeap.test_nlargest.<locals>.<lambda>r�T�rnrzrl)r-rrEr0�nlargestrSr�rrr�
test_nlargest�s����zTestHeap.test_nlargestcsj�fdd�}Gdd�d�}Gdd�d�}dd�td	�D�}t|d
d�}��|||�|���t||�dS)Ncs:�fdd��D���j�����fdd�tt���D�S)Ncsg|]}�|��qSrr)rBrY)�comprrrC�rDzDTestHeap.test_comparison_operator.<locals>.hsort.<locals>.<listcomp>csg|]	}�j���j�qSr)r0r
rYrM)r6rrrrC�r�)r0r	r-rR)r6r�r{)r�r6r�hsort�sz0TestHeap.test_comparison_operator.<locals>.hsortc@�eZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LTcS�
||_dSr r��rrYrrr�__init__��
z6TestHeap.test_comparison_operator.<locals>.LT.__init__cSs|j|jkSr r��r�otherrrr�__lt__��z4TestHeap.test_comparison_operator.<locals>.LT.__lt__N�rrrr�r�rrrr�LT��r�c@r�)z-TestHeap.test_comparison_operator.<locals>.LEcSr�r r�r�rrrr�r�z6TestHeap.test_comparison_operator.<locals>.LE.__init__cSs|j|jkSr r�r�rrr�__le__r�z4TestHeap.test_comparison_operator.<locals>.LE.__le__N)rrrr�r�rrrr�LEr�r�cSr@rrArMrrrrCrDz5TestHeap.test_comparison_operator.<locals>.<listcomp>reTr�)r-rSrr2r3)rr�r�r�r6�targetrr{r�test_comparison_operator�sz!TestHeap.test_comparison_operatorN)rrrr9r,rGrUrWrXrZrardrirur|r�r�r�r�r�rrrrr*0s$
				r*c@�eZdZeZdS)�TestHeapPythonN�rrrrr0rrrrr��r�rc@r�)�	TestHeapCN�rrrrr0rrrrr��r�c@seZdZdZdd�ZdS)�LenOnlyz:Dummy sequence class defining __len__ but not __getitem__.cCrv�NrPrr{rrr�__len__�zLenOnly.__len__N)rrr�__doc__r�rrrrr�sr�c@s,eZdZdZdd�ZeZZZZZ	dS)�CmpErrz;Dummy element that always raises an error during comparisoncC�t�r )�ZeroDivisionErrorr�rrr�__eq__r�z
CmpErr.__eq__N)
rrrr�r��__ne__r�r��__gt__�__ge__rrrrr�sr�ccs�|D]}|VqdS)zRegular generatorNr��seqnr7rrr�R"s��r�c@� eZdZdZdd�Zdd�ZdS)�GzSequence using __getitem__cCr�r �r��rr�rrrr�)r�z
G.__init__cCs
|j|Sr r�)rr7rrr�__getitem__+r�z
G.__getitem__N)rrrr�r�r�rrrrr�'sr�c@�(eZdZdZdd�Zdd�Zdd�ZdS)	�Iz Sequence using iterator protocolcC�||_d|_dS�Nrr�r�rrrr�0�
z
I.__init__cC�|Sr rr{rrr�__iter__3r�z
I.__iter__cC�2|jt|j�kr
t�|j|j}|jd7_|Sr:�r7rRr��
StopIteration�r�vrrr�__next__5�z
I.__next__N�rrrr�r�r�r�rrrrr�.�
r�c@r�)�Igz9Sequence using iterator protocol defined with a generatorcCr�r�r�r�rrrr�=r�zIg.__init__ccs�|jD]}|VqdSr r�)r�valrrrr�@s�
�zIg.__iter__N�rrrr�r�r�rrrrr�;�r�c@r�)�Xz Missing __getitem__ and __iter__cCr�r�r�r�rrrr�Fr�z
X.__init__cCr�r:r�r�rrrr�Ir�z
X.__next__N)rrrr�r�r�rrrrr�Dr�r�c@r�)�NzIterator missing __next__()cCr�r�r�r�rrrr�Qr�z
N.__init__cCr�r rr{rrrr�Tr�z
N.__iter__Nr�rrrrr�Or�r�c@r�)	�EzTest propagation of exceptionscCr�r�r�r�rrrr�Yr�z
E.__init__cCr�r rr{rrrr�\r�z
E.__iter__cCsdddS)Nrbrrr{rrrr�^r�z
E.__next__Nr�rrrrr�Wr�r�c@r�)	�SzTest immediate stopcCsdSr rr�rrrr�cr�z
S.__init__cCr�r rr{rrrr�er�z
S.__iter__cCr�r )r�r{rrrr�gr�z
S.__next__Nr�rrrrr�as
r�)rocCsttdd�ttt|�����S)z Test multiple tiers of iteratorscSr�r rr�rrrrxmryzL.<locals>.<lambda>)ro�mapr�r�r�r�rrr�Lksr�c@r�)�SideEffectLTcCs||_||_dSr )�valuer5)rr�r5rrrr�qr�zSideEffectLT.__init__cCsg|jdd�<|j|jkSr )r5r�r�rrrr�uszSideEffectLT.__lt__Nr�rrrrr�psr�c@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�TestErrorHandlingcCsb|jj|jjfD]}|�ttf|d�q|jj|jj|jj|jj	fD]}|�ttf|dd�q"dSr�)
r0r	r
r2r3r4rr
r�r��rr�rrr�test_non_sequence|s��z#TestErrorHandling.test_non_sequencecCs�|jj|jjfD]}|�ttf|t��q|jj|jjfD]
}|�ttf|t�d�q|jj	|jj
fD]}|�t|dt��q3dS�NrPrc)r0r	r
r2r3r4r�rr
r�r�r�rrr�
test_len_only�s�zTestErrorHandling.test_len_onlycCs�t�t�t�g}|jj|jjfD]	}|�t||�q|jj|jjfD]
}|�t||d�q"|jj|jj	fD]
}|�t|d|�q5dSr�)
r�r0r	r
r2r�rr
r�r�)rrtr�rrr�test_cmp_err�s�zTestErrorHandling.test_cmp_errcCsD|jj|jj|jj|jj|jj|jjfD]}|�tt	f|d�qdSr�)
r0r	r
rr
r�r�r2r3r4r�rrr�test_arg_parsing�s��z"TestErrorHandling.test_arg_parsingc
Cs�|jj|jjfD]Y}ddtd�dtddd�fD]I}tttttfD]}|�	t
|d||���t
|d|���q |�	t
|dt|���g�|�t
|dt|��|�t
|dt|��|�t|dt|��qqdS)	NZ123�rO)r;g333333�?rJi��rc)r0r�r�r-r�r�r�r�r�rrEr�r2r3r�r�r�r�)rr�r~�grrr�test_iterable_args�s&��z$TestErrorHandling.test_iterable_argscshg����fdd�td�D��|�ttf��|j��td���Wd�dS1s-wYdS)Nc3��|]}t|��VqdSr �r�rM�r5rr�	<genexpr>���z@TestErrorHandling.test_heappush_mutating_heap.<locals>.<genexpr>��r�)�extendr-r2rV�RuntimeErrorr0rr�r{rr�r�test_heappush_mutating_heap�s
"�z-TestErrorHandling.test_heappush_mutating_heapcs`g����fdd�td�D��|�ttf��|j���Wd�dS1s)wYdS)Nc3r�r r�rMr�rrr��r�z?TestErrorHandling.test_heappop_mutating_heap.<locals>.<genexpr>r�)r�r-r2rVr�r0r
r{rr�r�test_heappop_mutating_heap�s
"�z,TestErrorHandling.test_heappop_mutating_heapcsBG�fdd�dt�}g�|j��|d��|�t|jj�d�dS)Nc�eZdZ�fdd�ZdS)zMTestErrorHandling.test_comparison_operator_modifiying_heap.<locals>.EvilClassc����tSr ��clear�NotImplemented�r�or�rrr���zTTestErrorHandling.test_comparison_operator_modifiying_heap.<locals>.EvilClass.__lt__N�rrrr�rr�rr�	EvilClass��r�rr;)r^r0rr2rVr)rr�rr�r�(test_comparison_operator_modifiying_heap�sz:TestErrorHandling.test_comparison_operator_modifiying_heapcs�G�fdd�dt�}G�fdd�dt�}gg��|j��|d��|j��|d��|�ttf|jj�|d��|�ttf|jj�|d��dS)Ncr�)zOTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.hcr�r r�r���list2rrr��r�zVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.h.__lt__Nr�rrrrr`�r�r`cr�)zOTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.gcr�r r�r���list1rrr��r�zVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.g.__lt__Nr�rrrrr��r�r�rr;)r^r0rr2rVr�)rr`r�r)rrr�2test_comparison_operator_modifiying_heap_two_heaps�s
 zDTestErrorHandling.test_comparison_operator_modifiying_heap_two_heapsN)rrrr�r�r�r�r�r�r�rrrrrrr�zs	r�c@r�)�TestErrorHandlingPythonNr�rrrrr�r�rc@r�)�TestErrorHandlingCNr�rrrrr�r�r�__main__)(r�r.Zunittestr!�testrZtest.supportrrr�operatorrZimport_fresh_modulerrrrr)r*r�r�r�r�r�r�r�r�r�r�r�r��	itertoolsror�r�r�rrr�mainrrrr�<module>sL]
	
	
Z�