Your IP : 216.73.216.60


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_itertools.cpython-38.opt-2.pyc

U

i�f���@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
�8/opt/alt/python38/lib64/python3.8/test/test_itertools.py�lzipsrcCsd|S�N�r
��xr
r
r�oneargsrcGst�dSr)�
ValueErrorrr
r
r�errfuncsrccsdD]
}|VqdS)N�rrrr
��ir
r
r�gen3srcCs|ddkS)Nrrr
rr
r
r�isEven$srcCs|ddkS)Nrrr
rr
r
r�isOdd(srcGs|Srr
rr
r
r�tupleize,srccst|�D]
}|VqdSr��range��nrr
r
r�irange/sr"c@seZdZdd�Zdd�ZdS)�StopNowcCs|Srr
��selfr
r
r�__iter__5szStopNow.__iter__cCst�dSr��
StopIterationr$r
r
r�__next__7szStopNow.__next__N��__name__�
__module__�__qualname__r&r)r
r
r
rr#3sr#cCstt||��Sr�r	�islice)r!�seqr
r
r�take:sr1cCsttj|d�S�Nr)r�operator�mul��iterabler
r
r�prod>sr7cCsttd|d��Sr2)r7r�r!r
r
r�factAsr9cCs|dS�Nrr
��rr
r
r�testRFsr=cCs|dSrr
r;r
r
r�testR2Isr>cCs|dkS)N�
r
rr
r
r�undertenLsr@cCsg|]}|fdd��qS)cSst�t�||��Sr)�pickle�loads�dumps)�s�protor
r
r�<lambda>O�z<listcomp>.<lambda>r
)�.0rEr
r
r�
<listcomp>Os�rIc@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)Nrcs^�dkrtd��t|t�r|Sztt|���}Wntk
rH|YSX��fdd�|D�S)Nr?zinfinite recursion encounteredcsg|]}�|�d��qS)rr
�rH�e)�expandrr
rrI`sz;TestBasicOps.pickletest.<locals>.expand.<locals>.<listcomp>)�RuntimeError�
isinstance�strr	r/�	TypeError)�itr�l�rN�stoprrrNVs

z'TestBasicOps.pickletest.<locals>.expandr)r)rArCrB�assertEqual�typer�nextr()r%ZprotocolrSrVr1�compare�dumpZi2�a�b�cZi3ZtookrZi4r
rUr�
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��	rK��i�i�)�initial�d�n�s�t�)rWr	�
accumulater�int�complexrr�map�assertRaisesrR�min�maxr3r4�chrrA�HIGHEST_PROTOCOLr_)r%�typrDrEr
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qdSrr
)�	iterablesrS�elementr
r
r�chain2�sz'TestBasicOps.test_chain.<locals>.chain2rg�def�abcdef�rK�abcdrr`)�chainrWr	r1ryrR)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)	Nrgr�r�r�rKr�rr`)rWr	r��
from_iterabler1ryrRr$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)
Nrgr�r�r\Zbcdefr�rKr�rr`r�rZ)�copy�deepcopy�
picklecopiersr�rWr	rYr1ryrRrrAr}r_)r%ZoperrSrEr
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
rrgr�r\r]r^�drM�fZghi)ryrRr��__setstate__�iterrWr	�r%rSr
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)"Nrgrr���cSs|Srr
�r\r
r
rrF�rGz0TestBasicOps.test_combinations.<locals>.<lambda>� �ABCD��A�B�r��C�r��D�r�r��r�r��r�r�rKr`r�rrr`�rrr`�rrr`c3s�t|��t��}||krdStt|��}t�fdd�|D��Vtt|��D]}|||||krLqnqLdS||d7<t|d|�D]}||dd||<q�t�fdd�|D��Vq@dS)Nc3s|]}�|VqdSrr
�rHr��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)Nc3s|]}�|VqdSrr
r�r�r
rr�szHTestBasicOps.test_combinations.<locals>.combinations2.<locals>.<genexpr>)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)Nc3s|]}�|VqdSrr
r�r�r
rr�	szHTestBasicOps.test_combinations.<locals>.combinations3.<locals>.<genexpr>)r�r��combinations_with_replacementr�setr�r
r�r�
combinations3s
z5TestBasicOps.test_combinations.<locals>.combinations3ricSsg|]}d|d�qS�rj�r
�rHrr
r
rrIsz2TestBasicOps.test_combinations.<locals>.<listcomp>rc3s|]}|�kVqdSrr
rL��valuesr
rr�sz1TestBasicOps.test_combinations.<locals>.<genexpr>csg|]}|�kr|�qSr
r
rL�r^r
rrIs)ryrR�combinationsrr�rWr	rYrr�r9r�r��
assertTrue�allrAr}r_)
r%�op�testIntermediater�r�r�r!r<�resultrEr
�r^r�r�test_combinations�sZ�
�
��6
�zTestBasicOps.test_combinationsc	Cs(|�ttf��tdd�W5QRXdS)N�AAi )ry�
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�abcder`r)rWr�r�rx�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)Nrgrrr�cSs|Srr
r�r
r
rrF2rGzATestBasicOps.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)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)N��repeatc3s|]}�|VqdSrr
r�r�r
rr�SszPTestBasicOps.test_combinations_with_replacement.<locals>.cwr2.<locals>.<genexpr>)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>.numcombsricSsg|]}d|d�qSr�r
r�r
r
rrI[szCTestBasicOps.test_combinations_with_replacement.<locals>.<listcomp>rcSsg|]\}}|�qSr
r
)rH�k�vr
r
rrIksc3s|]}|�kVqdSrr
rLr�r
rr�nszBTestBasicOps.test_combinations_with_replacement.<locals>.<genexpr>csg|]}|�kr|�qSr
r
rLr�r
rrIps)r�ryrRrr�rWr	rYrr�r�r�r�r��groupbyr�rAr}r_)
r%�cwrr�r�r�r�r�r!r<r�Z
regular_combsZnorunsrEr
r�r�"test_combinations_with_replacement+sR�
��z/TestBasicOps.test_combinations_with_replacementc	Cs(|�ttf��tdd�W5QRXdS)Nr��@)ryr�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�rWr�r�rxr�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)Nrgrrr�r�rDr`�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)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)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>.permutations2ricSsg|]}d|d�qSr�r
r�r
r
rrI�sz2TestBasicOps.test_permutations.<locals>.<listcomp>rc3s|]}|�kVqdSrr
rLr�r
rr��sz1TestBasicOps.test_permutations.<locals>.<genexpr>)N)N)ryrRr�rrWr	rr�r9r�r�r�r�rAr}r_)r%r�r�r!r<r��prEr
r�r�test_permutations�s:�

	, 
zTestBasicOps.test_permutationsc	Cs(|�ttf��tdd�W5QRXdS)Nr�r�)ryr�r�r�r$r
r
r�test_permutations_overflow�sz'TestBasicOps.test_permutations_overflowc
CsH|�tttttdd����d�|�ttttttdd�����d�dSr�)rWr�r�rxr�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)Nra�ABCDEFGrkr�rrcSs g|]}t|�t|�kr|�qSr
�r�r	�rH�tr
r
rrI�sz3TestBasicOps.test_combinatorics.<locals>.<listcomp>cs g|]}tt|���kr|�qSr
�r�r�r�r;r
rrI�scSs g|]}t|�t|�kr|�qSr
r�r�r
r
rrI�scs g|]}tt|���kr|�qSr
r�r�r;r
rrI�s)
rr	r�r�r�r�rWr�r9r�r��filter�__contains__)r%r!rDr7r�ZpermZcombr
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�'rar�r`rjcSs
t�|�Sr)r�r�r
r
rrF�rGz,TestBasicOps.test_compress.<locals>.<lambda>cSs
t�|�Sr)r�r�r�r
r
rrF�rGZCEFZBCDEFr�)rWr	�compressr�r�r�rryrRr�rY)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),Nrg�r\r�r]r�r^rr`)r\r`)r]rK)r^rjrr�)r\r�)r]r���)r\r)r]r�rKr\r?rj�
@g@g@�
@�y@��@��1.1z2.1z3.1rkr��zcount(3)zcount(4)���z	count(-9)i����g�$@zcount(10.25)g$@zcount(10.0)���r�	count(%r))rWr�countr1r
ryrR�maxsizer	rrr�reprrYrX�float�sys�__mod__r�r�rAr}r_�exc_info)r%�BIGINTr^r�r1�r2�valuerEr
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);Nrgrr`)r\r)r]rj)r^rk)�start�stepr�)rr�)r]r�)r^r�r\r]r)r]rr�r)r]r`)r^rKrtrbrpr?rjg�?rg@rry!@ �rz.1z1.2z1.3ri�rcrg@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)rrz
count(%r, %r))rWrr	ryrRr1r
rr	rrrrYrXrvrr
rAr}r_)r%rr^rr�rrrEr
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?rgZ
abcabcabcar�rjrrrr\Z
bcabcabcabZ
cabcabcabcr�csg|]}t���qSr
�rYr�r�r
rrI�sz+TestBasicOps.test_cycle.<locals>.<listcomp>rtZcdeabcdeabcdeabcdeabcsg|]}t���qSr
rr�r�r
rrI�sri)rWr1�cycler	ryrRr/rrYr�r�rrAr}rBrCr_r�)r%rErS�_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�defgrgrrtZdefgabcdefgabcdefgab�abcdefgrrr�r
)rr�r	rWr1ryrRr�)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��keyrgcSs|Srr
rr
r
rrF�rGz+TestBasicOps.test_groupby.<locals>.<lambda>r?)rr?rt)r�rc)rr�rc)r�
rc)r��)rrbr%)r`rm�)r`rr&cSs|dSr:r
r;r
r
rrF�rGrrrcSsg|]\}}|�qSr
r
�rHr��gr
r
rrI�sz-TestBasicOps.test_groupby.<locals>.<listcomp>cSsg|]}|d�qS)rr
)rHr<r
r
rrI�sZ	AABBBAAAArl)r�rjZabracadabracSsg|]\}}|�qSr
r
r'r
r
rrIsr\r]r^r�r<cSs$g|]\}}tt|dd��r|�qSr�r.r'r
r
rrIscSs g|]\}}tt|��|f�qSr
�r�r	r'r
r
rrIs)rjr\)rr])rr^)rr�)rr<cSs g|]\}}tt|��|f�qSr
r)r'r
r
rrIsT)�reverser`c@seZdZdS)z0TestBasicOps.test_groupby.<locals>.ExpectedErrorN)r+r,r-r
r
r
r�
ExpectedErrorsr+c3st|�D]
}dVq��dS)NZyorr �r+r
r�
delayed_raise!sz0TestBasicOps.test_groupby.<locals>.delayed_raisecs�fdd�t||�D�S)Ncsg|]\}}�|��qSr
r
r'��funcr
rrI&sz;TestBasicOps.test_groupby.<locals>.gulp.<locals>.<listcomp>)r�)r6Zkeypr/r
r.r�gulp%sz'TestBasicOps.test_groupby.<locals>.gulpcseZdZ�fdd�ZdS)z+TestBasicOps.test_groupby.<locals>.DummyCmpcs��dSrr
)r%Zdstr,r
r�__eq__/sz2TestBasicOps.test_groupby.<locals>.DummyCmp.__eq__N)r+r,r-r1r
r,r
r�DummyCmp.sr2r.cs$�jdkr�jd8_|S��dSr�)�skip)�obj�r+�keyfuncr
rr69s
z*TestBasicOps.test_groupby.<locals>.keyfunc)r)rWr	r�r�ryrR�appendrrAr}rBrCr=r>r�r�r
rYr��	Exceptionr3)r%rD�dupr�r(�elemrEZikZig�keysZexpectedkeysrSrZg1Zg2Zg3r<r-r0r2r
r5r�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)NrarrrKrcSs|Srr
rr
r
rrFLrGz*TestBasicOps.test_filter.<locals>.<lambda>cSs|Srr
rr
r
rrFMrGrir`)rWr	r�rr�boolr1r	ryrRrYr�r�rAr}rBrCr_�r%�ansr^rEr
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)Nrarr`rjrrrKricSs|Srr
rr
r
rrFgrGz/TestBasicOps.test_filterfalse.<locals>.<lambda>cSs|Srr
rr
r
rrFhrG)rWr	�filterfalserrr=r1r	ryrRrYrAr}r_�r%rEr
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
�rHr�yr
r
rrIpsz)TestBasicOps.test_zip.<locals>.<listcomp>rgr�r�r�rar�r`cSsg|]}tt|���qSr
�r�r	�rHZpairr
r
rrIysr�cSsg|]}|�qSr
r
rGr
r
rrI{s)	r
r	rWr	rrr1ryrR)r%r?r
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)Nrgr�cSsg|]\}}||f�qSr
r
rDr
r
rrI�sz5TestBasicOps.test_zip_tuple_reuse.<locals>.<listcomp>r�r�r�cSsg|]\}}||f�qSr
r
rDr
r
rrI�srcSsg|]\}}||f�qSr
r
rDr
r
rrI�scSsg|]\}}||f�qSr
r
rDr
r
rrI�s)r	rxr�r
rWrzr{r��dict�fromkeysr�r	r�rrAr}rBrCrYr_)r%�idsr?rEr�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)Nrgrar��i4i�i�ri�i�cs"g|]�t�fdd��D���qS)cs$g|]}�t|�kr|�nd�qSr�r�)rH�argrr
rrI�sz;TestBasicOps.test_ziplongest.<locals>.<listcomp>.<listcomp>�r�)rHrrrrI�s�z0TestBasicOps.test_ziplongest.<locals>.<listcomp>cSsg|]}tdd�|D���qS)css|]}|dkrdp|VqdS)N�Xr
rLr
r
rr��sz:TestBasicOps.test_ziplongest.<locals>.<listcomp>.<genexpr>rPr�r
r
rrI�srQ��	fillvaluer`r�r)zzip_longest('abc', fv=1)z3zip_longest('abc', fillvalue=1, bogus_keyword=None)zDid not raise Type in:  cSsg|]}tt|���qSr
rFrGr
r
rrI�sr�cSsg|]}|�qSr
r
rGr
r
rrI�s)rgr)rr{rxr�rWr	�zip_longestrIr1r	r
ryrR�eval�globals�localsZfail)r%�targetZstmtr
rr�test_ziplongest�sD

"(�
�(���zTestBasicOps.test_ziplongestcCs^ttttdd���}|�t|�t|��tttttdd����}|�tt�	|��t|��dS)Nrgr�)
r	rxr�rTrWrzr{r�rIrJ)r%rKr
r
r�test_zip_longest_tuple_reuse�sz)TestBasicOps.test_zip_longest_tuple_reusec	Csdttjd�D]P}|�|tdd��|�|tdd��|�|tdddd��|�|tdd��qdS)Nrrgr�ZdefghrRr�)rrAr}r_rTrBr
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
r\r
r�BadIterable�sr^)rRryrTZassertIsr])r%r^�cmr
r\r�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)�orvr�rM)r%rar�rMr
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�rarMr$r
r
rr)�s
z5TestBasicOps.test_bug_7244.<locals>.Repeater.__next__N�r+r,r-rbr&r)r
r
r
r�Repeater�srdrr`rrKc
SsPg}t||dd�D]8\}}t�d��t||f�W5QRX|�||f�q|S)NrrR�stdout)rTrZcaptured_output�printr7)rrr�rr�r
r
r�run�sz'TestBasicOps.test_bug_7244.<locals>.runr�r�rrR)r(rWrOrTrYry)r%rdrrrgrSr
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
rhr��r]rr`�rrr�r�r��rrr�rrKr�rirai��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)rNrN)rHr�r
r
rr�sz>TestBasicOps.test_product.<locals>.product1.<locals>.<genexpr>css|]\}}||VqdSrr
�rHr�rr
r
rr�scss|]\}}||VqdSrr
rlr
r
rr�&s)	r	rxr��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)Nr�rcs g|]}�D]}||g�qqSr
r
rDr�r
rrI0sz?TestBasicOps.test_product.<locals>.product2.<locals>.<listcomp>)r	rxr�rm)rrorpr�r7r
r�r�product2+sz+TestBasicOps.test_product.<locals>.product2r�rgr)r\r]r^rr"r#rpcsg|]}t����qSr
)�randomZchoice)rHr��Zargtypesr
rrI7sz-TestBasicOps.test_product.<locals>.<listcomp>rj)rrWr	r�rIr�ryrRr�r�rsZ	randranger7rxr�)r%rr�r<rqrrrZexpected_lenr
rtr�test_products:��"	
�
zTestBasicOps.test_productc	Cs2|�ttf��tdgdddi�W5QRXdS)Nrhr�r�i)ryr�r�r�r$r
r
r�test_product_overflow?sz"TestBasicOps.test_product_overflowc
CsH|�tttttdd����d�|�ttttttdd�����d�dS)Nrgr�r)rWr�r�rxr�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
rhr�rirr`rjr�r�r�rkr�rr)	rrWr	r�r�r�rAr}r_)r%rr�rEr
r
r�test_product_picklingIs�z"TestBasicOps.test_product_picklingcCsLtdd�}|�d�|�t|�d�tddd�}|�d�|�tt|�dS)Nr�)r`)r�)rr`r
)rrry)r�r�rWrYryr()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\r`)�object�times)rr\)rr\)rr\rrrKy�?zrepeat((1+0j))rjzrepeat((1+0j), 5)zrepeat((1+0j), 0)r?rZaar)rWr	r�rrr1ryrRrrYr�r�rAr}r_)r%r<r^rEr
r
r�test_repeatbs.�
zTestBasicOps.test_repeatcCs`|�ttdd��d�|�ttdd��d�|�ttddd��d�|�ttddd��d�dS)Nr\r�zrepeat('a', 0)r��r|)rWrr�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)Nr`rrirrkrgrjr�r�r�rr?rK)rWr	rxr3�powrrr	r1ryrR�negrYrrrr�r�rAr}r_r>r
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)Nr`rrirrkrKrji�rKrj�extrar?)rWr	�starmapr3r�r
rr1r	r�ryrRrYrrrr�r�rAr}r_r>r
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?rtr`�r?r`rt�r?rt)r?r?�r?r`�rtrp)))r?rqr`)r?rpr`))r?rq)r?rp))rq)rpr?rrr`rK���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
rrbsz2TestBasicOps.test_islice.<locals>.IntLike.__init__cSs|jSrr�r$r
r
r�	__index__sz3TestBasicOps.test_islice.<locals>.IntLike.__index__N)r+r,r-rbr�r
r
r
r�IntLikesr�rj)rWr	r/rr�ryrRrr�r	r
rYr�r�rAr}r_�weakref�refZassertIsNotNonerZ
gc_collectZassertIsNoner{)	r%rZtgtargsrSZrar^rEZwrr�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)
Nrr`rjrtrrKrarkr�r�r?r)rWr	�	takewhiler@ryrRr3r�rYrrr=r(r�r�rrAr}r_)r%r�r�rEr
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)Nrr`rjrtrrKrarkr�r�r?)rWr	�	dropwhiler@ryrRr3r�rYrrr�r�rrAr}r_)r%r�rEr
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��rprjrrr`rrrgr�rMZinvalidr�cSsg|]}t|��qSr
�r	r�r
r
rrI~sz)TestBasicOps.test_tee.<locals>.<listcomp>r?�	__class__r��<r�)�teerWr	r"rrrYrsZshuffler7ryrRrXrr�r�r�r��proxy�getattr�ReferenceErrorr�r1r�rAr}r_r�)r%r!r\r]rr��orderZlistsZitsrr^r�r��t1�t2ZtnewZt3r�r?Zlong_ansrEr
r
r�test_tee>s� 
 
$<








zTestBasicOps.test_teecCs8ttdd��\}}zt|�~Wn~~�YnXdS)Ni-1)r�r�rn)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)�firstrY)r%r�rir
rr)�sz1TestBasicOps.test_tee_reenter.<locals>.I.__next__N)r+r,r-r�r&r)r
rir
r�I�sr�r�)r��assertRaisesRegexrOrY)r%r�r\r
rir�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__Nr*r
r�r
rr��sr�)rXrr�)�	threadingZEventr�ZThreadrYrr��joinr�r�rO)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
rrFrGz1TestBasicOps.test_StopIteration.<locals>.<lambda>cSs|Srr
rr
r
rrFrG)ryr(rYr
r�rr�r#r/r�r�r�rArxr�r�r�)r%r�r��qr
r
r�test_StopIterations zTestBasicOps.test_StopIterationcCs6tdggd�}t|�t��|�t�t|���dSr2)r�rY�gc�collectr��
is_trackedr�r
r
r�test_combinations_result_gcsz(TestBasicOps.test_combinations_result_gccCs6tdggd�}t|�t��|�t�t|���dSr2)r�rYr�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�rYr�r�r�r�r�r
r
r�test_permutations_result_gc,sz(TestBasicOps.test_permutations_result_gccCs4tdgg�}t|�t��|�t�t|���dSr)r�rYr�r�r�r�r�r
r
r�test_product_result_gc4sz#TestBasicOps.test_product_result_gccCs*tgg�}t��|�t�t|���dSr)rTr�r�r�r�rYr�r
r
r�test_zip_longest_result_gc<s
z'TestBasicOps.test_zip_longest_result_gc)rKrN)<r+r,r-r_rr�r�r�r�r�rZbigaddrspacetestr�Zimpl_detailr�r�r�r�r�r�r�r�r�rrrrr<r@rCrHrLrYrZr[r`rhrurvrwrxrzr}rr�r�r�r�r�r�r�r�r�r��cpython_onlyr�r�r�r�r�r
r
r
rrJRs�
)#

P

L

?

!"07*$

*
(:


^	



rJc@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�	Nrrr`rKrjrar?rb)rWr	rur$r
r
rrFszTestExamples.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�)rrAr}rurWr	rBrCrYr�r�)r%r�ZaccumulatedrErSr
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)
rur3�is_rWrYrrAr}rBrCr	r�r�)r%rSrEZit_copyr
r
r�test_accumulate_reducible_noneXsz+TestExamples.test_accumulate_reducible_nonecCs|�d�tdd��d�dS�Nr�r�ZDEFr�)rWr�r�r$r
r
rr�bszTestExamples.test_chaincCs |�d�t�ddg��d�dSr�)rWr�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�rKr`rr�r�r�)rWr	r�rr$r
r
rr�hs�
�zTestExamples.test_combinationsc	Cs&|�ttdd��ddddddg�dS)	Nr�rr�r�r�r�r�r�)rWr	r�r$r
r
rr�ns�z/TestExamples.test_combinations_with_replacementcCs*|�ttdddddddg��td��dS)Nr�rrr�)rWr	r�r$r
r
rr�rszTestExamples.test_compresscCs(|�tttd�d��dddddg�dS)Nr?rjr"r�r#r$)rWr	r/r	r$r
r
rruszTestExamples.test_countcCs"|�tttd�d��td��dS)Nr�r�ZABCDABCDABCD)rWr	r/rr$r
r
rrxszTestExamples.test_cyclec
Cs.|�ttdd�dddddg��dddg�dS)NcSs|dkS�Nrjr
rr
r
rrF|rGz-TestExamples.test_dropwhile.<locals>.<lambda>rrKra)rWr	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
rrIsz-TestExamples.test_groupby.<locals>.<listcomp>ZAAAABBBCCDAABBBZABCDABcSsg|]\}}t|��qSr
r�r'r
r
rrI�sZ
AAAABBBCCDZAAAAZBBBZCCr�)rWr�r	r$r
r
rr<~s��zTestExamples.test_groupbycCs,|�ttdd�td���dddddg�dS)	NcSs|dSrr
rr
r
rrF�rGz*TestExamples.test_filter.<locals>.<lambda>r?rr`rjrirl)rWr	r�rr$r
r
rr@�szTestExamples.test_filtercCs,|�ttdd�td���dddddg�dS)	NcSs|dSrr
rr
r
rrF�rGz/TestExamples.test_filterfalse.<locals>.<lambda>r?rrrKrark)rWr	rArr$r
r
rrC�szTestExamples.test_filterfalsecCs"|�tttdd��dddg�dS)N)rr`r?)rjrr`r�rlr)rWr	rxr�r$r
r
rr��szTestExamples.test_mapcCst|�ttdd��td��|�ttddd��td��|�ttddd��td��|�ttdddd��td��dS)	Nr�r�ABrK�CD�CDEFGr�ACEG)rWr	r/r$r
r
rr��szTestExamples.test_islicecCs|�ttdd��ddg�dS)Nr��xy�r�r�r�rE)rWr	r
r$r
r
rrH�szTestExamples.test_zipcCs&|�ttdddd��ddddg�dS)	Nr�r��-rRr�r�)r�r�)r�r�)rWr	rTr$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 DCr`r)rrr)rrr)rrr)rrr)rrr)rWr	r�rxr��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 Dyrr`r�)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rWr	r�rxr�r�rr$r
r
rru�s���zTestExamples.test_productcCs |�ttdd��dddg�dS)Nr?r`)rWr	r�r$r
r
rr}�szTestExamples.test_repeatcCs&|�tttdddg��dddg�dS)N)rrj)r`rr�r�rlr)rWr	r�r�r$r
r
r�test_stapmap�s�zTestExamples.test_stapmapc
Cs,|�ttdd�dddddg��ddg�dS)NcSs|dkSr�r
rr
r
rrF�rGz-TestExamples.test_takewhile.<locals>.<lambda>rrKra)rWr	r�r$r
r
rr��szTestExamples.test_takewhileN)r+r,r-rr�r�r�r�r�r�r�rrr�r<r@rCr�r�rHr�r�rur}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�)�slicerrVr
r
rr�rrYr(r
�	enumerate)
r6rrDrrVrrSZnextirr�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�rKr�r�rr�r?r`rr�)rWr	r/r�rr	rY)r%rSr^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)r7rY)r%�iteratorZ	containerr
r
r�	makecycle�s
zTestGC.makecyclecCs g}|�tdd|dg�|�dS�Nrrr`)r�ru�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�r�r�r
r
rr��szTestGC.test_compresscCs6g}tdtft|d��}|�t|d�|d��|�dS)N�Intrrr)rXrvrIr�r	)r%r\r�r
r
rr�szTestGC.test_countcCsg}|�t|gd�|�dSr)r�rr�r
r
rrszTestGC.test_cyclecCs g}|�ttd||g�|�dSr:)r�r�r=r�r
r
rr�szTestGC.test_dropwhilecCs$g}|�t|gddd��|�dS)NrcSs|Srr
rr
r
rrF
rGz%TestGC.test_groupby.<locals>.<lambda>)r�r�r�r
r
rr<szTestGC.test_groupbycCs>d}dd�}tt|�|d�D]\}}|j�dg��|�qdS)Nr?cSs|Srr
rr
r
rrFrGz'TestGC.test_issue2246.<locals>.<lambda>r r)r�r�__dict__�
setdefaultr7)r%r!r6rr�r
r
r�test_issue2246szTestGC.test_issue2246cCs$g}|�tdd�|gd�|�dS)NcSsdS)NTr
rr
r
rrFrGz$TestGC.test_filter.<locals>.<lambda>r)r�r�r�r
r
rr@szTestGC.test_filtercCsg}|�tdd�|�|�dS)NcSsdSr�r
rr
r
rrFrGz)TestGC.test_filterfalse.<locals>.<lambda>)r�rAr�r
r
rrCszTestGC.test_filterfalsecCs&g}|�t|gd|gd�|�dS)Nrr`)r�r
r�r
r
rrHszTestGC.test_zipcCsPg}|�t|gd|gd�|�|dg}|�t|gd|gd|d�|�dS)Nrr`rR)r�rT)r%r\r]r
r
rr�szTestGC.test_zip_longestcCs$g}|�tdd�|gd�|�dS)NcSs|Srr
rr
r
rrF'rGz!TestGC.test_map.<locals>.<lambda>r)r�rxr�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)Nrrr`r�)r�r�r�r
r
rru1szTestGC.test_productcCsg}|�t|�|�dSr)r�r�r�r
r
rr}5szTestGC.test_repeatcCs(g}|�tdd�||fgd�|�dS)NcWs|Srr
�r�r
r
rrF;rGz%TestGC.test_starmap.<locals>.<lambda>r)r�r�r�r
r
rr�9szTestGC.test_starmapcCs"g}|�ttdd||g�|�dS)Nrr)r�r�r=r�r
r
rr�=szTestGC.test_takewhileN)r+r,r-r�rr�r�r�r�r�rrr�r<r�r@rCrHr�r�r�r�rur}r�r�r
r
r
rr��s.r�ccs|D]
}|VqdSrr
��seqnrr
r
r�RAsr�c@seZdZdd�Zdd�ZdS)�GcCs
||_dSr�r��r%r�r
r
rrbHsz
G.__init__cCs
|j|Srr�)r%rr
r
r�__getitem__Jsz
G.__getitem__N)r+r,r-rbr�r
r
r
rr�Fsr�c@s$eZdZdd�Zdd�Zdd�ZdS)r�cCs||_d|_dSr:r�r�r
r
rrbOsz
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__Nrcr
r
r
rr�Msr�c@seZdZdd�Zdd�ZdS)�IgcCs||_d|_dSr:r�r�r
r
rrb\szIg.__init__ccs|jD]
}|VqdSrr�r�r
r
rr&_s
zIg.__iter__N�r+r,r-rbr&r
r
r
rr�Zsr�c@seZdZdd�Zdd�ZdS)rQcCs||_d|_dSr:r�r�r
r
rrbesz
X.__init__cCs2|jt|j�krt�|j|j}|jd7_|Sr2r�r�r
r
rr)hs
z
X.__next__N)r+r,r-rbr)r
r
r
rrQcsrQc@seZdZdd�Zdd�ZdS)�NcCs||_d|_dSr:r�r�r
r
rrbpsz
N.__init__cCs|Srr
r$r
r
rr&ssz
N.__iter__Nr�r
r
r
rr�nsr�c@s$eZdZdd�Zdd�Zdd�ZdS)�EcCs||_d|_dSr:r�r�r
r
rrbxsz
E.__init__cCs|Srr
r$r
r
rr&{sz
E.__iter__cCsdddS)Nr`rr
r$r
r
rr)}sz
E.__next__Nrcr
r
r
rr�vsr�c@s$eZdZdd�Zdd�Zdd�ZdS)�ScCsdSrr
r�r
r
rrb�sz
S.__init__cCs|Srr
r$r
r
rr&�sz
S.__iter__cCst�dSrr'r$r
r
rr)�sz
S.__next__Nrcr
r
r
rr��sr�cCsttdd�ttt|�����S)NcSs|Srr
rr
r
rrF�rGzL.<locals>.<lambda>)r�rxr�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�rWr	rur�ryrRrQr��ZeroDivisionErrorr�)r%rDr<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�?rM�rj)rr�r�r�r�r�r�rWr	r�ryrRrQr�r�r��r%rDr(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�rr�rMr�rjr)rr�r�r�r�r�r�r�rWr	r�r�ryrRrQr�r�r�)r%rDr!r(r
r
rr��s(z%TestVariousIteratorArgs.test_compresscCsZddtd�dtddd�fD]:}|�ttt|��|�ttt|��|�ttt|��qdSr�)rryrRr�rQr�r�r�)r%rDr
r
rru�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�rr�rMr�rjr`)rr�r�r�r�r�r�r�r	r/rrWryrRrQr�r�r�)r%rDr(ZtgtlenZexpectedZactualr
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�rir"rMr�rjcSsg|]\}}|�qSr
r
)rHr�Zsbr
r
rrI�sz8TestVariousIteratorArgs.test_groupby.<locals>.<listcomp>)rr�r�r�r�r�r�rWr�r	ryrRrQr�r�r�r�r
r
rr<�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?rrr�rMr�rjcSsg|]}t|�r|�qSr
)rr�r
r
rrI�sz7TestVariousIteratorArgs.test_filter.<locals>.<listcomp>)rr�r�r�r�r�r�rWr	r�rryrRrQr�r�r�r�r
r
rr@�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?rrr�rMr�rjcSsg|]}t|�r|�qSr
)rr�r
r
rrI�sz<TestVariousIteratorArgs.test_filterfalse.<locals>.<listcomp>)rr�r�r�r�r�r�rWr	rArryrRrQr�r�r�r�r
r
rrC�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�rWr	r
rryrRrQr�r�r�r�r
r
rrH�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�rWr	rTr
ryrRrQr�r�r�r�r
r
rrY�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?rrpr�rtr�rjcSsg|]}t|��qSr
)rr�r
r
rrI�sz4TestVariousIteratorArgs.test_map.<locals>.<listcomp>cSsg|]}||�qSr
r
r�r
r
rrI�s)rr�r�r�r�r�r�rWr	rxrr3r�ryrRrQr�r�r�r�r
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�rr�rMr�rjrrr?)rr�r�r�r�r�r�rWr	r/ryrRrQr�r�r�r�r
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?rrpr�rtr�rjcSsg|]}||�qSr
r
r�r
r
rrIsz8TestVariousIteratorArgs.test_starmap.<locals>.<listcomp>)rr�r�r�r�r�r�rrWr	r�r3r�ryrRrQr�r�r�)r%rDr(Zssr
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?rrr�rMr�rj)rr�r�r�r�r�r�rr7rWr	r�ryrRrQr�r�r��r%rDr(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�rr7rWr	r�ryrRrQr�r�r�r�r
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�rr�rMr�rjr)rr�r�r�r�r�r�r�rWr	ryrRrQr�r�r�)r%rDr(Zit1Zit2r
r
rr�sz TestVariousIteratorArgs.test_teeN)r+r,r-rr�r�rurr<r@rCrHrYr�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��rWr3�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
rr0sz2LengthTransparency.test_repeat_with_negative_timesN)r+r,r-r}rr
r
r
rr�)sr�c@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	rxr
r�rY)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�)rKrjra)r	rrW)r%r�r��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)r7�AssertionErrorr
�Zhistr
r�gen1Ys


z,RegressionTests.test_sf_950057.<locals>.gen1c3s��d�dV��d�dS)Nr`rrK)r7rrr
r�gen2`s
z,RegressionTests.test_sf_950057.<locals>.gen2FrrT)ryrr	r�rWr)r%rrr
rr�test_sf_950057UszRegressionTests.test_sf_950057c	Cs:t�dd�td�D��}|�t��t|�W5QRXdS)Ncss|]
}dVqdS)r
Nr
)rHZunusedr
r
rr�vszERegressionTests.test_long_chain_of_empty_iterables.<locals>.<genexpr>i���)r�r�rryr(rYr�r
r
r�"test_long_chain_of_empty_iterablesqsz2RegressionTests.test_long_chain_of_empty_iterablescs0�fdd�}ttd�|�D]\}�t��qdS)Ncs|dkrt��|dkS)Nrjrar�r8rir
rr�{sz,RegressionTests.test_issue30347_1.<locals>.fr?)r�rr	)r%r�r�r
rir�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
rrb�sz5RegressionTests.test_issue30347_2.<locals>.K.__init__cs�d7��dkrt�d�dS)NrTr)r%�other�r(rr
rr1�s
z3RegressionTests.test_issue30347_2.<locals>.K.__eq__N)r+r,r-rbr1r
rr
r�K�sr
rr?rr)rYr�r)r%r
r�r
rr�test_issue30347_2�s
	z!RegressionTests.test_issue30347_2N)
r+r,r-rrrZskip_if_pgo_taskr	r
rr
r
r
rr�6s
r�c@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)rb)r%�newargr��clsr
rrb�szKSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.Subclass.__init__)N)r+r,r-rbr
rr
r�Subclass�srr)rzkeyword argumentsr)r�r
r�rAr�rxr�r/r�r�rr�rRZassertNotInr)r%r�errr
rr�test_keywords_in_subclass�s�z0SubclassWithKwargsTest.test_keywords_in_subclassN)r+r,r-rr
r
r
rr�src@s:eZdZdd�ZejZdd�Zdd�Zdd�Zd	d
�Z	dS)�
SizeofTestcCst�d�|_dS)Nr!)�structZcalcsize�ssize_tr$r
r
r�setUp�szSizeofTest.setUpcCsFt�d�}|j}|tdd�|d|j�|td�|d|j�dS)NZ3PirhZ12r)
rgrgrgrgrgrgrgrgrgrgr?)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�r`r?rK)rrrr�rrrr
r
r�test_combinations_sizeof�s
z#SizeofTest.test_combinations_sizeofcCsPt}t�d�}|j}||dd�|d|j�||td�d�|d|j�dSr )r�rrrrr)r%r�rrr
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�rKr`r�rjr?)rrrr�rrrr
r
r�test_permutations_sizeof�s
�
�
��z#SizeofTest.test_permutations_sizeofN)
r+r,r-rrrrr!r"r#r
r
r
rr�sra�" 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�gettotalrefcountrrj)rJr�r�r�r�rr�r�rrZrun_unittest�hasattrr
r�rr�r�r%rfZrun_doctest�modulesr+)�verboseZtest_classesr�Zcountsrr
r
r�	test_main
s$�


r)�__main__T)r()N)@ZunittestZtestr�	itertoolsr��decimalrZ	fractionsrr3rsr�rA�	functoolsrr
rr�r�ZMAX_Py_ssize_tr
Zminsizerrrrrrrr"r#r1r7r9r=r>r@rr}r�ZTestCaserJr�r�r�r�r�r�r�rQr�r�r�r�r�r�r�rr�rr$Z__test__r)r+r
r
r
r�<module>s�
�}n*e
	
	
\&;