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.10/test/__pycache__/test_itertools.cpython-310.opt-2.pyc
o

�i���@szddlZddlmZddlTddlZddlmZddlmZddl	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�r;e>dQdR�dSdS)T�N)�support)�*)�Decimal)�Fraction)�reduce�cGstt|��S�N)�list�zip��args�r
�0/usr/local/lib/python3.10/test/test_itertools.py�lzip�rcCs
	d|S�N�r
��xr
r
r�oneargsrcGs	t�r)�
ValueErrorrr
r
r�errfuncsrccs�	dD]}|VqdS)N�rrrr
��ir
r
r�gen3�
��rcC�	|ddkS)Nrrr
rr
r
r�isEven$�rcCr)Nrrr
rr
r
r�isOdd(rr cG�|Srr
rr
r
r�tupleize,�r"ccs�t|�D]}|VqdSr��range��nrr
r
r�irange/s��r(c@�eZdZ	dd�Zdd�ZdS)�StopNowcCr!rr
��selfr
r
r�__iter__5r#zStopNow.__iter__cC�t�r��
StopIterationr+r
r
r�__next__7r#zStopNow.__next__N��__name__�
__module__�__qualname__r-r1r
r
r
rr*3�r*cCs	tt||��Sr�r	�islice)r'�seqr
r
r�take:sr:cCsttj|d�S�Nr)r�operator�mul��iterabler
r
r�prod>sr@cCs	ttd|d��Sr;)r@r%�r'r
r
r�factAsrBcC�|dS�Nrr
��rr
r
r�testRF�rGcCrCrr
rEr
r
r�testR2IrHrIcC�|dkS)N�
r
rr
r
r�undertenLrHrLcCsg|]}|fdd��qS)cSst�t�||��Sr)�pickle�loads�dumps)�s�protor
r
r�<lambda>Osz<listcomp>.<lambda>r
)�.0rQr
r
r�
<listcomp>Os�rTc@s@eZdZdudd�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�Zd7d8�Zd9d:�Z e
�
d�d;d<��Z!d=d>�Z"e
�
d�d?d@��Z#dAdB�Z$dCdD�Z%dEdF�Z&dGdH�Z'dIdJ�Z(e
jdKdL��Z)e
�
d�dMdN��Z*dOdP�Z+dQdR�Z,dSdT�Z-dUdV�Z.dWdX�Z/dYdZ�Z0d[d\�Z1d]d^�Z2d_d`�Z3dadb�Z4dcdd�Z5dedf�Z6dgdh�Z7didj�Z8e
j9dkdl��Z:e
j9dmdn��Z;e
j9dodp��Z<e
j9dqdr��Z=e
j9dsdt��Z>dS)v�TestBasicOps�rNcs	d��fdd�	�t�||�}t�|�}|�t|�t|���|��|�}}	|�||	�|r9�|�}
|�||
�t�|�}d}zt|�D]
}
t|�|d7}qEWn	tyZYnwt�||�}t�|�}�|��|�}}	|�||	�|r��||d��}
|�||
�dSdS)Nrcs\�dkrtd��t|t�r|Sz	tt|���}Wnty#|YSw��fdd�|D�S)NrKzinfinite recursion encounteredcsg|]	}�|�d��qS)rr
�rS�e)�expandrr
rrT`sz;TestBasicOps.pickletest.<locals>.expand.<locals>.<listcomp>)�RuntimeError�
isinstance�strr	r8�	TypeError)�itr�l�rY�stoprrrYVs
�z'TestBasicOps.pickletest.<locals>.expandr�r)rMrOrN�assertEqual�typer%�nextr0)r,�protocolr^rar:�compare�dumpZi2�a�b�cZi3ZtookrZi4r
r`r�
pickletestTs8


��
�zTestBasicOps.pickletestc	Csv|�tttd���gd��|�tttd�d��gd��ttttfD]}|�ttt|td����tt|gd����q#|�ttd��gd��|�ttg��g�|�ttdg��dg�|�	t
ttd�dd�|�	t
t�|j	t
ttd�d	�|�	t
ttd
gg��gd�}|�tt|t��gd��|�tt|t��gd
��|�tt|t
j��gd��|�	t
��tt|t��Wd�n1s�wYttjd
�D]}|�|ttd���|�|ttd�dd��q�|�ttgd�dd��gd��|�ttgd�dd��gd��|�ttgdd��dg�|�	t
��ttddgd��Wd�dS1�s4wYdS)NrK)
rr��rK����$�-r>�abc)ri�abrt��rnrr)
r��	rwrvrrmrVrrn)
rrrrrrrrrr)
rrxryryryryryryryry)
r��i�i�rrrrr)�initial)rKrwr)rKrorz�d)r}�n�s�t�)rcr	�
accumulater%�int�complexrr�map�assertRaisesr]�min�maxr<r=�chrrM�HIGHEST_PROTOCOLrl)r,�typrPrQr
r
r�test_accumulate}sP�������  $�zTestBasicOps.test_accumulatecCs�dd�}t|fD]=}|�t|dd��td��|�t|d��td��|�t|d��g�|�td|dd��td��|�tt|d	d
��qdS)Ncws"�	|D]
}|D]}|VqqdSrr
)�	iterablesr^�elementr
r
r�chain2�s���z'TestBasicOps.test_chain.<locals>.chain2rt�def�abcdef�rV�abcdrrm)�chainrcr	r:r�r])r,r�rkr
r
r�
test_chain�s�zTestBasicOps.test_chaincCs�|�tt�ddg��td��|�tt�dg��td��|�tt�dg��g�|�tdt�ddg��td��|�ttt�ddg��dS)	Nrtr�r�r�rVr�rrm)rcr	r��
from_iterabler:r�r]r+r
r
r�test_chain_from_iterable�s
 z%TestBasicOps.test_chain_from_iterablec	Cs�tjgtD]O}tdd�}|�t||��td��|�t|�d�|�t||��td��|�t|td���g�|�td|tdd���td��|�t	t|td	d
���qt
tjd�D]}|j
|tdd�td�d�q]dS)
Nrtr�r�riZbcdefr�rVr�rrmr�rg)�copy�deepcopy�
picklecopiersr�rcr	rer:r�r]r%rMr�rl)r,Zoperr^rQr
r
r�test_chain_reducible�s
 �z!TestBasicOps.test_chain_reduciblecCs�|�tt�jd�|�tt�jg�|�tt�jd�|�tt�jgf�|�tt�jtg�gf�t�}|�tddg�f�|�t|�gd��t�}|�tddg�tdg�f�|�t|�gd��dS)Nr
rrtr�)rirjrk�drX�f�ghi)r�rirjrkr�rXr�)r�r]r��__setstate__�iterrcr	�r,r^r
r
r�test_chain_setstate�sz TestBasicOps.test_chain_setstatec
	s�|�ttd�|�ttddd�|�ttd�|�ttdd�dd�gtD][}|�t|tdd���g�|�t|tdd���gd	��tdd�}t|�|�t||��gd
��|�t|ttd�d���gd
��ttd�d�}t|�|�t||��gd��q&dd�}dd�}dd�}td�D]�}dd�t|�D��t|d�D]�}tt�|��}|�t	|�||kr�dn
t
|�t
|�t
||��|�t	|�t	t|���|�|t|��|D];�|�t	��|�|�t	t���|�|�t��t���|�
t�fdd��D���|�t���fdd��D��q�|�|t|�|���|�|t|�|���|�|t|�|���ttjd�D]}	|�|	t�|���q@q�q�dS)Nrtrr���cSr!rr
�rir
r
rrR��z0TestBasicOps.test_combinations.<locals>.<lambda>� �ABCD���A�B�r��C�r��D�r�r��r�r��r�r�)r�r�r�r�r�rVrm�r�rrrm�rrrm�rrrm)r�r�r�c3s��	t|��t��}||krdStt|��}t�fdd�|D��V	tt|��D]}|||||kr7nq)dS||d7<t|d|�D]}||dd||<qIt�fdd�|D��Vq#)Nc3��|]}�|VqdSrr
�rSr��poolr
r�	<genexpr>���zHTestBasicOps.test_combinations.<locals>.combinations1.<locals>.<genexpr>rc3r�rr
r�r�r
rr��r���tuple�lenr	r%�reversed)r?rFr'�indicesr�jr
r�r�
combinations1�s&���z5TestBasicOps.test_combinations.<locals>.combinations1c3sT�	t|��t��}tt|�|�D]}t|�t|�kr't�fdd�|D��VqdS)Nc3r�rr
r�r�r
rr�r�zHTestBasicOps.test_combinations.<locals>.combinations2.<locals>.<genexpr>)r�r��permutationsr%�sortedr	�r?rFr'r�r
r�r�
combinations2�����z5TestBasicOps.test_combinations.<locals>.combinations2c3sT�	t|��t��}tt|�|�D]}tt|��|kr't�fdd�|D��VqdS)Nc3r�rr
r�r�r
rr�	r�zHTestBasicOps.test_combinations.<locals>.combinations3.<locals>.<genexpr>)r�r��combinations_with_replacementr%�setr�r
r�r�
combinations3r�z5TestBasicOps.test_combinations.<locals>.combinations3rvcS�g|]}d|d�qS�rw�r
�rSrr
r
rrT�z2TestBasicOps.test_combinations.<locals>.<listcomp>rc3��|]}|�vVqdSrr
rW��valuesr
rr�r�z1TestBasicOps.test_combinations.<locals>.<genexpr>c�g|]}|�vr|�qSr
r
rW�rkr
rrTr�)r�r]�combinationsrr�rcr	rer%r�rBr�r��
assertTrue�allrMr�rl)
r,�op�testIntermediater�r�r�r'rF�resultrQr
�rkr�r�test_combinations�s`�
���4
����zTestBasicOps.test_combinationscC�>|�ttf��tdd�Wd�dS1swYdS)N�AAi )r��
OverflowError�MemoryErrorr�r+r
r
r�test_combinations_overflow �"�z'TestBasicOps.test_combinations_overflowz"tuple reuse is specific to CPythonc
C�H|�tttttdd����d�|�ttttttdd�����d�dS�N�abcdermr)rcr�r�r��idr��assertNotEqualr	r+r
r
r�test_combinations_tuple_reuse&� (z*TestBasicOps.test_combinations_tuple_reusec
	s\t}|�t|d�|�t|ddd�|�t|d�|�t|dd�dd�gtD]&}|�t||dd���gd��|dd�}t|�|�t||��gd	��q(d
d�}dd
�}dd�}td�D]�}dd�t|�D��t|d�D]�}t|�|��}	|�t	|	�|||��|�t	|	�t	t
|	���|�|	t|	��tt�|��}
|dks�|dkr�|�|	|
�n|�
t
|	�t
|
�k�|	D]D�|�t	��|�dd�t��D�}|�t	|�t	t
|���|�t��t���|�
t�fdd��D���|�|�fdd��D��q�|�|	t|�|���|�|	t|�|���ttjd�D]}|�||�|���qqpq_dS)Nrtrrr�cSr!rr
r�r
r
rrR2r�zATestBasicOps.test_combinations_with_replacement.<locals>.<lambda>�ABC�)r�r�r�r��r�r�r��r�r�)r�r�r�r�r�c3s��	t|��t��}|s|rdSdg|}t�fdd�|D��V	tt|��D]}|||dkr4nq(dS||dg||||d�<t�fdd�|D��Vq")Nrc3r�rr
r�r�r
rr�Cr�zPTestBasicOps.test_combinations_with_replacement.<locals>.cwr1.<locals>.<genexpr>rc3r�rr
r�r�r
rr�Kr�)r�r�r�r%)r?rFr'r�rr
r�r�cwr1;s"�
��z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr1c3sV�	t|��t��}tt|�|d�D]}t|�t|�kr(t�fdd�|D��VqdS)N��repeatc3r�rr
r�r�r
rr�Sr�zPTestBasicOps.test_combinations_with_replacement.<locals>.cwr2.<locals>.<genexpr>)r�r��productr%r�r	r�r
r�r�cwr2Ms���z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr2cSs4|s|rdSdSt||d�t|�t|d�S�Nrr)rB)r'rFr
r
r�numcombsUs$zATestBasicOps.test_combinations_with_replacement.<locals>.numcombsrvcSr�r�r
r�r
r
rrT[r�zCTestBasicOps.test_combinations_with_replacement.<locals>.<listcomp>rcS�g|]\}}|�qSr
r
)rS�k�vr
r
rrTk�c3r�rr
rWr�r
rr�nr�zBTestBasicOps.test_combinations_with_replacement.<locals>.<genexpr>cr�r
r
rWr�r
rrTpr�)r�r�r]rr�rcr	rer%r�r�r�r�r��groupbyr�rMr�rl)
r,�cwrr�r�r�r�r�r'rFr�Z
regular_combsZnorunsrQr
r�r�"test_combinations_with_replacement+sX�
�����z/TestBasicOps.test_combinations_with_replacementcCr�)Nr��@)r�r�r�r�r+r
r
r�+test_combinations_with_replacement_overflowwr�z8TestBasicOps.test_combinations_with_replacement_overflowc
CsLt}|�tttt|dd����d�|�ttttt|dd�����d�dSr�)r�rcr�r�r�r�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��gd��dd	d
�}ddd�}td
�D]�}dd�t|�D��t|d�D]�}tt�|��}|�t|�||krsdn	t|�t||��|�t|�tt	|���|�|t
|��|D]"}|�t|�|�|�tt	|��|�|�t�fdd�|D���q�|�|t|�|���|�|t|�|���||kr�|�|tt�d���|�|tt����tt
jd�D]}|�|t�|��q�q_qNdS)Nrtrrr�r�rPrm)�rr�rr�rr�rr)rr)rrc3s@�	t|��t��}|dur|n|}||krdStt|��}tt||d|d��ddd�}t�fdd�|d|�D��V|r�tt|��D]O}||d8<||dkrs||dd�|||d�||d�<||||<qH||}||||||<||<t�fdd�|d|�D��VndS|sBdSdS)Nr���c3r�rr
r�r�r
rr��r�zHTestBasicOps.test_permutations.<locals>.permutations1.<locals>.<genexpr>rc3r�rr
r�r�r
rr��r�r�)r?rFr'r�Zcyclesrr�r
r�r�
permutations1�s,�$ ( �z5TestBasicOps.test_permutations.<locals>.permutations1c3sf�	t|��t��}|dur|n|}tt|�|d�D]}tt|��|kr0t�fdd�|D��VqdS)Nr�c3r�rr
r�r�r
rr��r�zHTestBasicOps.test_permutations.<locals>.permutations2.<locals>.<genexpr>)r�r�r�r%r�r�r
r�r�
permutations2�s���z5TestBasicOps.test_permutations.<locals>.permutations2rvcSr�r�r
r�r
r
rrT�r�z2TestBasicOps.test_permutations.<locals>.<listcomp>rc3r�rr
rWr�r
rr��r�z1TestBasicOps.test_permutations.<locals>.<genexpr>r)r�r]r�rrcr	r%r�rBr�r�r�r�rMr�rl)r,rrr'rFr��prQr
r�r�test_permutations�s@�

	,���zTestBasicOps.test_permutationscCr�)Nr�r�)r�r�r�r�r+r
