HEX
Server: Apache
System: Linux opal14.opalstack.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User: curbgloabal_opal (1234)
PHP: 8.1.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/test/__pycache__/test_heapq.cpython-36.pyc
3

ai�>�@s�dZddlZddlZddlmZddlmZmZddlmZej	ddgd�Z
ej	ddgd	�Zd
ddd
ddddgZGdd�de�Z
Gdd�d�ZGdd�dee�Zeed�Gdd�dee��ZGdd�d�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�ZGd6d7�d7�Z Gd8d9�d9e e�Z!eed�Gd:d;�d;e e��Z"e#d<k�r�ej$�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&x tD]}|jtt|�jd�qWdS)Nr)�
func_names�assertEqual�getattr�py_heapq�
__module__)�self�fname�r�"/usr/lib64/python3.6/test_heapq.py�test_py_functionss
zTestModules.test_py_functionszrequires _heapqcCs&x tD]}|jtt|�jd�qWdS)Nr)rrr�c_heapqr)rrrrr�test_c_functionss
zTestModules.test_c_functionsN)�__name__r�__qualname__rrrrrrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS) �TestHeapcCs�g}g}|j|�x:td�D].}tj�}|j|�|jj||�|j|�qWg}x(|rz|jj|�}|j|�|j|�qTW|dd�}|j�|j||�|j|�|j	t
|jjg�y*|j	t
|jjdd�|j	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_pops.



zTestHeap.test_push_popcCs<x6t|�D]*\}}|r
|dd?}|j|||k�q
WdS)N�)�	enumerateZ
assertTrue)rr*�posr-�	parentposrrrr!;szTestHeap.check_invariantcCsZxBttd��dgD],}dd�t|�D�}|jj|�|j|�qW|jt|jjd�dS)N�i NcSsg|]}tj��qSr)r#)�.0Zdummyrrr�
<listcomp>Dsz)TestHeap.test_heapify.<locals>.<listcomp>)�listr"r%rr!r'r()r�sizer*rrr�test_heapifyBs
zTestHeap.test_heapifycCsndd�td�D�}g}x2|D]*}|jj||�t|�dkr|jj|�qW|j�|j|t|�dd��dS)NcSsg|]}tjd��qS)i�)r#�	randrange)r5r,rrrr6Ksz-TestHeap.test_naive_nbest.<locals>.<listcomp>i��
i����)r"r%r
�lenr	r&r�sorted)rr+r*r-rrr�test_naive_nbestJs
zTestHeap.test_naive_nbestccs2yx|jj|�VqWWntk
r,YnXdS)N)r%r	�
IndexError)rr*rrr�heapiterTs
zTestHeap.heapitercCs�dd�td�D�}|dd�}|jj|�x.|dd�D]}||dkr8|jj||�q8W|jt|j|��t|�dd��|jt	|jjd�|jt	|jjdd�|jt
|jjgd�dS)NcSsg|]}tjd��qS)i�)r#r:)r5r,rrrr6bsz'TestHeap.test_nbest.<locals>.<listcomp>i�r;ri����)r"r%rrrr7r@r=r'r(r?)rr+r*r-rrr�
test_nbest\s"zTestHeap.test_nbestcCs�dd�td�D�}|dd�}|jj|�x"|dd�D]}|jj||�q8W|jt|j|��t|�dd��|j|jjgd�d�dS)NcSsg|]}tjd��qS)i�)r#r:)r5r,rrrr6osz4TestHeap.test_nbest_with_pushpop.<locals>.<listcomp>i�r;�xi����)r"r%rrrr7r@r=)rr+r*r-rrr�test_nbest_with_pushpopns"z TestHeap.test_nbest_with_pushpopcCs�g}|jj|d�}|j||fgdf�dg}|jj|d�}|j||fdgdf�|jt|d�t�|jt|�t�dg}|jj|d�}|j||fdgdf�dg}|jj|d�}|j||fdgdf�dS)Nr;g$@r�	�)r%rr�type�int�float)r�hrBrrr�test_heappushpopwszTestHeap.test_heappushpopcs�x�td�D]�}tjd�}dd�t|�D�}|d@rL|dd���jj��n g�x|D]}�jj�|�qVW��fdd�t|�D�}�j|t|��q
WdS)N�d�2cSsg|]}tjd��qS)�)r#r:)r5r,rrrr6�sz*TestHeap.test_heapsort.<locals>.<listcomp>r0csg|]}�jj���qSr)r%r	)r5r,)r*rrrr6�s)r"r#r:r%rr
rr=)rZtrialr8r+r-Zheap_sortedr)r*rr�
test_heapsort�s

