Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 18.188.209.215
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_heapq.cpython-310.pyc
o

`b�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_max�_heapreplace_max�_heapify_maxc@s&eZdZdd�Zeed�dd��ZdS)�TestModulescC�"tD]}|�tt|�jd�qdS)Nr)�
func_names�assertEqual�getattr�py_heapq�
__module__��selfZfname�r�8/usr/local/python-3.10/lib/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)r rr!r$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�item�resultsZdata_sortedrrr�
test_push_pop2s2



�
�zTestHeap.test_push_popcCs8t|�D]\}}|r|dd?}|�|||k�qdS�N�)�	enumerateZ
assertTrue)rr7�posr:�	parentposrrrr.Ns��zTestHeap.check_invariantcCsVttd��dgD]}dd�t|�D�}|j�|�|�|�q	|�t|jjd�dS)N�� NcS�g|]}t���qSr�r0)�.0Zdummyrrr�
<listcomp>W�z)TestHeap.test_heapify.<locals>.<listcomp>)�listr/r2r	r.r4r5)r�sizer7rrr�test_heapifyUs
zTestHeap.test_heapifycCsjdd�td�D�}g}|D]}|j�||�t|�dkr"|j�|�q
|��|�|t|�dd��dS)NcS�g|]}t�d��qS����r0�	randrange�rFr9rrrrG^�z-TestHeap.test_naive_nbest.<locals>.<listcomp>���
���)r/r2r�lenr
r3r�sorted�rr8r7r:rrr�test_naive_nbest]s�zTestHeap.test_naive_nbestccs*�z		|j�|�VqtyYdSwr")r2r
�
IndexError)rr7rrr�heapitergs���zTestHeap.heapitercCs�dd�td�D�}|dd�}|j�|�|dd�D]}||dkr*|j�||�q|�t|�|��t|�dd��|�t	|jjd�|�t	|jjdd�|�t
|jjgd�dS)NcSrLrMrOrQrrrrGurRz'TestHeap.test_nbest.<locals>.<listcomp>rSrTrrU)r/r2r	r
rrIr[rWr4r5rZrXrrr�
test_nbestos�"zTestHeap.test_nbestcCs�dd�td�D�}|dd�}|j�|�|dd�D]	}|j�||�q|�t|�|��t|�dd��|�|j�gd�d�dS)NcSrLrMrOrQrrrrG�rRz4TestHeap.test_nbest_with_pushpop.<locals>.<listcomp>rSrTrU�x)r/r2r	rrrIr[rWrXrrr�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)NrTg$@r�	�)r2rr�type�int�float)r�hr]rrr�test_heappushpop�szTestHeap.test_heappushpopcCs4ddg}|�|j�|�d�|�|j�|�d�dS)N��)rr2r)rrdrrr�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�2cSrL)�rOrQrrrrG�rRz*TestHeap.test_heapsort.<locals>.<listcomp>r>csg|]}�j����qSr)r2r
rQ�r7rrrrG�s)r/r0rPr2r	rrrW)rZtrialrJr8r:Zheap_sortedrrlr�
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)
Nrkri�ABCi�����rr>)FT��key�reverse)r/r0rP�choicer1rrWr�chainrIr2r%)
r�inputsr9�row�j�tuprqrrZseqs�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>�rq)rrIr2r%�rrrr�test_empty_merges�s&zTestHeap.test_empty_mergescCsNdd�}|�t��t|j�|�|���Wd�dS1s wYdS)Ncss*�ttd��}td�D]}||VqdS)NrT�)rIr/)�sr9rrr�iterable�s
��zCTestHeap.test_merge_does_not_suppress_index_error.<locals>.iterable)r4rZrIr2r%)rr�rrr�(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)r rr!rrrr�Int�sr�rC�rocSsg|]}|j�qSr)�pairrQrrrrG�sz1TestHeap.test_merge_stability.<locals>.<listcomp>)rbr/r0rPr�r1r3r2r%rrW)rr�rur9�streamr]�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�qSrMrOrQrrrrG��z+TestHeap.test_nsmallest.<locals>.<listcomp>rScS�|dddS�Nri#rNr�r]rrrr}��z)TestHeap.test_nsmallest.<locals>.<lambda>�	rr>rgrTrii�i�rSiLr)r/rrIr2�	nsmallestrW�rr8�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�rMrOrQrrrrG�r�z*TestHeap.test_nlargest.<locals>.<listcomp>rScSr�r�rr�rrrr}�r�z(TestHeap.test_nlargest.<locals>.<lambda>r�T�rrrrp)r/rrIr2�nlargestrWr�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)rFr])�comprrrG�rHzDTestHeap.test_comparison_operator.<locals>.hsort.<locals>.<listcomp>csg|]	}�j���j�qSr)r2r
r]rQ)r8rrrrG�r�)r2r	r/rV)r8r�r�)r�r8r�hsort�sz0TestHeap.test_comparison_operator.<locals>.hsortc@�eZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LTcS�
||_dSr"r��rr]rrr�__init__��
z6TestHeap.test_comparison_operator.<locals>.LT.__init__cSs|j|jkSr"r��r�otherrrr�__lt__��z4TestHeap.test_comparison_operator.<locals>.LT.__lt__N�r rr!r�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)r rr!r�r�rrrr�LEr�r�cSrDrrErQrrrrGrHz5TestHeap.test_comparison_operator.<locals>.<listcomp>riTr�)r/rWrr4r5)rr�r�r�r8�targetrr�r�test_comparison_operator�sz!TestHeap.test_comparison_operatorN)r rr!r<r.rKrYr[r\r^rerhrmrzr�r�r�r�r�r�rrrrr,0s$
				r,c@�eZdZeZdS)�TestHeapPythonN�r rr!rr2rrrrr��r�rc@r�)�	TestHeapCN�r rr!rr2rrrrr��r�c@seZdZdZdd�ZdS)�LenOnlyz:Dummy sequence class defining __len__ but not __getitem__.cCr{�NrTrr�rrr�__len__�zLenOnly.__len__N)r rr!�__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)
r rr!r�r��__ne__r�r��__gt__�__ge__rrrrr�sr�ccs�|D]}|VqdS)zRegular generatorNr��seqnr9rrr�R"s��r�c@� eZdZdZdd�Zdd�ZdS)�GzSequence using __getitem__cCr�r"�r��rr�rrrr�)r�z
G.__init__cCs
|j|Sr"r�)rr9rrr�__getitem__+r�z
G.__getitem__N)r rr!r�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=�r9rVr��
StopIteration�r�vrrr�__next__5�z
I.__next__N�r rr!r�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�r rr!r�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)r rr!r�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)Nrfrrr�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�)rtcCsttdd�ttt|�����S)z Test multiple tiers of iteratorscSr�r"rr�rrrr}mr~zL.<locals>.<lambda>)rt�mapr�r�r�r�rrr�Lksr�c@r�)�SideEffectLTcCs||_||_dSr")�valuer7)rr�r7rrrr�qr�zSideEffectLT.__init__cCsg|jdd�<|j|jkSr")r7r�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�)
r2r	r
r4r5r6rr
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�NrTrg)r2r	r
r4r5r6r�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�r2r	r
r4r�rr
r�r�)rryr�rrr�test_cmp_err�s�zTestErrorHandling.test_cmp_errcCsD|jj|jj|jj|jj|jj|jjfD]}|�tt	f|d�qdSr�)
r2r	r
rr
r�r�r4r5r6r�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�rS)r>g333333�?rNi��rg)r2r�r�r/r�r�r�r�r�rrIr�r4r5r�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�rQ�r7rr�	<genexpr>���z@TestErrorHandling.test_heappush_mutating_heap.<locals>.<genexpr>��r�)�extendr/r4rZ�RuntimeErrorr2rr�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�rQr�rrr��r�z?TestErrorHandling.test_heappop_mutating_heap.<locals>.<genexpr>r�)r�r/r4rZr�r2r
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�r rr!r�rr�rr�	EvilClass��rrr>)rbr2rr4rZr)rrrr�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��rzVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.h.__lt__Nrrrrrrd�rrdcr�)zOTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.gcr�r"r�r���list1rrr��rzVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.g.__lt__Nrrrrrr��rr�rr>)rbr2rr4rZr�)rrdr�r)r	rr�2test_comparison_operator_modifiying_heap_two_heaps�s
 zDTestErrorHandling.test_comparison_operator_modifiying_heap_two_heapsN)r rr!r�r�r�r�r�r�r�rr
rrrrr�zs	r�c@r�)�TestErrorHandlingPythonNr�rrrrr�r�rc@r�)�TestErrorHandlingCNr�rrrrr�r�r�__main__)(r�r0Zunittestr#�testrZtest.supportrrr�operatorrZimport_fresh_modulerrrrr+r,r�r�r�r�r�r�r�r�r�r�r�r��	itertoolsrtr�r�r�rrr �mainrrrr�<module>sL]
	
	
Z�
© 2025 GrazzMean