Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_heapq.cpython-38.opt-1.pyc
U

>��g�A�@s�dZddlZddlZddlZddlmZddlmZmZddlm	Z	ej
ddgd�Zej
ddgd	�Zd
ddd
ddddgZ
Gdd�de�Zdd�ZGdd�d�ZGdd�dee�Zeed�Gdd�dee��ZGdd�d�ZGdd �d �Zd!d"�ZGd#d$�d$�ZGd%d&�d&�ZGd'd(�d(�ZGd)d*�d*�ZGd+d,�d,�ZGd-d.�d.�ZGd/d0�d0�Zdd1lmZd2d3�ZGd4d5�d5�Z Gd6d7�d7�Z!Gd8d9�d9e!e�Z"eed�Gd:d;�d;e!e��Z#e$d<k�r�e�%�dS)=zUnittests for heapq.�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�./opt/cppython/lib/python3.8/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�Wntk
r�YnXdS)N�)�check_invariant�range�random�append�moduler
r	�sortr�assertRaises�	TypeError�AttributeError)r�heap�data�i�item�resultsZdata_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.)�.0�dummyrrr�
<listcomp>Vsz)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�rCr7rrrrE]sz-TestHeap.test_naive_nbest.<locals>.<listcomp>���
���)r-r0r
�lenr	r1r�sorted�rr6r5r8rrr�test_naive_nbest\szTestHeap.test_naive_nbestccs.z|j�|�VqWntk
r(YnXdSr )r0r	�
IndexError)rr5rrr�heapiterfszTestHeap.heapitercCs�dd�td�D�}|dd�}|j�|�|dd�D]}||dkr6|j�||�q6|�t|�|��t|�dd��|�t	|jjd�|�t	|jjdd�|�t
|jjgd�dS)NcSsg|]}t�d��qSrIrKrMrrrrEtsz'TestHeap.test_nbest.<locals>.<listcomp>rNrOrrP)r-r0rrrrFrVrRr2r3rUrSrrr�
test_nbestns"zTestHeap.test_nbestcCs�dd�td�D�}|dd�}|j�|�|dd�D]}|j�||�q6|�t|�|��t|�dd��|�|j�gd�d�dS)NcSsg|]}t�d��qSrIrKrMrrrrE�sz4TestHeap.test_nbest_with_pushpop.<locals>.<listcomp>rNrOrP�x)r-r0rrrrFrVrRrSrrr�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)NrOg$@r�	�)r0rr�type�int�float)r�hrXrrr�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)�rKrMrrrrE�sz*TestHeap.test_heapsort.<locals>.<listcomp>r<csg|]}�j����qSr)r0r	rM�r5rrrrE�s)r-r.rLr0rr
rrR)rZtrialrGr6r8Zheap_sortedrrgr�
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)
Nrfrd�ABCi�����rr<)FT��key�reverse)r-r.rL�choicer/rrRr�chainrFr0r#)
r�inputsr7�row�j�tuprlrmZseqs�seqrrr�
test_merge�s �zTestHeap.test_mergecCs@|�t|j�gg��g�|�t|jjggdd�d��g�dS)NcSsdS)N�rrrrr�<lambda>��z,TestHeap.test_empty_merges.<locals>.<lambda>�rl)rrFr0r#�rrrr�test_empty_merges�szTestHeap.test_empty_mergesc	Cs8dd�}|�t��t|j�|�|���W5QRXdS)Ncss(ttd��}td�D]}||VqdS)NrO�)rFr-)�sr7rrr�iterable�szCTestHeap.test_merge_does_not_suppress_index_error.<locals>.iterable)r2rUrFr0r#)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�rA�rjcSsg|]
}|j�qSr)�pairrMrrrrE�sz1TestHeap.test_merge_stability.<locals>.<listcomp>)r]r-r.rLr�r/r1r0r#rrR)rr�rpr7�streamrX�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�qSrIrKrMrrrrE�sz+TestHeap.test_nsmallest.<locals>.<listcomp>rNcSs|dddS�Nri#rJr�rXrrrrw�rxz)TestHeap.test_nsmallest.<locals>.<lambda>�	rr<rbrOrdi�i�rNiLry)r-rrFr0�	nsmallestrR�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�qSrIrKrMrrrrE�sz*TestHeap.test_nlargest.<locals>.<listcomp>rNcSs|dddSr�rr�rrrrw�rxz(TestHeap.test_nlargest.<locals>.<lambda>r�T�rmryrk)r-rrFr0�nlargestrRr�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)rCrX)�comprrrE�szDTestHeap.test_comparison_operator.<locals>.hsort.<locals>.<listcomp>csg|]}�j���j�qSr)r0r	rXrM)r6rrrrE�s)r0rr-rQ)r6r�rz)r�r6r�hsort�sz0TestHeap.test_comparison_operator.<locals>.hsortc@seZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LTcSs
||_dSr r��rrXrrr�__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���qSrrBrMrrrrEsz5TestHeap.test_comparison_operator.<locals>.<listcomp>rdTr�)r-rRrr2r3)rr�r�r�r6�targetrrzr�test_comparison_operator�sz!TestHeap.test_comparison_operatorN)rrrr:r,rHrTrVrWrYr`rcrhrur{rr�r�r�r�rrrrr*/s"
				r*c@seZdZeZdS)�TestHeapPythonN�rrrrr0rrrrr�sr�rc@seZdZeZdS)�	TestHeapCN�rrrrr0rrrrr�sr�c@seZdZdZdd�ZdS)�LenOnlyz:Dummy sequence class defining __len__ but not __getitem__.cCsdS�NrOrrzrrr�__len__szLenOnly.__len__N)rrr�__doc__r�rrrrr�sr�c@s,eZdZdZdd�ZeZZZZZ	dS)�CmpErrz;Dummy element that always raises an error during comparisoncCst�dSr )�ZeroDivisionErrorr�rrr�__eq__sz
CmpErr.__eq__N)
rrrr�r��__ne__r�r��__gt__�__ge__rrrrr�sr�ccs|D]
}|VqdS)zRegular generatorNr��seqnr7rrr�R!sr�c@s eZdZdZdd�Zdd�ZdS)�GzSequence using __getitem__cCs
||_dSr �r��rr�rrrr�(sz
G.__init__cCs
|j|Sr r�)rr7rrr�__getitem__*sz
G.__getitem__N)rrrr�r�r�rrrrr�&sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�Iz Sequence using iterator protocolcCs||_d|_dS�Nrr�r�rrrr�/sz
I.__init__cCs|Sr rrzrrr�__iter__2sz
I.__iter__cCs2|jt|j�krt�|j|j}|jd7_|Sr;�r7rQr��
StopIteration�r�vrrr�__next__4s
z
I.__next__N�rrrr�r�r�r�rrrrr�-sr�c@s eZdZdZdd�Zdd�ZdS)�Igz9Sequence using iterator protocol defined with a generatorcCs||_d|_dSr�r�r�rrrr�<szIg.__init__ccs|jD]
}|VqdSr r�)r�valrrrr�?s
zIg.__iter__N�rrrr�r�r�rrrrr�:sr�c@s eZdZdZdd�Zdd�ZdS)�Xz Missing __getitem__ and __iter__cCs||_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�r�rrrrr�Csr�c@s eZdZdZdd�Zdd�ZdS)�NzIterator missing __next__()cCs||_d|_dSr�r�r�rrrr�Psz
N.__init__cCs|Sr rrzrrrr�Ssz
N.__iter__Nr�rrrrr�Nsr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�EzTest propagation of exceptionscCs||_d|_dSr�r�r�rrrr�Xsz
E.__init__cCs|Sr rrzrrrr�[sz
E.__iter__cCsdddS)Nrarrrzrrrr�]sz
E.__next__Nr�rrrrr�Vsr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�SzTest immediate stopcCsdSr rr�rrrr�bsz
S.__init__cCs|Sr rrzrrrr�dsz
S.__iter__cCst�dSr )r�rzrrrr�fsz
S.__next__Nr�rrrrr�`sr�)rocCsttdd�ttt|�����S)z Test multiple tiers of iteratorscSs|Sr rr�rrrrwlrxzL.<locals>.<lambda>)ro�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�NrOrb)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�)rrtr�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�rN)r<g333333�?rJi��rb)r0r�r�r-r�r�r�r�r�rrFr�r2r3r�r�r�r�)rr�r}�grrr�test_iterable_args�s&z$TestErrorHandling.test_iterable_argsc	sRg����fdd�td�D��|�ttf��|j��td���W5QRXdS)Nc3s|]}t|��VqdSr �r�rM�r5rr�	<genexpr>�sz@TestErrorHandling.test_heappush_mutating_heap.<locals>.<genexpr>��r�)�extendr-r2rU�RuntimeErrorr0r
r�rzrr�r�test_heappush_mutating_heap�sz-TestErrorHandling.test_heappush_mutating_heapc	sJg����fdd�td�D��|�ttf��|j���W5QRXdS)Nc3s|]}t|��VqdSr r�rMr�rrr��sz?TestErrorHandling.test_heappop_mutating_heap.<locals>.<genexpr>r�)r�r-r2rUr�r0r	rzrr�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
r2rUr)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
r2rUr�)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�r.Zunittestr!�testrrr�operatorrZimport_fresh_modulerrrrr)r*r�r�r�r�r�r�r�r�r�r�r�r��	itertoolsror�r�r�r�r�r�mainrrrr�<module>sN
�]
	
	
Z


F1le Man4ger