Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/__pycache__/test_heapq.cpython-39.opt-2.pyc

a

XC?h�A�@s�ddlZddlZddlZddlmZddlmZmZddlmZej	ddgd�Z
ej	ddgd�Zgd	�ZGd
d�de�Z
dd
�ZGdd�d�ZGdd�dee�Zeed�Gdd�dee��ZGdd�d�ZGdd�d�Zdd�ZGdd�d�ZGdd�d�ZGdd �d �ZGd!d"�d"�ZGd#d$�d$�ZGd%d&�d&�ZGd'd(�d(�Zdd)lmZd*d+�ZGd,d-�d-�ZGd.d/�d/�Z Gd0d1�d1e e�Z!eed�Gd2d3�d3e e��Z"e#d4k�r�e�$�dS)5�N)�support)�TestCase�
skipUnless)�
itemgetter�heapq�_heapq)Zblocked)Zfresh)�heapify�heappop�heappush�heappushpop�heapreplace�_heappop_max�_heapreplace_max�_heapify_maxc@s&eZdZdd�Zeed�dd��ZdS)�TestModulescCs"tD]}|�tt|�jd�qdS)Nr)�
func_names�assertEqual�getattr�py_heapq�
__module__��selfZfname�r�4/opt/alt/python39/lib64/python3.9/test/test_heapq.py�test_py_functionsszTestModules.test_py_functions�requires _heapqcCs"tD]}|�tt|�jd�qdS)Nr)rrr�c_heapqrrrrr�test_c_functionsszTestModules.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"'sz0load_tests.<locals>.HeapqMergeDocTestFinder.findN)rrrr"rrrr�HeapqMergeDocTestFinder&sr&)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�||�|�|�qg}|rt|j�|�}|�|�|�|�qN|dd�}|��|�||�|�|�|�	t
|jjg�z*|�	t
|jjdd�|�	t
|jjd�Wnty�Yn0dS)N�)�check_invariant�range�random�append�moduler
r	�sortr�assertRaises�	TypeError�AttributeError)r�heap�data�i�itemZresultsZdata_sortedrrr�
test_push_pop1s.



zTestHeap.test_push_popcCs8t|�D]*\}}|r|dd?}|�|||k�qdS�N�)�	enumerateZ
assertTrue)rr5�posr8�	parentposrrrr,MszTestHeap.check_invariantcCsVttd��dgD],}dd�t|�D�}|j�|�|�|�q|�t|jjd�dS)N�� NcSsg|]}t���qSr�r.)�.0Zdummyrrr�
<listcomp>V�z)TestHeap.test_heapify.<locals>.<listcomp>)�listr-r0rr,r2r3)r�sizer5rrr�test_heapifyTs
zTestHeap.test_heapifycCsjdd�td�D�}g}|D]*}|j�||�t|�dkr|j�|�q|��|�|t|�dd��dS)NcSsg|]}t�d��qS����r.�	randrange�rBr7rrrrC]rDz-TestHeap.test_naive_nbest.<locals>.<listcomp>���
���)r-r0r
�lenr	r1r�sorted�rr6r5r8rrr�test_naive_nbest\szTestHeap.test_naive_nbestccs,z|j�|�VqWnty&Yn0dSr )r0r	�
IndexError)rr5rrr�heapiterfszTestHeap.heapitercCs�dd�td�D�}|dd�}|j�|�|dd�D]}||dkr6|j�||�q6|�t|�|��t|�dd��|�t	|jjd�|�t	|jjdd�|�t
|jjgd�dS)NcSsg|]}t�d��qSrHrJrLrrrrCtrDz'TestHeap.test_nbest.<locals>.<listcomp>rMrNrrO)r-r0rrrrErUrQr2r3rTrRrrr�
test_nbestns"zTestHeap.test_nbestcCs�dd�td�D�}|dd�}|j�|�|dd�D]}|j�||�q6|�t|�|��t|�dd��|�|j�gd�d�dS)NcSsg|]}t�d��qSrHrJrLrrrrC�rDz4TestHeap.test_nbest_with_pushpop.<locals>.<listcomp>rMrNrO�x)r-r0rrrrErUrQrRrrr�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)NrNg$@r�	�)r0rr�type�int�float)r�hrWrrr�test_heappushpop�szTestHeap.test_heappushpopcCs4ddg}|�|j�|�d�|�|j�|�d�dS)N��)rr0r
)rr^rrr�test_heappop_max�szTestHeap.test_heappop_maxcs�td�D]�}t�d�}dd�t|�D�}|d@rJ|dd���j���ng�|D]}�j��|�qR��fdd�t|�D�}��|t|��qdS)N�d�2cSsg|]}t�d��qS)�rJrLrrrrC�rDz*TestHeap.test_heapsort.<locals>.<listcomp>r;csg|]}�j����qSr)r0r	rL�r5rrrrC�rD)r-r.rKr0rr
rrQ)rZtrialrFr6r8Zheap_sortedrrfr�
test_heapsort�s
zTestHeap.test_heapsortc
Cs�g}tt�d��D]F}g}tt�d��D]$}t�d�t�dd�f}|�|�q(|�|�qdtd�td�tdd�fD]t}dD]j}g}|D]}	|�t|	||d	��q�|�tt|�||d	�t	|j
j|||d	����|�t	|j
���g�q|qtdS)
Nrerc�ABCi�����rr;)FT��key�reverse)r-r.rKZchoicer/rrQr�chainrEr0r#)
r�inputsr7�row�j�tuprkrlZseqs�seqrrr�
test_merge�s �zTestHeap.test_mergecCs@|�t|j�gg��g�|�t|jjggdd�d��g�dS)NcSsdS)N�rrrrr�<lambda>�rDz,TestHeap.test_empty_merges.<locals>.<lambda>�rk)rrEr0r#�rrrr�test_empty_merges�szTestHeap.test_empty_mergescCsLdd�}|�t��&t|j�|�|���Wd�n1s>0YdS)Ncss(ttd��}td�D]}||VqdS)NrN�)rEr-)�sr7rrr�iterable�szCTestHeap.test_merge_does_not_suppress_index_error.<locals>.iterable)r2rTrEr0r#)rr{rrr�(test_merge_does_not_suppress_index_error�sz1TestHeap.test_merge_does_not_suppress_index_errorcCs�Gdd�dt�}ggggg}td�D]8}t�d�}t�d�}||�}||f|_||�|�q$|D]}|��qbdd�|jj|�D�}|�	|t
|��dS)Nc@seZdZdS)z*TestHeap.test_merge_stability.<locals>.IntN)rrrrrrr�Int�sr}r@�ricSsg|]
}|j�qSr)�pairrLrrrrC�rDz1TestHeap.test_merge_stability.<locals>.<listcomp>)r\r-r.rKrr/r1r0r#rrQ)rr}rnr7�streamrW�obj�resultrrr�test_merge_stability�s