zTestHeap.test_heapsortc

Csg}x\ttjd��D]J}g}x6ttjd��D]$}tjd�tjd
d�f}|j|�q,W|j|�qWx�dtd�td�tdd�gD]|}xvdD]n}g}x |D]}	|jt|	||d	��q�W|jtt|�||d	�t	|j
j|||d	����|jt	|j
j��g�q�Wq~WdS)NrMrK�ABCi�rr0FT)�key�reversei���)FT)r"r#r:Zchoicer$rr=r�chainr7r%�merge)
r�inputsr,�row�j�tuprPrQZseqs�seqrrr�
test_merge�s 

zTestHeap.test_mergecCs8dd�}|jt��t|jj|�|���WdQRXdS)Ncss,ttd��}xtd�D]}||VqWdS)Nr;�)r7r")�sr,rrr�iterable�szCTestHeap.test_merge_does_not_suppress_index_error.<locals>.iterable)r'r?r7r%rS)rr\rrr�(test_merge_does_not_suppress_index_error�sz1TestHeap.test_merge_does_not_suppress_index_errorcCs�Gdd�dt�}ggggg}xDtd�D]8}tjd�}tjd�}||�}||f|_||j|�q&Wx|D]}|j�qhWdd�|jj|�D�}|j	|t
|��dS)Nc@seZdZdS)z*TestHeap.test_merge_stability.<locals>.IntN)rrrrrrr�Int�sr^i N�i�cSsg|]
}|j�qSr)�pair)r5r,rrrr6�sz1TestHeap.test_merge_stability.<locals>.<listcomp>)rGr"r#r:r`r$r&r%rSrr=)rr^rTr,�streamrB�obj�resultrrr�test_merge_stability�s



