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_itertools.cpython-38.pyc
U

>��g���@svddlZddlmZddlTddlZddlmZddlmZddl	Z	ddl
Z
ddlZddlZddl
mZddlZddlZddlZddlZejZedZdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�d�Zdd�Zdd�Z dd�Z!d d!�Z"d"d#�Z#d$d%�Z$d&d'�e%ej&d�D�Z'Gd(d)�d)ej(�Z)Gd*d+�d+ej(�Z*Gd,d-�d-ej(�Z+Gd.d/�d/ej(�Z,d0d1�Z-Gd2d3�d3�Z.Gd4d5�d5�Z/Gd6d7�d7�Z0Gd8d9�d9�Z1Gd:d;�d;�Z2Gd<d=�d=�Z3Gd>d?�d?�Z4d@dA�Z5GdBdC�dCej(�Z6GdDdE�dEej(�Z7GdFdG�dGej(�Z8GdHdI�dIej(�Z9ej:GdJdK�dKej(��Z;dLZ<dMe<iZ=dSdNdO�Z>e?dPk�rre>dQdR�dS)T�N)�support)�*)�Decimal)�Fraction)�reduce�cGstt|��S�N)�list�zip��args�r
�2/opt/cppython/lib/python3.8/test/test_itertools.py�lzipsrcCsd|S)zTest function of one argument�r
��xr
r
r�oneargsrcGst�dS)z"Test function that raises an errorN)�
ValueErrorrr
r
r�errfuncsrccsdD]
}|VqdS)zNon-restartable source sequence�rrrNr
��ir
r
r�gen3srcCs|ddkS)�Test predicaterrr
rr
r
r�isEven$srcCs|ddkS)rrrr
rr
r
r�isOdd(srcGs|Srr
rr
r
r�tupleize,srccst|�D]
}|VqdSr��range��nrr
r
r�irange/sr"c@s eZdZdZdd�Zdd�ZdS)�StopNowz"Class emulating an empty iterable.cCs|Srr
��selfr
r
r�__iter__5szStopNow.__iter__cCst�dSr��
StopIterationr$r
r
r�__next__7szStopNow.__next__N)�__name__�
__module__�__qualname__�__doc__r&r)r
r
r
rr#3sr#cCstt||��S)zHConvenience function for partially consuming a long of infinite iterable�r	�islice)r!�seqr
r
r�take:sr1cCsttj|d�S�Nr)r�operator�mul��iterabler
r
r�prod>sr7cCsttd|d��S)Z	Factorialr)r7r�r!r
r
r�factAsr9cCs|dS�Nrr
��rr
r
r�testRFsr=cCs|dS�Nrr
r;r
r
r�testR2Isr?cCs|dkS)N�
r
rr
r
r�undertenLsrAcCsg|]}|fdd��qS)cSst�t�||��Sr)�pickle�loads�dumps)�s�protor
r
r�<lambda>O�z<listcomp>.<lambda>r
)�.0rFr
r
r�
<listcomp>Os�rJc@s(eZdZdodd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	e
jdd��Ze
�
d�dd��Zdd�Ze
jdd��Ze
�
d�dd��Zdd�Ze
jdd ��Ze
�
d�d!d"��Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Ze
�
d�d7d8��Zd9d:�Z e
�
d�d;d<��Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%e
jdEdF��Z&e
�
d�dGdH��Z'dIdJ�Z(dKdL�Z)dMdN�Z*dOdP�Z+dQdR�Z,dSdT�Z-dUdV�Z.dWdX�Z/dYdZ�Z0d[d\�Z1d]d^�Z2d_d`�Z3dadb�Z4dcdd�Z5e
j6dedf��Z7e
j6dgdh��Z8e
j6didj��Z9e
j6dkdl��Z:e
j6dmdn��Z;dS)p�TestBasicOps�rNcsd��fdd�	�t�||�}t�|�}|�t|�t|���|��|�}}	|�||	�|rp�|�}
|�||
�t�|�}d}z"t|�D]}
t|�|d7}q�Wntk
r�YnXt�||�}t�|�}�|��|�}}	|�||	�|�r�||d��}
|�||
�dS)zITest that an iterator is the same after pickling, also when part-consumedrcs^�dkrtd��t|t�r|Sztt|���}Wntk
rH|YSX��fdd�|D�S)Nr@zinfinite recursion encounteredcsg|]}�|�d��qS)rr
�rI�e)�expandrr
rrJ`sz;TestBasicOps.pickletest.<locals>.expand.<locals>.<listcomp>)�RuntimeError�
isinstance�strr	r/�	TypeError)�itr�l�rO�stoprrrOVs

z'TestBasicOps.pickletest.<locals>.expandrN)r)rBrDrC�assertEqual�typer�nextr()r%�protocolrTrWr1�compare�dumpZi2�a�b�cZi3ZtookrZi4r
rVr�
pickletestTs0



zTestBasicOps.pickletestcCs�|�tttd���ddddddddd	d
g
�|�tttd�d��ddddddddd	d
g
�ttttfD]@}|�ttt|td����tt|ddddddddd	d
g
���qf|�ttd��d
ddg�|�ttg��g�|�ttdg��dg�|�	t
ttd�dd�|�	t
t�|j	t
ttd�d�|�	t
ttdgg��ddddddddddg
}|�tt|t��ddddddddddg
�|�tt|t��ddddddddddg
�|�tt|t
j��ddddddddddg
�|�	t
��tt|t��W5QRXttjd�D]2}|�|ttd���|�|ttd�dd���q|�ttdddgdd��dddg�|�ttdddgdd��ddddg�|�ttgdd��dg�|�	t
��ttddgd��W5QRXdS) Nr@rr������$�-r5�abcr^�ab��rr��	rL��i�i�)�initial�d�n�s�t�)rXr	�
accumulater�int�complexrr�map�assertRaisesrS�min�maxr3r4�chrrB�HIGHEST_PROTOCOLra)r%�typrErFr
r
r�test_accumulate}sL�� ����$&zTestBasicOps.test_accumulatecCs�dd�}t|fD]z}|�t|dd��td��|�t|d��td��|�t|d��g�|�td|dd��td��|�tt|d	d
��qdS)Ncws|D]}|D]
}|VqqdS)zPure python version in the docsNr
)�	iterablesrT�elementr
r
r�chain2�sz'TestBasicOps.test_chain.<locals>.chain2ri�def�abcdef�rL�abcdrrb)�chainrXr	r1r{rS)r%r�r`r
r
r�
test_chain�szTestBasicOps.test_chaincCs�|�tt�ddg��td��|�tt�dg��td��|�tt�dg��g�|�tdt�ddg��td��|�ttt�ddg��dS)	Nrir�r�r�rLr�rrb)rXr	r��
from_iterabler1r{rSr$r
r
r�test_chain_from_iterable�s
 z%TestBasicOps.test_chain_from_iterablec	Cs�tjgtD]�}tdd�}|�t||��td��|�t|�d�|�t||��td��|�t|td���g�|�td|tdd���td��|�t	t|td	d
���qt
tjd�D]}|j
|tdd�td�d�q�dS)
Nrir�r�r^Zbcdefr�rLr�rrbr�r\)�copy�deepcopy�
picklecopiersr�rXr	rZr1r{rSrrBrra)r%ZoperrTrFr
r
r�test_chain_reducible�s
 z!TestBasicOps.test_chain_reduciblec
Cs�|�tt�jd�|�tt�jg�|�tt�jd�|�tt�jgf�|�tt�jtg�gf�t�}|�tddg�f�|�t|�ddddd	d
g�t�}|�tddg�tdg�f�|�t|�dddddd	d
g�dS)Nr
rrir�r^r_r`�drN�fZghi)r{rSr��__setstate__�iterrXr	�r%rTr
r
r�test_chain_setstate�sz TestBasicOps.test_chain_setstatec

s�|�ttd�|�ttddd�|�ttd�|�ttdd�dd�gtD]�}|�t|tdd���g�|�t|tdd���d	d
ddd
dg�tdd�}t|�|�t||��d
ddd
dg�|�t|ttd�d���ddddg�ttd�d�}t|�|�t||��dddg�qLdd�}dd�}dd�}td�D�]�}dd�t|�D��t|d�D�]Z}tt�|��}|�t	|�||k�r�dnt
|�t
|�t
||��|�t	|�t	t|���|�|t|��|D]x�|�t	��|�|�t	t���|�|�t��t���|�
t�fdd ��D���|�t���fd!d��D���q�|�|t|�|���|�|t|�|���|�|t|�|���ttjd�D]}	|�|	t�|���q��q\�q8dS)"Nrirr���cSs|Srr
�r^r
r
rrG�rHz0TestBasicOps.test_combinations.<locals>.<lambda>� �ABCD��A�B�r��C�r��D�r�r��r�r��r�r�rLrbr�rrrb�rrrb�rrrbc3s�t|��t��}||krdStt|��}t�fdd�|D��Vtt|��D]}|||||krLqnqLdS||d7<t|d|�D]}||dd||<q�t�fdd�|D��Vq@dS)�%Pure python version shown in the docsNc3s|]}�|VqdSrr
�rIr��poolr
r�	<genexpr>�szHTestBasicOps.test_combinations.<locals>.combinations1.<locals>.<genexpr>rc3s|]}�|VqdSrr
r�r�r
rr��s��tuple�lenr	r�reversed)r6r<r!�indicesr�jr
r�r�
combinations1�sz5TestBasicOps.test_combinations.<locals>.combinations1c3sPt|��t��}tt|�|�D],}t|�t|�krt�fdd�|D��VqdS)r�c3s|]}�|VqdSrr
r�r�r
rr�szHTestBasicOps.test_combinations.<locals>.combinations2.<locals>.<genexpr>N)r�r��permutationsr�sortedr	�r6r<r!r�r
r�r�
combinations2�s
z5TestBasicOps.test_combinations.<locals>.combinations2c3sPt|��t��}tt|�|�D],}tt|��|krt�fdd�|D��VqdS)zPure python version from cwr()c3s|]}�|VqdSrr
r�r�r
rr�	szHTestBasicOps.test_combinations.<locals>.combinations3.<locals>.<genexpr>N)r�r��combinations_with_replacementr�setr�r
r�r�
combinations3s
z5TestBasicOps.test_combinations.<locals>.combinations3rkcSsg|]}d|d�qS�rl�r
�rIrr
r
rrJsz2TestBasicOps.test_combinations.<locals>.<listcomp>rc3s|]}|�kVqdSrr
rM��valuesr
rr�sz1TestBasicOps.test_combinations.<locals>.<genexpr>csg|]}|�kr|�qSr
r
rM�r`r
rrJs)r{rS�combinationsrr�rXr	rZrr�r9r�r��
assertTrue�allrBrra)
r%�op�testIntermediater�r�r�r!r<�resultrFr
�r`r�r�test_combinations�sZ�
�
��6
�zTestBasicOps.test_combinationsc	Cs(|�ttf��tdd�W5QRXdS)N�AAi )r{�
OverflowError�MemoryErrorr�r$r
r
r�test_combinations_overflow sz'TestBasicOps.test_combinations_overflowz"tuple reuse is specific to CPythonc
CsH|�tttttdd����d�|�ttttttdd�����d�dS�N�abcderbr)rXr�r�rz�idr��assertNotEqualr	r$r
r
r�test_combinations_tuple_reuse&s z*TestBasicOps.test_combinations_tuple_reusec

stt}|�t|d�|�t|ddd�|�t|d�|�t|dd�dd�gtD]Z}|�t||dd���dd	d
ddd
g�|dd�}t|�|�t||��d	d
ddd
g�qPdd�}dd�}dd�}td�D�]�}dd�t|�D��t|d�D�]z}t|�|��}	|�t	|	�|||��|�t	|	�t	t
|	���|�|	t|	��tt�|��}
|dk�sd|dk�rr|�|	|
�n|�
t
|	�t
|
�k�|	D]��|�t	��|�dd�t��D�}|�t	|�t	t
|���|�t��t���|�
t�fdd��D���|�|�fdd��D���q�|�|	t|�|���|�|	t|�|���ttjd�D]}|�||�|���qRq�q�dS)Nrirrr�cSs|Srr
r�r
r
rrG2rHzATestBasicOps.test_combinations_with_replacement.<locals>.<lambda>�ABC�r�r�r�r��r�r�r��r�r�c3s�t|��t��}|s|rdSdg|}t�fdd�|D��Vtt|��D]}|||dkrJqhqJdS||dg||||d�<t�fdd�|D��Vq>dS)r�Nrc3s|]}�|VqdSrr
r�r�r
rr�CszPTestBasicOps.test_combinations_with_replacement.<locals>.cwr1.<locals>.<genexpr>rc3s|]}�|VqdSrr
r�r�r
rr�Ks)r�r�r�r)r6r<r!r�rr
r�r�cwr1;s
z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr1c3sRt|��t��}tt|�|d�D],}t|�t|�kr t�fdd�|D��Vq dS)r���repeatc3s|]}�|VqdSrr
r�r�r
rr�SszPTestBasicOps.test_combinations_with_replacement.<locals>.cwr2.<locals>.<genexpr>N)r�r��productrr�r	r�r
r�r�cwr2Ms
z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr2cSs4|s|rdSdSt||d�t|�t|d�S�Nrr)r9)r!r<r
r
r�numcombsUszATestBasicOps.test_combinations_with_replacement.<locals>.numcombsrkcSsg|]}d|d�qSr�r
r�r
r
rrJ[szCTestBasicOps.test_combinations_with_replacement.<locals>.<listcomp>rcSsg|]\}}|�qSr
r
)rI�k�vr
r
rrJksc3s|]}|�kVqdSrr
rMr�r
rr�nszBTestBasicOps.test_combinations_with_replacement.<locals>.<genexpr>csg|]}|�kr|�qSr
r
rMr�r
rrJps)r�r{rSrr�rXr	rZrr�r�r�r�r��groupbyr�rBrra)
r%�cwrr�r�r�r�r�r!r<r�Z
regular_combsZnorunsrFr
r�r�"test_combinations_with_replacement+sR�
��z/TestBasicOps.test_combinations_with_replacementc	Cs(|�ttf��tdd�W5QRXdS)Nr��@)r{r�r�r�r$r
r
r�+test_combinations_with_replacement_overflowwsz8TestBasicOps.test_combinations_with_replacement_overflowc
CsLt}|�tttt|dd����d�|�ttttt|dd�����d�dSr�)r�rXr�r�rzr�r�r	)r%r�r
r
r�.test_combinations_with_replacement_tuple_reuse}s z;TestBasicOps.test_combinations_with_replacement_tuple_reusec	s|�tt�|�ttddd�|�ttd�|�ttdd�|�ttdd��g�|�ttdd�|�tttd�d��dd	d
ddd
g�ddd�}ddd�}td�D�]`}dd�t|�D��t|d�D�]:}tt�|��}|�t|�||kr�dnt|�t||��|�t|�tt	|���|�|t
|��|D]F}|�t|�|�|�tt	|��|�|�t�fdd�|D����q4|�|t|�|���|�|t|�|���||k�r�|�|tt�d���|�|tt����tt
jd�D]}|�|t�|���q�q�q�dS)Nrirrr�r�rErb�rr�rr�rr�rr)rr)rrc3s:t|��t��}|dkr|n|}||kr,dStt|��}tt||d|d��ddd�}t�fdd�|d|�D��V|�r6tt|��D]�}||d8<||dkr�||dd�|||d�||d�<||||<q�||}||||||<||<t�fdd�|d|�D��Vq|q�dSq|dS)r�Nr���c3s|]}�|VqdSrr
r�r�r
rr��szHTestBasicOps.test_permutations.<locals>.permutations1.<locals>.<genexpr>rc3s|]}�|VqdSrr
r�r�r
rr��sr�)r6r<r!r�Zcyclesrr�r
r�r�
permutations1�s&$ ( z5TestBasicOps.test_permutations.<locals>.permutations1c3sbt|��t��}|dkr|n|}tt|�|d�D],}tt|��|kr0t�fdd�|D��Vq0dS)r�Nr�c3s|]}�|VqdSrr
r�r�r
rr��szHTestBasicOps.test_permutations.<locals>.permutations2.<locals>.<genexpr>)r�r�r�rr�r�r
r�r�
permutations2�sz5TestBasicOps.test_permutations.<locals>.permutations2rkcSsg|]}d|d�qSr�r
r�r
r
rrJ�sz2TestBasicOps.test_permutations.<locals>.<listcomp>rc3s|]}|�kVqdSrr
rMr�r
rr��sz1TestBasicOps.test_permutations.<locals>.<genexpr>)N)N)r{rSr�rrXr	rr�r9r�r�r�r�rBrra)r%r�r�r!r<r��prFr
r�r�test_permutations�s:�

	, 
zTestBasicOps.test_permutationsc	Cs(|�ttf��tdd�W5QRXdS)Nr�r�)r{r�r�r�r$r
r
r�test_permutations_overflow�sz'TestBasicOps.test_permutations_overflowc
CsH|�tttttdd����d�|�ttttttdd�����d�dSr�)rXr�r�rzr�r�r�r	r$r
r
r�test_permutations_tuple_reuse�s z*TestBasicOps.test_permutations_tuple_reusec	std�D�]}dd|�}td�D�]�tt|�d��}tt|���}tt|���}tt|���}|�t|�|��|�t|�|r�t|�d�t��t|d�n��|�t|��|kr�dnt|�t|���|�t|��|kr�dnt|�t��t|���|�|t	t
|���|�|t	t
|���|�|t	t
|���|�|t	t
|���|�|dd�|D��|�|�fd	d�|D��|�|d
d�|D��|�|�fdd�|D��|�|ttt
|�j|���|�|ttt
|�j|���|�|t	t
|�t
|�@��q"qdS)Nrc�ABCDEFGrmr�rrcSs g|]}t|�t|�kr|�qSr
�r�r	�rI�tr
r
rrJ�sz3TestBasicOps.test_combinatorics.<locals>.<listcomp>cs g|]}tt|���kr|�qSr
�r�r�r�r;r
rrJ�scSs g|]}t|�t|�kr|�qSr
r�r�r
r
rrJ�scs g|]}tt|���kr|�qSr
r�r�r;r
rrJ�s)
rr	r�r�r�r�rXr�r9r�r��filter�__contains__)r%r!rEr7r��perm�combr
r;r�test_combinatorics�s,:,4zTestBasicOps.test_combinatoricscCs~|�ttdddddddgd��td��|�ttdddddddg��td��|�ttdddddddg��td��|�ttdddddddg��td��|�ttddddg��td��|�ttdddddddg��td	��d
}t�ttd�|��}t�td��}|�tt||��dd
dg|�|�ttdtd��|�tttd�d�|�tttd��|�tttd�d�dd�dd�gt	D]�}dddddddgddfdddddddgddfdddddddgddfddddgddfdddddddgd	dffD]|\}}}}|�t|t||d���t|��|�t|t||���t|��t||�}|�r�t
|�|�t||��t|���q��q�dS)N�ABCDEFrr)�data�	selectors�ACEFr�ZACr�ZBC�'rcr�rbrlcSs
t�|�Sr)r�r�r
r
rrG�rHz,TestBasicOps.test_compress.<locals>.<lambda>cSs
t�|�Sr)r�r�r�r
r
rrG�rHZCEFZBCDEFr�)rXr	�compressr�r�r�rr{rSr�rZ)r%r!r�r�r�Zresult1Zresult2r�r
r
r�
test_compress�s6(&&& & � 
zTestBasicOps.test_compressc	Csb|�tdt��dddg�|�tdtd��dddg�|�td	tdtd���ddg�|�td	tdtd
���ddg�|�td	tdtd
���ddg�|�ttd	dd�|�ttd�|�tdttd��tt	tdtd���|�tdttd��tt	tdtd���|�tdtd��dddg�|�tdtd��dddg�|�tdtt
d���t
d�t
d�t
d�g�|�tdttd	d���td	d�tdd�tdd�g�dd>}|�tdt|��||d|d	g�td�}|�t|�d �t
|�|�t|�d!�td"�}|�t|�d#�t
|�|�t
|�d$�|�ttd%��d&�|�ttd'��d(�|�tt
td'���t�tjdtjdd)d
d*dtjdtjdfD](}tt|��}d+�|�}|�||��q�d
dtdtdfD]`}t|�}|�t
t�|��|�|�t
t�|��|�t	tjd�D]}|�|t|���q,�q�tdtd�t��dS),Nri�r^r�r_r�r`rrb)r^rb)r_rL)r`rlrr�)r^r�)r_r���)r^r)r_r�rLr^r@rl�
@g@g@�
@�y@��@��1.1z2.1z3.1rmr��zcount(3)zcount(4)���z	count(-9)i����g�$@zcount(10.25)g$@zcount(10.0)���r�	count(%r))rXr�countr1r
r{rS�maxsizer	rrr�reprrZrY�float�sys�__mod__r�r�rBrra�exc_info)r%�BIGINTr`r�r1�r2�valuerFr
r
r�
test_counts\   ����$4
zTestBasicOps.test_countcCsj|�tdtdd��dddg�|�tdtddd��dddg�|�tdtdd	��d
ddg�|�ttd
d�|�tdtdd��dddg�|�tdtdd��dddg�|�tdtdd��dddg�|�tdttdd��tdttdtdd���|�tdttdd��tdttdtdd���|�tdtdtd��ttdddtdtd���|�tdtdd��dddg�|�tdtdd��dddg�|�tdtt	d �t	d!���t	d �t	d"�t	d#�g�|�tdtt
dd�t
dd$���t
dd�t
d%d&�t
dd&�g�dd'>}|�tdt|d	��d|d|g�|�ttdtdd(���tdd)d*g��tdd�}|�t|�d+�t|�|�t|�d,�td-d�}|�t|�d.�t|�|�t|�d.�td-d/�}|�t|�d0�t|�|�t|�d1�|�t|�d1�|�ttd2d��d3�|�ttd2d��d4�|�ttd2d5��d6�|�ttdd5��d7�tdd5�}|�t
t|��t�|�t
t|��t�tjdtjdd8dddtjdtjdfD]�}tjdtjdd8ddddtjdtjdf	D]h}tt||��}|dk�rd9|}nd:||f}|�||�ttjd�D]}|�|t||���qD�q��q�dS);Nrirrb)r^r)r_rl)r`rm)�start�stepr�)rr)r_r�)r`r�r^r_r)r_rrr)r_rb)r`rLrvrdrrr@rlg�?rg@rry!@ �r	z.1z1.2z1.3rk�rer
g@g)@g.@zcount(3, 5)zcount(8, 5)rzcount(-9, 0)rz
count(-9, -3)zcount(-12, -3)g%@zcount(10.5, 1.25)zcount(10.5)g�?zcount(10.5, 1.0)zcount(10, 1.0)rr
z
count(%r, %r))rXrrr{rSr1rrr	rrrrZrYrxrrrBrra)r%rr`rr�rrrFr
r
r�test_count_with_stride?sp��28���"&



46

z#TestBasicOps.test_count_with_stridec
s|�tdtd��td��|�ttd��g�|�tt�|�ttd�|�tttt��d��ddddddddddg
�td��|�t��d	�|�tdt	�
���td
��ttj
d�D]d}|�tdt�t��|���td
��t��|�tdt�t��|���td��t��t��q�ttj
d�D]}|�|td���q.ttj
d�D]�}td�}t|���fd
d�td�D�}t��|�}t�|�}|�td|�td��td�}t|���fdd�td�D�}t��|�}t�|�}|�td|�td���qTdS)Nr@riZ
abcabcabcar�rlrrrr^Z
bcabcabcabZ
cabcabcabcr�csg|]}t���qSr
�rZr�r�r
rrJ�sz+TestBasicOps.test_cycle.<locals>.<listcomp>rvZcdeabcdeabcdeabcdeabcsg|]}t���qSr
rr�r�r
rrJ�srk)rXr1�cycler	r{rSr/rrZr�r�rrBrrCrDrar�)r%rFrT�_r�r�r
r�r�
test_cyclevsB0��


zTestBasicOps.test_cyclec	Cs td�}|�td�df�|�td|�td��td�}|�td�df�|�td|�td��|�t��td��td�dg�W5QRX|�t�� td�}|�td�df�W5QRXtd|�|�t��td��td�df�W5QRX|�ttd	�jd
�|�ttd	�jgf�dS)N�defgrirrvZdefgabcdefgabcdefgab�abcdefgrrr�r
)rr�r	rXr1r{rSr�)r%r`r
r
r�test_cycle_setstate�s  
 z TestBasicOps.test_cycle_setstatec
s|�gttg���|�gttgtd���|�tttdg��|�ttd�|�ttddd�d�dddd	d
ddd
g}g}t|dd��D],\}}|D]}|�||d�|�|�q�q�|�||�ttj	d�D]Z}g}t�
t�t|t�|��D],\}}|D]}|�||d�|�|�q�q�|�||�q�g}t|t�D]V\}}t|t
�D]@\}}|D]0}|�||d�|�||d�|�|��qZ�qN�q<|�||�ttj	d�D]�}g}t�
t�t|t�|��D]d\}}t�
t�t|t
�|��D]@\}}|D]0}|�||d�|�||d�|�|��q��q�q�|�||��q�dd�t|t�D�}	tdd�|D��}
|�t|	�|
�|�t|	�t|
��ttdtd���}t|t�}t|�\}}
t|�\}}t|�\}}|�t|
�g�|�t|�g�|�t|�d�t|�|�t|�g�ttj	d�D]J}t|t�}t|�\}}t|�t|�|�tt�
t�||���g��q$d}dd�tt|��D�}|�|dddddg�dd�tt|��D�}|�|dddg�d d�tt|��D�}|�|d!d"d#d$d%g�td&d�tt|��D�d'd(�dd)�}|�|d!d%d"g�Gd*d+�d+t��d5�fd,d-�	}dtfd.d/�}|��||d��|��||d��G�fd0d1�d1�}|�|�dg}|j�||td2�|��||���fd3d4��d�_|��|dg��d�_|��|ddg��dS)6N��keyricSs|Srr
rr
r
rrG�rHz+TestBasicOps.test_groupby.<locals>.<lambda>r@)rr@rv)r�re)rr�re)r�
re)r��)rrdr*)rbro�)rbrr+cSs|dSr:r
r;r
r
rrG�rHrrrcSsg|]\}}|�qSr
r
�rIr��gr
r
rrJ�sz-TestBasicOps.test_groupby.<locals>.<listcomp>cSsg|]}|d�qS)rr
)rIr<r
r
rrJ�sZ	AABBBAAAArn)r�rlZabracadabracSsg|]\}}|�qSr
r
r,r
r
rrJsr^r_r`r�r<cSs$g|]\}}tt|dd��r|�qSr�r.r,r
r
rrJscSs g|]\}}tt|��|f�qSr
�r�r	r,r
r
rrJs)rlr^)rr_)rr`)rr�)rr<cSs g|]\}}tt|��|f�qSr
r.r,r
r
rrJsT)�reverserbc@seZdZdS)z0TestBasicOps.test_groupby.<locals>.ExpectedErrorN)r*r+r,r
r
r
r�
ExpectedErrorsr0c3st|�D]
}dVq��dS)NZyorr �r0r
r�
delayed_raise!sz0TestBasicOps.test_groupby.<locals>.delayed_raisecs�fdd�t||�D�S)Ncsg|]\}}�|��qSr
r
r,��funcr
rrJ&sz;TestBasicOps.test_groupby.<locals>.gulp.<locals>.<listcomp>)r�)r6Zkeypr4r
r3r�gulp%sz'TestBasicOps.test_groupby.<locals>.gulpcseZdZ�fdd�ZdS)z+TestBasicOps.test_groupby.<locals>.DummyCmpcs��dSrr
)r%�dstr1r
r�__eq__/sz2TestBasicOps.test_groupby.<locals>.DummyCmp.__eq__N)r*r+r,r7r
r1r
r�DummyCmp.sr8r3cs$�jdkr�jd8_|S��dSr�)�skip)�obj�r0�keyfuncr
rr<9s
z*TestBasicOps.test_groupby.<locals>.keyfunc)r)rXr	r�r�r{rS�appendrrBrrCrDr=r?r�r�r
rZr��	Exceptionr9)r%rE�dupr�r-�elemrFZikZig�keysZexpectedkeysrTr Zg1Zg2Zg3r<r2r5r8r
r;r�test_groupby�s�
�   

"&zTestBasicOps.test_groupbyc
Cs�|�ttttd���dddg�|�ttddddddg��ddg�|�tttdddddg��ddg�|�tdttt���ddddg�|�t	t�|�t	tdd��|�t	tdd�td�d	�|�t	ttd
�|�t	t
ttd�td���dddg}tttd��}|�tt�|��|�tttd��}|�tt�|��|�tt
jd�D]`}tttd��}|�tt
�t
�||���|�t
|�|�tt
�t
�||���|dd���qNtt
jd�D] }tttd��}|�||��q�dS)NrcrrrLrcSs|Srr
rr
r
rrGLrHz*TestBasicOps.test_filter.<locals>.<lambda>cSs|Srr
rr
r
rrGMrHrkrb)rXr	r�rr�boolr1rr{rSrZr�r�rBrrCrDra�r%�ansr`rFr
r
r�test_filterFs, $$"
*zTestBasicOps.test_filterc
Cs"|�ttttd���dddg�|�ttddddddg��dddg�|�tttdddddg��dddg�|�tdttt���ddddg�|�t	t�|�t	td	d
��|�t	tdd
�td�d�|�t	ttd�|�t	t
ttd�td���ttjd�D]}|�
|tttd����qdS)NrcrrbrlrrrLrkcSs|Srr
rr
r
rrGgrHz/TestBasicOps.test_filterfalse.<locals>.<lambda>cSs|Srr
rr
r
rrGhrH)rXr	�filterfalserrrCr1rr{rSrZrBrra�r%rFr
r
r�test_filterfalseas &&"zTestBasicOps.test_filterfalsecCs*dd�tdt��D�}|�|dddg�|�ttdtd���tdtd���|�ttdtd	���tdtd	���|�td	tdt���tdtd	���|�ttd��td��|�tt��t��|�ttd	�|�tttd	�d	�|�d
d�tdd�D�tdd��|�dd�tdd�D�tdd��dS)
NcSsg|]\}}||f�qSr
r
�rIr�yr
r
rrJpsz)TestBasicOps.test_zip.<locals>.<listcomp>rirrrrcr�rbcSsg|]}tt|���qSr
�r�r	�rIZpairr
r
rrJysr�cSsg|]}|�qSr
r
rMr
r
rrJ{s)	r
rrXr	rrr1r{rS)r%rEr
r
r�test_zipns$$$��zTestBasicOps.test_zipc	Cs�ttttdd���}|�t|�t|��tttttdd����}|�tt�	|��t|��dd�t
�
tdt���D�}|�|dddg�dd�t
�tdt���D�}|�|dddg�t
tjd	�D]:}d
d�t�t�tdt��|��D�}|�|dddg�q�t
tjd	�D]F}tdt��}t|�dd�t�t�||��D�}|�|ddg��qt
tjd	�D]}|�|tdt����qddS)Nrir�cSsg|]\}}||f�qSr
r
rJr
r
rrJ�sz5TestBasicOps.test_zip_tuple_reuse.<locals>.<listcomp>rrrcSsg|]\}}||f�qSr
r
rJr
r
rrJ�srcSsg|]\}}||f�qSr
r
rJr
r
rrJ�scSsg|]\}}||f�qSr
r
rJr
r
rrJ�s)r	rzr�r
rXr|r}r��dict�fromkeysr�rr�rrBrrCrDrZra)r%�idsrErFr�r
r
r�test_zip_tuple_reuse~s$$z!TestBasicOps.test_zip_tuple_reusecsNdtd�gtd�dgtd�tdd�tdd�gtd�td�tdd�td	�td
�gtd�td�tdd�td	�td
�td�gfD]x��fdd�tttt����D�}|�tt���|�|�tt�i��|�d
d�|D�}|�tt�tdd���|�qz|�tdtdt	���tt
dtd����|�tt��tt
���|�ttg��tt
g���|�ttd��tt
d���|�ttdi��tt
td�dgd���|�ttd�|�tttd�d�dD]@}zt
|t�t��Wntk
�r�YnX|�d|��q�|�dd�tdd�D�tt
dd���|�dd�tdd�D�tt
dd���dS)Nrircr
��i4i�i�ri�i�cs"g|]�t�fdd��D���qS)cs$g|]}�t|�kr|�nd�qSr�r�)rI�argrr
rrJ�sz;TestBasicOps.test_ziplongest.<locals>.<listcomp>.<listcomp>�r�)rIrrrrJ�s�z0TestBasicOps.test_ziplongest.<locals>.<listcomp>cSsg|]}tdd�|D���qS)css|]}|dkrdp|VqdS)N�Xr
rMr
r
rr��sz:TestBasicOps.test_ziplongest.<locals>.<listcomp>.<genexpr>rVr�r
r
rrJ�srW��	fillvaluerbr�r")zzip_longest('abc', fv=1)z3zip_longest('abc', fillvalue=1, bogus_keyword=None)zDid not raise Type in:  cSsg|]}tt|���qSr
rLrMr
r
rrJ�sr�cSsg|]}|�qSr
r
rMr
r
rrJ�s)rir")rr}rzr�rXr	�zip_longestrOr1rr
r{rS�eval�globals�localsZfail)r%�targetZstmtr
rr�test_ziplongest�sD

"(�
�(���zTestBasicOps.test_ziplongestcCs^ttttdd���}|�t|�t|��tttttdd����}|�tt�	|��t|��dS)Nrir�)
r	rzr�rZrXr|r}r�rOrP)r%rQr
r
r�test_zip_longest_tuple_reuse�sz)TestBasicOps.test_zip_longest_tuple_reusec	Csdttjd�D]P}|�|tdd��|�|tdd��|�|tdddd��|�|tdd��qdS)Nrrir�ZdefghrXr�)rrBrrarZrHr
r
r�test_zip_longest_pickling�s
z&TestBasicOps.test_zip_longest_picklingc	sJt��G�fdd�d�}|�t��}t|��W5QRX|�|j��dS)NcseZdZ�fdd�ZdS)z?TestBasicOps.test_zip_longest_bad_iterable.<locals>.BadIterablecs��dSrr
r$��	exceptionr
rr&�szHTestBasicOps.test_zip_longest_bad_iterable.<locals>.BadIterable.__iter__N)r*r+r,r&r
rbr
r�BadIterable�srd)rSr{rZZassertIsrc)r%rd�cmr
rbr�test_zip_longest_bad_iterable�s
z*TestBasicOps.test_zip_longest_bad_iterablecCs�Gdd�d�}|ddt�}|ddt�}dd�}|�|||�d	d	d	d
g�|ddt�}|ddt�}t||dd�}|�t|�d	�|�t|�d	�|�t|�d	�|�tt|�dS)
Nc@s$eZdZdd�Zdd�Zdd�ZdS)z,TestBasicOps.test_bug_7244.<locals>.RepeatercSs||_t|�|_||_dSr)�orxr�rN)r%rgr�rNr
r
r�__init__�s
z5TestBasicOps.test_bug_7244.<locals>.Repeater.__init__cSs|Srr
r$r
r
rr&�sz5TestBasicOps.test_bug_7244.<locals>.Repeater.__iter__cSs(|jdkr|jd8_|jS|j�dSr�)r�rgrNr$r
r
rr)�s
z5TestBasicOps.test_bug_7244.<locals>.Repeater.__next__N)r*r+r,rhr&r)r
r
r
r�Repeater�srirrbrrLc
SsPg}t||dd�D]8\}}t�d��t||f�W5QRX|�||f�q|S)NrrX�stdout)rZrZcaptured_output�printr=)rrr�rr�r
r
r�run�sz'TestBasicOps.test_bug_7244.<locals>.runr�r�rrX)r(rXrPrZrZr{)r%rirrrlrTr
r
r�
test_bug_7244�szTestBasicOps.test_bug_7244csgdgfdgddgftd�td�gddd	d
ddgftd
�td�td�ggftd�td
�td�ggftd�td�td
�ggffD]R\}}|�tt|��|�td�D],}|�tt||��tt|t|d����q�q~|�ttttd�gd���d�|�tttd�d�dd�}dd�}dddtd
�td�tdddd�td�td�t	td��g	�td�D]�}�fdd �tt
�d!��D�}tt
t|��}|�ttt|���|�|�tt|��t||���|�tt|��t||���t
t|�}|�ttt|���|��qXdS)"Nr
rjr��r_rrb�rrr�r�r��rrr�rrLr�rkrci��cs�ttt|��|�dd�}t|�}|dkr4dVdStdd�|D��rJdSdg|}tdd�t||�D��Vtt|��D]h}||t||�dkr�qz||d7<t|d|�D]}d||<q�tdd�t||�D��VqnqzdSqndS)	Nr�rrr
css|]}t|�dkVqdS)rNrT)rIr�r
r
rr�sz>TestBasicOps.test_product.<locals>.product1.<locals>.<genexpr>css|]\}}||VqdSrr
�rIr�rr
r
rr�scss|]\}}||VqdSrr
rqr
r
rr�&s)	r	rzr��getr��anyr
r�r)r�kwds�poolsr!r�rr�r
r
r�product1s$

z+TestBasicOps.test_product.<locals>.product1c?sTttt|��|�dd�}gg}|D]��fdd�|D�}q$|D]}t|�Vq@dS)z Pure python version used in docsr�rcs g|]}�D]}||g�qqSr
r
rJr�r
rrJ0sz?TestBasicOps.test_product.<locals>.product2.<locals>.<listcomp>N)r	rzr�rr)rrtrur�r7r
r�r�product2+sz+TestBasicOps.test_product.<locals>.product2r�rir)r^r_r`r#r'r(rrcsg|]}t����qSr
)�random�choice)rIr��Zargtypesr
rrJ7sz-TestBasicOps.test_product.<locals>.<listcomp>rl)rrXr	r�rOr�r{rSr�r�rx�	randranger7rzr�)r%rr�r<rvrwrZexpected_lenr
rzr�test_products:��"	
�
zTestBasicOps.test_productc	Cs2|�ttf��tdgdddi�W5QRXdS)Nrjr�r�i)r{r�r�r�r$r
r
r�test_product_overflow?sz"TestBasicOps.test_product_overflowc
CsH|�tttttdd����d�|�ttttttdd�����d�dS)Nrir�r)rXr�r�rzr�r�r�r	r$r
r
r�test_product_tuple_reuseDs z%TestBasicOps.test_product_tuple_reusec	Cs�gdgfdgddgftd�td�gddd	d
ddgftd
�td�td�ggftd�td
�td�ggftd�td�td
�ggffD]`\}}|�tt�t|���|�|�tt�t|���|�ttjd�D]}|�|t|��q�q~dS)Nr
rjr�rnrrbror�r�r�rpr�rr)	rrXr	r�r�r�rBrra)r%rr�rFr
r
r�test_product_picklingIs�z"TestBasicOps.test_product_picklingcCsLtdd�}|�d�|�t|�d�tddd�}|�d�|�tt|�dS)Nr�)rb)r�)rrbr
)rrr�)r�r�rXrZr{r()r%r�r
r
r�test_product_issue_25021Xs


z%TestBasicOps.test_product_issue_25021cCs�|�ttddd��dddg�|�ttd�td��dddg�|�ttdd��dddg�|�tdtd��dddg�|�ttdd��g�|�ttdd��g�|�tt�|�ttddd	�|�ttdd�td
�}|�t|�d�td
d�}|�t|�d
�t|�|�t|�d�tddd�}|�t	|�d�|�tdt
�
|��td��|�tdt
�|��td��ttj
d�D]}|�|tddd���q|dS)Nr^rb)�object�times)rr^)rr^)rr^rrrLy�?zrepeat((1+0j))rlzrepeat((1+0j), 5)zrepeat((1+0j), 0)r@rZaar)rXr	r�rrr1r{rSrrZr�r�rBrra)r%r<r`rFr
r
r�test_repeatbs.�
zTestBasicOps.test_repeatcCs`|�ttdd��d�|�ttdd��d�|�ttddd��d�|�ttddd��d�dS)Nr^r�zrepeat('a', 0)r��r�)rXrr�r$r
r
r�test_repeat_with_negative_times|sz,TestBasicOps.test_repeat_with_negative_timesc	Cs�|�tttjtd�tdd���dddg�|�tttdtd���dd	d
g�|�tttdt���dd	d
g�|�tdttdt���dd	g�|�tttjg��g�|�	t
t�|�	t
ttdtd�td���|�	t
ttj�|�	t
ttdtd���|�	t
tttd
gdg��|�	t
tttd
gdg��dd	d
g}ttdt��}|�tt�|��|�ttdt��}|�tt�|��|�ttjd�D] }ttdt��}|�||��q�dS)Nrbrrkrrmrirlrrrrr@rL)rXr	rzr3�powrrrr1r{rS�negrZrrrr�r�rBrrarDr
r
r�test_map�s6����
zTestBasicOps.test_mapc
Cs�|�tttjttd�tdd����dddg�|�tdttjtt�td����dddg�|�tttjg��g�|�tttjt	ddg�g��dg�|�
ttttjdg��|�
tt�|�
tttjd	gd
�|�
tttdd	g��|�
t
tttd	g��|�
ttttd	g��dddg}ttjttd�tdd���}|�tt�|��|�ttjttd�tdd���}|�tt�|��|�ttjd�D].}ttjttd�tdd���}|�||��q�dS)NrbrrkrrmrLrli�rLrl�extrar@)rXr	�starmapr3r�r
rr1rr�r{rSrZrrrr�r�rBrrarDr
r
r�test_starmap�s,"� �$
zTestBasicOps.test_starmapc		CsHdD]*}|�tttd�f|���tt|���qdD].\}}|�tttd�f|���tt|���q4|�tttd�d��ttd���|�tttd�dd��ttd���|�tttd�ddd��ttd���|�tttd�dd��ttdd���|�tttd�ddd��ttddd���ttd��}|�tt|d��ttd���|�t|�ttdd���ttd��}|�tt|dd��g�|�t|�ttdd���td�}|�tt|�|�tt|dddd�|�tt|d	dd�|�tt|dd	d
�|�tt|ddd
�|�tt|ddd�|�tt|d�|�tt|dd�|�tt|dd�|�tt|ddd�|�tt|ddd�|�tttt	�ddt
���d�t	�}|�tt|ddd
��dg�|�t|�d�dD]�}|�tt�ttd�f|����tt|���|�tt�
ttd�f|����tt|���ttjd�D] }|�|ttd�f|����q:�q�dd�dD�}t�|�}t|d�}|�|��t|�t��|�|��Gdd�dt�}|�tttd�|d���ttd���|�tttd�|d�|d
���ttdd
���|�tttd�|d�|d
�|d���ttdd
d���dS)N)�r@rvrb�r@rbrv�r@rv)r@r@�r@rb�rvrr)))r@rsrb)r@rrrb))r@rs)r@rr))rs)rrr@rrrbrL���r�rr^�2)r�r�r�r�r�css|]
}|VqdSrr
r�r
r
rr�sz+TestBasicOps.test_islice.<locals>.<genexpr>r�c@seZdZdd�Zdd�ZdS)z)TestBasicOps.test_islice.<locals>.IntLikecSs
||_dSr��val�r%r�r
r
rrhsz2TestBasicOps.test_islice.<locals>.IntLike.__init__cSs|jSrr�r$r
r
r�	__index__sz3TestBasicOps.test_islice.<locals>.IntLike.__index__N)r*r+r,rhr�r
r
r
r�IntLikesr�rl)rXr	r/rr�r{rSrr�rrrZr�r�rBrra�weakref�refZassertIsNotNoner�
gc_collectZassertIsNoner�)	r%rZtgtargsrTZrar`rF�wrr�r
r
r�test_islice�sv
�
�"$&&* 
�
�"

&�$�zTestBasicOps.test_islicecCsNddddddddg}|�ttt|��dddg�|�tttg��g�|�tt�|�tttj�|�tttjd	gd
�|�tttdd	g��|�t	ttt
d	g��ttddddddg�}|�t|�dddg�|�tt|�|�tt
�
tt|���dddg�|�tt
�tt|���dddg�ttjd�D]}|�|tt|���q0dS)
NrrbrlrvrrLrcrmr�r�r@r)rXr	�	takewhilerAr{rSr3r�rZrrrCr(r�r�rrBrra)r%r�r�rFr
r
r�test_takewhiles""�zTestBasicOps.test_takewhilecCs ddddddddg}|�ttt|��dddddg�|�tttg��g�|�tt�|�tttj�|�tttjd	gd
�|�tttdd	g��|�t	ttt
d	g��|�tt�tt|���dddddg�|�tt�tt|���dddddg�t
tjd�D]}|�|tt|���qdS)NrrbrlrvrrLrcrmr�r�r@)rXr	�	dropwhilerAr{rSr3r�rZrrr�r�rrBrra)r%r�rFr
r
r�test_dropwhile-s &�zTestBasicOps.test_dropwhilecCsd}tg�\}}|�t|�g�|�t|�g�tt|��\}}|�t||�tt|�t|���tt|��\}}|�t|�tt|���|�t|�tt|���tt|��\}}td�D]}|�t|�|�q�~|�t|�tt|���tt|��\}}td�D]}|�t|�|��q~|�t|�ttd|���td�D]�}dg|dg|}t�|�ggf}tt|��}|D] }t||�}	||�	|	��qv|�|dtt|���|�|dtt|����q<|�
tt�|�
ttd�|�
ttddgd�|�
ttddgdd�td	�\}}t|�d
�}
|�t|
�td
��ttd�d�\}}}
td�D]}|�t|�|��qX|�t|�ttd���|�t|
�t|
�gttd���|�t|�ttdd���|�t|
�ttdd���|�
ttd	d�|�
t
tgd
�td�D]P}td	|�}|�t|�t�|�t|�|�|�dd�|D�td	�g|��qtd	�\}}t|�\}
}|�||
k�td	�\}
}t|
�}|�
t|�|�
t|d�||
�}|�t|
�t|�k�o�t|�k�o�td	�kn�ttd��\}}t�|�}|�t|d�t|��~|�
tt|d�td	�}ttd��}td	�\}}|�tt�|��|�|�tt�|��|�tttd���\}}|�tt�|��|�|�tt�|��|�td	�\}}td|�td|�|�tt�|��|dd��|�tt�|��|dd��|�t|�|dd��|�t|�|dd��ttd��\}}td|�td|�|�tt�|��|dd��|�tt�|��|dd��|�t|�|dd��|�t|�|dd��td	�\}}|�tt�|��|�|�tt�|��|�|�t|�|�|�t|�|�ttd��\}}|�tt�|��|�|�tt�|��|�|�t|�|�|�t|�|�td	�\}}td|�td|�|�tt�|��|dd��|�tt�|��|dd��|�t|�|dd��|�t|�|dd��ttd��\}}td|�td|�|�tt�|��|dd��|�tt�|��|dd��|�t|�|dd��|�t|�|dd��ttjd�D]F}|�|ttd	���td	�\}}|j|||d�|j|||d��q�dS)N��rrrlrrrbrrrir�rS�invalidr�cSsg|]}t|��qSr
�r	r�r
r
rrJ~sz)TestBasicOps.test_tee.<locals>.<listcomp>r@�	__class__r��<r�)�teerXr	r"rrrZrx�shuffler=r{rSrYrr�r�r�r��proxy�getattr�ReferenceErrorr�r1r�rBrrar�)r%r!r^r_rr��orderZlistsZitsrr`r�r��t1�t2ZtnewZt3r�rEZlong_ansrFr
r
r�test_tee>s� 
 
$<








zTestBasicOps.test_teecCs8ttdd��\}}zt|�~Wn~~�YnXdS)Ni-1)r�r�rs)r%ZforwardZbackwardr
r
r�test_tee_del_backward�sz"TestBasicOps.test_tee_del_backwardc	sDG�fdd�d�}t|��\}�|�td��t|�W5QRXdS)Ncs$eZdZdZdd�Z�fdd�ZdS)z(TestBasicOps.test_tee_reenter.<locals>.ITcSs|Srr
r$r
r
rr&�sz1TestBasicOps.test_tee_reenter.<locals>.I.__iter__cs|j}d|_|rt��SdS�NF)�firstrZ)r%r�rnr
rr)�sz1TestBasicOps.test_tee_reenter.<locals>.I.__next__N)r*r+r,r�r&r)r
rnr
r�I�sr�r�)r��assertRaisesRegexrPrZ)r%r�r^r
rnr�test_tee_reenter�s
zTestBasicOps.test_tee_reenterc	s�t���t���G��fdd�d�}t|��\}}tjt|gd�}|��z,���|�	t
d��t|�W5QRXW5���|��XdS)Ncs"eZdZdd�Z��fdd�ZdS)z+TestBasicOps.test_tee_concurrent.<locals>.IcSs|Srr
r$r
r
rr&�sz4TestBasicOps.test_tee_concurrent.<locals>.I.__iter__cs������dSr)r��waitr$�Zfinishrr
rr)�sz4TestBasicOps.test_tee_concurrent.<locals>.I.__next__N)r*r+r,r&r)r
r�r
rr��sr�)r^rr�)�	threading�Eventr��ThreadrZrr��joinr�r�rP)r%r�r^r_�threadr
r�r�test_tee_concurrent�sz TestBasicOps.test_tee_concurrentcCs$|�ttt��ttttfD]*}|�tt|g��|�tt|t���q|�tttgd��|�tttt�d��t	g�\}}|�tt|�|�tt|�t	t��\}}|�tt|�|�tt|�|�ttt
dd��ttt
tttfD]6}|�tt|dd�g��|�tt|dd�t���q�dS)NrcSs|Srr
rr
r
rrGrHz1TestBasicOps.test_StopIteration.<locals>.<lambda>cSs|Srr
rr
r
rrGrH)r{r(rZr
r�rr�r#r/r�r�r�rGrzr�r�r�)r%r�r��qr
r
r�test_StopIterations zTestBasicOps.test_StopIterationcCs6tdggd�}t|�t��|�t�t|���dSr2)r�rZ�gc�collectr��
is_trackedr�r
r
r�test_combinations_result_gcsz(TestBasicOps.test_combinations_result_gccCs6tdggd�}t|�t��|�t�t|���dSr2)r�rZr�r�r�r�r�r
r
r�,test_combinations_with_replacement_result_gc$sz9TestBasicOps.test_combinations_with_replacement_result_gccCs6tdggd�}t|�t��|�t�t|���dSr2)r�rZr�r�r�r�r�r
r
r�test_permutations_result_gc,sz(TestBasicOps.test_permutations_result_gccCs4tdgg�}t|�t��|�t�t|���dSr)r�rZr�r�r�r�r�r
r
r�test_product_result_gc4sz#TestBasicOps.test_product_result_gccCs*tgg�}t��|�t�t|���dSr)rZr�r�r�r�rZr�r
r
r�test_zip_longest_result_gc<s
z'TestBasicOps.test_zip_longest_result_gc)rLrN)<r*r+r,rar�r�r�r�r�r�rZbigaddrspacetestr�Zimpl_detailr�r�r�r�r�r�r�r�rrrr!r$rBrFrIrNrRr_r`rarfrmr|r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r��cpython_onlyr�r�r�r�r�r
r
r
rrKRs�
)#

P

L

?

!"07*$

*
(:


^	



rKc@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#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/S)0�TestExamplesc	Cs,|�ttdddddg��dddddg�dS�	NrrrbrLrlrcr@rd)rXr	rwr$r
r
rr�FszTestExamples.test_accumulatec
Cs�dddddg}dddddg}ttjd�D]h}t|�}|�tt�t�||���|dd��|�t|�d�|�tt�t�||���|dd��q*t|�}|�t|�d�|�tt	�
|��|dd��|�tt	�	|��|dd��dSr�)rrBrrwrXr	rCrDrZr�r�)r%r�ZaccumulatedrFrTr
r
r�test_accumulate_reducibleIs&(z&TestExamples.test_accumulate_reduciblecCs�tdddgtj�}|�t|�d�ttjd�D]*}t�t�	||��}|�t
|�ddg�q0|�t
t�|��ddg�|�t
t�|��ddg�dS)NrTF)
rwr3�is_rXrZrrBrrCrDr	r�r�)r%rTrFZit_copyr
r
r�test_accumulate_reducible_noneXsz+TestExamples.test_accumulate_reducible_nonecCs|�d�tdd��d�dS�Nr�r�ZDEFr�)rXr�r�r$r
r
rr�bszTestExamples.test_chaincCs |�d�t�ddg��d�dSr�)rXr�r�r�r$r
r
rr�esz%TestExamples.test_chain_from_iterablec	CsH|�ttdd��ddddddg�|�tttd	�d
��ddd
dg�dS)Nr�rr�r�r�r�r�r�rLrbrr�r�r�)rXr	r�rr$r
r
rr�hs�
�zTestExamples.test_combinationsc	Cs&|�ttdd��ddddddg�dS)	Nr�rr�r�r�r�r�r�)rXr	r�r$r
r
rr�ns�z/TestExamples.test_combinations_with_replacementcCs*|�ttdddddddg��td��dS)Nr�rrr�)rXr	rr$r
r
rrrszTestExamples.test_compresscCs(|�tttd�d��dddddg�dS)Nr@rlr'r�r(r))rXr	r/rr$r
r
rruszTestExamples.test_countcCs"|�tttd�d��td��dS)Nr�r�ZABCDABCDABCD)rXr	r/rr$r
r
rr!xszTestExamples.test_cyclec
Cs.|�ttdd�dddddg��dddg�dS)NcSs|dkS�Nrlr
rr
r
rrG|rHz-TestExamples.test_dropwhile.<locals>.<lambda>rrLrc)rXr	r�r$r
r
rr�{szTestExamples.test_dropwhilecCsT|�dd�td�D�td��|�dd�td�D�td�td�td	�td
�g�dS)NcSsg|]\}}|�qSr
r
r,r
r
rrJsz-TestExamples.test_groupby.<locals>.<listcomp>ZAAAABBBCCDAABBBZABCDABcSsg|]\}}t|��qSr
r�r,r
r
rrJ�sZ
AAAABBBCCDZAAAAZBBBZCCr�)rXr�r	r$r
r
rrB~s��zTestExamples.test_groupbycCs,|�ttdd�td���dddddg�dS)	NcSs|dSr>r
rr
r
rrG�rHz*TestExamples.test_filter.<locals>.<lambda>r@rrbrlrkrn)rXr	r�rr$r
r
rrF�szTestExamples.test_filtercCs,|�ttdd�td���dddddg�dS)	NcSs|dSr>r
rr
r
rrG�rHz/TestExamples.test_filterfalse.<locals>.<lambda>r@rrrLrcrm)rXr	rGrr$r
r
rrI�szTestExamples.test_filterfalsecCs"|�tttdd��dddg�dS)N)rrbr@)rlrrbr�rnr
)rXr	rzr�r$r
r
rr��szTestExamples.test_mapcCst|�ttdd��td��|�ttddd��td��|�ttddd��td��|�ttdddd��td��dS)	Nr�r�ABrL�CD�CDEFGr�ACEG)rXr	r/r$r
r
rr��szTestExamples.test_islicecCs|�ttdd��ddg�dS)Nr��xy�r�r�r�rK)rXr	r
r$r
r
rrN�szTestExamples.test_zipcCs&|�ttdddd��ddddg�dS)	Nr�r��-rXr�r�)r�r�)r�r�)rXr	rZr$r
r
r�test_zip_longest�s
�zTestExamples.test_zip_longestc	CsL|�ttdd��tttd�����|�tttd���ddddd	d
g�dS)Nr�rz#AB AC AD BA BC BD CA CB CD DA DB DCrbr)rrr)rrr)rrr)rrr)rrr)rXr	r�rzr��splitrr$r
r
rr��s��zTestExamples.test_permutationscCsT|�ttdd��tttd�����|�tttd�dd��ddd	d
ddd
dg�dS)Nr�r�zAx Ay Bx By Cx Cy Dx Dyrrbr�)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rXr	r�rzr�r�rr$r
r
rr|�s���zTestExamples.test_productcCs |�ttdd��dddg�dS)Nr@rb)rXr	r�r$r
r
rr��szTestExamples.test_repeatcCs&|�tttdddg��dddg�dS)N)rrl)rbrr�r�rnr
)rXr	r�r�r$r
r
r�test_stapmap�s�zTestExamples.test_stapmapc
Cs,|�ttdd�dddddg��ddg�dS)NcSs|dkSr�r
rr
r
rrG�rHz-TestExamples.test_takewhile.<locals>.<lambda>rrLrc)rXr	r�r$r
r
rr��szTestExamples.test_takewhileN)r*r+r,r�r�r�r�r�r�r�rrr!r�rBrFrIr�r�rNr�r�r|r�r�r�r
r
r
rr�Ds.
r�c@s eZdZedd��Zdd�ZdS)�TestPurePythonRoughEquivalentsc
gs�t|�}|jpd|jptj|jp"d}}}tt|||��}zt|�}Wn.t	k
rvt
t|�|�D]\}}	qfYdSXz,t|�D]\}}	||kr�|	Vt|�}q�Wn2t	k
r�t
t|d|�|�D]\}}	q�YnXdSr�)�slicerrWrrrr�rrZr(r
�	enumerate)
r6rrErrWrrTZnextirr�r
r
rr/�s"$z%TestPurePythonRoughEquivalents.islicec	Cs6|�t|�dd��td��|�t|�ddd��td��|�t|�ddd��td��|�t|�dddd��td��ttd	��}|�t|�|d
��ttd
���|�t|�ttd
d	���ttd	��}|�t|�|d
d
��g�|�t|�ttd
d	���t�}|�t|�|dd
d��dg�|�t|�d
�dS)
Nr�rr�rLr�r�rr�r@rbrr�)rXr	r/r�rrrZ)r%rTr`r
r
r�test_islice_recipe�s  z1TestPurePythonRoughEquivalents.test_islice_recipeN)r*r+r,�staticmethodr/r�r
r
r
rr��s
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#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/S)0�TestGCcCs|�|�t|�~~dSr)r=rZ)r%�iterator�	containerr
r
r�	makecycle�s
zTestGC.makecyclecCs g}|�tdd|dg�|�dS�Nrrrb)r�rw�r%r^r
r
rr��szTestGC.test_accumulatecCsg}|�t|�|�dSr)r�r�r�r
r
rr��szTestGC.test_chaincCsg}|�t�|g�|�dSr)r�r�r�r�r
r
rr��szTestGC.test_chain_from_iterablecCs"g}|�tdd|dgd�|�dSr�)r�r�r�r
r
rr��szTestGC.test_combinationscCs"g}|�tdd|dgd�|�dSr�)r�r�r�r
r
rr��sz)TestGC.test_combinations_with_replacementc
Cs&g}|�tdddddddg�|�dS)Nr�rr)r�rr�r
r
rr�szTestGC.test_compresscCs6g}tdtft|d��}|�t|d�|d��|�dS)N�Intrrr)rYrxrOr�r)r%r^r�r
r
rr�szTestGC.test_countcCsg}|�t|gd�|�dSr>)r�rr�r
r
rr!szTestGC.test_cyclecCs g}|�ttd||g�|�dSr:)r�r�rCr�r
r
rr�szTestGC.test_dropwhilecCs$g}|�t|gddd��|�dS)NrcSs|Srr
rr
r
rrG
rHz%TestGC.test_groupby.<locals>.<lambda>)r�r�r�r
r
rrBszTestGC.test_groupbycCs>d}dd�}tt|�|d�D]\}}|j�dg��|�qdS)Nr@cSs|Srr
rr
r
rrGrHz'TestGC.test_issue2246.<locals>.<lambda>r%r)r�r�__dict__�
setdefaultr=)r%r!r<rr�r
r
r�test_issue2246szTestGC.test_issue2246cCs$g}|�tdd�|gd�|�dS)NcSsdS)NTr
rr
r
rrGrHz$TestGC.test_filter.<locals>.<lambda>r)r�r�r�r
r
rrFszTestGC.test_filtercCsg}|�tdd�|�|�dS)NcSsdSr�r
rr
r
rrGrHz)TestGC.test_filterfalse.<locals>.<lambda>)r�rGr�r
r
rrIszTestGC.test_filterfalsecCs&g}|�t|gd|gd�|�dS)Nrrb)r�r
r�r
r
rrNszTestGC.test_zipcCsPg}|�t|gd|gd�|�|dg}|�t|gd|gd|d�|�dS)NrrbrX)r�rZ)r%r^r_r
r
rr�szTestGC.test_zip_longestcCs$g}|�tdd�|gd�|�dS)NcSs|Srr
rr
r
rrG'rHz!TestGC.test_map.<locals>.<lambda>r)r�rzr�r
r
rr�%szTestGC.test_mapcCs g}|�t|gdd�|�dSr>)r�r/r�r
r
rr�)szTestGC.test_islicecCs"g}|�tdd|dgd�|�dSr�)r�r�r�r
r
rr�-szTestGC.test_permutationscCs$g}|�tdd|dgdd�|�dS)Nrrrbr�)r�r�r�r
r
rr|1szTestGC.test_productcCsg}|�t|�|�dSr)r�r�r�r
r
rr�5szTestGC.test_repeatcCs(g}|�tdd�||fgd�|�dS)NcWs|Srr
�r�r
r
rrG;rHz%TestGC.test_starmap.<locals>.<lambda>r)r�r�r�r
r
rr�9szTestGC.test_starmapcCs"g}|�ttdd||g�|�dS)Nrr)r�r�rCr�r
r
rr�=szTestGC.test_takewhileN)r*r+r,r�r�r�r�r�r�rrr!r�rBr�rFrIrNr�r�r�r�r|r�r�r�r
r
r
rr��s.r�ccs|D]
}|VqdS)zRegular generatorNr
��seqnrr
r
r�RAsr�c@s eZdZdZdd�Zdd�ZdS)�GzSequence using __getitem__cCs
||_dSr�r��r%r�r
r
rrhHsz
G.__init__cCs
|j|Srr�)r%rr
r
r�__getitem__Jsz
G.__getitem__N)r*r+r,r-rhr�r
r
r
rr�Fsr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r�z Sequence using iterator protocolcCs||_d|_dSr:r�r�r
r
rrhOsz
I.__init__cCs|Srr
r$r
r
rr&Rsz
I.__iter__cCs2|jt|j�krt�|j|j}|jd7_|Sr2�rr�r�r(�r%r�r
r
rr)Ts
z
I.__next__N�r*r+r,r-rhr&r)r
r
r
rr�Msr�c@s eZdZdZdd�Zdd�ZdS)�Igz9Sequence using iterator protocol defined with a generatorcCs||_d|_dSr:r�r�r
r
rrh\szIg.__init__ccs|jD]
}|VqdSrr�r�r
r
rr&_s
zIg.__iter__N�r*r+r,r-rhr&r
r
r
rr�Zsr�c@s eZdZdZdd�Zdd�ZdS)rWz Missing __getitem__ and __iter__cCs||_d|_dSr:r�r�r
r
rrhesz
X.__init__cCs2|jt|j�krt�|j|j}|jd7_|Sr2r�r�r
r
rr)hs
z
X.__next__N)r*r+r,r-rhr)r
r
r
rrWcsrWc@s eZdZdZdd�Zdd�ZdS)�NzIterator missing __next__()cCs||_d|_dSr:r�r�r
r
rrhpsz
N.__init__cCs|Srr
r$r
r
rr&ssz
N.__iter__Nr�r
r
r
rr�nsr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�EzTest propagation of exceptionscCs||_d|_dSr:r�r�r
r
rrhxsz
E.__init__cCs|Srr
r$r
r
rr&{sz
E.__iter__cCsdddS)Nrbrr
r$r
r
rr)}sz
E.__next__Nr�r
r
r
rr�vsr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�SzTest immediate stopcCsdSrr
r�r
r
rrh�sz
S.__init__cCs|Srr
r$r
r
rr&�sz
S.__iter__cCst�dSrr'r$r
r
rr)�sz
S.__next__Nr�r
r
r
rr��sr�cCsttdd�ttt|�����S)z Test multiple tiers of iteratorscSs|Srr
rr
r
rrG�rHzL.<locals>.<lambda>)r�rzr�r�r�r�r
r
r�L�sr�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!S)"�TestVariousIteratorArgscCs�dddddg}dddddg}t|�}tttttfD]}|�tt||���|�q2|�ttt	|���g�|�
ttt|��|�
ttt
|��|�
tttt|���dSr�)r�r�r�r�r�r�rXr	rwr�r{rSrWr��ZeroDivisionErrorr�)r%rEr<r!r-r
r
rr��sz'TestVariousIteratorArgs.test_accumulatec	Cs�ddtd�dtddd�fD]�}ttttttfD]V}|�tt	||���t||���|�tt	||�||���t||��t||���q.|�
ttt	t|���|�
ttt	t
|���|�
ttt	t|���qdS�N�123r�r
�Zdog333333�?rS�rl)rr�r�r�r�r�r�rXr	r�r{rSrWr�r�r��r%rEr-r
r
rr��s 4z"TestVariousIteratorArgs.test_chainc	Cs�ddtd�dtddd�fD]�}t|�}ttttttfD]*}|�t	t
||�td���t	||���q6|�t
t
t|�td��|�t
t
t|�td��|�tt	t
t|�td���qdS)	Nr�r�r
rrSrrlr)rr�r�r�r�r�r�r�rXr	rr�r{rSrWr�r�r�)r%rEr!r-r
r
rr�s(z%TestVariousIteratorArgs.test_compresscCsZddtd�dtddd�fD]:}|�ttt|��|�ttt|��|�ttt|��qdSr�)rr{rSr�rWr�r�r�)r%rEr
r
rr|�sz$TestVariousIteratorArgs.test_productcCs�ddtd�dtddd�fD]�}ttttttfD]B}t|�d}t||��d}tt	t
||��|��}|�||�q.|�t
t
t|��|�t
t
t|��|�ttt
t|���qdS)	Nr�r�r
rrSrrlrb)rr�r�r�r�r�r�r�r	r/rrXr{rSrWr�r�r�)r%rEr-ZtgtlenZexpected�actualr
r
rr!�sz"TestVariousIteratorArgs.test_cyclecCs�td�td�td�dtddd�fD]z}ttttttfD]*}|�dd	�t||��D�t	||���q6|�
ttt|��|�
ttt
|��|�
tt	tt|���q"dS)
Nr@rr
�rkr'rSrrlcSsg|]\}}|�qSr
r
)rIr�Zsbr
r
rrJ�sz8TestVariousIteratorArgs.test_groupby.<locals>.<listcomp>)rr�r�r�r�r�r�rXr�r	r{rSrWr�r�r�rr
r
rrB�s&(z$TestVariousIteratorArgs.test_groupbyc	Cs�td�td�td�dtddd�fD]�}ttttttfD],}|�tt	t
||���dd	�||�D��q6|�tt	t
t
|��|�tt	t
t|��|�ttt	t
t|���q"dS)
Nr@rr
rrSrrlcSsg|]}t|�r|�qSr
)rr�r
r
rrJ�sz7TestVariousIteratorArgs.test_filter.<locals>.<listcomp>)rr�r�r�r�r�r�rXr	r�rr{rSrWr�r�r�rr
r
rrF�s&�z#TestVariousIteratorArgs.test_filterc	Cs�td�td�td�dtddd�fD]�}ttttttfD],}|�tt	t
||���dd	�||�D��q6|�tt	t
t
|��|�tt	t
t|��|�ttt	t
t|���q"dS)
Nr@rr
rrSrrlcSsg|]}t|�r|�qSr
)rr�r
r
rrJ�sz<TestVariousIteratorArgs.test_filterfalse.<locals>.<listcomp>)rr�r�r�r�r�r�rXr	rGrr{rSrWr�r�r�rr
r
rrI�s&�z(TestVariousIteratorArgs.test_filterfalsec	Cs�ddtd�dtddd�fD]�}ttttttfD]P}|�tt	||���t
||���|�tt	||�||���t
||�||���q.|�tt	t
|��|�tt	t|��|�ttt	t|���qdSr�)rr�r�r�r�r�r�rXr	r
rr{rSrWr�r�r�rr
r
rrN�s .z TestVariousIteratorArgs.test_zipc
Cs�ddtd�dtddd�fD]�}ttttttfD]X}|�tt	||���tt
||����|�tt	||�||���tt
||�||����q.|�tt	t
|��|�tt	t|��|�ttt	t|���qdSr�)rr�r�r�r�r�r�rXr	rZr
r{rSrWr�r�r�rr
r
rr_�s$2z'TestVariousIteratorArgs.test_ziplongestc
Cs�td�td�td�dtddd�fD]�}ttttttfD]\}|�tt	t
||���dd	�||�D��|�tt	tj||�||���d
d	�||�D��q6|�
tt	t
t|��|�
tt	t
t|��|�
ttt	t
t|���q"dS)Nr@rrrrrvr�rlcSsg|]}t|��qSr
)rr�r
r
rrJ�sz4TestVariousIteratorArgs.test_map.<locals>.<listcomp>cSsg|]}||�qSr
r
r�r
r
rrJ�s)rr�r�r�r�r�r�rXr	rzrr3r�r{rSrWr�r�r�rr
r
rr��s&��z TestVariousIteratorArgs.test_mapc
Cs�ddtd�dtddd�fD]�}ttttttfD]4}|�tt	||�ddd	��t||��ddd	��q.|�
tt	t|�d
�|�
tt	t
|�d
�|�
ttt	t|�d
��qdS)NZ12345r�r
rrSrrlrrr@)rr�r�r�r�r�r�rXr	r/r{rSrWr�r�r�rr
r
rr��s2z#TestVariousIteratorArgs.test_islicec	Cs�td�td�td�dtddd�fD]�}ttttttfD]8}t||�}|�t	t
tj||���dd	�||�D��q6|�
tt
tjt|��|�
tt
tjt|��|�
tt	t
tjt|���q"dS)
Nr@rrrrrvr�rlcSsg|]}||�qSr
r
r�r
r
rrJsz8TestVariousIteratorArgs.test_starmap.<locals>.<listcomp>)rr�r�r�r�r�r�rrXr	r�r3r�r{rSrWr�r�r�)r%rEr-�ssr
r
rr��s&
�z$TestVariousIteratorArgs.test_starmapc	Cs�td�td�td�dtddd�fD]�}ttttttfD]F}g}||�D]}t|�sVqb|�|�qF|�	t
tt||���|�q6|�t
ttt|��|�t
ttt|��|�tt
ttt|���q"dS�Nr@rr
rrSrrl)rr�r�r�r�r�r�rr=rXr	r�r{rSrWr�r�r��r%rEr-Ztgtr@r
r
rr�s&z&TestVariousIteratorArgs.test_takewhilec	Cs�td�td�td�dtddd�fD]�}ttttttfD]H}g}||�D]}|sXt|�rXqF|�|�qF|�	t
tt||���|�q6|�t
ttt|��|�t
ttt|��|�tt
ttt|���q"dSr)rr�r�r�r�r�r�rr=rXr	r�r{rSrWr�r�r�rr
r
rr�s&z&TestVariousIteratorArgs.test_dropwhilecCs�ddtd�dtddd�fD]�}ttttttfD]D}t||��\}}|�t	|�t	||���|�t	|�t	||���q.|�
ttt|��|�
ttt
|��|�
tt	tt|��d�qdS)	Nr�r�r
rrSrrlr)rr�r�r�r�r�r�r�rXr	r{rSrWr�r�r�)r%rEr-Zit1Zit2r
r
rr�sz TestVariousIteratorArgs.test_teeN)r*r+r,r�r�rr|r!rBrFrIrNr_r�r�r�r�r�r�r
r
r
rr��s 						
r�c@seZdZdd�Zdd�ZdS)�LengthTransparencycCsL|�t�tdd��d�|�t�tdd��d�|�t�td�d�d�dS)Nr�rr��rXr3�length_hintr�r$r
r
rr�+szLengthTransparency.test_repeatcCsh|�t�tdd��d�|�t�tdd��d�|�t�tddd��d�|�t�tddd��d�dS)Nr�rr�r�r	r$r
r
rr�0sz2LengthTransparency.test_repeat_with_negative_timesN)r*r+r,r�r�r
r
r
rr)src@s:eZdZdd�Zdd�Zejdd��Zdd�Zd	d
�Z	dS)�RegressionTestscs<dd�}�fdd�}g�|d|d�tt�}|��|�dS)NcsTdgf��fdd�	}t|�}t|�|dd�<t||�}t|gt|���t��dS)Nrcs|r|dd�=�t���|Srr)rr��r��zr
rr-?s
z@RegressionTests.test_sf_793826.<locals>.mutatingtuple.<locals>.g)r	rzr
r�rZ)Ztuple1r�Ztuple2r-�items�genr
rr�
mutatingtuple;s
z5RegressionTests.test_sf_793826.<locals>.mutatingtuplecs|att��dd�<dSr)�Tr	r��r�r
rr�Jsz)RegressionTests.test_sf_793826.<locals>.fr�)rLrlrc)r	rrX)r%rr��secondr
rr�test_sf_7938268szRegressionTests.test_sf_793826cs��fdd�}�fdd�}g�|�ttt|�|d���|��ddg�g�|�ttt|�|d���|��ddg�g�|�ttt|���|��ddg�dS)	Nc3s,��d�dV��d�t���d�dS)Nrrr)r=�AssertionErrorr
�Zhistr
r�gen1Ys


z,RegressionTests.test_sf_950057.<locals>.gen1c3s��d�dV��d�dS)NrbrrL)r=rrr
r�gen2`s
z,RegressionTests.test_sf_950057.<locals>.gen2FrrT)r{rr	r�rXr)r%rrr
rr�test_sf_950057UszRegressionTests.test_sf_950057c	Cs:t�dd�td�D��}|�t��t|�W5QRXdS)Ncss|]
}dVqdS)r
Nr
)rIZunusedr
r
rr�vszERegressionTests.test_long_chain_of_empty_iterables.<locals>.<genexpr>i���)r�r�rr{r(rZr�r
r
r�"test_long_chain_of_empty_iterablesqsz2RegressionTests.test_long_chain_of_empty_iterablescs0�fdd�}ttd�|�D]\}�t��qdS)Ncs|dkrt��|dkS)Nrlrcr�r8rnr
rr�{sz,RegressionTests.test_issue30347_1.<locals>.fr@)r�rr	)r%r�r�r
rnr�test_issue30347_1zsz!RegressionTests.test_issue30347_1csJG��fdd�d�}d�tttd�|��d�td�D]}t�d�q6dS)Ncs"eZdZdd�Z��fdd�ZdS)z,RegressionTests.test_issue30347_2.<locals>.KcSsdSrr
r�r
r
rrh�sz5RegressionTests.test_issue30347_2.<locals>.K.__init__cs�d7��dkrt�d�dS)NrTr)r%�other�r-rr
rr7�s
z3RegressionTests.test_issue30347_2.<locals>.K.__eq__N)r*r+r,rhr7r
rr
r�K�srrr@rr)rZr�r)r%rr�r
rr�test_issue30347_2�s
	z!RegressionTests.test_issue30347_2N)
r*r+r,rrrZskip_if_pgo_taskrrrr
r
r
rr6s
rc@seZdZdd�ZdS)�SubclassWithKwargsTestcs~tttttttttt	t
tfD]\�G�fdd�d��}z|dd�Wqtk
rv}z|�
d|jd�W5d}~XYqXqdS)NcseZdZd�fdd�	ZdS)zBSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.SubclassNcs�j|f|��dSr)rh)r%�newargr��clsr
rrh�szKSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.Subclass.__init__)N)r*r+r,rhr
r"r
r�Subclass�sr$r)r!zkeyword argumentsr)r�r
r�rGr�rzr�r/r�r�rrrSZassertNotInr)r%r$�errr
r"r�test_keywords_in_subclass�s�z0SubclassWithKwargsTest.test_keywords_in_subclassN)r*r+r,r&r
r
r
rr �sr c@s:eZdZdd�ZejZdd�Zdd�Zdd�Zd	d
�Z	dS)�
SizeofTestcCst�d�|_dS)Nr!)�struct�calcsize�ssize_tr$r
r
r�setUp�szSizeofTest.setUpcCsFt�d�}|j}|tdd�|d|j�|td�|d|j�dS)NZ3PirjZ12r)
ririririririririririr@)r�calcobjsize�check_sizeofr�r*�r%�basesize�checkr
r
r�test_product_sizeof�s
zSizeofTest.test_product_sizeofcCsLt�d�}|j}|tdd�|d|j�|ttd�d�|d|j�dS�NZ3Pnir�rbr@rL)rr,r-r�r*rr.r
r
r�test_combinations_sizeof�s
z#SizeofTest.test_combinations_sizeofcCsPt}t�d�}|j}||dd�|d|j�||td�d�|d|j�dSr2)r�rr,r-r*r)r%r�r/r0r
r
r�)test_combinations_with_replacement_sizeof�s

z4SizeofTest.test_combinations_with_replacement_sizeofcCs�t�d�}|j}|td�|d|jd|j�|tdd�|d|jd|j�|tdd�|d|jd|j�|ttd�d�|d|jd|j�dS)NZ4Pnir�rLrbr�rlr@)rr,r-r�r*rr.r
r
r�test_permutations_sizeof�s
�
�
��z#SizeofTest.test_permutations_sizeofN)
r*r+r,r+rr-r1r3r4r5r
r
r
rr'�sr'a�" Doctest for examples in the library reference: libitertools.tex


>>> amounts = [120.15, 764.05, 823.14]
>>> for checknum, amount in zip(count(1200), amounts):
...     print('Check %d is for $%.2f' % (checknum, amount))
...
Check 1200 is for $120.15
Check 1201 is for $764.05
Check 1202 is for $823.14

>>> import operator
>>> for cube in map(operator.pow, range(1,4), repeat(3)):
...    print(cube)
...
1
8
27

>>> reportlines = ['EuroPython', 'Roster', '', 'alex', '', 'laura', '', 'martin', '', 'walter', '', 'samuele']
>>> for name in islice(reportlines, 3, None, 2):
...    print(name.title())
...
Alex
Laura
Martin
Walter
Samuele

>>> from operator import itemgetter
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
>>> di = sorted(sorted(d.items()), key=itemgetter(1))
>>> for k, g in groupby(di, itemgetter(1)):
...     print(k, list(map(itemgetter(0), g)))
...
1 ['a', 'c', 'e']
2 ['b', 'd', 'f']
3 ['g']

# Find runs of consecutive numbers using groupby.  The key to the solution
# is differencing with a range so that consecutive numbers all appear in
# same group.
>>> data = [ 1,  4,5,6, 10, 15,16,17,18, 22, 25,26,27,28]
>>> for k, g in groupby(enumerate(data), lambda t:t[0]-t[1]):
...     print(list(map(operator.itemgetter(1), g)))
...
[1]
[4, 5, 6]
[10]
[15, 16, 17, 18]
[22]
[25, 26, 27, 28]

>>> def take(n, iterable):
...     "Return first n items of the iterable as a list"
...     return list(islice(iterable, n))

>>> def prepend(value, iterator):
...     "Prepend a single value in front of an iterator"
...     # prepend(1, [2, 3, 4]) -> 1 2 3 4
...     return chain([value], iterator)

>>> def enumerate(iterable, start=0):
...     return zip(count(start), iterable)

>>> def tabulate(function, start=0):
...     "Return function(0), function(1), ..."
...     return map(function, count(start))

>>> import collections
>>> def consume(iterator, n=None):
...     "Advance the iterator n-steps ahead. If n is None, consume entirely."
...     # Use functions that consume iterators at C speed.
...     if n is None:
...         # feed the entire iterator into a zero-length deque
...         collections.deque(iterator, maxlen=0)
...     else:
...         # advance to the empty slice starting at position n
...         next(islice(iterator, n, n), None)

>>> def nth(iterable, n, default=None):
...     "Returns the nth item or a default value"
...     return next(islice(iterable, n, None), default)

>>> def all_equal(iterable):
...     "Returns True if all the elements are equal to each other"
...     g = groupby(iterable)
...     return next(g, True) and not next(g, False)

>>> def quantify(iterable, pred=bool):
...     "Count how many times the predicate is true"
...     return sum(map(pred, iterable))

>>> def padnone(iterable):
...     "Returns the sequence elements and then returns None indefinitely"
...     return chain(iterable, repeat(None))

>>> def ncycles(iterable, n):
...     "Returns the sequence elements n times"
...     return chain(*repeat(iterable, n))

>>> def dotproduct(vec1, vec2):
...     return sum(map(operator.mul, vec1, vec2))

>>> def flatten(listOfLists):
...     return list(chain.from_iterable(listOfLists))

>>> def repeatfunc(func, times=None, *args):
...     "Repeat calls to func with specified arguments."
...     "   Example:  repeatfunc(random.random)"
...     if times is None:
...         return starmap(func, repeat(args))
...     else:
...         return starmap(func, repeat(args, times))

>>> def pairwise(iterable):
...     "s -> (s0,s1), (s1,s2), (s2, s3), ..."
...     a, b = tee(iterable)
...     try:
...         next(b)
...     except StopIteration:
...         pass
...     return zip(a, b)

>>> def grouper(n, iterable, fillvalue=None):
...     "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
...     args = [iter(iterable)] * n
...     return zip_longest(*args, fillvalue=fillvalue)

>>> def roundrobin(*iterables):
...     "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
...     # Recipe credited to George Sakkis
...     pending = len(iterables)
...     nexts = cycle(iter(it).__next__ for it in iterables)
...     while pending:
...         try:
...             for next in nexts:
...                 yield next()
...         except StopIteration:
...             pending -= 1
...             nexts = cycle(islice(nexts, pending))

>>> def powerset(iterable):
...     "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
...     s = list(iterable)
...     return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

>>> def unique_everseen(iterable, key=None):
...     "List unique elements, preserving order. Remember all elements ever seen."
...     # unique_everseen('AAAABBBCCDAABBB') --> A B C D
...     # unique_everseen('ABBCcAD', str.lower) --> A B C D
...     seen = set()
...     seen_add = seen.add
...     if key is None:
...         for element in iterable:
...             if element not in seen:
...                 seen_add(element)
...                 yield element
...     else:
...         for element in iterable:
...             k = key(element)
...             if k not in seen:
...                 seen_add(k)
...                 yield element

>>> def unique_justseen(iterable, key=None):
...     "List unique elements, preserving order. Remember only the element just seen."
...     # unique_justseen('AAAABBBCCDAABBB') --> A B C D A B
...     # unique_justseen('ABBCcAD', str.lower) --> A B C A D
...     return map(next, map(itemgetter(1), groupby(iterable, key)))

>>> def first_true(iterable, default=False, pred=None):
...     '''Returns the first true value in the iterable.
...
...     If no true value is found, returns *default*
...
...     If *pred* is not None, returns the first item
...     for which pred(item) is true.
...
...     '''
...     # first_true([a,b,c], x) --> a or b or c or x
...     # first_true([a,b], x, f) --> a if f(a) else b if f(b) else x
...     return next(filter(pred, iterable), default)

>>> def nth_combination(iterable, r, index):
...     'Equivalent to list(combinations(iterable, r))[index]'
...     pool = tuple(iterable)
...     n = len(pool)
...     if r < 0 or r > n:
...         raise ValueError
...     c = 1
...     k = min(r, n-r)
...     for i in range(1, k+1):
...         c = c * (n - k + i) // i
...     if index < 0:
...         index += c
...     if index < 0 or index >= c:
...         raise IndexError
...     result = []
...     while r:
...         c, n, r = c*r//n, n-1, r-1
...         while index >= c:
...             index -= c
...             c, n = c*(n-r)//n, n-1
...         result.append(pool[-1-n])
...     return tuple(result)


This is not part of the examples but it tests to make sure the definitions
perform as purported.

>>> take(10, count())
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

>>> list(prepend(1, [2, 3, 4]))
[1, 2, 3, 4]

>>> list(enumerate('abc'))
[(0, 'a'), (1, 'b'), (2, 'c')]

>>> list(islice(tabulate(lambda x: 2*x), 4))
[0, 2, 4, 6]

>>> it = iter(range(10))
>>> consume(it, 3)
>>> next(it)
3
>>> consume(it)
>>> next(it, 'Done')
'Done'

>>> nth('abcde', 3)
'd'

>>> nth('abcde', 9) is None
True

>>> [all_equal(s) for s in ('', 'A', 'AAAA', 'AAAB', 'AAABA')]
[True, True, True, False, False]

>>> quantify(range(99), lambda x: x%2==0)
50

>>> a = [[1, 2, 3], [4, 5, 6]]
>>> flatten(a)
[1, 2, 3, 4, 5, 6]

>>> list(repeatfunc(pow, 5, 2, 3))
[8, 8, 8, 8, 8]

>>> import random
>>> take(5, map(int, repeatfunc(random.random)))
[0, 0, 0, 0, 0]

>>> list(pairwise('abcd'))
[('a', 'b'), ('b', 'c'), ('c', 'd')]

>>> list(pairwise([]))
[]

>>> list(pairwise('a'))
[]

>>> list(islice(padnone('abc'), 0, 6))
['a', 'b', 'c', None, None, None]

>>> list(ncycles('abc', 3))
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']

>>> dotproduct([1,2,3], [4,5,6])
32

>>> list(grouper(3, 'abcdefg', 'x'))
[('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'x', 'x')]

>>> list(roundrobin('abc', 'd', 'ef'))
['a', 'd', 'e', 'b', 'f', 'c']

>>> list(powerset([1,2,3]))
[(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]

>>> all(len(list(powerset(range(n)))) == 2**n for n in range(18))
True

>>> list(powerset('abcde')) == sorted(sorted(set(powerset('abcde'))), key=len)
True

>>> list(unique_everseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D']

>>> list(unique_everseen('ABBCcAD', str.lower))
['A', 'B', 'C', 'D']

>>> list(unique_justseen('AAAABBBCCDAABBB'))
['A', 'B', 'C', 'D', 'A', 'B']

>>> list(unique_justseen('ABBCcAD', str.lower))
['A', 'B', 'C', 'A', 'D']

>>> first_true('ABC0DEF1', '9', str.isdigit)
'0'

>>> population = 'ABCDEFGH'
>>> for r in range(len(population) + 1):
...     seq = list(combinations(population, r))
...     for i in range(len(seq)):
...         assert nth_combination(population, r, i) == seq[i]
...     for i in range(-len(seq), 0):
...         assert nth_combination(population, r, i) == seq[i]


�
libreftestc	Cs�tttttttttf	}t	j
|�|rxttd�rxddl
}dgd}tt|��D]"}t	j
|�|��t��||<qLt|�t	�tjt|�dS)N�gettotalrefcountrrl)rKr�r�rrr r�r�r'rZrun_unittest�hasattrrr�rr�r�r7rkZrun_doctest�modulesr*)�verboseZtest_classesr�Zcountsrr
r
r�	test_main
s$�


r;�__main__T)r:)N)@Zunittest�testr�	itertoolsr��decimalrZ	fractionsrr3rxr�rB�	functoolsrrr(r�r�ZMAX_Py_ssize_trZminsizerrrrrrrr"r#r1r7r9r=r?rArrr�ZTestCaserKr�r�r�r�r�r�r�rWr�r�r�r�r�rrr r�r'r6Z__test__r;r*r
r
r
r�<module>s�
�}n*e
	
	
\&;



F1le Man4ger