zTestHeap.test_merge_stabilityc
Cs�dd�td�D�}ddd�fD]b}dD]X}|�t|j�||��t|�d|��|�t|jj|||d��t||d�d|��q&qdS)NcSsg|]}t�d�|f�qSrHrJrLrrrrC�rDz+TestHeap.test_nsmallest.<locals>.<listcomp>rMcSs|dddS�Nri#rIr�rWrrrru�rDz)TestHeap.test_nsmallest.<locals>.<lambda>�	rr;rarNrci�i�rMiLrv)r-rrEr0�	nsmallestrQ�rr6�f�nrrr�test_nsmallest�s��zTestHeap.test_nsmallestc
Cs�dd�td�D�}ddd�fD]h}dD]^}|�t|j�||��t|dd�d|��|�t|jj|||d	��t||dd
�d|��q&qdS)NcSsg|]}t�d�|f�qSrHrJrLrrrrC�rDz*TestHeap.test_nlargest.<locals>.<listcomp>rMcSs|dddSr�rr�rrrru�rDz(TestHeap.test_nlargest.<locals>.<lambda>r�T�rlrvrj)r-rrEr0�nlargestrQr�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)rBrW)�comprrrC�rDzDTestHeap.test_comparison_operator.<locals>.hsort.<locals>.<listcomp>csg|]}�j���j�qSr)r0r	rWrL)r6rrrrC�rD)r0rr-rP)r6r�rw)r�r6r�hsort�sz0TestHeap.test_comparison_operator.<locals>.hsortc@seZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LTcSs
||_dSr r��rrWrrr�__init__�sz6TestHeap.test_comparison_operator.<locals>.LT.__init__cSs|j|jkSr r��r�otherrrr�__lt__�sz4TestHeap.test_comparison_operator.<locals>.LT.__lt__N�rrrr�r�rrrr�LT�sr�c@seZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LEcSs
||_dSr r�r�rrrr�sz6TestHeap.test_comparison_operator.<locals>.LE.__init__cSs|j|jkSr r�r�rrr�__le__sz4TestHeap.test_comparison_operator.<locals>.LE.__le__N)rrrr�r�rrrr�LEsr�cSsg|]}t���qSrrArLrrrrCrDz5TestHeap.test_comparison_operator.<locals>.<listcomp>rcTr�)r-rQrr2r3)rr�r�r�r6�targetrrwr�test_comparison_operator�sz!TestHeap.test_comparison_operatorN)rrrr9r,rGrSrUrVrXr_rbrgrsrxr|r�r�r�r�rrrrr*/s"
				r*c@seZdZeZdS)�TestHeapPythonN�rrrrr0rrrrr�sr�rc@seZdZeZdS)�	TestHeapCN�rrrrr0rrrrr�sr�c@seZdZdd�ZdS)�LenOnlycCsdS�NrNrrwrrr�__len__szLenOnly.__len__N)rrrr�rrrrr�sr�c@s(eZdZdd�ZeZZZZZdS)�CmpErrcCst�dSr )�ZeroDivisionErrorr�rrr�__eq__sz