zTestHeap.test_merge_stabilityc
Cs�dd�td�D�}xvddd�fD]f}x`dD]X}|jt|jj||��t|�d|��|jt|jj|||d��t||d�d|��q*Wq WdS)NcSsg|]}tjd�|f�qS)i�)r#r:)r5r,rrrr6�sz+TestHeap.test_nsmallest.<locals>.<listcomp>��cSs|dddS)Nri#i�r)rBrrr�<lambda>�sz)TestHeap.test_nsmallest.<locals>.<lambda>rr0�r;rK����L)rP)	rr0rgr;rKrhrirerj)r"rr7r%�	nsmallestr=)rr+�f�nrrr�test_nsmallest�s
zTestHeap.test_nsmallestc
Cs�dd�td�D�}x|ddd�fD]l}xfdD]^}|jt|jj||��t|dd�d|��|jt|jj|||d��t||dd�d|��q*Wq WdS)NcSsg|]}tjd�|f�qS)i�)r#r:)r5r,rrrr6�sz*TestHeap.test_nlargest.<locals>.<listcomp>��cSs|dddS)Nri#i�r)rBrrrrf�sz(TestHeap.test_nlargest.<locals>.<lambda>rr0rgr;rK����LT)rQ)rP)rPrQ)	rr0rgr;rKrprqrorr)r"rr7r%�nlargestr=)rr+rlrmrrr�
test_nlargest�s
zTestHeap.test_nlargestcsj�fdd�}Gdd�d�}Gdd�d�}dd�td	�D�}t|d
d�}�j|||�|��jt||�dS)Ncs:�fdd��D���jj����fdd�tt���D�S)Ncsg|]}�|��qSrr)r5rB)�comprrr6�szDTestHeap.test_comparison_operator.<locals>.hsort.<locals>.<listcomp>csg|]}�jj��j�qSr)r%r	rB)r5r,)r+rrrr6�s)r%rr"r<)r+ru)r)rur+r�hsort�sz0TestHeap.test_comparison_operator.<locals>.hsortc@seZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LTcSs
||_dS)N)rB)rrBrrr�__init__�sz6TestHeap.test_comparison_operator.<locals>.LT.__init__cSs|j|jkS)N)rB)r�otherrrr�__lt__�sz4TestHeap.test_comparison_operator.<locals>.LT.__lt__N)rrrrwryrrrr�LT�srzc@seZdZdd�Zdd�ZdS)z-TestHeap.test_comparison_operator.<locals>.LEcSs
||_dS)N)rB)rrBrrrrw�sz6TestHeap.test_comparison_operator.<locals>.LE.__init__cSs|j|jkS)N)rB)rrxrrr�__le__�sz4TestHeap.test_comparison_operator.<locals>.LE.__le__N)rrrrwr{rrrr�LE�sr|cSsg|]}tj��qSr)r#)r5r,rrrr6�sz5TestHeap.test_comparison_operator.<locals>.<listcomp>rKT)rQ)r"r=rr'r()rrvrzr|r+�targetr)rr�test_comparison_operator�sz!TestHeap.test_comparison_operatorN)rrrr/r!r9r>r@rArCrJrNrYr]rdrnrtr~rrrrrs
				rc@seZdZeZdS)�TestHeapPythonN)rrrrr%rrrrr�srzrequires _heapqc@seZdZeZdS)�	TestHeapCN)rrrrr%rrrrr��sr�c@seZdZdZdd�ZdS)�LenOnlyz:Dummy sequence class defining __len__ but not __getitem__.cCsdS)Nr;r)rrrr�__len__�szLenOnly.__len__N)rrr�__doc__r�rrrrr��sr�c@seZdZdZdd�ZdS)�GetOnlyz:Dummy sequence class defining __getitem__ but not __len__.cCsdS)Nr;r)rZndxrrr�__getitem__�szGetOnly.__getitem__N)rrrr�r�rrrrr��sr�c@s,eZdZdZdd�ZeZZZZZ	dS)�CmpErrz;Dummy element that always raises an error during comparisoncCst�dS)N)�ZeroDivisionError)rrxrrr�__eq__sz
CmpErr.__eq__N)
rrrr�r��__ne__ryr{�__gt__�__ge__rrrrr�sr�ccsx|D]
}|VqWdS)zRegular generatorNr)�seqnr,rrr�Rs
r�c@s eZdZdZdd�Zdd�ZdS)�GzSequence using __getitem__cCs
||_dS)N)r�)rr�rrrrwsz
G.__init__cCs
|j|S)N)r�)rr,rrrr�sz
G.__getitem__N)rrrr�rwr�rrrrr�sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�Iz Sequence using iterator protocolcCs||_d|_dS)Nr)r�r,)rr�rrrrwsz
I.__init__cCs|S)Nr)rrrr�__iter__sz
I.__iter__cCs2|jt|j�krt�|j|j}|jd7_|S)Nr0)r,r<r��
StopIteration)r�vrrr�__next__s
z
I.__next__N)rrrr�rwr�r�rrrrr�sr�c@s eZdZdZdd�Zdd�ZdS)�Igz9Sequence using iterator protocol defined with a generatorcCs||_d|_dS)Nr)r�r,)rr�rrrrw"szIg.__init__ccsx|jD]
}|VqWdS)N)r�)r�valrrrr�%szIg.__iter__N)rrrr�rwr�rrrrr� sr�c@s eZdZdZdd�Zdd�ZdS)�Xz Missing __getitem__ and __iter__cCs||_d|_dS)Nr)r�r,)rr�rrrrw+sz
X.__init__cCs2|jt|j�krt�|j|j}|jd7_|S)Nr0)r,r<r�r�)rr�rrrr�.s
z
X.__next__N)rrrr�rwr�rrrrr�)sr�c@s eZdZdZdd�Zdd�ZdS)�NzIterator missing __next__()cCs||_d|_dS)Nr)r�r,)rr�rrrrw6sz
N.__init__cCs|S)Nr)rrrrr�9sz
N.__iter__N)rrrr�rwr�rrrrr�4sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�EzTest propagation of exceptionscCs||_d|_dS)Nr)r�r,)rr�rrrrw>sz
E.__init__cCs|S)Nr)rrrrr�Asz
E.__iter__cCsdddS)N�rr)rrrrr�Csz
E.__next__N)rrrr�rwr�r�rrrrr�<sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�SzTest immediate stopcCsdS)Nr)rr�rrrrwHsz
S.__init__cCs|S)Nr)rrrrr�Jsz
S.__iter__cCst�dS)N)r�)rrrrr�Lsz
S.__next__N)rrrr�rwr�r�rrrrr�Fsr�)rRcCsttdd�ttt|�����S)z Test multiple tiers of iteratorscSs|S)Nr)rBrrrrfRszL.<locals>.<lambda>)rR�mapr�r�r�)r�rrr�LPsr�c@seZdZdd�Zdd�ZdS)�SideEffectLTcCs||_||_dS)N)�valuer*)rr�r*rrrrwVszSideEffectLT.__init__cCsg|jdd�<|j|jkS)N)r*r�)rrxrrrryZszSideEffectLT.__lt__N)rrrrwryrrrrr�Usr�c@s\eZdZdd�Zdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�TestErrorHandlingcCsjx*|jj|jjfD]}|jttf|d�qWx8|jj|jj|jj|jj	fD]}|jttf|dd�qJWdS)Nr;)
r%rr	r'r(r)r
rrsrk)rrlrrr�test_non_sequenceas
z#TestErrorHandling.test_non_sequencecCs�x,|jj|jjfD]}|jttf|t��qWx.|jj|jjfD]}|jttf|t�d�q@Wx*|jj	|jj
fD]}|jt|dt��qpWdS)Nr;rg)r%rr	r'r(r)r�r
rrsrk)rrlrrr�
test_len_onlyhszTestErrorHandling.test_len_onlycCs�x(|jj|jjfD]}|jt|t��qWx*|jj|jjfD]}|jt|t�d�q<Wx*|jj|jj	fD]}|jt|dt��qhWdS)Nr;rg)
r%rr	r'r(r�r
rrsrk)rrlrrr�
test_get_onlypszTestErrorHandling.test_get_onlycCs�t�t�t�g}x&|jj|jjfD]}|jt||�q"Wx(|jj|jjfD]}|jt||d�qJWx(|jj|jj	fD]}|jt|d|�qtWdS)Nr;rg)
r�r%rr	r'r�r
rrsrk)rrXrlrrrr�xscCsHxB|jj|jj|jj|jj|jj|jjfD]}|jtt	f|d�q*WdS)Nr;)
r%rr	r
rrsrkr'r(r))rrlrrr�test_arg_parsing�sz"TestErrorHandling.test_arg_parsingc	Cs�x�|jj|jjfD]�}x�ddtd�d
tddd�fD]�}x:tttttfD](}|j	t
|d	||���t
|d	|���qFW|j	t
|d	t|���g�|jt
|d	t|��|jt
|d	t|��|jt|d	t|��q2WqWdS)NZ123�i�r0�333333�?i�i��rg)r0r�)r%rsrkr"r�r�r�r�r�rr7r�r'r(r�r�r�r�)rrlr[�grrr�test_iterable_args�s (z$TestErrorHandling.test_iterable_argscsRg��j�fdd�td�D��|jttf��|jj�td���WdQRXdS)Nc3s|]}t|��VqdS)N)r�)r5r,)r*rr�	<genexpr>�sz@TestErrorHandling.test_heappush_mutating_heap.<locals>.<genexpr>��r�)�extendr"r'r?�RuntimeErrorr%r
r�)rr)r*r�test_heappush_mutating_heap�sz-TestErrorHandling.test_heappush_mutating_heapc	sJg��j�fdd�td�D��|jttf��|jj��WdQRXdS)Nc3s|]}t|��VqdS)N)r�)r5r,)r*rrr��sz?TestErrorHandling.test_heappop_mutating_heap.<locals>.<genexpr>r�)r�r"r'r?r�r%r	)rr)r*r�test_heappop_mutating_heap�sz,TestErrorHandling.test_heappop_mutating_heapcsBG�fdd�dt�}g�|jj�|d��|jt|jj�d�dS)NcseZdZ�fdd�ZdS)zMTestErrorHandling.test_comparison_operator_modifiying_heap.<locals>.EvilClasscs�j�tS)N)�clear�NotImplemented)r�o)r*rrry�szTTestErrorHandling.test_comparison_operator_modifiying_heap.<locals>.EvilClass.__lt__N)rrrryr)r*rr�	EvilClass�sr�rr0)rGr%r
r'r?r)rr�r)r*r�(test_comparison_operator_modifiying_heap�sz:TestErrorHandling.test_comparison_operator_modifiying_heapcs�G�fdd�dt�}G�fdd�dt�}gg��|jj�|d��|jj�|d��|jttf|jj�|d��|jttf|jj�|d��dS)NcseZdZ�fdd�ZdS)zOTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.hcs�j�tS)N)r�r�)rr�)�list2rrry�szVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.h.__lt__N)rrrryr)r�rrrI�srIcseZdZ�fdd�ZdS)zOTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.gcs�j�tS)N)r�r�)rr�)�list1rrry�szVTestErrorHandling.test_comparison_operator_modifiying_heap_two_heaps.<locals>.g.__lt__N)rrrryr)r�rrr��sr�rr0)rGr%r
r'r?r�)rrIr�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�_s	r�c@seZdZeZdS)�TestErrorHandlingPythonN)rrrrr%rrrrr��sr�c@seZdZeZdS)�TestErrorHandlingCN)rrrrr%rrrrr��sr��__main__)%r�r#ZunittestZtestrrr�operatorrZimport_fresh_modulerrrrrrr�r�r�r�r�r�r�r�r�r�r�r��	itertoolsrRr�r�r�r�r�r�mainrrrr�<module>sF

P

	
	
b