r
r�test_permutations_overflow�r�z'TestBasicOps.test_permutations_overflowc
Cr�r�)rcr�r�r�r�r�r�r	r+r
r
r�test_permutations_tuple_reuse�r�z*TestBasicOps.test_permutations_tuple_reusec	std�D�]}dd|�}td�D]��tt|�d��}tt|���}tt|���}tt|���}|�t|�|��|�t|�|rSt|�d�t��t|d�n��|�t|��|krbdn	t|�t|���|�t|��|krxdn
t|�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
|�@��qqdS)Nrn�ABCDEFGrxr�rrcS� g|]}t|�t|�kr|�qSr
�r�r	�rS�tr
r
rrT�� z3TestBasicOps.test_combinatorics.<locals>.<listcomp>c� g|]}tt|���kr|�qSr
�r�r�rrEr
rrT�rcSr
r
rrr
r
rrT�rcrr
rrrEr
rrT�r)
r%r	r�r�r�r�rcr�rBr�r��filter�__contains__)r,r'rPr@r��perm�combr
rEr�test_combinatorics�s0:,4��zTestBasicOps.test_combinatoricsc
Cs,|�ttdgd�d��td��|�ttdgd���td��|�ttdgd���td��|�ttdgd���td��|�ttdgd���td	��|�ttd
gd���td��d
}t�ttd�|��}t�td��}|�tt||��gd�|�|�ttdtd��|�tttd�d�|�tttd��|�tttd�d�dd�dd�gt	D]e}dgd�ddfdgd�ddfdgd�ddfdgd�d	dfd
gd�ddffD]=\}}}}|�t|t||d���t|��|�t|t||���t|��t||�}|�rt
|�|�t||��t|��q�q�dS)N�ABCDEF�rrrrrr)�data�	selectors�ACEF)rrrrrrr�)rrrrrr�rrrZACr�)rrrrrrZBC�'rnr�rrmrwcSs
t�|�Sr)r�r�r
r
rrR��
z,TestBasicOps.test_compress.<locals>.<lambda>cSs
t�|�Sr)r�r�r�r
r
rrR�r!ZCEFZBCDEFr�)rcr	�compressr�r�r�r%r�r]r�re)r,r'rrr�Zresult1Zresult2r�r
r
r�
test_compress�s< � 
���zTestBasicOps.test_compressc	CsZ|�tdt��gd��|�tdtd��gd��|�tdtdtd���ddg�|�tdtdtd���d	d
g�|�tdtdtd���dd
g�|�ttddd�|�ttd�|�tdttd��tt	tdtd���|�tdttd��tt	tdtd���|�tdtd��gd��|�tdtd��gd��|�tdtt
d���t
d�t
d�t
d�g�|�tdttdd���tdd�tdd�tdd�g�dd>}|�tdt|��||d|dg�td�}|�t|�d�t
|�|�t|�d�td�}|�t|�d�t
|�|�t
|�d �|�ttd!��d"�|�ttd#��d$�|�tt
td#���t�tjdtjdd%dd&dtjdtjdfD]}tt|��}d'�|�}|�||��qPddtdtdfD]0}t|�}|�t
t�|��|�|�t
t�|��|�t	tjd�D]}|�|t|���q��qotdtd�t��dS)(Nrt��rir�rjr�rkrrm)�rirm�rjrV)rkrwrr(r)r)rir)rjr���)rir*)rjr�rVrirKrw�
@)r+g@g@�
@�)r,y@��@��1.1z2.1z3.1rxr��zcount(3)zcount(4)���z	count(-9)i����g�$@zcount(10.25)g$@zcount(10.0)���r�	count(%r))rcr�countr:r
r�r]�maxsizer	r%rr�reprrerd�float�sys�__mod__r�r�rMr�rl�exc_info)r,�BIGINTrkr�r1�r2�valuerQr
r
r�
test_counts\   ����$4
�zTestBasicOps.test_countcCsX|�tdtdd��gd��|�tdtddd��gd��|�tdtdd��gd��|�ttd	d
�|�tdtdd��gd��|�tdtdd
��gd��|�tdtdd��gd��|�tdttdd��tdttdtdd���|�tdttdd��tdttdtdd���|�tdtdtd��ttdddtdtd���|�tdtdd��gd��|�tdtdd��gd��|�tdtt	d�t	d���t	d�t	d�t	d�g�|�tdtt
dd�t
d
d���t
dd�t
dd�t
dd�g�d
d>}|�tdt|d��d|d|g�|�ttdtdd ���tgd!���tdd�}|�t|�d"�t|�|�t|�d#�td$d�}|�t|�d%�t|�|�t|�d%�td$d&�}|�t|�d'�t|�|�t|�d(�|�t|�d(�|�ttd)d��d*�|�ttd)d
��d+�|�ttd)d,��d-�|�ttdd,��d.�tdd,�}|�t
t|��t�|�t
t|��t�tjdtjdd/dddtjdtjdfD]Q}tjdtjdd/ddd
dtjdtjdf	D]4}tt||��}|d
k�rd0|}nd1||f}|�||�ttjd
�D]}|�|t||���q�q�q�dS)2Nrtrrm)�rir)rjrw)rkrx)�start�stepr)rA)r%)rjr)rkr�rirjr)r?)rjrr'r)r?)rjrm)rkrVr�ror}rKrwg�?)rr+g@r,)rr-y!@ �r.z.1z1.2z1.3rv�rpr/g@)rKg)@g.@zcount(3, 5)zcount(8, 5)r0z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)r1r2z
count(%r, %r))rcrr3r�r]r:r4r%r	rrr5rerdr�r6r7rMr�rl)r,r:rkrr�r;r<rQr
r
r�test_count_with_stride?sv��28���"$



46

���z#TestBasicOps.test_count_with_stridecCsl|�tdtd��td��|�ttd��g�|�tt�|�ttd�|�tttt��d��gd��dS)NrKrtZ
abcabcabcar�rw)
rrrrrrrrrr)rcr:�cycler	r�r]r8rr+r
r
r�
test_cyclevs
$zTestBasicOps.test_cyclecs�td��|�t��d�|�tdt����td��ttj	d�D]2}|�tdt�
t��|���td��t��|�tdt�
t��|���td��t��t��q!ttj	d�D]
}|�|td��q[ttj	d�D]T}t
d�}t|���fdd	�td
�D�}t��|�}t�
|�}|�td|�td��t
d�}t|���fd
d	�td�D�}t��|�}t�
|�}|�td|�td��qmdS)NrtrirKZ
bcabcabcabrZ
cabcabcabcr�c�g|]}t���qSr
�rer�r�r
rrT�r�z7TestBasicOps.test_cycle_copy_pickle.<locals>.<listcomp>rr�ZcdeabcdeabcdeabcdeabcrFr
rGr�r�r
rrT�r�rv)rDrcrer:r�r�r	r%rMr�rNrOrlr�)r,rQr^�_rr�r
r�r�test_cycle_copy_pickle}s:��


�z#TestBasicOps.test_cycle_copy_picklecCs6gd�}|D]}t�|�}|�td|�gd��qdS)N)sHcitertools
cycle
(c__builtin__
iter
((lI1
aI2
aI3
atRI1
btR((lI1
aI0
tb.s?citertools
cycle
(c__builtin__
iter
(](KKKetRKbtR(]KaKtb.s>�citertools
cycle
c__builtin__
iter
](KKKe�RKb�R]KaK�b.s;�citertools
cycle
cbuiltins
iter
](KKKe�RKb�R]KaK�b.sH��=�	itertools�cycle��builtins�iter�](KKKe�RKb�R]KaK�b.sHcitertools
cycle
(c__builtin__
iter
((lp0
I1
aI2
aI3
atRI1
btR(g0
I1
tb.s?citertools
cycle
(c__builtin__
iter
(]q(KKKetRKbtR(hKtb.s>�citertools
cycle
c__builtin__
iter
]q(KKKe�RKb�RhK�b.s;�citertools
cycle
cbuiltins
iter
]q(KKKe�RKb�RhK�b.sG��<�	itertools�cycle��builtins�iter�]�(KKKe�RKb�RhK�b.sIcitertools
cycle
(c__builtin__
iter
((lI1
aI2
aI3
atRI1
btR((lI1
aI00
tb.sAcitertools
cycle
(c__builtin__
iter
(](KKKetRKbtR(]KaI00
tb.s=�citertools
cycle
c__builtin__
iter
](KKKe�RKb�R]Ka��b.s:�citertools
cycle
cbuiltins
iter
](KKKe�RKb�R]Ka��b.sG��<�	itertools�cycle��builtins�iter�](KKKe�RKb�R]Ka��b.sIcitertools
cycle
(c__builtin__
iter
((lp0
I1
aI2
aI3
atRI1
btR(g0
I01
tb.sAcitertools
cycle
(c__builtin__
iter
(]q(KKKetRKbtR(hI01
tb.s=�citertools
cycle
c__builtin__
iter
]q(KKKe�RKb�Rh��b.s:�citertools
cycle
cbuiltins
iter
]q(KKKe�RKb�Rh��b.sF��;�	itertools�cycle��builtins�iter�]�(KKKe�RKb�Rh��b.rK)
rrmrrrmrrrmrr)rMrNrcr:)r,Z	testcasesrr^r
r
r�test_cycle_unpickle_compat�s

�z'TestBasicOps.test_cycle_unpickle_compatcCs\td�}|�td�df�|�td|�td��td�}|�td�df�|�td|�td��|�t��td��td�dg�Wd�n1sKwY|�t��td�}|�td�df�Wd�n1smwYtd|�|�t��td��td�df�Wd�n1s�wY|�ttd	�jd
�|�ttd	�jgf�dS)N�defgrtrr�Zdefgabcdefgabcdefgab�abcdefgrrr�r
)rDr�r	rcr:r�r]r�)r,rkr
r
r�test_cycle_setstate�s&��
�z TestBasicOps.test_cycle_setstatec
s�|�gttg���|�gttgtd���|�tttdg��|�ttd�|�ttddd�d�gd�}g}t|dd��D]\}}|D]}|�||d�|�|�qEq?|�||�ttj	d	�D]-}g}t�
t�t|t�|��D]\}}|D]}|�||d�|�|�qyqs|�||�qcg}t|t�D](\}}t|t
�D]\}}|D]}|�||d�|�||d
�|�|�q�q�q�|�||�ttj	d	�D]F}g}t�
t�t|t�|��D]/\}}t�
t�t|t
�|��D]\}}|D]}|�||d�|�||d
�|�|�q�q�q�|�||�q�dd�t|t�D�}	td
d�|D��}
|�t|	�|
�|�t|	�t|
��ttdtd���}t|t�}t|�\}}
t|�\}}t|�\}}|�t|
�g�|�t|�g�|�t|�d�t|�|�t|�g�ttj	d	�D]%}t|t�}t|�\}}t|�t|�|�tt�
t�||���g��q�d}dd�tt|��D�}|�|gd��dd�tt|��D�}|�|gd��dd�tt|��D�}|�|gd��tdd�tt|��D�dd�dd�}|�|gd��Gdd�dt��d(�fdd �	}dtfd!d"�}|��||d��|��||d	��G�fd#d$�d$�}|�|�dg}|j�||td%�|��||���fd&d'��d�_|��|dg��d	�_|��|ddg��dS))N��keyrtcSr!rr
rr
r
rrR�r�z+TestBasicOps.test_groupby.<locals>.<lambda>rK))rrKr�)r�rp)rr�rp)r�
rp)r��)rrorS)rmrz�)rmrBrTcSrCrDr
rEr
r
rrR��rrrcSr�r
r
�rSr��gr
r
rrTr�z-TestBasicOps.test_groupby.<locals>.<listcomp>cSsg|]}|d�qSrbr
)rSrFr
r
rrTr�Z	AABBBAAAAry)r�rwZabracadabracSr�r
r
rVr
r
rrT2r�)rirjrkr�rFcSs$g|]\}}tt|dd��r|�qSrr7rVr
r
rrT5�$)rirjrFcS� g|]\}}tt|��|f�qSr
�r�r	rVr
r
rrT8r)�rwri�rrj)rrk)rr��rrFcSrYr
rZrVr
r
rrT;rT)�reverserm)r[r]r\c@seZdZdS)z0TestBasicOps.test_groupby.<locals>.ExpectedErrorN)r3r4r5r
r
r
r�
ExpectedError?sr_c3s�t|�D]}dVq��)NZyor$r&�r_r
r�
delayed_raiseAs�z0TestBasicOps.test_groupby.<locals>.delayed_raisecs�fdd�t||�D�S)Ncsg|]\}}�|��qSr
r
rV��funcr
rrTFr�z;TestBasicOps.test_groupby.<locals>.gulp.<locals>.<listcomp>)r�)r?Zkeyprcr
rbr�gulpEsz'TestBasicOps.test_groupby.<locals>.gulpc�eZdZ�fdd�ZdS)z+TestBasicOps.test_groupby.<locals>.DummyCmpc���rr
)r,�dstr`r
r�__eq__Or#z2TestBasicOps.test_groupby.<locals>.DummyCmp.__eq__N)r3r4r5rhr
r`r
r�DummyCmpN�rirbcs �jdkr�jd8_|S��r�)�skip)�obj�r_�keyfuncr
rrnYs
z*TestBasicOps.test_groupby.<locals>.keyfuncrb)rcr	r�r�r�r]�appendr%rMr�rNrOrGrIr�r�r
rer��	Exceptionrk)r,rP�dupr�rW�elemrQZikZig�keysZexpectedkeysr^rHZg1Zg2Zg3rFrardrir
rmr�test_groupby�s�� ���  ��

"&zTestBasicOps.test_groupbyc
Cs�|�ttttd���gd��|�ttdgd���ddg�|�tttgd���ddg�|�tdttt���gd��|�t	t�|�t	tdd	��|�t	td
d	�td�d�|�t	ttd�|�t	t
ttd�td���gd�}tttd��}|�tt�|��|�tttd��}|�tt�|��|�tt
jd�D]/}tttd��}|�tt
�t
�||���|�t
|�|�tt
�t
�||���|dd��q�tt
jd�D]}tttd��}|�||�q�dS)
Nrn)rrrV�rrrrrrrrV)rrrVrncSr!rr
rr
r
rrRlr�z*TestBasicOps.test_filter.<locals>.<lambda>cSr!rr
rr
r
rrRmr�rvrm)rcr	rrr%�boolr:r3r�r]rer�r�rMr�rNrOrl�r,�ansrkrQr
r
r�test_filterfs.(�zTestBasicOps.test_filtercCs
|�ttttd���gd��|�ttdgd���gd��|�tttgd���gd��|�tdttt���gd��|�t	t�|�t	tdd��|�t	td	d�td�d
�|�t	ttd�|�t	t
ttd�td���ttjd�D]
}|�
|tttd���qudS)
Nrnr ru�rrrrV)rrmrwrvcSr!rr
rr
r
rrR�r�z/TestBasicOps.test_filterfalse.<locals>.<lambda>cSr!rr
rr
r
rrR�r�rvrmr)rcr	�filterfalserr%rvr:r3r�r]rerMr�rl�r,rQr
r
r�test_filterfalse�s�zTestBasicOps.test_filterfalsecCs(dd�tdt��D�}|�|gd��|�ttdtd���tdtd���|�ttdtd���tdtd���|�tdtdt���tdtd���|�ttd��td��|�tt��t��|�ttd�|�tttd�d�|�dd�tdd	�D�tdd	��|�d
d�tdd	�D�tdd	��dS)NcS�g|]\}}||f�qSr
r
�rSr�yr
r
rrT�r�z)TestBasicOps.test_zip.<locals>.<listcomp>rtr$rnr�rmcS�g|]}tt|���qSr
�r�r	�rSZpairr
r
rrT�r�r�cS�g|]}|�qSr
r
r�r
r
rrT��)	r
r3rcr	r%rr:r�r])r,rxr
r
r�test_zip�s$$$��zTestBasicOps.test_zipc	Cszttttdd���}|�t|�t|��tttttdd����}|�tt�	|��t|��dd�t
�
tdt���D�}|�|gd��dd�t
�tdt���D�}|�|gd��t
tjd�D]}dd�t�t�tdt��|��D�}|�|gd��q`t
tjd�D]"}tdt��}t|�d	d�t�t�||��D�}|�|d
dg�q�t
tjd�D]}|�|tdt���q�dS)Nrtr�cSr~r
r
rr
r
rrT�r�z5TestBasicOps.test_zip_tuple_reuse.<locals>.<listcomp>r$cSr~r
r
rr
r
rrT�r�rcSr~r
r
rr
r
rrT�r�cSr~r
r
rr
r
rrT�r�r&r')r	r�r�r
rcr�r�r��dict�fromkeysr�r3r�r%rMr�rNrOrerl)r,�idsrxrQr�r
r
r�test_zip_tuple_reuse�s&$�z!TestBasicOps.test_zip_tuple_reusecsTdtd�gtd�dgtd�tdd�tdd�gtd�td�tdd�td	�td
�gtd�td�tdd�td	�td
�td�gfD]@��fdd�tttt����D�}|�tt���|�|�tt�ii���|�d
d�|D�}|�tt�itdd����|�q=|�tdtdt	���tt
dtd����|�tt��tt
���|�ttg��tt
g���|�ttd��tt
d���|�ttdii���tt
td�dgd���|�ttd�|�tttd�d�dD]}z
t
|t�t��Wn	ty�Yq�w|�d|�q�|�dd�tdd�D�tt
dd���|�dd�tdd�D�tt
dd���dS)Nrtrnr/��i4i�i�ri�i�cs"g|]
�t�fdd��D���qS)cs$g|]}�t|�kr|�nd�qSr�r�)rS�argrr
rrT�rXz;TestBasicOps.test_ziplongest.<locals>.<listcomp>.<listcomp>�r�)rSrrrrT�s�z0TestBasicOps.test_ziplongest.<locals>.<listcomp>cSsg|]}tdd�|D���qS)css �|]}|dur
dp|VqdS)N�Xr
rWr
r
rr��s�z:TestBasicOps.test_ziplongest.<locals>.<listcomp>.<genexpr>r�rr
r
rrT�sr���	fillvaluermr�rK)zzip_longest('abc', fv=1)z3zip_longest('abc', fillvalue=1, bogus_keyword=None)zDid not raise Type in:  cSr�r
r�r�r
r
rrT�r�r�cSr�r
r
r�r
r
rrT�r�)rtrK)r%r�r�r�rcr	�zip_longestr�r:r3r
r�r]�eval�globals�localsZfail)r,�targetZstmtr
rr�test_ziplongest�sF

"(�
�"(����zTestBasicOps.test_ziplongestcCs^ttttdd���}|�t|�t|��tttttdd����}|�tt�	|��t|��dS)Nrtr�)
r	r�r�r�rcr�r�r�r�r�)r,r�r
r
r�test_zip_longest_tuple_reuse�sz)TestBasicOps.test_zip_longest_tuple_reusec	Csdttjd�D](}|�|tdd��|�|tdd��|�|tdddd��|�|tdd��qdS)Nrrtr�Zdefghr�r�)r%rMr�rlr�r|r
r
r�test_zip_longest_pickling�s�z&TestBasicOps.test_zip_longest_picklingcs^t��G�fdd�d�}|�t��
}t|��Wd�n1s!wY|�|j��dS)Ncre)z?TestBasicOps.test_zip_longest_bad_iterable.<locals>.BadIterablecrfrr
r+��	exceptionr
rr-�r#zHTestBasicOps.test_zip_longest_bad_iterable.<locals>.BadIterable.__iter__N)r3r4r5r-r
r�r
r�BadIterable�rjr�)r]r�r�ZassertIsr�)r,r��cmr
r�r�test_zip_longest_bad_iterable�s�z*TestBasicOps.test_zip_longest_bad_iterablecCs�Gdd�d�}|ddt�}|ddt�}dd�}|�|||�gd	��|ddt�}|ddt�}t||d
d�}|�t|�d�|�t|�d�|�t|�d�|�tt|�dS)
Nc@s$eZdZdd�Zdd�Zdd�ZdS)z,TestBasicOps.test_bug_7244.<locals>.RepeatercSs||_t|�|_||_dSr)�or�rrX)r,r�rrXr
r
r�__init__s

z5TestBasicOps.test_bug_7244.<locals>.Repeater.__init__cSr!rr
r+r
r
rr-r#z5TestBasicOps.test_bug_7244.<locals>.Repeater.__iter__cSs$|jdkr|jd8_|jS|j�r�)rr�rXr+r
r
rr1s
z5TestBasicOps.test_bug_7244.<locals>.Repeater.__next__N�r3r4r5r�r-r1r
r
r
r�Repeater�sr�rrmrrVc	Ssdg}t||dd�D]&\}}t�d��t||f�Wd�n1s#wY|�||f�q	|S)Nrr��stdout)r�rZcaptured_output�printro)r;r<r�rr�r
r
r�runs�z'TestBasicOps.test_bug_7244.<locals>.run)rrrrrr�r)r0rcrZr�rer�)r,r�r;r<r�r^r
r
r�
test_bug_7244�szTestBasicOps.test_bug_7244c	CsT|�ttd��g�|�ttd��g�|�ttd��dg�f|�ttd��gd��|�tttd���tttd�tdd����|�t��t�Wd�n1sUwY|�t��
td	d
�Wd�n1sowY|�t��
td	d�Wd�n1s�wY|�t��
td�Wd�dS1s�wYdS)Nr�riru�rirjr�)r�)rjrk)rkr�)r�rXrrrtrKr>)rcr	�pairwiser%r
r�r]r+r
r
r�
test_pairwise%s.������
"�zTestBasicOps.test_pairwisecs�gdgfdgddgftd�td�ggd�ftd�td�td�ggftd�td�td�ggftd�td�td�ggffD]+\}}|�tt|��|�td	�D]}|�tt||��tt|it|d
�����qMq;|�ttttd�gd���d
�|�tttd�d�dd�}dd�}dddtd�td	�tdddd�td�td�t	td��g	�td�D]P}�fdd�tt
�d��D�}tt
t|��}|�ttt|���|�|�tt|��t||���|�tt|��t||���t
t|�}|�ttt|���|�q�dS)Nr
rur��rjrrm�)rrrrr)rrrrrVr�rvrni��cs��ttt|��|�dd�}t|�}|dkrdVdStdd�|D��r&dSdg|}tdd�t||�D��V	tt|��D]3}||t||�dkrNq?||d7<t|d|�D]}d||<q]tdd�t||�D��VndSq9)	Nr�rrr
css�|]	}t|�dkVqdS)rNr�)rSr�r
r
rr�N��z>TestBasicOps.test_product.<locals>.product1.<locals>.<genexpr>cs��|]	\}}||VqdSrr
�rSr�rr
r
rr�Qr�csr�rr
r�r
r
rr�Yr�)	r	r�r��getr��anyr
r�r%)r�kwds�poolsr'r�rr�r
r
r�product1Hs*�

�z+TestBasicOps.test_product.<locals>.product1c?sX�	ttt|��|�dd�}gg}|D]��fdd�|D�}q|D]}t|�Vq"dS)Nr�rcs g|]}�D]}||g�qqSr
r
rr�r
rrTcrz?TestBasicOps.test_product.<locals>.product2.<locals>.<listcomp>)r	r�r�r�)rr�r�r�r@r
r�r�product2^s��z+TestBasicOps.test_product.<locals>.product2r�rtr)rirjrkrLrPrQr}csg|]}t����qSr
)�random�choice)rSr���argtypesr
rrTjsz-TestBasicOps.test_product.<locals>.<listcomp>rw)r%rcr	r�r�r�r�r]r�r�r��	randranger@r�r�)r,rr�rFr�r�rZexpected_lenr
r�r�test_product8s:���"	�
�zTestBasicOps.test_productcCsH|�ttf��tdgdddi�Wd�dS1swYdS)Nrur�r�i)r�r�r�r�r+r
r
r�test_product_overflowrs"�z"TestBasicOps.test_product_overflowc
Cr�)Nrtr�r)rcr�r�r�r�r�r�r	r+r
r
r�test_product_tuple_reusewr�z%TestBasicOps.test_product_tuple_reusec	Cs�gdgfdgddgftd�td�ggd�ftd�td�td�ggftd�td�td�ggftd�td�td�ggffD]0\}}|�tt�t|���|�|�tt�t|���|�ttjd	�D]
}|�|t|��q`q;dS)
Nr
rur�r�rrmr�rr)	r%rcr	r�r�r�rMr�rl)r,rr�rQr
r
r�test_product_pickling|s���z"TestBasicOps.test_product_picklingcCsLtdd�}|�d�|�t|�d�tddd�}|�d�|�tt|�dS)Nr)rm)r�)rrmr
)rrr�)r�r�rcrer�r0)r,rr
r
r�test_product_issue_25021�s


z%TestBasicOps.test_product_issue_25021cCs�|�ttddd��gd��|�ttd�td��gd��|�ttdd��gd��|�tdtd��gd��|�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)Nrirm)�object�times)ririri))rri)rri)rrirr*rVy�?zrepeat((1+0j))rwzrepeat((1+0j), 5)zrepeat((1+0j), 0)rKrZaar)rcr	r�rr%r:r�r]r5rer�r�rMr�rl)r,rFrkrQr
r
r�test_repeat�s0�
�zTestBasicOps.test_repeatcCs`|�ttdd��d�|�ttdd��d�|�ttddd��d�|�ttddd��d�dS)Nrirzrepeat('a', 0)r��r�)rcr5r�r+r
r
r�test_repeat_with_negative_times�sz,TestBasicOps.test_repeat_with_negative_timesc	Cs�|�tttjtd�tdd���gd��|�tttdtd���gd��|�tttdt���gd��|�tdttdt���d	d
g�|�tttjg��g�|�	t
t�|�	t
ttdtd�td���|�	t
ttj�|�	t
ttdtd���|�	t
tttdgdg��|�	t
tttdgdg��gd�}ttdt��}|�tt�|��|�ttdt��}|�tt�|��|�ttjd�D]}ttdt��}|�||�q�dS)
Nrmrrv�rrrxrtrwr$rr%r&rKrV)rcr	r�r<�powr%r"r3r:r�r]�negrerrrr�r�rMr�rlrwr
r
r�test_map�s8�����zTestBasicOps.test_mapc
Cs�|�tttjttd�tdd����gd��|�tdttjtt�td����gd��|�tttjg��g�|�tttjt	ddg�g��dg�|�
ttttjdg��|�
tt�|�
tttjdgd	�|�
tttd
dg��|�
t
tttdg��|�
ttttdg��gd�}ttjttd�tdd���}|�tt�|��|�ttjttd�tdd���}|�tt�|��|�ttjd�D]}ttjttd�tdd���}|�||�q�dS)Nrmrrvr�rVrwi�rVrw�extrarK)rcr	�starmapr<r�r
r%r:r3r�r�r]rerrrr�r�rMr�rlrwr
r
r�test_starmap�s."� �$�zTestBasicOps.test_starmapc		CsRdD]}|�tttd�g|�R��tt|���qdD]\}}|�tttd�g|�R��tt|���q|�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]J}|�tt�ttd�g|�R���tt|���|�tt�
ttd�g|�R���tt|���ttjd�D]}|�|ttd�g|�R���q��qjdd�dD�}t�|�}t|d�}|�|��t|�t��|�|��Gdd�dt�}|�tttd�|d���ttd���|�tttd�|d�|d
���ttdd
���|�tttd�|d�|d
�|d���ttdd
d���dS)N)�rKr�rm�rKrmr��rKr�)rKrK�rKrm�r�r})))rKr~rm)rKr}rm))rKr~)rKr}))r~)r}rKrrrmrV���rrri�2)r�r�r�r�r�css�|]}|VqdSrr
r�r
r
rr�7��z+TestBasicOps.test_islice.<locals>.<genexpr>rc@�eZdZdd�Zdd�ZdS)z)TestBasicOps.test_islice.<locals>.IntLikecS�
||_dSr��val�r,r�r
r
rr�B�
z2TestBasicOps.test_islice.<locals>.IntLike.__init__cSs|jSrr�r+r
r
r�	__index__Dsz3TestBasicOps.test_islice.<locals>.IntLike.__index__N)r3r4r5r�r�r
r
r
r�IntLikeAsr�rw)rcr	r8r%r�r�r]rr�r3r4rer�r�rMr�rl�weakref�refZassertIsNotNoner�
gc_collectZassertIsNoner�)	r,rZtgtargsr^ZrarkrQ�wrr�r
r
r�test_islice�sx
�
�"$&&*  
� 
� �

&�$�zTestBasicOps.test_islicecCs0gd�}|�ttt|��gd��|�tttg��g�|�tt�|�tttj�|�tttjdgd�|�tttddg��|�t	ttt
dg��ttgd��}|�t|�gd��|�tt|�|�tt
�
tt|���gd��|�tt
�tt|���gd��ttjd�D]}|�|tt|��q�dS)	N�rrmrwr�rrVrnrxr r�r�rK)rrrrrr�rrrr)rcr	�	takewhilerLr�r]r<r�rerrrvr0r�r�r%rMr�rl)r,rrrQr
r
r�test_takewhileLs$ ��zTestBasicOps.test_takewhilecCsgd�}|�ttt|��gd��|�tttg��g�|�tt�|�tttj�|�tttjdgd�|�tttddg��|�t	ttt
dg��|�tt�tt|���gd��|�tt�tt|���gd��t
tjd�D]}|�|tt|��qrdS)Nr�)r�rrVrnrxr�r�rKr)rcr	�	dropwhilerLr�r]r<r�rerrr�r�r%rMr�rl)r,rrQr
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]E}dg|dg|}t�|�ggf}tt|��}|D]}t||�}	||�	|	�q�|�|dtt|���|�|dtt|���q�|�
tt�|�
ttd�|�
ttddgd�|�
ttddgdd�td	�\}}t|�d
�}
|�t|
�td
��ttd�d�\}}}
td�D]}|�t|�|��q)|�t|�ttd���|�t|
�t|
�gttd���|�t|�ttdd���|�t|
�ttdd���|�
ttd	d�|�
t
tgd
�td�D](}td	|�}|�t|�t�|�t|�|�|�dd�|D�td	�g|��qtd	�\}}t|�\}
}|�||
u�td	�\}
}t|
�}|�
t|�|�
t|d�||
�}|�t|
�t|�k�o�t|�k�o�td	�kn�ttd��\}}t�|�}|�t|d�t|��~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]#}|�|ttd	���td	�\}}|j|||d�|j|||d��q�dS)N��r}rwrrrmrrrtr�r��invalidrcS�g|]}t|��qSr
�r	r�r
r
rrT�r�z)TestBasicOps.test_tee.<locals>.<listcomp>rK�	__class__r�<r�)�teercr	r(rr%rer��shuffleror�r]rdrr�r�r�r��proxy�getattrrr��ReferenceErrorr�r:r�rMr�rlr�)r,r'rirjrr��orderZlistsZitsr=rkr�r��t1�t2ZtnewZt3rrxZlong_ansrQr
r
r�test_teeqs� 
 
$<








�zTestBasicOps.test_teecCs0ttdd��\}}zt|�~WdS~~�)Ni-1)r�r�r�)r,ZforwardZbackwardr
r
r�test_tee_del_backwardsz"TestBasicOps.test_tee_del_backwardcsZG�fdd�d�}t|��\}�|�td��
t|�Wd�dS1s&wYdS)Ncs$eZdZdZdd�Z�fdd�ZdS)z(TestBasicOps.test_tee_reenter.<locals>.ITcSr!rr
r+r
r
rr-r#z1TestBasicOps.test_tee_reenter.<locals>.I.__iter__cs|j}d|_|rt��SdS�NF)�firstre)r,r�r�r
rr1s
�z1TestBasicOps.test_tee_reenter.<locals>.I.__next__N)r3r4r5r�r-r1r
r�r
r�Isr�r�)r��assertRaisesRegexrZre)r,r�rir
r�r�test_tee_reenters


"�zTestBasicOps.test_tee_reentercs�t���t���G��fdd�d�}t|��\}}tjt|gd�}|��z4���|�td��t|�Wd�n1s?wYW��	�|�
�dSW��	�|�
�dS��	�|�
�w)Nc�"eZdZdd�Z��fdd�ZdS)z+TestBasicOps.test_tee_concurrent.<locals>.IcSr!rr
r+r
r
rr-#r#z4TestBasicOps.test_tee_concurrent.<locals>.I.__iter__cs������dSr)r��waitr+�Zfinishr@r
rr1%sz4TestBasicOps.test_tee_concurrent.<locals>.I.__next__Nr2r
r�r
rr�"�r�)r�rr�)�	threading�Eventr��Threadrer@r�r�rZr��join)r,r�rirj�threadr
r�r�test_tee_concurrents$
���
z 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]}|�tt|dd�g��|�tt|dd�t���qtdS)NrcSr!rr
rr
r
rrRHr�z1TestBasicOps.test_StopIteration.<locals>.<lambda>cSr!rr
rr
r
rrRIr�)r�r0rer
r�rDr�r*r8r�r�rr{r�r�r�r�)r,r�r�qr
r
r�test_StopIteration4s"�zTestBasicOps.test_StopIterationcC�6tdggd�}t|�t��|�t�t|���dSr;)r�re�gc�collectr��
is_trackedr�r
r
r�test_combinations_result_gcKsz(TestBasicOps.test_combinations_result_gccCr	r;)r�rer
rr�rr�r
r
r�,test_combinations_with_replacement_result_gcX�z9TestBasicOps.test_combinations_with_replacement_result_gccCr	r;)r�rer
rr�rr�r
r
r�test_permutations_result_gc`rz(TestBasicOps.test_permutations_result_gccCs4tdgg�}t|�t��|�t�t|���dSr)r�rer
rr�rr�r
r
r�test_product_result_gchsz#TestBasicOps.test_product_result_gccCs*tgg�}t��|�t�t|���dSr)r�r
rr�rrer�r
r
r�test_zip_longest_result_gcps
z'TestBasicOps.test_zip_longest_result_gc)rVrN)?r3r4r5rlr�r�r�r�r�r�rZbigaddrspacetestr�Zimpl_detailr�r�r�rr	r
rrr#r>rCrErIrJrMrtryr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�cpython_onlyr
rrrrr
r
r
rrURs�
)#

P

L

?

!"07$$

*
(:


^	



rUc@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�TestExamplescCs |�ttgd���gd��dS�N�rrrmrVrw�rrmrnrKro)rcr	r�r+r
r
rr�z� zTestExamples.test_accumulatec
Cs�gd�}gd�}ttjd�D]4}t|�}|�tt�t�||���|dd��|�t|�d�|�tt�t�||���|dd��qt|�}|�t|�d�|�tt	�
|��|dd��|�tt	�	|��|dd��dS)Nrrr)r%rMr�r�rcr	rNrOrer�r�)r,rZaccumulatedrQr^r
r
r�test_accumulate_reducible}s&("z&TestExamples.test_accumulate_reduciblecCs�tgd�tj�}|�t|�d�ttjd�D]}t�t�	||��}|�t
|�ddg�q|�t
t�|��ddg�|�t
t�|��ddg�dS)N)NNNrTF)
r�r<�is_rcrer%rMr�rNrOr	r�r�)r,r^rQZit_copyr
r
r�test_accumulate_reducible_none�sz+TestExamples.test_accumulate_reducible_nonecCs|�d�tdd��d�dS�Nr�r�ZDEFr)rcrr�r+r
r
rr��szTestExamples.test_chaincCs |�d�t�ddg��d�dSr)rcrr�r�r+r
r
rr��rz%TestExamples.test_chain_from_iterablecCs<|�ttdd��gd��|�tttd�d��gd��dS)Nr�rr�rVrmr�)rcr	r�r%r+r
r
rr��s��zTestExamples.test_combinationscC�|�ttdd��gd��dS)Nr�rr�)rcr	r�r+r
r
rr��s�z/TestExamples.test_combinations_with_replacementcCs"|�ttdgd���td��dS)Nrrr)rcr	r"r+r
r
rr#��"zTestExamples.test_compresscCs"|�tttd�d��gd��dS)NrKrw)rKrPr�rQrR)rcr	r8r3r+r
r
rr>�rzTestExamples.test_countcCs"|�tttd�d��td��dS)Nr�r�ZABCDABCDABCD)rcr	r8rDr+r
r
rrE�rzTestExamples.test_cyclecCs&|�ttdd�gd���gd��dS)NcSrJ�Nrwr
rr
r
rrR�rUz-TestExamples.test_dropwhile.<locals>.<lambda>�rrVrnrVr)rnrVr)rcr	r�r+r
r
rr���&zTestExamples.test_dropwhilecCsT|�dd�td�D�td��|�dd�td�D�td�td�td	�td
�g�dS)NcSr�r
r
rVr
r
rrT�r�z-TestExamples.test_groupby.<locals>.<listcomp>ZAAAABBBCCDAABBBZABCDABcSsg|]\}}t|��qSr
r�rVr
r
rrT�r�Z
AAAABBBCCDZAAAAZBBBZCCr�)rcr�r	r+r
r
rrt�s��zTestExamples.test_groupbycC�&|�ttdd�td���gd��dS)NcS�|dSrr
rr
r
rrR�rUz*TestExamples.test_filter.<locals>.<lambda>rK)rrmrwrvry)rcr	rr%r+r
r
rry�r!zTestExamples.test_filtercCr")NcSr#rr
rr
r
rrR�rUz/TestExamples.test_filterfalse.<locals>.<lambda>rK)rrrVrnrx)rcr	r{r%r+r
r
rr}�r!zTestExamples.test_filterfalsecCs |�tttdd��gd��dS)N)rrmrK)rwrrm�r�ryr/)rcr	r�r�r+r
r
rr��rzTestExamples.test_mapcCst|�ttdd��td��|�ttddd��td��|�ttddd��td��|�ttdddd��td��dS)	Nrr�ABrV�CD�CDEFGr�ACEG)rcr	r8r+r
r
rr��s"zTestExamples.test_islicecCs|�ttdd��ddg�dS)Nr��xy�r�r�r�r�)rcr	r
r+r
r
rr���zTestExamples.test_zipcCs"|�ttdddd��gd��dS)Nr�r)�-r�)r*r+)r�r-)r�r-)rcr	r�r+r
r
r�test_zip_longest���zTestExamples.test_zip_longestcCsD|�ttdd��tttd�����|�tttd���gd��dS)Nr�rz#AB AC AD BA BC BD CA CB CD DA DB DCrm)r)rrr)rrr)rrr)rrr)rrr)rcr	r�r�r��splitr%r+r
r
rr	�s��zTestExamples.test_permutationscCsH|�ttdd��tttd�����|�tttd�dd��gd��dS)Nr�r)zAx Ay Bx By Cx Cy Dx Dyrrmr�)rz)rrr)rrr)rrr)rrrr)rrrr�)rcr	r�r�r�r0r%r+r
r
rr��s��zTestExamples.test_productcCr)NrKrm)rKrKrK)rcr	r�r+r
r
rr��r,zTestExamples.test_repeatcCs"|�tttgd���gd��dS)N))rrw)rmrr�r$)rcr	r�r�r+r
r
r�test_stapmap�r/zTestExamples.test_stapmapcCs&|�ttdd�gd���ddg�dS)NcSrJrr
rr
r
rrR�rUz-TestExamples.test_takewhile.<locals>.<lambda>r rrV)rcr	r�r+r
r
rr��r!zTestExamples.test_takewhileN)r3r4r5r�rrr�r�r�r�r#r>rEr�rtryr}r�r�r�r.r	r�r�r1r�r
r
r
rrxs0
rc@s eZdZedd��Zdd�ZdS)�TestPurePythonRoughEquivalentsc
gs��t|�}|jp	d|jptj|jpd}}}tt|||��}zt|�}Wnt	y;t
t|�|�D]\}}	q3YdSwzt|�D]\}}	||krP|	Vt|�}qAWdSt	ylt
t|d|�|�D]\}}	qdYdSwr�)�slicer@rar7r4rAr�r%rer0r
�	enumerate)
r?rrPr@rarAr^Znextirr�r
r
rr8�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%rVr&r'rr(rKrmrr�)rcr	r8r�r%r3re)r,r^rkr
r
r�test_islice_recipe�s  z1TestPurePythonRoughEquivalents.test_islice_recipeN)r3r4r5�staticmethodr8r5r
r
r
rr2�s
r2c@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/d0�Zd1S)2�TestGCcCs|�|�t|�~~dSr)rore)r,�iterator�	containerr
r
r�	makecycles
zTestGC.makecyclecCs g}|�tdd|dg�|�dS�Nrrrm)r:r��r,rir
r
rr��zTestGC.test_accumulatecC�g}|�t|�|�dSr)r:r�r<r
r
rr��zTestGC.test_chaincCsg}|�t�|g�|�dSr)r:r�r�r<r
r
rr�szTestGC.test_chain_from_iterablecC�"g}|�tdd|dgd�|�dSr;)r:r�r<r
r
rr�#�zTestGC.test_combinationscCr@r;)r:r�r<r
r
rr�'rAz)TestGC.test_combinations_with_replacementcCsg}|�tdgd��|�dS)Nr)rrrrrr)r:r"r<r
r
rr#+�zTestGC.test_compresscCs6g}tdtft|d��}|�t|d�|d��|�dS)N�Intrrr)rdr�r�r:r3)r,rirCr
r
rr>/szTestGC.test_countcC�g}|�t|gd�|�dSr)r:rDr<r
r
rrE4rBzTestGC.test_cyclecCs g}|�ttd||g�|�dSrD)r:r�rvr<r
r
rr�8r=zTestGC.test_dropwhilecCs$g}|�t|gddd��|�dS)NrcSr!rr
rr
r
rrR>r�z%TestGC.test_groupby.<locals>.<lambda>)r:r�r<r
r
rrt<� zTestGC.test_groupbycCs>d}dd�}tt|�|d�D]\}}|j�dg��|�qdS)NrKcSr!rr
rr
r
rrRCr�z'TestGC.test_issue2246.<locals>.<lambda>rNr)r�r%�__dict__�
setdefaultro)r,r'rnrr�r
r
r�test_issue2246@s
�zTestGC.test_issue2246cC�$g}|�tdd�|gd�|�dS)NcS�dS)NTr
rr
r
rrRIr�z$TestGC.test_filter.<locals>.<lambda>r)r:rr<r
r
rryGrEzTestGC.test_filtercCsg}|�tdd�|�|�dS)NcSrJr�r
rr
r
rrRMr�z)TestGC.test_filterfalse.<locals>.<lambda>)r:r{r<r
r
rr}KrBzTestGC.test_filterfalsecCs&g}|�t|gd|gd�|�dS)Nrrm)r:r
r<r
r
rr�Os"zTestGC.test_zipcCsPg}|�t|gd|gd�|�|dg}|�t|gd|gd|d�|�dS)Nrrmr�)r:r�)r,rirjr
r
rr.Ss&zTestGC.test_zip_longestcCrI)NcSr!rr
rr
r
rrR[r�z!TestGC.test_map.<locals>.<lambda>r)r:r�r<r
r
rr�YrEzTestGC.test_mapcCs g}|�t|gdd�|�dSr)r:r8r<r
r
rr�]r=zTestGC.test_islicecCrDr)r:r�r<r
r
rr�arBzTestGC.test_pairwisecCr@r;)r:r�r<r
r
rr	erAzTestGC.test_permutationscCs$g}|�tdd|dgdd�|�dS)Nrrrmr�)r:r�r<r
r
rr�irEzTestGC.test_productcCr>r)r:r�r<r
r
rr�mr?zTestGC.test_repeatcCs(g}|�tdd�||fgd�|�dS)NcWr!rr
�rr
r
rrRsr�z%TestGC.test_starmap.<locals>.<lambda>r)r:r�r<r
r
rr�qs$zTestGC.test_starmapcCs"g}|�ttdd||g�|�dS)Nrr)r:r�rvr<r
r
rr�urAzTestGC.test_takewhileN)r3r4r5r:r�r�r�r�r�r#r>rEr�rtrHryr}r�r.r�r�r�r	r�r�r�r�r
r
r
rr7s2r7ccs�	|D]}|VqdSrr
��seqnrr
r
r�RyrrNc@r))�GcCr�r�rM�r,rMr
r
rr��r�z
G.__init__cCs
|j|SrrP)r,rr
r
r�__getitem__�r�z
G.__getitem__N)r3r4r5r�rRr
r
r
rrO~r6rOc@�&eZdZ	dd�Zdd�Zdd�ZdS)r�cC�||_d|_dSrDrLrQr
r
rr���
z
I.__init__cCr!rr
r+r
r
rr-�r#z
I.__iter__cC�2|jt|j�kr
t�|j|j}|jd7_|Sr;�rr�rMr0�r,r�r
r
rr1��z
I.__next__Nr�r
r
r
rr���
r�c@r))�IgcCrTrDrLrQr
r
rr��rUzIg.__init__ccs�|jD]}|VqdSrrPr�r
r
rr-�s�
�zIg.__iter__N�r3r4r5r�r-r
r
r
rr[��r[c@r))r�cCrTrDrLrQr
r
rr��rUz
X.__init__cCrVr;rWrXr
r
rr1�rYz
X.__next__N)r3r4r5r�r1r
r
r
rr��r]r�c@r))�NcCrTrDrLrQr
r
rr��rUz
N.__init__cCr!rr
r+r
r
rr-�r#z
N.__iter__Nr\r
r
r
rr^�r]r^c@rS)�EcCrTrDrLrQr
r
rr��rUz
E.__init__cCr!rr
r+r
r
rr-�r#z
E.__iter__cCsdddS)Nrmrr
r+r
r
rr1�rz
E.__next__Nr�r
r
r
rr_�rZr_c@rS)�ScC�dSrr
rQr
r
rr��r#z
S.__init__cCr!rr
r+r
r
rr-�r#z
S.__iter__cCr.rr/r+r
r
rr1�r#z
S.__next__Nr�r
r
r
rr`�s
r`cCs 	ttdd�ttt|�����S)NcSr!rr
rr
r
rrR�r�zL.<locals>.<lambda>)r�r�rNr[rOrPr
r
r�L�srbc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�TestVariousIteratorArgscCs�gd�}gd�}t|�}tttttfD]}|�tt||���|�q|�ttt	|���g�|�
ttt|��|�
ttt
|��|�
tttt|���dSr)r�rOr�r[rbrNrcr	r�r`r�r]r�r^�ZeroDivisionErrorr_)r,rPrFr'rWr
r
rr��sz'TestVariousIteratorArgs.test_accumulatec	Cs�ddtd�dtddd�fD]W}ttttttfD]+}|�tt	||���t||���|�tt	||�||���t||��t||���q|�
ttt	t|���|�
ttt	t
|���|�
ttt	t|���q
dS�N�123r�r/�Zdog333333�?r��rw)r%rOr�r[r`rbrNrcr	r�r�r]r�r^rdr_�r,rPrWr
r
rr��s 4�z"TestVariousIteratorArgs.test_chainc	Cs�ddtd�dtddd�fD]J}t|�}ttttttfD]}|�t	t
||�td���t	||���q|�t
t
t|�td��|�t
t
t|�td��|�tt	t
t|�td���q
dS�	Nrfr�r/rgr�rhrwr)r%r�rOr�r[r`rbrNrcr	r"r�r�r]r�r^rdr_)r,rPr'rWr
r
rr#�s(�z%TestVariousIteratorArgs.test_compresscCsZddtd�dtddd�fD]}|�ttt|��|�ttt|��|�ttt|��q
dSre)r%r�r]r�r�r^rdr_)r,rPr
r
rr��s
�z$TestVariousIteratorArgs.test_productcCs�ddtd�dtddd�fD]I}ttttttfD]!}t|�d}t||��d}tt	t
||��|��}|�||�q|�t
t
t|��|�t
t
t|��|�ttt
t|���q
dS)	Nrfr�r/rgr�rhrwrm)r%rOr�r[r`rbrNr�r	r8rDrcr�r]r�r^rdr_)r,rPrWZtgtlen�expected�actualr
r
rrE�s�z"TestVariousIteratorArgs.test_cyclecCs�td�td�td�dtddd�fD]=}ttttttfD]}|�dd	�t||��D�t	||���q|�
ttt|��|�
ttt
|��|�
tt	tt|���qdS)
NrKrr/�rvrPr�rhrwcSr�r
r
)rSr�Zsbr
r
rrT�r�z8TestVariousIteratorArgs.test_groupby.<locals>.<listcomp>)r%rOr�r[r`rbrNrcr�r	r�r]r�r^rdr_rir
r
rrt�s&(�z$TestVariousIteratorArgs.test_groupbyc	C�td�td�td�dtddd�fD]A}ttttttfD]}|�tt	t
||���dd	�||�D��q|�tt	t
t
|��|�tt	t
t|��|�ttt	t
t|���qdS)
NrKrr/rmr�rhrwcS�g|]}t|�r|�qSr
)rr�r
r
rrTr�z7TestVariousIteratorArgs.test_filter.<locals>.<listcomp>)r%rOr�r[r`rbrNrcr	rrr�r]r�r^rdr_rir
r
rry��&��z#TestVariousIteratorArgs.test_filterc	Crn)
NrKrr/rmr�rhrwcSror
)r r�r
r
rrTr�z<TestVariousIteratorArgs.test_filterfalse.<locals>.<listcomp>)r%rOr�r[r`rbrNrcr	r{rr�r]r�r^rdr_rir
r
rr}rpz(TestVariousIteratorArgs.test_filterfalsec	Cs�ddtd�dtddd�fD]P}ttttttfD](}|�tt	||���t
||���|�tt	||�||���t
||�||���q|�tt	t
|��|�tt	t|��|�ttt	t|���q
dSre)r%rOr�r[r`rbrNrcr	r
rr�r]r�r^rdr_rir
r
rr�s .�z TestVariousIteratorArgs.test_zipc
Cs�ddtd�dtddd�fD]T}ttttttfD],}|�tt	||���tt
||����|�tt	||�||���tt
||�||����q|�tt	t
|��|�tt	t|��|�ttt	t|���q
dSre)r%rOr�r[r`rbrNrcr	r�r
r�r]r�r^rdr_rir
r
rr�s$2�z'TestVariousIteratorArgs.test_ziplongestc
Cs�td�td�td�dtddd�fD]Y}ttttttfD].}|�tt	t
||���dd	�||�D��|�tt	tj||�||���d
d	�||�D��q|�
tt	t
t|��|�
tt	t
t|��|�
ttt	t
t|���qdS)NrKrr}rmr�r�rwcSr�r
)rr�r
r
rrT&r�z4TestVariousIteratorArgs.test_map.<locals>.<listcomp>cS�g|]}||�qSr
r
r�r
r
rrT(r�)r%rOr�r[r`rbrNrcr	r�rr<r�r�r]r�r^rdr_rir
r
rr�"s&���z TestVariousIteratorArgs.test_mapc
Cs�ddtd�dtddd�fD]E}ttttttfD]}|�tt	||�ddd	��t||��ddd	��q|�
tt	t|�d
�|�
tt	t
|�d
�|�
ttt	t|�d
��q
dS)NZ12345r�r/rgr�rhrwrrrK)r%rOr�r[r`rbrNrcr	r8r�r]r�r^rdr_rir
r
rr�-s2�z#TestVariousIteratorArgs.test_islicecCs�ddtd�dtddd�fD]I}ttttttfD]!}t||��}tt||dd���}tt	||���}|�
||�q|�tt	t
|��|�tt	t|��|�ttt	t|���q
dSrj)r%rOr�r[r`rbrNr	r
r�rcr�r]r�r^rdr_)r,rPrWr9rkrlr
r
rr�5s�z%TestVariousIteratorArgs.test_pairwisec	Cs�td�td�td�dtddd�fD]J}ttttttfD]}t||�}|�t	t
tj||���dd	�||�D��q|�
tt
tjt|��|�
tt
tjt|��|�
tt	t
tjt|���qdS)
NrKrr}rmr�r�rwcSrqr
r
r�r
r
rrTEr�z8TestVariousIteratorArgs.test_starmap.<locals>.<listcomp>)r%rOr�r[r`rbrNrrcr	r�r<r�r�r]r�r^rdr_)r,rPrW�ssr
r
rr�@s&
��z$TestVariousIteratorArgs.test_starmapc	Cs�td�td�td�dtddd�fD]N}ttttttfD]#}g}||�D]
}t|�s+n|�|�q#|�	t
tt||���|�q|�t
ttt|��|�t
ttt|��|�tt
ttt|���qdS�NrKrr/rmr�rhrw)r%rOr�r[r`rbrNrrorcr	r�r�r]r�r^rdr_�r,rPrWZtgtrrr
r
rr�Js&�z&TestVariousIteratorArgs.test_takewhilec	Cs�td�td�td�dtddd�fD]O}ttttttfD]$}g}||�D]}|s,t|�r,q#|�|�q#|�	t
tt||���|�q|�t
ttt|��|�t
ttt|��|�tt
ttt|���qdSrs)r%rOr�r[r`rbrNr rorcr	r�r�r]r�r^rdr_rtr
r
rr�Vs&�z&TestVariousIteratorArgs.test_dropwhilecCs�ddtd�dtddd�fD]L}ttttttfD]"}t||��\}}|�t	|�t	||���|�t	|�t	||���q|�
ttt|��|�
ttt
|��|�
tt	tt|��d�q
dS)	Nrfr�r/rgr�rhrwr)r%rOr�r[r`rbrNr�rcr	r�r]r�r^rdr_)r,rPrWZit1Zit2r
r
rr�bs�z TestVariousIteratorArgs.test_teeN)r3r4r5r�r�r#r�rErtryr}r�r�r�r�r�r�r�r�r�r
r
r
rrc�s$						
rcc@r�)�LengthTransparencycCsL|�t�tdd��d�|�t�tdd��d�|�t�td�d�d�dS)Nr�rr��rcr<�length_hintr�r+r
r
rr�nszLengthTransparency.test_repeatcCsh|�t�tdd��d�|�t�tdd��d�|�t�tddd��d�|�t�tddd��d�dS)Nrrr�r�rvr+r
r
rr�ssz2LengthTransparency.test_repeat_with_negative_timesN)r3r4r5r�r�r
r
r
rrulsruc@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���|SrrG)r=r��r��zr
rrW�s
z@RegressionTests.test_sf_793826.<locals>.mutatingtuple.<locals>.g)r	r�r
r�re)Ztuple1r�Ztuple2rW�items�genr
ryr�
mutatingtuple~s
z5RegressionTests.test_sf_793826.<locals>.mutatingtuplecs|att��dd�<dSr)�Tr	rK�r�r
rr��sz)RegressionTests.test_sf_793826.<locals>.fr�)rVrwrn)r	r~rc)r,r}r��secondr
rr�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�r�)ro�AssertionErrorr
�Zhistr
r�gen1�s
�

z,RegressionTests.test_sf_950057.<locals>.gen1c3s ���d�dV��d�dS)NrmrrV)rorr�r
r�gen2�s�
z,RegressionTests.test_sf_950057.<locals>.gen2FrrT)r�r�r	r�rcrD)r,r�r�r
r�r�test_sf_950057�szRegressionTests.test_sf_950057cCsPt�dd�td�D��}|�t��
t|�Wd�dS1s!wYdS)Ncss�|]}dVqdS)r
Nr
)rSZunusedr
r
rr��r�zERegressionTests.test_long_chain_of_empty_iterables.<locals>.<genexpr>i���)r�r�r%r�r0rer�r
r
r�"test_long_chain_of_empty_iterables�s
"�z2RegressionTests.test_long_chain_of_empty_iterablescs0�fdd�}ttd�|�D]\}�t��q
dS)Ncs|dkrt��|dkS)Nrwrnr�rAr�r
rr��sz,RegressionTests.test_issue30347_1.<locals>.frK)r�r%r	)r,r�r�r
r�r�test_issue30347_1�s
�z!RegressionTests.test_issue30347_1csJG��fdd�d�}d�tttd�|��d�td�D]}t�d�qdS)Ncr�)z,RegressionTests.test_issue30347_2.<locals>.KcSrarr
rXr
r
rr��r#z5RegressionTests.test_issue30347_2.<locals>.K.__init__cs�d7��dkr
t�d�dS)NrTrG)r,�other�rWrr
rrh�s
z3RegressionTests.test_issue30347_2.<locals>.K.__eq__N)r3r4r5r�rhr
r�r
r�K�rr�rrKrr)rer�r%)r,r�r�r
r�r�test_issue30347_2�s	�z!RegressionTests.test_issue30347_2N)
r3r4r5r�r�rZskip_if_pgo_taskr�r�r�r
r
r
rrxys
rxc@seZdZdd�ZdS)�SubclassWithKwargsTestcs~tttttttttt	t
tfD].�G�fdd�d��}z|dd�Wqty<}z|�
d|jd�WYd}~qd}~wwdS)NcseZdZd�fdd�	ZdS)zBSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.SubclassNcs�j|g|�R�dSr)r�)r,�newargr��clsr
rr��szKSubclassWithKwargsTest.test_keywords_in_subclass.<locals>.Subclass.__init__r)r3r4r5r�r
r�r
r�Subclass�sr�r)r�zkeyword argumentsr)r�r
rr{r�r�r�r8r�r�rDr"r]ZassertNotInr)r,r��errr
r�r�test_keywords_in_subclass�s����z0SubclassWithKwargsTest.test_keywords_in_subclassN)r3r4r5r�r
r
r
rr��sr�c@s:eZdZdd�ZejZdd�Zdd�Zdd�Zd	d
�Z	dS)�
SizeofTestcCst�d�|_dS)Nr')�struct�calcsize�ssize_tr+r
r
r�setUp�szSizeofTest.setUpcCsFt�d�}|j}|tdd�|d|j�|td�|d|j�dS)NZ3PiruZ12r)
rtrtrtrtrtrtrtrtrtrtrK)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�rmrKrV)rr�r�r�r�r%r�r
r
r�test_combinations_sizeof�s
"z#SizeofTest.test_combinations_sizeofcCsPt}t�d�}|j}||dd�|d|j�||td�d�|d|j�dSr�)r�rr�r�r�r%)r,r�r�r�r
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�rVrmr�rwrK)rr�r�r�r�r%r�r
r
r�test_permutations_sizeof�s
�
�
��z#SizeofTest.test_permutations_sizeofN)
r3r4r5r�rr�r�r�r�r�r
r
r
rr��sr�a�- Doctest for examples in the library reference: libitertools.tex


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

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

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

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

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

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

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

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

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

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

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

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

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

>>> def pad_none(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 grouper(iterable, n, *, incomplete='fill', fillvalue=None):
...     "Collect data into non-overlapping fixed-length chunks or blocks"
...     # grouper('ABCDEFG', 3, fillvalue='x') --> ABC DEF Gxx
...     # grouper('ABCDEFG', 3, incomplete='strict') --> ABC DEF ValueError
...     # grouper('ABCDEFG', 3, incomplete='ignore') --> ABC DEF
...     args = [iter(iterable)] * n
...     if incomplete == 'fill':
...         return zip_longest(*args, fillvalue=fillvalue)
...     if incomplete == 'strict':
...         return zip(*args, strict=True)
...     if incomplete == 'ignore':
...         return zip(*args)
...     else:
...         raise ValueError('Expected fill, strict, or ignore')

>>> def triplewise(iterable):
...     "Return overlapping triplets from an iterable"
...     # pairwise('ABCDEFG') -> ABC BCD CDE DEF EFG
...     for (a, _), (b, c) in pairwise(pairwise(iterable)):
...         yield a, b, c

>>> import collections
>>> def sliding_window(iterable, n):
...     # sliding_window('ABCDEFG', 4) -> ABCD BCDE CDEF DEFG
...     it = iter(iterable)
...     window = collections.deque(islice(it, n), maxlen=n)
...     if len(window) == n:
...         yield tuple(window)
...     for x in it:
...         window.append(x)
...         yield tuple(window)

>>> 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 partition(pred, iterable):
...     "Use a predicate to partition entries into false entries and true entries"
...     # partition(is_odd, range(10)) --> 0 2 4 6 8   and  1 3 5 7 9
...     t1, t2 = tee(iterable)
...     return filterfalse(pred, t1), filter(pred, t2)

>>> def before_and_after(predicate, it):
...     ''' Variant of takewhile() that allows complete
...         access to the remainder of the iterator.
...
...         >>> all_upper, remainder = before_and_after(str.isupper, 'ABCdEfGhI')
...         >>> str.join('', all_upper)
...         'ABC'
...         >>> str.join('', remainder)
...         'dEfGhI'
...
...         Note that the first iterator must be fully
...         consumed before the second iterator can
...         generate valid results.
...     '''
...     it = iter(it)
...     transition = []
...     def true_iterator():
...         for elem in it:
...             if predicate(elem):
...                 yield elem
...             else:
...                 transition.append(elem)
...                 return
...     def remainder_iterator():
...         yield from transition
...         yield from it
...     return true_iterator(), remainder_iterator()

>>> 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(islice(pad_none('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('abcdefg', 3, fillvalue='x'))
[('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'x', 'x')]

>>> it = grouper('abcdefg', 3, incomplete='strict')
>>> next(it)
('a', 'b', 'c')
>>> next(it)
('d', 'e', 'f')
>>> next(it)
Traceback (most recent call last):
  ...
ValueError: zip() argument 2 is shorter than argument 1

>>> list(grouper('abcdefg', n=3, incomplete='ignore'))
[('a', 'b', 'c'), ('d', 'e', 'f')]

>>> list(triplewise('ABCDEFG'))
[('A', 'B', 'C'), ('B', 'C', 'D'), ('C', 'D', 'E'), ('D', 'E', 'F'), ('E', 'F', 'G')]

>>> list(sliding_window('ABCDEFG', 4))
[('A', 'B', 'C', 'D'), ('B', 'C', 'D', 'E'), ('C', 'D', 'E', 'F'), ('D', 'E', 'F', 'G')]

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

>>> def is_odd(x):
...     return x % 2 == 1

>>> evens, odds = partition(is_odd, range(10))
>>> list(evens)
[0, 2, 4, 6, 8]
>>> list(odds)
[1, 3, 5, 7, 9]

>>> it = iter('ABCdEfGhI')
>>> all_upper, remainder = before_and_after(str.isupper, it)
>>> ''.join(all_upper)
'ABC'
>>> ''.join(remainder)
'dEfGhI'

>>> 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}tt|��D]}t	j
|�|��t��||<q&t|�t	�tjt|�dS)N�gettotalrefcountrrw)rUrcr7rxrur�rr2r�rZrun_unittest�hasattrr7r
r%r�rr�r�Zrun_doctest�modulesr3)�verboseZtest_classesr
�countsrr
r
r�	test_main�
s �


r��__main__T)r�r)@Zunittest�testr�	itertoolsr�ZdecimalrZ	fractionsrr<r�r�rM�	functoolsrr7r�rr
ZMAX_Py_ssize_tr4Zminsizerrrrrr r"r(r*r:r@rBrGrIrLr%r�r�ZTestCaserUrr2r7rNrOr�r[r�r^r_r`rbrcrurxr�rr�r�Z__test__r�r3r
r
r
r�<module>s�
�2n*i
	
	'
\&