CmpErr.__eq__N)	rrrr��__ne__r�r��__gt__�__ge__rrrrr�sr�ccs|D]
}|VqdSr r��seqnr7rrr�R!sr�c@seZdZdd�Zdd�ZdS)�GcCs
||_dSr �r��rr�rrrr�(sz
G.__init__cCs
|j|Sr r�)rr7rrr�__getitem__*sz
G.__getitem__N)rrrr�r�rrrrr�&sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�IcCs||_d|_dS�Nrr�r�rrrr�/sz
I.__init__cCs|Sr rrwrrr�__iter__2sz
I.__iter__cCs2|jt|j�krt�|j|j}|jd7_|Sr:�r7rPr��
StopIteration�r�vrrr�__next__4sz
I.__next__N�rrrr�r�r�rrrrr�-sr�c@seZdZdd�Zdd�ZdS)�IgcCs||_d|_dSr�r�r�rrrr�<szIg.__init__ccs|jD]
}|VqdSr r�)r�valrrrr�?s
zIg.__iter__N�rrrr�r�rrrrr�:sr�c@seZdZdd�Zdd�ZdS)�XcCs||_d|_dSr�r�r�rrrr�Esz
X.__init__cCs2|jt|j�krt�|j|j}|jd7_|Sr:r�r�rrrr�Hsz
X.__next__N)rrrr�r�rrrrr�Csr�c@seZdZdd�Zdd�ZdS)�NcCs||_d|_dSr�r�r�rrrr�Psz
N.__init__cCs|Sr rrwrrrr�Ssz
N.__iter__Nr�rrrrr�Nsr�c@s$eZdZdd�Zdd�Zdd�ZdS)�EcCs||_d|_dSr�r�r�rrrr�Xsz
E.__init__cCs|Sr rrwrrrr�[sz
E.__iter__cCsdddS)Nr`rrrwrrrr�]sz
E.__next__Nr�rrrrr�Vsr�c@s$eZdZdd�Zdd�Zdd�ZdS)�ScCsdSr rr�rrrr�bsz
S.__init__cCs|Sr rrwrrrr�dsz
S.__iter__cCst�dSr )r�rwrrrr�fsz
S.__next__Nr�rrrrr�`sr�)rmcCsttdd�ttt|�����S)NcSs|Sr rr�rrrrulrDzL.<locals>.<lambda>)rm�mapr�r�r�r�rrr�Ljsr�c@seZdZdd�Zdd�ZdS)�SideEffectLTcCs||_||_dSr )�valuer5)rr�r5rrrr�pszSideEffectLT.__init__cCsg|jdd�<|j|jkSr )r5r�r�rrrr�tszSideEffectLT.__lt__Nr�rrrrr�osr�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�qDdSr�)
r0rr	r2r3r4r
r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��qfdS�NrNra)r0rr	r2r3r4r�r
rr�r�r�rrr�
test_len_only�szTestErrorHandling.test_len_onlycCs�t�t�t�g}|jj|jjfD]}|�t||�q |jj|jjfD]}|�t||d�qD|jj|jj	fD]}|�t|d|�qjdSr�)
r�r0rr	r2r�r
rr�r�)rrrr�rrr�test_cmp_err�szTestErrorHandling.test_cmp_errcCsD|jj|jj|jj|jj|jj|jjfD]}|�tt	f|d�q(dSr�)
r0rr	r
rr�r�r2r3r4r�rrr�test_arg_parsing�s
�z"TestErrorHandling.test_arg_parsingc
Cs�|jj|jjfD]�}ddtd�dtddd�fD]�}tttttfD](}|�	t
|d||���t
|d|���q@|�	t
|dt|���g�|�t
|dt|��|�t
|dt|��|�t|dt|��q.qdS)	NZ123�rM)r;g333333�?rIi��ra)r0r�r�r-r�r�r�r�r�rrEr�r2r3r�r�r�r�)rr�rz�grrr�test_iterable_args�s&z$TestErrorHandling.test_iterable_argscsfg����fdd�td�D��|�ttf��$|j��td���Wd�n1sX0YdS)Nc3s|]}t|��VqdSr �r�rL�r5rr�	<genexpr>�rDz@TestErrorHandling.test_heappush_mutating_heap.<locals>.<genexpr>��r�)�extendr-r2rT�RuntimeErrorr0r
r�rwrr�r�test_heappush_mutating_heap�sz-TestErrorHandling.test_heappush_mutating_heapcs^g����fdd�td�D��|�ttf��|j���Wd�n1sP0YdS)Nc3s|]}t|��VqdSr r�rLr�rrr��rDz?TestErrorHandling.test_heappop_mutating_heap.<locals>.<genexpr>r�)r�r-r2rTr�r0r	rwrr�r�test_heappop_mutating_heap�sz,TestErrorHandling.test_heappop_mutating_heapcsBG�fdd�dt�}g�|j��|d��|�t|jj�d�dS)NcseZdZ�fdd�ZdS)zMTestErrorHandling.test_comparison_operator_modifiying_heap.<locals>.EvilClasscs���tSr ��clear�NotImplemented�r�or�rrr��szTTestErrorHandling.test_comparison_operator_modifiying_heap.<locals>.EvilClass.__lt__N�rrrr�rr�rr�	EvilClass�sr�rr;)r\r0r
r2rTr)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)NcseZdZ�fdd�ZdS)zOTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.hcs���tSr r�r���list2rrr��szVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.h.__lt__Nr�rr�rrr^�sr^cseZdZ�fdd�ZdS)zOTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.gcs���tSr r�r���list1rrr��szVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.g.__lt__Nr�rr�rrr��sr�rr;)r\r0r
r2rTr�)rr^r�r)r�r�r�2test_comparison_operator_modifiying_heap_two_heaps�s
zDTestErrorHandling.test_comparison_operator_modifiying_heap_two_heapsN)rrrr�r�r�r�r�r�r�r�r�rrrrr�ys	r�c@seZdZeZdS)�TestErrorHandlingPythonNr�rrrrr��sr�c@seZdZeZdS)�TestErrorHandlingCNr�rrrrr��sr��__main__)%r.Zunittestr!�testrrr�operatorrZimport_fresh_modulerrrrr)r*r�r�r�r�r�r�r�r�r�r�r�r��	itertoolsrmr�r�r�r�r�r�mainrrrr�<module>sD]
	
	
Z