Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_heapq.cpython-39.opt-1.pyc

a

��g�A�@s�dZddlZddlZddlZddlmZddlmZmZddlm	Z	ej
ddgd�Zej
ddgd	�Zgd
�Z
Gdd�de�Zd
d�ZGdd�d�ZGdd�dee�Zeed�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*lmZd+d,�ZGd-d.�d.�Z Gd/d0�d0�Z!Gd1d2�d2e!e�Z"eed�Gd3d4�d4e!e��Z#e$d5k�r�e�%�dS)6zUnittests 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�+/usr/local/lib/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�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>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�rCr7rrrrE]rFz-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��qSrJrLrNrrrrEtrFz'TestHeap.test_nbest.<locals>.<listcomp>rOrPrrQ)r-r0rrrrGrWrSr2r3rVrTrrr�
test_nbestns"zTestHeap.test_nbestcCs�dd�td�D�}|dd�}|j�|�|dd�D]}|j�||�q6|�t|�|��t|�dd��|�|j�gd�d�dS)NcSsg|]}t�d��qSrJrLrNrrrrE�rFz4TestHeap.test_nbest_with_pushpop.<locals>.<listcomp>rOrPrQ�x)r-r0rrrrGrWrSrTrrr�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�	�)r0rr�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]�}t�d�}dd�t|�D�}|d@rJ|dd���j���ng�|D]}�j��|�qR��fdd�t|�D�}��|t|��qdS)N�d�2cSsg|]}t�d��qS)�rLrNrrrrE�rFz*TestHeap.test_heapsort.<locals>.<listcomp>r<csg|]}�j����qSr)r0r	rN�r5rrrrE�rF)r-r.rMr0rr
rrS)rZtrialrHr6r8Zheap_sortedrrhr�
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)
Nrgre�ABCi�����rr<)FT��key�reverse)r-r.rM�choicer/rrSr�chainrGr0r#)
r�inputsr7�row�j�tuprmrnZseqs�seqrrr�
test_merge�s �zTestHeap.test_mergecCs@|�t|j�gg��g�|�t|jjggdd�d��g�dS)NcSsdS)N�rrrrr�<lambda>�rFz,TestHeap.test_empty_merges.<locals>.<lambda>�rm)rrGr0r#�rrrr�test_empty_merges�szTestHeap.test_empty_mergescCsLdd�}|�t��&t|j�|�|���Wd�n1s>0YdS)Ncss(ttd��}td�D]}||VqdS)NrP�)rGr-)�sr7rrr�iterable�szCTestHeap.test_merge_does_not_suppress_index_error.<locals>.iterable)r2rVrGr0r#)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�rkcSsg|]
}|j�qSr)�pairrNrrrrE�rFz1TestHeap.test_merge_stability.<locals>.<listcomp>)r^r-r.rMr�r/r1r0r#rrS)rr�rqr7�streamrY�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�qSrJrLrNrrrrE�rFz+TestHeap.test_nsmallest.<locals>.<listcomp>rOcSs|dddS�Nri#rKr�rYrrrrx�rFz)TestHeap.test_nsmallest.<locals>.<lambda>�	rr<rcrPrei�i�rOiLry)r-rrGr0�	nsmallestrS�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�qSrJrLrNrrrrE�rFz*TestHeap.test_nlargest.<locals>.<listcomp>rOcSs|dddSr�rr�rrrrx�rFz(TestHeap.test_nlargest.<locals>.<lambda>r�T�rnryrl)r-rrGr0�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)rCrY)�comprrrE�rFzDTestHeap.test_comparison_operator.<locals>.hsort.<locals>.<listcomp>csg|]}�j���j�qSr)r0r	rYrN)r6rrrrE�rF)r0rr-rR)r6r�rz)r�r6r�hsort�sz0TestHeap.test_comparison_operator.<locals>.hsortc@seZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LTcSs
||_dSr r��rrYrrr�__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���qSrrBrNrrrrErFz5TestHeap.test_comparison_operator.<locals>.<listcomp>reTr�)r-rSrr2r3)rr�r�r�r6�targetrrzr�test_comparison_operator�sz!TestHeap.test_comparison_operatorN)rrrr:r,rIrUrWrXrZrardrirvr{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�NrPrrzrrr�__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;�r7rRr��
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)Nrbrrrzrrrr�]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�)rpcCsttdd�ttt|�����S)z Test multiple tiers of iteratorscSs|Sr rr�rrrrxlrFzL.<locals>.<lambda>)rp�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�NrPrc)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�)rrur�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�rO)r<g333333�?rKi��rc)r0r�r�r-r�r�r�r�r�rrGr�r2r3r�r�r�r�)rr�r}�grrr�test_iterable_args�s&z$TestErrorHandling.test_iterable_argscsfg����fdd�td�D��|�ttf��$|j��td���Wd�n1sX0YdS)Nc3s|]}t|��VqdSr �r�rN�r5rr�	<genexpr>�rFz@TestErrorHandling.test_heappush_mutating_heap.<locals>.<genexpr>��r�)�extendr-r2rV�RuntimeErrorr0r
r�rzrr�r�test_heappush_mutating_heap�sz-TestErrorHandling.test_heappush_mutating_heapcs^g����fdd�td�D��|�ttf��|j���Wd�n1sP0YdS)Nc3s|]}t|��VqdSr r�rNr�rrr��rFz?TestErrorHandling.test_heappop_mutating_heap.<locals>.<genexpr>r�)r�r-r2rVr�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
r2rVr)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
r2rVr�)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��	itertoolsrpr�r�r�r�r�r�mainrrrr�<module>sF]
	
	
Z


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists