HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_itertools.cpython-37.opt-2.pyc
B

��g���@snddlZddlmZddlTddlZddlmZddlmZddl	Z	ddl
Z
ddlZddlZddl
mZddlZddlZddlZejZedZdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�d�Zdd�Zdd�Zdd�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�Z/Gd8d9�d9�Z0Gd:d;�d;�Z1Gd<d=�d=�Z2Gd>d?�d?�Z3d@dA�Z4GdBdC�dCej'�Z5GdDdE�dEej'�Z6GdFdG�dGej'�Z7GdHdI�dIej'�Z8ej9GdJdK�dKej'��Z:dLZ;dMe;iZ<dSdNdO�Z=e>dPk�rje=dQdR�dS)T�N)�support)�*)�Decimal)�Fraction)�reduce�cGstt|��S)N)�list�zip)�args�r�//usr/local/lib/python3.7/test/test_itertools.py�lzipsr
cCsd|S)N�r)�xrrr�oneargsrcGst�dS)N)�
ValueError)r
rrr�errfuncsrccsxdD]
}|VqWdS)N)rrrr)�irrr�gen3s
rcCs|ddkS)Nrrr)rrrr�isEven"srcCs|ddkS)Nrrr)rrrr�isOdd&srcGs|S)Nr)r
rrr�tupleize*srccsxt|�D]
}|Vq
WdS)N)�range)�nrrrr�irange-src@seZdZdd�Zdd�ZdS)�StopNowcCs|S)Nr)�selfrrr�__iter__3szStopNow.__iter__cCst�dS)N)�
StopIteration)rrrr�__next__5szStopNow.__next__N)�__name__�
__module__�__qualname__rrrrrrr1srcCstt||��S)N)r�islice)r�seqrrr�take8sr%cCsttj|d�S)Nr)r�operator�mul)�iterablerrr�prod<sr)cCsttd|d��S)Nr)r)r)rrrr�fact?sr*cCs|dS)Nrr)�rrrr�testRDsr,cCs|dS)Nrr)r+rrr�testR2Gsr-cCs|dkS)N�
r)rrrr�undertenJsr/cCsg|]}|fdd��qS)cSst�t�||��S)N)�pickle�loads�dumps)�s�protorrr�<lambda>M�z<listcomp>.<lambda>r)�.0r4rrr�
<listcomp>Msr8c@s�eZdZdcdd�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$e
jdCdD��Z%e
�
d�dEdF��Z&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�Z4dS)d�TestBasicOps�rNcsd��fdd�	�t�||�}t�|�}|�t|�t|���|��|�}}	|�||	�|rp�|�}
|�||
�t�|�}d}y&x t|�D]}
t|�|d7}q�WWntk
r�YnXt�||�}t�|�}�|��|�}}	|�||	�|�r�||d��}
|�||
�dS)NrcsZ�dkrtd��t|t�r|Sytt|���}Wntk
rD|SX��fdd�|D�S)Nr.zinfinite recursion encounteredcsg|]}�|�d��qS)rr)r7�e)�expandrrrr8^sz;TestBasicOps.pickletest.<locals>.expand.<locals>.<listcomp>)�RuntimeError�
isinstance�strrr#�	TypeError)�itr�l)r<�stop)rrr<Ts
z'TestBasicOps.pickletest.<locals>.expandr)r)r0r2r1�assertEqual�typer�nextr)rZprotocolrArCr%�compare�dumpZi2�a�b�cZi3ZtookrZi4r)r<rCr�
pickletestRs0



zTestBasicOps.pickletestcCs,|�tttd���ddddddddd	d
g
�|�tttd�d��ddddddddd	d
g
�xPttttfD]@}|�ttt|td����tt|ddddddddd	d
g
���qhW|�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��WdQRXx,ttjd�D]}|�|ttd����q
WdS)Nr.rr������$�-)r(�abcrI�ab��)rr��	r:��i�i�)rDr�
accumulater�int�complexrr�map�assertRaisesr@�min�maxr&r'�chrr0�HIGHEST_PROTOCOLrL)r�typr3r4rrr�test_accumulate{s4(zTestBasicOps.test_accumulatecCs�dd�}x�t|fD]z}|�t|dd��td��|�t|d��td��|�t|d��g�|�td|dd��td��|�tt|d	d
��qWdS)Ncws&x |D]}x|D]
}|VqWqWdS)Nr)�	iterablesrA�elementrrr�chain2�s

z'TestBasicOps.test_chain.<locals>.chain2rT�def�abcdef�r:�abcdrrM)�chainrDrr%r`r@)rrirKrrr�
test_chain�szTestBasicOps.test_chaincCs�|�tt�ddg��td��|�tt�dg��td��|�tt�dg��g�|�tdt�ddg��td��|�ttt�ddg��dS)	NrTrjrkrlr:rmrrM)rDrrn�
from_iterabler%r`r@)rrrr�test_chain_from_iterable�s
 z%TestBasicOps.test_chain_from_iterablec	Cs�x�tjgtD]�}tdd�}|�t||��td��|�t|�d�|�t||��td��|�t|td���g�|�td|tdd���td��|�t	t|td	d
���qWx0t
tjd�D]}|j
|tdd�td�d�q�WdS)
NrTrjrkrIZbcdefrlr:rmrrMr)rG)�copy�deepcopy�
picklecopiersrnrDrrFr%r`r@rr0rdrL)rZoperrAr4rrr�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)NrrrTrjrIrJrK�dr;�fZghi)r`r@rn�__setstate__�iterrDr)rrArrr�test_chain_setstate�sz TestBasicOps.test_chain_setstatec

s�|�ttd�|�ttddd�|�ttd�|�ttdd�x�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�qNWdd�}dd�}dd�}�x�td�D�]�}dd�t|�D���xtt|d�D�]b}tt�|��}|�t	|�||k�r�dnt
|�t
|�t
||��|�t	|�t	t|���|�|t|��x�|D]x�|�t	��|�|�t	t���|�|�t��t���|�
t�fdd ��D���|�t���fd!d��D���q�W|�|t|�|���|�|t|�|���|�|t|�|���x*ttjd�D]}	|�|	t�|���q�W�qhW�q@WdS)"NrTrr���cSs|S)Nr)rIrrrr5�r6z0TestBasicOps.test_combinations.<locals>.<lambda>� �ABCD)�A�B)r~�C)r~�D)rr�)rr�)r�r�r:rM)rrr)rrrM)rrrM)rrrMc3s�t|��t��}||krdStt|��}t�fdd�|D��Vx�x.tt|��D]}|||||krPPqPWdS||d7<x*t|d|�D]}||dd||<q�Wt�fdd�|D��VqBWdS)Nc3s|]}�|VqdS)Nr)r7r)�poolrr�	<genexpr>�szHTestBasicOps.test_combinations.<locals>.combinations1.<locals>.<genexpr>rc3s|]}�|VqdS)Nr)r7r)r�rrr��s)�tuple�lenrr�reversed)r(r+r�indicesr�jr)r�r�
combinations1�sz5TestBasicOps.test_combinations.<locals>.combinations1c3sTt|��t��}x>tt|�|�D],}t|�t|�kr t�fdd�|D��Vq WdS)Nc3s|]}�|VqdS)Nr)r7r)r�rrr��szHTestBasicOps.test_combinations.<locals>.combinations2.<locals>.<genexpr>)r�r��permutationsr�sortedr)r(r+rr�r)r�r�
combinations2�s
z5TestBasicOps.test_combinations.<locals>.combinations2c3sTt|��t��}x>tt|�|�D],}tt|��|kr t�fdd�|D��Vq WdS)Nc3s|]}�|VqdS)Nr)r7r)r�rrr�szHTestBasicOps.test_combinations.<locals>.combinations3.<locals>.<genexpr>)r�r��combinations_with_replacementr�set)r(r+rr�r)r�r�
combinations3�s
z5TestBasicOps.test_combinations.<locals>.combinations3rVcSsg|]}d|d�qS)rW�r)r7rrrrr8sz2TestBasicOps.test_combinations.<locals>.<listcomp>rc3s|]}|�kVqdS)Nr)r7r;)�valuesrrr�sz1TestBasicOps.test_combinations.<locals>.<genexpr>csg|]}|�kr|�qSrr)r7r;)rKrrr8s)r`r@�combinationsrrtrDrrFrr�r*r�r��
assertTrue�allr0rdrL)
r�op�testIntermediater�r�r�rr+�resultr4r)rKr�r�test_combinations�sP
6

zTestBasicOps.test_combinationsc	Cs(|�ttf��tdd�WdQRXdS)N�AAi )r`�
OverflowError�MemoryErrorr�)rrrr�test_combinations_overflowsz'TestBasicOps.test_combinations_overflowz"tuple reuse is specific to CPythonc
CsH|�tttttdd����d�|�ttttttdd�����d�dS)N�abcderMr)rDr�r�r_�idr��assertNotEqualr)rrrr�test_combinations_tuple_reuses z*TestBasicOps.test_combinations_tuple_reusec

s�t}|�t|d�|�t|ddd�|�t|d�|�t|dd�xldd�gtD]Z}|�t||dd���dd	d
ddd
g�|dd�}t|�|�t||��d	d
ddd
g�qRWdd�}dd�}dd�}�x�td�D�]�}dd�t|�D���x�t|d�D�]�}t|�|��}	|�t	|	�|||��|�t	|	�t	t
|	���|�|	t|	��tt�|��}
|dk�sp|dk�r~|�|	|
�n|�
t
|	�t
|
�k�x�|	D]��|�t	��|�dd�t��D�}|�t	|�t	t
|���|�t��t���|�
t�fdd��D���|�|�fdd��D���q�W|�|	t|�|���|�|	t|�|���x*ttjd�D]}|�||�|���qdWq�Wq�WdS)NrTrrr{cSs|S)Nr)rIrrrr5*r6zATestBasicOps.test_combinations_with_replacement.<locals>.<lambda>�ABC)r~r~)r~r)r~r�)rr)rr�)r�r�c3s�t|��t��}|s|rdSdg|}t�fdd�|D��Vxfx*tt|��D]}|||dkrNPqNWdS||dg||||d�<t�fdd�|D��Vq@WdS)Nrc3s|]}�|VqdS)Nr)r7r)r�rrr�;szPTestBasicOps.test_combinations_with_replacement.<locals>.cwr1.<locals>.<genexpr>rc3s|]}�|VqdS)Nr)r7r)r�rrr�Cs)r�r�r�r)r(r+rr�rr)r�r�cwr13s
z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr1c3sVt|��t��}x@tt|�|d�D],}t|�t|�kr"t�fdd�|D��Vq"WdS)N)�repeatc3s|]}�|VqdS)Nr)r7r)r�rrr�KszPTestBasicOps.test_combinations_with_replacement.<locals>.cwr2.<locals>.<genexpr>)r�r��productrr�r)r(r+rr�r)r�r�cwr2Es
z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr2cSs4|s|rdSdSt||d�t|�t|d�S)Nrr)r*)rr+rrr�numcombsMszATestBasicOps.test_combinations_with_replacement.<locals>.numcombsrVcSsg|]}d|d�qS)rWr�r)r7rrrrr8SszCTestBasicOps.test_combinations_with_replacement.<locals>.<listcomp>rcSsg|]\}}|�qSrr)r7�k�vrrrr8csc3s|]}|�kVqdS)Nr)r7r;)r�rrr�fszBTestBasicOps.test_combinations_with_replacement.<locals>.<genexpr>csg|]}|�kr|�qSrr)r7r;)rKrrr8hs)r�r`r@rrtrDrrFrr�r�r�r�r��groupbyr�r0rdrL)
r�cwrr�r�r�r�r�rr+r�Z
regular_combsZnorunsr4r)rKr�r�"test_combinations_with_replacement#sL

z/TestBasicOps.test_combinations_with_replacementc	Cs(|�ttf��tdd�WdQRXdS)Nr�i@)r`r�r�r�)rrrr�+test_combinations_with_replacement_overflowosz8TestBasicOps.test_combinations_with_replacement_overflowc
CsLt}|�tttt|dd����d�|�ttttt|dd�����d�dS)Nr�rMr)r�rDr�r�r_r�r�r)rr�rrr�.test_combinations_with_replacement_tuple_reuseus 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�}�x|td�D�]n}dd�t|�D���xTt|d�D�]B}tt�|��}|�t|�||kr�dnt|�t||��|�t|�tt	|���|�|t
|��xN|D]F}|�t|�|�|�tt	|��|�|�t�fdd�|D����q>W|�|t|�|���|�|t|�|���||k�r�|�|tt�d���|�|tt����x*tt
jd�D]}|�|t�|���q�Wq�Wq�WdS)NrTrrr{r|r3rM)rr)rr)rr)rr)rr)rrc3s@t|��t��}|dkr|n|}||kr,dStt|��}tt||d|d��ddd�}t�fdd�|d|�D��Vx�|�r:x�tt|��D]�}||d8<||dkr�||dd�|||d�||d�<||||<q�||}||||||<||<t�fdd�|d|�D��VPq�WdSq~WdS)Nr���c3s|]}�|VqdS)Nr)r7r)r�rrr��szHTestBasicOps.test_permutations.<locals>.permutations1.<locals>.<genexpr>rc3s|]}�|VqdS)Nr)r7r)r�rrr��s)r�r�rrr�)r(r+rr�Zcyclesrr�r)r�r�
permutations1�s&$ ( z5TestBasicOps.test_permutations.<locals>.permutations1c3sft|��t��}|dkr|n|}x@tt|�|d�D],}tt|��|kr2t�fdd�|D��Vq2WdS)N)r�c3s|]}�|VqdS)Nr)r7r)r�rrr��szHTestBasicOps.test_permutations.<locals>.permutations2.<locals>.<genexpr>)r�r�r�rr�)r(r+rr�r)r�r�
permutations2�sz5TestBasicOps.test_permutations.<locals>.permutations2rVcSsg|]}d|d�qS)rWr�r)r7rrrrr8�sz2TestBasicOps.test_permutations.<locals>.<listcomp>rc3s|]}|�kVqdS)Nr)r7r;)r�rrr��sz1TestBasicOps.test_permutations.<locals>.<genexpr>)N)N)r`r@r�rrDrrr�r*r�r�r�r�r0rdrL)rr�r�rr+r��pr4r)r�r�test_permutations{s8

	,
"
zTestBasicOps.test_permutationsc	Cs(|�ttf��tdd�WdQRXdS)Nr~i@)r`r�r�r�)rrrr�test_permutations_overflow�sz'TestBasicOps.test_permutations_overflowc
CsH|�tttttdd����d�|�ttttttdd�����d�dS)Nr�rMr)rDr�r�r_r�r�r�r)rrrr�test_permutations_tuple_reuse�s z*TestBasicOps.test_permutations_tuple_reusec	s(�x td�D�]}dd|�}�x�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*WqWdS)NrN�ABCDEFGrX)r�rrcSs g|]}t|�t|�kr|�qSr)r�r)r7�trrrr8�sz3TestBasicOps.test_combinatorics.<locals>.<listcomp>cs g|]}tt|���kr|�qSr)r�r�)r7r�)r+rrr8�scSs g|]}t|�t|�kr|�qSr)r�r)r7r�rrrr8�scs g|]}tt|���kr|�qSr)r�r�)r7r�)r+rrr8�s)
rrr�r�r�r�rDr�r*r�r��filter�__contains__)rrr3r)r�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��xdd�dd�gt	D]�}x�dddddddgddfdddddddgddfdddddddgddfddddgddfdddddddgd	dfgD]|\}}}}|�t|t||d���t|��|�t|t||���t|��t||�}|�r�t
|�|�t||��t|���q�W�q�WdS)N�ABCDEFrr)�data�	selectors�ACEFrlZACr�ZBCi'rN)rrrMrWcSs
t�|�S)N)rr)rIrrrr5�r6z,TestBasicOps.test_compress.<locals>.<lambda>cSs
t�|�S)N)rrrs)rIrrrr5�r6ZCEFZBCDEFr�)rDr�compressrnrpr�rr`r@rtrF)rrr�r�r�Zresult1Zresult2r�rrr�
test_compress�s6(&&& & & 
zTestBasicOps.test_compressc	Csn|�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�x\tjdtjdd)d
d*dtjdtjdfD](}tt|��}d+�|�}|�||��q�Wx|d
dtdtdfD]d}t|�}|�t
t�|��|�|�t
t�|��|�x(t	tjd�D]}|�|t|���q4W�q�Wtdtd�t��dS),NrT)rIr)rJr)rKrrM)rIrM)rJr:)rKrWrr�)rIr�)rJr���)rIr�)rJr{r:rIr.rWg
@g@g@y
@�y@�y@�z1.1z2.1z3.1rXri�zcount(3)zcount(4)i����z	count(-9)i����g�$@zcount(10.25)g$@zcount(10.0)i����rz	count(%r))rDr
�countr%r	r`r@�maxsizerrrr�reprrFrE�float�sys�__mod__rrrsr0rdrL�exc_info)r�BIGINTrKr�r1�r2�valuer4rrr�
test_countsT   $6
zTestBasicOps.test_countcCsv|�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�x�tjdtjdd8dddtjdtjdfD]�}x�tjdtjdd8ddddtjdtjdf	D]l}tt||��}|dk�r"d9|}nd:||f}|�||�x*ttjd�D]}|�|t||���qJW�q�W�q�WdS);NrTrrM)rIr)rJrW)rKrX)�start�stepr�)r�)rIr)rJr�)rKr{rIrJr)rJr)rKrr)rJrM)rKr:�rO�dr.rWg�?g
@g@y
@�y@�y!@ �z1.1z.1z1.2z1.3rV�rPi�g@g)@g.@zcount(3, 5)zcount(8, 5)i����zcount(-9, 0)r�z
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)i����z	count(%r)z
count(%r, %r))rDr
r�r`r@r%r�rrrrr�rFrEr]r�r�r0rdrL)rr�rKrr�r�r�r4rrr�test_count_with_stride7sf28""&



68

z#TestBasicOps.test_count_with_stridec
s|�tdtd��td��|�ttd��g�|�tt�|�ttd�|�tttt��d��ddddddddddg
�td��|�t��d	�|�tdt	�
���td
��xvttj
d�D]d}|�tdt�t��|���td
��t��|�tdt�t��|���td��t��t��q�Wx(ttj
d�D]}|�|td���q4Wx�ttj
d�D]�}td�}t|���fd
d�td�D�}t��|�}t�|�}|�td|�td��td�}t|���fdd�td�D�}t��|�}t�|�}|�td|�td���q^WdS)Nr.rTZ
abcabcabcarlrWrrrrIZ
bcabcabcabZ
cabcabcabcr�csg|]}t���qSr)rF)r7r)rKrrr8�sz+TestBasicOps.test_cycle.<locals>.<listcomp>r�Zcdeabcdeabcdeabcdeabcsg|]}t���qSr)rF)r7r)rKrrr8�srV)rDr%�cyclerr`r@r#rrFrrrsrr0rdr1r2rLry)rr4rA�_r�rvr)rKr�
test_cyclens>0



zTestBasicOps.test_cyclec	Cs td�}|�td�df�|�td|�td��td�}|�td�df�|�td|�td��|�t��td��td�dg�WdQRX|�t�� td�}|�td�df�WdQRXtd|�|�t��td��td�df�WdQRX|�ttd	�jd
�|�ttd	�jgf�dS)N�defgrTrr�Zdefgabcdefgabcdefgab�abcdefgrrrlr)r�rxrrDr%r`r@r�)rrKrrr�test_cycle_setstate�s  
 z TestBasicOps.test_cycle_setstatec
s6|�gttg���|�gttgtd���|�tttdg��|�ttd�|�ttddd�d�dddd	d
ddd
g}g}xBt|dd��D]0\}}x&|D]}|�||d�|�|�q�Wq�W|�||�xvttj	d�D]d}g}xNt�
t�t|t�|��D]2\}}x(|D] }|�||d�|�|��qWq�W|�||�q�Wg}xlt|t�D]^\}}xRt|t
�D]D\}}x8|D]0}|�||d�|�||d�|�|��qvW�qhW�qTW|�||�x�ttj	d�D]�}g}x�t�
t�t|t�|��D]l\}}x`t�
t�t|t
�|��D]D\}}x8|D]0}|�||d�|�||d�|�|��q$W�qW�q�W|�||��q�Wdd�t|t�D�}	tdd�|D��}
|�t|	�|
�|�t|	�t|
��ttdtd���}t|t�}t|�\}}
t|�\}}t|�\}}|�t|
�g�|�t|�g�|�t|�d�t|�|�t|�g�x\ttj	d�D]J}t|t�}t|�\}}t|�t|�|�tt�
t�||���g��qXWd}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)�keyrTcSs|S)Nr)rrrrr5�r6z+TestBasicOps.test_groupby.<locals>.<lambda>r.)rr.r�)r�rP)rr�rP)r�
rP)r��)rrOr�)rMrZ�)rMr�r�cSs|dS)Nrr)r+rrrr5�r6rrrcSsg|]\}}|�qSrr)r7r��grrrr8�sz-TestBasicOps.test_groupby.<locals>.<listcomp>cSsg|]}|d�qS)rr)r7r+rrrr8�sZ	AABBBAAAArY)r~rWZabracadabracSsg|]\}}|�qSrr)r7r�r�rrrr8
srIrJrKrvr+cSs$g|]\}}tt|dd��r|�qS)rr)rr#)r7r�r�rrrr8
scSs g|]\}}tt|��|f�qSr)r�r)r7r�r�rrrr8s)rWrI)rrJ)rrK)rrv)rr+cSs g|]\}}tt|��|f�qSr)r�r)r7r�r�rrrr8sT)�reverserMc@seZdZdS)z0TestBasicOps.test_groupby.<locals>.ExpectedErrorN)r r!r"rrrr�
ExpectedErrorsr�c3s xt|�D]
}dVq
W��dS)NZyo)r)rr)r�rr�
delayed_raises
z0TestBasicOps.test_groupby.<locals>.delayed_raisecs�fdd�t||�D�S)Ncsg|]\}}�|��qSrr)r7r�r�)�funcrrr8sz;TestBasicOps.test_groupby.<locals>.gulp.<locals>.<listcomp>)r�)r(Zkeypr�r)r�r�gulpsz'TestBasicOps.test_groupby.<locals>.gulpcseZdZ�fdd�ZdS)z+TestBasicOps.test_groupby.<locals>.DummyCmpcs��dS)Nr)r�dst)r�rr�__eq__'sz2TestBasicOps.test_groupby.<locals>.DummyCmp.__eq__N)r r!r"r�r)r�rr�DummyCmp&sr�)r�cs$�jdkr�jd8_|S��dS)Nrr)�skip)�obj)r��keyfuncrrr�1s
z*TestBasicOps.test_groupby.<locals>.keyfunc)r)rDrr�r�r`r@�appendrr0rdr1r2r,r-r�r�r	rFr��	Exceptionr�)rr3�dupr�r��elemr4ZikZig�keysZexpectedkeysrAr�Zg1Zg2Zg3r+r�r�r�r)r�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�|��|�xrtt
jd�D]`}tttd��}|�tt
�t
�||���|�t
|�|�tt
�t
�||���|dd���qPWx2tt
jd�D] }tttd��}|�||��q�WdS)NrNrrr:rcSs|S)Nr)rrrrr5Dr6z*TestBasicOps.test_filter.<locals>.<lambda>cSs|S)Nr)rrrrr5Er6rVrM)rDrr�rr�boolr%r�r`r@rFrrrsr0rdr1r2rL)r�ansrKr4rrr�test_filter>s, $$"
,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���x.ttjd�D]}|�
|tttd����qWdS)NrNrrMrWrrr:rVcSs|S)Nr)rrrrr5_r6z/TestBasicOps.test_filterfalse.<locals>.<lambda>cSs|S)Nr)rrrrr5`r6)rDr�filterfalserrr�r%r�r`r@rFr0rdrL)rr4rrr�test_filterfalseYs &&"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�qSrr)r7r�yrrrr8hsz)TestBasicOps.test_zip.<locals>.<listcomp>rT)rIr)rJr)rKrrNrkrMcSsg|]}tt|���qSr)r�r)r7�pairrrrr8qsrjcSsg|]}|�qSrr)r7r�rrrr8ss)	r	r�rDrrr
r%r`r@)rr�rrr�test_zipfs$$$zTestBasicOps.test_zipc	Cs�ttttdd���}|�t|�t|��tttttdd����}|�tt�	|��t|��dd�t
�
tdt���D�}|�|dddg�dd�t
�tdt���D�}|�|dddg�xLt
tjd	�D]:}d
d�t�t�tdt��|��D�}|�|dddg�q�WxXt
tjd	�D]F}tdt��}t|�dd�t�t�||��D�}|�|ddg��qWx,t
tjd	�D]}|�|tdt����qnWdS)NrTrjcSsg|]\}}||f�qSrr)r7rr�rrrr8~sz5TestBasicOps.test_zip_tuple_reuse.<locals>.<listcomp>)rIr)rJr)rKrcSsg|]\}}||f�qSrr)r7rr�rrrr8�srcSsg|]\}}||f�qSrr)r7rr�rrrr8�scSsg|]\}}||f�qSrr)r7rr�rrrr8�s)rr_r�r	rDrarbr��dict�fromkeysrrr�rsrr0rdr1r2rFrL)r�idsr�r4r�rrr�test_zip_tuple_reusevs$$z!TestBasicOps.test_zip_tuple_reusecsVx�dtd�gtd�dgtd�tdd�tdd�gtd�td�tdd�td	�td
�gtd�td�tdd�td	�td
�td�ggD]x��fdd�tttt����D�}|�tt���|�|�tt�i��|�d
d�|D�}|�tt�tdd���|�q|W|�tdtdt	���tt
dtd����|�tt��tt
���|�ttg��tt
g���|�ttd��tt
d���|�ttdi��tt
td�dgd���|�ttd�|�tttd�d�xHdD]@}yt
|t�t��Wntk
�r�YnX|�d|��q�W|�dd�tdd�D�tt
dd���|�dd�tdd�D�tt
dd���dS)NrTrNi�i�i4i�i�ri�i�cs"g|]�t�fdd��D���qS)cs$g|]}�t|�kr|�nd�qS)N)r�)r7�arg)rrrr8�sz;TestBasicOps.test_ziplongest.<locals>.<listcomp>.<listcomp>)r�)r7)r
)rrr8�sz0TestBasicOps.test_ziplongest.<locals>.<listcomp>cSsg|]}tdd�|D���qS)css|]}|dkrdp|VqdS)N�Xr)r7r;rrrr��sz:TestBasicOps.test_ziplongest.<locals>.<listcomp>.<genexpr>)r�)r7r�rrrr8�sr�)�	fillvaluerMrkr�)zzip_longest('abc', fv=1)z3zip_longest('abc', fillvalue=1, bogus_keyword=None)zDid not raise Type in:  cSsg|]}tt|���qSr)r�r)r7r�rrrr8�srjcSsg|]}|�qSrr)r7r�rrrr8�s)rTr�)rrbr_r�rDr�zip_longestr�r%r�r	r`r@�eval�globals�localsZfail)r�targetZstmtr)r
r�test_ziplongest�s<

"0
 (
zTestBasicOps.test_ziplongestcCs^ttttdd���}|�t|�t|��tttttdd����}|�tt�	|��t|��dS)NrTrj)
rr_r�rrDrarbr�r�r�)rr�rrr�test_zip_longest_tuple_reuse�sz)TestBasicOps.test_zip_longest_tuple_reusec	Cshxbttjd�D]P}|�|tdd��|�|tdd��|�|tdddd��|�|tdd��qWdS)NrrTrjZdefgh)r�rl)rr0rdrLr)rr4rrr�test_zip_longest_pickling�s
z&TestBasicOps.test_zip_longest_picklingcCs�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|�|_||_dS)N)�or]r�r;)rrr�r;rrr�__init__�s
z5TestBasicOps.test_bug_7244.<locals>.Repeater.__init__cSs|S)Nr)rrrrr�sz5TestBasicOps.test_bug_7244.<locals>.Repeater.__iter__cSs(|jdkr|jd8_|jS|j�dS)Nrr)r�rr;)rrrrr�s
z5TestBasicOps.test_bug_7244.<locals>.Repeater.__next__N)r r!r"r	rrrrrr�Repeater�sr
rrMrr:c
SsTg}xJt||dd�D]8\}}t�d��t||f�WdQRX|�||f�qW|S)Nr)r��stdout)rrZcaptured_output�printr�)r�r�r�rr�rrr�run�sz'TestBasicOps.test_bug_7244.<locals>.run)rr)rrr)r�)rrDr=rrFr`)rr
r�r�r
rArrr�
test_bug_7244�szTestBasicOps.test_bug_7244csx�gdgfdgddgftd�td�gddd	d
ddgftd
�td�td�ggftd�td
�td�ggftd�td�td
�ggfgD]V\}}|�tt|��|�x8td�D],}|�tt||��tt|t|d����q�Wq�W|�ttttd�gd���d�|�tttd�d�dd�}dd�}dddtd
�td�tdddd�td�td�t	td��g	�x�td�D]�}�fdd �tt
�d!��D�}tt
t|��}|�ttt|���|�|�tt|��t||���|�tt|��t||���t
t|�}|�ttt|���|��qbWdS)"NrrU)rI)rJrrM)rr)rr)rr)rr)rr)rrrr:)r�rVrNi��cs�ttt|��|�dd�}t|�}|dkr4dVdStdd�|D��rJdSdg|}tdd�t||�D��Vx�x~tt|��D]j}||t||�dkr�q~||d7<xt|d|�D]}d||<q�Wtdd�t||�D��VPq~WdSqpWdS)	Nr�rrrcss|]}t|�dkVqdS)rN)r�)r7r�rrrr�sz>TestBasicOps.test_product.<locals>.product1.<locals>.<genexpr>css|]\}}||VqdS)Nr)r7r�rrrrr�
scss|]\}}||VqdS)Nr)r7r�rrrrr�s)	rr_r��getr��anyr	r�r)r
�kwds�poolsrr�rr�rrr�product1s&
z+TestBasicOps.test_product.<locals>.product1c?s\ttt|��|�dd�}gg}x|D]��fdd�|D�}q&Wx|D]}t|�VqFWdS)Nr�rcs g|]}�D]}||g�qqSrr)r7rr�)r�rrr8sz?TestBasicOps.test_product.<locals>.product2.<locals>.<listcomp>)rr_r�r)r
rrr�r)r)r�r�product2s

z+TestBasicOps.test_product.<locals>.product2rlrTr)rIrJrKr�r�r�r�csg|]}t����qSr)�random�choice)r7r�)�argtypesrrr8#sz-TestBasicOps.test_product.<locals>.<listcomp>rW)rrDrr�r�r�r`r@r�r�rZ	randranger)r_ry)rr
r�r+rrrZexpected_lenr)rr�test_product�s2$"	
zTestBasicOps.test_productc	Cs2|�ttf��tdgdddi�WdQRXdS)NrUr|r�i)r`r�r�r�)rrrr�test_product_overflow+sz"TestBasicOps.test_product_overflowc
CsH|�tttttdd����d�|�ttttttdd�����d�dS)NrTrjr)rDr�r�r_r�r�r�r)rrrr�test_product_tuple_reuse0s z%TestBasicOps.test_product_tuple_reusec	Cs�x�gdgfdgddgftd�td�gddd	d
ddgftd
�td�td�ggftd�td
�td�ggftd�td�td
�ggfgD]d\}}|�tt�t|���|�|�tt�t|���|�x&ttjd�D]}|�|t|��q�Wq�WdS)NrrU)rI)rJrrM)rr)rr)rr)rr)rr)rrrr)	rrDrrrr�rsr0rdrL)rr
r�r4rrr�test_product_pickling5s$z"TestBasicOps.test_product_picklingcCsLtdd�}|�d�|�t|�d�tddd�}|�d�|�tt|�dS)N)rr)rM)ri)rrMr)rri)r�rxrDrFr`r)rr�rrr�test_product_issue_25021Ds


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��x,ttj
d�D]}|�|tddd���q~WdS)NrIrM)�object�times)rrI)rrI)rrIrr�r:y�?zrepeat((1+0j))rWzrepeat((1+0j), 5)zrepeat((1+0j), 0)r.rZaar)rDrr�r
rr%r`r@r�rFrrrsr0rdrL)rr+rKr4rrr�test_repeatNs,
zTestBasicOps.test_repeatcCs`|�ttdd��d�|�ttdd��d�|�ttddd��d�|�ttddd��d�dS)NrIr�zrepeat('a', 0)r{)r)rDr�r�)rrrr�test_repeat_with_negative_timeshsz,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�|��|�x2ttjd�D] }ttdt��}|�||��q�WdS)NrMrrVrrXrTrW)rIr)rJr)rKrrr.r:)rDrr_r&�powrrr�r%r`r@�negrFrrrrrrsr0rdrL)rr�rKr4rrr�test_mapns.

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�|��|�x@ttjd�D].}ttjttd�tdd���}|�||��q�WdS)NrMrrVrrXr:rWi)r:rW�extrar.)rDr�starmapr&r!r	rr%r�ryr`r@rFrrrrrrsr0rdrL)rr�rKr4rrr�test_starmap�s(" $
zTestBasicOps.test_starmapc		CsXx2dD]*}|�tttd�f|���tt|���qWx6dD].\}}|�tttd�f|���tt|���q:W|�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�x�dD]�}|�tt�ttd�f|����tt|���|�tt�
ttd�f|����tt|���x2ttjd�D] }|�|ttd�f|����qFW�q�Wdd�dD�}t�|�}t|d�}|�|��t|�t��|�|��Gdd�dt�}|�tttd�|d���ttd���|�tttd�|d�|d
���ttdd
���|�tttd�|d�|d
�|d���ttdd
d���dS)N))r.r�rM)r.rMr�)r.r�)r.r.)r.rM)r�r�)))r.�nrM)r.r�rM))r.r')r.r�))r')r�r.rrrMr:���r�rrI�2))r.r�rM)r.rMr�)r.r�)r.rM)r�css|]
}|VqdS)Nr)r7rrrrr��sz+TestBasicOps.test_islice.<locals>.<genexpr>)rrc@seZdZdd�Zdd�ZdS)z)TestBasicOps.test_islice.<locals>.IntLikecSs
||_dS)N)�val)rr*rrrr	�sz2TestBasicOps.test_islice.<locals>.IntLike.__init__cSs|jS)N)r*)rrrr�	__index__�sz3TestBasicOps.test_islice.<locals>.IntLike.__index__N)r r!r"r	r+rrrr�IntLike�sr,rW)rDrr#rryr`r@rr�r�r�rFrrrsr0rdrL�weakref�refZassertIsNotNonerZ
gc_collectZassertIsNoner)	rr
ZtgtargsrAZrarKr4Zwrr,rrr�test_islice�sj
"$&&* 
&

&$zTestBasicOps.test_islicecCsRddddddddg}|�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�x*ttjd�D]}|�|tt|���q2WdS)
NrrMrWr�rr:rNrX)r:rWr$r.r)rDr�	takewhiler/r`r@r&r!rFrrr�rrrrsrr0rdrL)rr�r�r4rrr�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�x*t
tjd�D]}|�|tt|���qWdS)NrrMrWr�rr:rNrX)r:rWr$r.)rDr�	dropwhiler/r`r@r&r!rFrrrrrsrr0rdrL)rr�r4rrr�test_dropwhiles &zTestBasicOps.test_dropwhilecCsd}tg�\}}|�t|�g�|�t|�g�tt|��\}}|�t||�tt|�t|���tt|��\}}|�t|�tt|���|�t|�tt|���tt|��\}}x td�D]}|�t|�|�q�W~|�t|�tt|���tt|��\}}x"td�D]}|�t|�|��qW~|�t|�ttd|���x�td�D]�}dg|dg|}t�|�ggf}tt|��}x(|D] }t||�}	||�	|	��q�W|�|dtt|���|�|dtt|����qFW|�
tt�|�
ttd�|�
ttddgd�|�
ttddgdd�td	�\}}t|�d
�}
|�t|
�td
��ttd�d�\}}}
x"td�D]}|�t|�|��qjW|�t|�ttd���|�t|
�t|
�gttd���|�t|�ttdd���|�t|
�ttdd���|�
ttd	d�|�
t
tgd
�x\td�D]P}td	|�}|�t|�t�|�t|�|�|�dd�|D�td	�g|��qWtd	�\}}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��xXttjd�D]F}|�|ttd	���td	�\}}|j|||d�|j|||d��q�WdS)N��r�rWrrrMrrrTrji�Zinvalidr�cSsg|]}t|��qSr)r)r7rrrrr8jsz)TestBasicOps.test_tee.<locals>.<listcomp>r.�	__class__i'�<)rG)�teerDrrr
rrFrZshuffler�r`r@rErr�r�r�r-�proxy�getattr�ReferenceErrorrrr%rsr0rdrLry)rrrIrJrr��orderZlistsZitsr�rKr�rvZt1Zt2ZtnewZt3r�r�Zlong_ansr4rrr�test_tee*s� 

 
&<








zTestBasicOps.test_teecCs8ttdd��\}}yt|�~Wn~~�YnXdS)Ni-1)r7r�r)rZforwardZbackwardrrr�test_tee_del_backward�sz"TestBasicOps.test_tee_del_backwardc	sDG�fdd�d�}t|��\}�|�td��t|�WdQRXdS)Ncs$eZdZdZdd�Z�fdd�ZdS)z(TestBasicOps.test_tee_reenter.<locals>.ITcSs|S)Nr)rrrrr�sz1TestBasicOps.test_tee_reenter.<locals>.I.__iter__cs|j}d|_|rt��SdS)NF)�firstrF)rr>)rJrrr�sz1TestBasicOps.test_tee_reenter.<locals>.I.__next__N)r r!r"r>rrr)rJrr�I�sr?r7)r7�assertRaisesRegexr=rF)rr?rIr)rJr�test_tee_reenter�s
zTestBasicOps.test_tee_reenterc	s�t���t���G��fdd�d�}t|��\}}tjt|gd�}|��z,���|�td��t|�WdQRXWd��	�|�
�XdS)Ncs"eZdZdd�Z��fdd�ZdS)z+TestBasicOps.test_tee_concurrent.<locals>.IcSs|S)Nr)rrrrr�sz4TestBasicOps.test_tee_concurrent.<locals>.I.__iter__cs������dS)N)r��wait)r)�finishr�rrr�sz4TestBasicOps.test_tee_concurrent.<locals>.I.__next__N)r r!r"rrr)rCr�rrr?�sr?)rr
r7)�	threadingZEventr7ZThreadrFr�rBr@r=r��join)rr?rIrJZthreadr)rCr�r�test_tee_concurrent�sz TestBasicOps.test_tee_concurrentcCs,|�ttt��x:ttttfD]*}|�tt|g��|�tt|t���qW|�tttgd��|�tttt�d��t	g�\}}|�tt|�|�tt|�t	t��\}}|�tt|�|�tt|�|�ttt
dd��xJttt
tttfD]6}|�tt|dd�g��|�tt|dd�t���q�WdS)NrcSs|S)Nr)rrrrr5r6z1TestBasicOps.test_StopIteration.<locals>.<lambda>cSs|S)Nr)rrrrr5r6)r`rrFr	rnr�r�rr#r7r�r�r�r_r0r2r%)rrwr��qrrr�test_StopIteration�s zTestBasicOps.test_StopIteration)r:rN)5r r!r"rLrfrorqrurzr�rZbigaddrspacetestr�Zimpl_detailr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrrrr r#r&r/r1r3r<r=rArFrHrrrrr9Psb
)

PL?!"07*$
*(:
^	r9c@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)	NrrrMr:rWrNr.rO)rDrr\)rrrrrfszTestExamples.test_accumulatec
Cs�dddddg}dddddg}xzttjd�D]h}t|�}|�tt�t�||���|dd��|�t|�d�|�tt�t�||���|dd��q,Wt|�}|�t|�d�|�tt	�
|��|dd��|�tt	�	|��|dd��dS)	NrrrMr:rWrNr.rO)rr0rdr\rDrr1r2rFrrrs)rr�Zaccumulatedr4rArrr�test_accumulate_reducibles&*z&TestExamples.test_accumulate_reduciblecCs�tdddgtj�}|�t|�d�x<ttjd�D]*}t�t�	||��}|�t
|�ddg�q2W|�t
t�|��ddg�|�t
t�|��ddg�dS)NrTF)
r\r&�is_rDrFrr0rdr1r2rrrrs)rrAr4Zit_copyrrr�test_accumulate_reducible_nonesz+TestExamples.test_accumulate_reducible_nonecCs|�d�tdd��d�dS)Nrlr��DEFr�)rDrErn)rrrrro!szTestExamples.test_chaincCs |�d�t�ddg��d�dS)Nrlr�rMr�)rDrErnrp)rrrrrq$sz%TestExamples.test_chain_from_iterablec	CsH|�ttdd��ddddddg�|�tttd	�d
��ddd
dg�dS)Nr}r)r~r)r~r�)r~r�)rr�)rr�)r�r�r:rM)rrr)rrrM)rrrM)rrrM)rDrr�r)rrrrr�'szTestExamples.test_combinationsc	Cs&|�ttdd��ddddddg�dS)	Nr�r)r~r~)r~r)r~r�)rr)rr�)r�r�)rDrr�)rrrrr�-sz/TestExamples.test_combinations_with_replacementcCs*|�ttdddddddg��td��dS)Nr�rrr�)rDrr�)rrrrr�1szTestExamples.test_compresscCs(|�tttd�d��dddddg�dS)Nr.rWr�r�r�r�)rDrr#r�)rrrrr�4szTestExamples.test_countcCs"|�tttd�d��td��dS)Nr}r�ZABCDABCDABCD)rDrr#r�)rrrrr�7szTestExamples.test_cyclec
Cs.|�ttdd�dddddg��dddg�dS)NcSs|dkS)NrWr)rrrrr5;r6z-TestExamples.test_dropwhile.<locals>.<lambda>rr:rN)rDrr2)rrrrr3:szTestExamples.test_dropwhilecCsT|�dd�td�D�td��|�dd�td�D�td�td�td	�td
�g�dS)NcSsg|]\}}|�qSrr)r7r�r�rrrr8>sz-TestExamples.test_groupby.<locals>.<listcomp>ZAAAABBBCCDAABBBZABCDABcSsg|]\}}t|��qSr)r)r7r�r�rrrr8@sZ
AAAABBBCCDZAAAAZBBBZCCr�)rDr�r)rrrrr�=s
zTestExamples.test_groupbycCs,|�ttdd�td���dddddg�dS)	NcSs|dS)Nrr)rrrrr5Dr6z*TestExamples.test_filter.<locals>.<lambda>r.rrMrWrVrY)rDrr�r)rrrrr�CszTestExamples.test_filtercCs,|�ttdd�td���dddddg�dS)	NcSs|dS)Nrr)rrrrr5Gr6z/TestExamples.test_filterfalse.<locals>.<lambda>r.rrr:rNrX)rDrr�r)rrrrr�FszTestExamples.test_filterfalsecCs"|�tttdd��dddg�dS)N)rrMr.)rWrrMr|rYi�)rDrr_r!)rrrrr#IszTestExamples.test_mapcCst|�ttdd��td��|�ttddd��td��|�ttddd��td��|�ttdddd��td��dS)	Nr�r�ABr:�CD�CDEFGr�ACEG)rDrr#)rrrrr/LszTestExamples.test_islicecCs|�ttdd��ddg�dS)Nr}�xy)r~r)rr�)rDrr	)rrrrr�RszTestExamples.test_zipcCs&|�ttdddd��ddddg�dS)	Nr}rR�-)r�)r~r)rr�)r�rS)r�rS)rDrr)rrrr�test_zip_longestUszTestExamples.test_zip_longestc	CsL|�ttdd��tttd�����|�tttd���ddddd	d
g�dS)Nr}rz#AB AC AD BA BC BD CA CB CD DA DB DCrM)rrr)rrr)rrr)rrr)rrr)rrr)rDrr�r_r��splitr)rrrrr�YszTestExamples.test_permutationscCsT|�ttdd��tttd�����|�tttd�dd��ddd	d
ddd
dg�dS)Nr}rRzAx Ay Bx By Cx Cy Dx DyrrM)r�)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rrr)rDrr�r_r�rUr)rrrrr_s
zTestExamples.test_productcCs |�ttdd��dddg�dS)Nr.rM)rDrr�)rrrrrfszTestExamples.test_repeatcCs&|�tttdddg��dddg�dS)N)rrW)rMr)r.rMr|rYi�)rDrr%r!)rrrr�test_stapmapiszTestExamples.test_stapmapc
Cs,|�ttdd�dddddg��ddg�dS)NcSs|dkS)NrWr)rrrrr5nr6z-TestExamples.test_takewhile.<locals>.<lambda>rr:rN)rDrr0)rrrrr1mszTestExamples.test_takewhileN)r r!r"rfrJrLrorqr�r�r�r�r�r3r�r�r�r#r/r�rTr�rrrVr1rrrrrIs.
rIc@s eZdZedd��Zdd�ZdS)�TestPurePythonRoughEquivalentsc
gs�t|�}|jpd|jptj|jp"d}}}tt|||��}yt|�}Wn0t	k
rxxt
t|�|�D]\}}	qhWdSXy0x*t|�D]\}}	||kr�|	Vt|�}q�WWn6t	k
r�x t
t|d|�|�D]\}}	q�WYnXdS)Nrr)�slicer�rCr�r�r�ryrrFrr	�	enumerate)
r(r
r3r�rCr�rAZnextirrhrrrr#ss"$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�rrNr:rOrPrrQr.rMrr))rDrr#ryrr�rF)rrArKrrr�test_islice_recipe�s  z1TestPurePythonRoughEquivalents.test_islice_recipeN)r r!r"�staticmethodr#rZrrrrrWqsrWc@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|�~~dS)N)r�rF)r�iterator�	containerrrr�	makecycle�s
zTestGC.makecyclecCs g}|�tdd|dg�|�dS)NrrrM)r_r\)rrIrrrrf�szTestGC.test_accumulatecCsg}|�t|�|�dS)N)r_rn)rrIrrrro�szTestGC.test_chaincCsg}|�t�|g�|�dS)N)r_rnrp)rrIrrrrq�szTestGC.test_chain_from_iterablecCs"g}|�tdd|dgd�|�dS)NrrrM)r_r�)rrIrrrr��szTestGC.test_combinationscCs"g}|�tdd|dgd�|�dS)NrrrM)r_r�)rrIrrrr��sz)TestGC.test_combinations_with_replacementc
Cs&g}|�tdddddddg�|�dS)Nr�rr)r_r�)rrIrrrr��szTestGC.test_compresscCs6g}tdtft|d��}|�t|d�|d��|�dS)N�Int)rrr)rEr]r�r_r�)rrIr`rrrr��szTestGC.test_countcCsg}|�t|gd�|�dS)Nr)r_r�)rrIrrrr��szTestGC.test_cyclecCs g}|�ttd||g�|�dS)Nr)r_r2r�)rrIrrrr3�szTestGC.test_dropwhilecCs$g}|�t|gddd��|�dS)NrcSs|S)Nr)rrrrr5�r6z%TestGC.test_groupby.<locals>.<lambda>)r_r�)rrIrrrr��szTestGC.test_groupbycCsBd}dd�}x0tt|�|d�D]\}}|j�dg��|�qWdS)Nr.cSs|S)Nr)rrrrr5�r6z'TestGC.test_issue2246.<locals>.<lambda>)r�r)r�r�__dict__�
setdefaultr�)rrr�rr�rrr�test_issue2246�szTestGC.test_issue2246cCs$g}|�tdd�|gd�|�dS)NcSsdS)NTr)rrrrr5�r6z$TestGC.test_filter.<locals>.<lambda>r)r_r�)rrIrrrr��szTestGC.test_filtercCsg}|�tdd�|�|�dS)NcSsdS)NFr)rrrrr5�r6z)TestGC.test_filterfalse.<locals>.<lambda>)r_r�)rrIrrrr��szTestGC.test_filterfalsecCs&g}|�t|gd|gd�|�dS)NrrM)r_r	)rrIrrrr��szTestGC.test_zipcCsPg}|�t|gd|gd�|�|dg}|�t|gd|gd|d�|�dS)NrrM)r�)r_r)rrIrJrrrrT�szTestGC.test_zip_longestcCs$g}|�tdd�|gd�|�dS)NcSs|S)Nr)rrrrr5�r6z!TestGC.test_map.<locals>.<lambda>r)r_r_)rrIrrrr#�szTestGC.test_mapcCs g}|�t|gdd�|�dS)Nr)r_r#)rrIrrrr/�szTestGC.test_islicecCs"g}|�tdd|dgd�|�dS)NrrrM)r_r�)rrIrrrr��szTestGC.test_permutationscCs$g}|�tdd|dgdd�|�dS)NrrrM)r�)r_r�)rrIrrrr�szTestGC.test_productcCsg}|�t|�|�dS)N)r_r�)rrIrrrr�szTestGC.test_repeatcCs(g}|�tdd�||fgd�|�dS)NcWs|S)Nr)r�rrrr5�r6z%TestGC.test_starmap.<locals>.<lambda>r)r_r%)rrIrrrr&�szTestGC.test_starmapcCs"g}|�ttdd||g�|�dS)Nrr)r_r0r�)rrIrrrr1�szTestGC.test_takewhileN)r r!r"r_rfrorqr�r�r�r�r�r3r�rcr�r�r�rTr#r/r�rrr&r1rrrrr\�s.r\ccsx|D]
}|VqWdS)Nr)�seqnrrrr�Rs
rec@seZdZdd�Zdd�ZdS)�GcCs
||_dS)N)rd)rrdrrrr	sz
G.__init__cCs
|j|S)N)rd)rrrrr�__getitem__	sz
G.__getitem__N)r r!r"r	rgrrrrrfsrfc@s$eZdZdd�Zdd�Zdd�ZdS)r?cCs||_d|_dS)Nr)rdr)rrdrrrr	sz
I.__init__cCs|S)Nr)rrrrrsz
I.__iter__cCs2|jt|j�krt�|j|j}|jd7_|S)Nr)rr�rdr)rr�rrrrs
z
I.__next__N)r r!r"r	rrrrrrr?sr?c@seZdZdd�Zdd�ZdS)�IgcCs||_d|_dS)Nr)rdr)rrdrrrr	szIg.__init__ccsx|jD]
}|VqWdS)N)rd)rr*rrrrszIg.__iter__N)r r!r"r	rrrrrrhsrhc@seZdZdd�Zdd�ZdS)r�cCs||_d|_dS)Nr)rdr)rrdrrrr	$sz
X.__init__cCs2|jt|j�krt�|j|j}|jd7_|S)Nr)rr�rdr)rr�rrrr's
z
X.__next__N)r r!r"r	rrrrrr�"sr�c@seZdZdd�Zdd�ZdS)�NcCs||_d|_dS)Nr)rdr)rrdrrrr	/sz
N.__init__cCs|S)Nr)rrrrr2sz
N.__iter__N)r r!r"r	rrrrrri-sric@s$eZdZdd�Zdd�Zdd�ZdS)�EcCs||_d|_dS)Nr)rdr)rrdrrrr	7sz
E.__init__cCs|S)Nr)rrrrr:sz
E.__iter__cCsdddS)NrMrr)rrrrr<sz
E.__next__N)r r!r"r	rrrrrrrj5srjc@s$eZdZdd�Zdd�Zdd�ZdS)�ScCsdS)Nr)rrdrrrr	Asz
S.__init__cCs|S)Nr)rrrrrCsz
S.__iter__cCst�dS)N)r)rrrrrEsz
S.__next__N)r r!r"r	rrrrrrrk?srkcCsttdd�ttt|�����S)NcSs|S)Nr)rrrrr5Jr6zL.<locals>.<lambda>)rnr_rerhrf)rdrrr�LHsrlc@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|�}x.tttttfD]}|�tt||���|�q4W|�ttt	|���g�|�
ttt|��|�
ttt
|��|�
tttt|���dS)	NrrrMr:rWrNr.rO)r�rfr?rhrlrerDrr\rkr`r@r�ri�ZeroDivisionErrorrj)rr3r+rr�rrrrfOsz'TestVariousIteratorArgs.test_accumulatec	Cs�x�ddtd�dtddd�fD]�}xjttttttfD]V}|�tt	||���t||���|�tt	||�||���t||��t||���q2W|�
ttt	t|���|�
ttt	t
|���|�
ttt	t|���qWdS)N�123rli�)�dog333333�?i�i�rW)rrfr?rhrkrlrerDrrnr`r@r�rirnrj)rr3r�rrrroZs  6z"TestVariousIteratorArgs.test_chainc	Cs�x�ddtd�dtddd�fD]�}t|�}x>ttttttfD]*}|�t	t
||�td���t	||���q:W|�t
t
t|�td��|�t
t
t|�td��|�tt	t
t|�td���qWdS)	Nrorli�)rpg333333�?i�i�rWr)rr�rfr?rhrkrlrerDrr�r�r`r@r�rirnrj)rr3rr�rrrr�cs *z%TestVariousIteratorArgs.test_compresscCs^xXddtd�dtddd�fD]:}|�ttt|��|�ttt|��|�ttt|��qWdS)Nrorli�)rpg333333�?i�i�rW)rr`r@r�r�rirnrj)rr3rrrrls z$TestVariousIteratorArgs.test_productcCs�x�ddtd�dtddd�fD]�}xVttttttfD]B}t|�d}t||��d}tt	t
||��|��}|�||�q2W|�t
t
t|��|�t
t
t|��|�ttt
t|���qWdS)	Nrorli�)rpg333333�?i�i�rWrM)rrfr?rhrkrlrer�rr#r�rDr`r@r�rirnrj)rr3r�ZtgtlenZexpected�actualrrrr�rs z"TestVariousIteratorArgs.test_cyclecCs�x�td�td�td�dtddd�fD]~}x>ttttttfD]*}|�dd	�t||��D�t	||���q:W|�
ttt|��|�
ttt
|��|�
tt	tt|���q$WdS)
Nr.ri�)rVr�i�i�rWcSsg|]\}}|�qSrr)r7r�Zsbrrrr8�sz8TestVariousIteratorArgs.test_groupby.<locals>.<listcomp>)rrfr?rhrkrlrerDr�rr`r@r�rirnrj)rr3r�rrrr�}s(*z$TestVariousIteratorArgs.test_groupbyc	Cs�x�td�td�td�dtddd�fD]�}x@ttttttfD],}|�tt	t
||���dd	�||�D��q:W|�tt	t
t
|��|�tt	t
t|��|�ttt	t
t|���q$WdS)
Nr.ri�)rVr�i�i�rWcSsg|]}t|�r|�qSr)r)r7rrrrr8�sz7TestVariousIteratorArgs.test_filter.<locals>.<listcomp>)rrfr?rhrkrlrerDrr�rr`r@r�rirnrj)rr3r�rrrr��s(z#TestVariousIteratorArgs.test_filterc	Cs�x�td�td�td�dtddd�fD]�}x@ttttttfD],}|�tt	t
||���dd	�||�D��q:W|�tt	t
t
|��|�tt	t
t|��|�ttt	t
t|���q$WdS)
Nr.ri�)rVr�i�i�rWcSsg|]}t|�r|�qSr)r)r7rrrrr8�sz<TestVariousIteratorArgs.test_filterfalse.<locals>.<listcomp>)rrfr?rhrkrlrerDrr�rr`r@r�rirnrj)rr3r�rrrr��s(z(TestVariousIteratorArgs.test_filterfalsec	Cs�x�ddtd�dtddd�fD]�}xdttttttfD]P}|�tt	||���t
||���|�tt	||�||���t
||�||���q2W|�tt	t
|��|�tt	t|��|�ttt	t|���qWdS)Nrorli�)rpg333333�?i�i�rW)rrfr?rhrkrlrerDrr	r
r`r@r�rirnrj)rr3r�rrrr��s  0z TestVariousIteratorArgs.test_zipc
Cs�x�ddtd�dtddd�fD]�}xlttttttfD]X}|�tt	||���tt
||����|�tt	||�||���tt
||�||����q2W|�tt	t
|��|�tt	t|��|�ttt	t|���qWdS)Nrorli�)rpg333333�?i�i�rW)rrfr?rhrkrlrerDrrr	r`r@r�rirnrj)rr3r�rrrr�s $4z'TestVariousIteratorArgs.test_ziplongestc
Cs�x�td�td�td�dtddd�fD]�}xpttttttfD]\}|�tt	t
||���dd	�||�D��|�tt	tj||�||���d
d	�||�D��q:W|�
tt	t
t|��|�
tt	t
t|��|�
ttt	t
t|���q$WdS)Nr.rr�)rVr�r�r)rWcSsg|]}t|��qSr)r)r7rrrrr8�sz4TestVariousIteratorArgs.test_map.<locals>.<listcomp>cSsg|]}||�qSrr)r7rrrrr8�s)rrfr?rhrkrlrerDrr_rr&r!r`r@r�rirnrj)rr3r�rrrr#�s(z TestVariousIteratorArgs.test_mapc
Cs�x�ddtd�dtddd�fD]�}xHttttttfD]4}|�tt	||�ddd	��t||��ddd	��q2W|�
tt	t|�d
�|�
tt	t
|�d
�|�
ttt	t|�d
��qWdS)NZ12345rli�)rpg333333�?i�i�rWrrr.)rrfr?rhrkrlrerDrr#r`r@r�rirnrj)rr3r�rrrr/�s 4z#TestVariousIteratorArgs.test_islicec	Cs�x�td�td�td�dtddd�fD]�}xLttttttfD]8}t||�}|�t	t
tj||���dd	�||�D��q:W|�
tt
tjt|��|�
tt
tjt|��|�
tt	t
tjt|���q$WdS)
Nr.rr�)rVr�r�r)rWcSsg|]}||�qSrr)r7rrrrr8�sz8TestVariousIteratorArgs.test_starmap.<locals>.<listcomp>)rrfr?rhrkrlrer
rDrr%r&r!r`r@r�rirnrj)rr3r��ssrrrr&�s(
z$TestVariousIteratorArgs.test_starmapc	Cs�x�td�td�td�dtddd�fD]�}x\ttttttfD]H}g}x$||�D]}t|�sZP|�|�qLW|�	t
tt||���|�q:W|�t
ttt|��|�t
ttt|��|�tt
ttt|���q$WdS)Nr.ri�)rVr�i�i�rW)rrfr?rhrkrlrerr�rDrr0r`r@r�rirnrj)rr3r��tgtr�rrrr1�s(z&TestVariousIteratorArgs.test_takewhilec	Cs�x�td�td�td�dtddd�fD]�}x`ttttttfD]L}g}x(||�D]}|s^t|�r^qL|�|�qLW|�	t
tt||���|�q:W|�t
ttt|��|�t
ttt|��|�tt
ttt|���q$WdS)Nr.ri�)rVr�i�i�rW)rrfr?rhrkrlrerr�rDrr2r`r@r�rirnrj)rr3r�rsr�rrrr3�s(z&TestVariousIteratorArgs.test_dropwhilecCs�x�ddtd�dtddd�fD]�}xXttttttfD]D}t||��\}}|�t	|�t	||���|�t	|�t	||���q2W|�
ttt|��|�
ttt
|��|�
tt	tt|��d�qWdS)	Nrorli�)rpg333333�?i�i�rWr)rrfr?rhrkrlrer7rDrr`r@r�rirnrj)rr3r�Zit1Zit2rrrr<�s z TestVariousIteratorArgs.test_teeN)r r!r"rfror�rr�r�r�r�r�rr#r/r&r1r3r<rrrrrmMs 						
rmc@seZdZdd�Zdd�ZdS)�LengthTransparencycCsL|�t�tdd��d�|�t�tdd��d�|�t�td�d�d�dS)Nr)rr�)rDr&�length_hintr�)rrrrr�szLengthTransparency.test_repeatcCsh|�t�tdd��d�|�t�tdd��d�|�t�tddd��d�|�t�tddd��d�dS)Nr�rr{)r)rDr&rur�)rrrrr �sz2LengthTransparency.test_repeat_with_negative_timesN)r r!r"rr rrrrrt�srtc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�RegressionTestscs<dd�}�fdd�}g�|d|d�tt�}|��|�dS)NcsTdgf��fdd�	}t|�}t|�|dd�<t||�}t|gt|���t��dS)Nrcs|r|dd�=�t���|S)N)rF)r�r>)rw�zrrr��s
z@RegressionTests.test_sf_793826.<locals>.mutatingtuple.<locals>.g)rr_r	r�rF)Ztuple1rwZtuple2r��items�genr)rwrwr�
mutatingtuple�s
z5RegressionTests.test_sf_793826.<locals>.mutatingtuplecs|att��dd�<dS)N)�Tr)r�)r>rrrw	sz)RegressionTests.test_sf_793826.<locals>.f)rrrM)r:rWrN)rr{rD)rrzrw�secondr)r>r�test_sf_793826�s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)�histrr�gen1s


z,RegressionTests.test_sf_950057.<locals>.gen1c3s��d�dV��d�dS)NrMrr:)r�)r)rrr�gen2s
z,RegressionTests.test_sf_950057.<locals>.gen2FrrT)r`r~rrnrDr�)rr�r�r)rr�test_sf_950057szRegressionTests.test_sf_950057c	Cs:t�dd�td�D��}|�t��t|�WdQRXdS)Ncss|]
}dVqdS)rNr)r7Zunusedrrrr�4szERegressionTests.test_long_chain_of_empty_iterables.<locals>.<genexpr>i���)rnrprr`rrF)rrArrr�"test_long_chain_of_empty_iterables0sz2RegressionTests.test_long_chain_of_empty_iterablescs4�fdd�}x"ttd�|�D]\}�t��qWdS)Ncs|dkrt��|dkS)NrWrN)r)r)rJrrrw9sz,RegressionTests.test_issue30347_1.<locals>.fr.)r�rr)rrwr�r)rJr�test_issue30347_18sz!RegressionTests.test_issue30347_1csNG��fdd�d�}d�tttd�|��d�xtd�D]}t�d�q8WdS)Ncs"eZdZdd�Z��fdd�ZdS)z,RegressionTests.test_issue30347_2.<locals>.KcSsdS)Nr)rr�rrrr	Bsz5RegressionTests.test_issue30347_2.<locals>.K.__init__cs�d7��dkrt�d�dS)NrT)rF)r�other)r�rrrr�Ds
z3RegressionTests.test_issue30347_2.<locals>.K.__eq__N)r r!r"r	r�r)r�rrr�KAsr�rr.rr)rFr�r)rr�r�r)r�rr�test_issue30347_2@s
	z!RegressionTests.test_issue30347_2N)r r!r"r}r�r�r�r�rrrrrv�s
rvc@seZdZdd�ZdS)�SubclassWithKwargsTestcs�x|tttttttttt	t
tfD]\�G�fdd�d��}y|dd�Wqtk
rx}z|�
d|jd�Wdd}~XYqXqWdS)NcseZdZd�fdd�	ZdS)zBSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.SubclassNcs�j|f|��dS)N)r	)r�newargr
)�clsrrr	VszKSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.Subclass.__init__)N)r r!r"r	r)r�rr�SubclassUsr�r)r�zkeyword argumentsr)r�r	r�r�rnr_r%r#r0r2r�r�r@ZassertNotInr
)rr��errr)r�r�test_keywords_in_subclassQsz0SubclassWithKwargsTest.test_keywords_in_subclassN)r r!r"r�rrrrr�Psr�c@s:eZdZdd�ZejZdd�Zdd�Zdd�Zd	d
�Z	dS)�
SizeofTestcCst�d�|_dS)Nr)�struct�calcsize�ssize_t)rrrr�setUp`szSizeofTest.setUpcCsFt�d�}|j}|tdd�|d|j�|td�|d|j�dS)NZ3PirUZ12r)
rTrTrTrTrTrTrTrTrTrTr.)r�calcobjsize�check_sizeofr�r�)r�basesize�checkrrr�test_product_sizeofes
zSizeofTest.test_product_sizeofcCsLt�d�}|j}|tdd�|d|j�|ttd�d�|d|j�dS)N�3PnirmrMr.r:)rr�r�r�r�r)rr�r�rrr�test_combinations_sizeofks
z#SizeofTest.test_combinations_sizeofcCsPt}t�d�}|j}||dd�|d|j�||td�d�|d|j�dS)Nr�rmrMr.r:)r�rr�r�r�r)rr�r�r�rrr�)test_combinations_with_replacement_sizeofqs

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)NZ4Pnirmr:rMr�rWr.)rr�r�r�r�r)rr�r�rrr�test_permutations_sizeofxs


z#SizeofTest.test_permutations_sizeofN)
r r!r"r�rr�r�r�r�r�rrrrr�^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
|�|r|ttd�r|ddl
}dgd}x2tt|��D]"}t	j
|�|��t��||<qNWt|�t	�tjt|�dS)N�gettotalrefcountrrW)r9rmr\rvrtr�rIrWr�rZrun_unittest�hasattrr��gcrr�Zcollectr�rZrun_doctest�modulesr )�verboseZtest_classesr�Zcountsrrrr�	test_main�	s


r��__main__T)r�)N)?ZunittestZtestr�	itertoolsr-�decimalrZ	fractionsrr&rrrr0�	functoolsrr�r�rDZMAX_Py_ssize_tr�Zminsizer
rrrrrrrrr%r)r*r,r-r/rrdrtZTestCaser9rIrWr\rerfr?rhr�rirjrkrlrmrtrvr�Zcpython_onlyr�r�Z__test__r�r rrrr�<module>s�
>n*e
	
	
[
_