Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_itertools.cpython-310.pyc
o

�9j���@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
�*/usr/lib/python3.10/test/test_itertools.py�lzip�rcCsd|S)zTest function of one argument�r
��xr
r
r�oneargsrcG�t�)z"Test function that raises an error)�
ValueErrorrr
r
r�errfuncsrccs�dD]}|VqdS)zNon-restartable source sequence�rrrNr
��ir
r
r�gen3���rcC�|ddkS)�Test predicaterrr
rr
r
r�isEven$�rcCr)rrrr
rr
r
r�isOdd(r r!cG�|Srr
rr
r
r�tupleize,�r#ccs�t|�D]}|VqdSr��range��nrr
r
r�irange/s��r)c@� eZdZdZdd�Zdd�ZdS)�StopNowz"Class emulating an empty iterable.cCr"rr
��selfr
r
r�__iter__5r$zStopNow.__iter__cCrr��
StopIterationr,r
r
r�__next__7r$zStopNow.__next__N)�__name__�
__module__�__qualname__�__doc__r.r1r
r
r
rr+3�r+cCstt||��S)zHConvenience function for partially consuming a long of infinite iterable�r	�islice)r(�seqr
r
r�take:sr:cCsttj|d�S�Nr)r�operator�mul��iterabler
r
r�prod>sr@cCsttd|d��S)�	Factorialr)r@r&�r(r
r
r�factAsrCcC�|dS�Nrr
��rr
r
r�testRF�rHcCrD�Nrr
rFr
r
r�testR2IrIrKcC�|dkS)N�
r
rr
r
r�undertenLrIrNcCsg|]}|fdd��qS)cSst�t�||��Sr)�pickle�loads�dumps)�s�protor
r
r�<lambda>Osz<listcomp>.<lambda>r
)�.0rSr
r
r�
<listcomp>Os�rVc@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�rNcsd��fdd�	�t�||�}t�|�}|�t|�t|���|��|�}}	|�||	�|r8�|�}
|�||
�t�|�}d}zt|�D]
}
t|�|d7}qDWn	tyYYnwt�||�}t�|�}�|��|�}}	|�||	�|r��||d��}
|�||
�dSdS)zITest that an iterator is the same after pickling, also when part-consumedrcs\�dkrtd��t|t�r|Sz	tt|���}Wnty#|YSw��fdd�|D�S)NrMzinfinite recursion encounteredcsg|]	}�|�d��qS)rr
�rU�e)�expandrr
rrV`sz;TestBasicOps.pickletest.<locals>.expand.<locals>.<listcomp>)�RuntimeError�
isinstance�strr	r8�	TypeError)�itr�l�r[�stoprrr[Vs
�z'TestBasicOps.pickletest.<locals>.expandrN�r)rOrQrP�assertEqual�typer&�nextr0)r-�protocolr`rcr:�compare�dump�i2�a�b�c�i3�tookr�i4r
rbr�
pickletestTs6


��
�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)NrM)
rr��rM����$�-r>�abc)rl�abrz��rtrr)
r��	r}r|rrsrXrrt)
rrrrrrrrrr)
rr~rrrrrrrr)
r��i�i�rrrrr)�initial)rMr}r)rMrur��d)r��n�s�t�)rer	�
accumulater&�int�complexrr�map�assertRaisesr_�min�maxr<r=�chrrO�HIGHEST_PROTOCOLrr)r-�typrRrSr
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]}|VqqdS)zPure python version in the docsNr
)�	iterablesr`�elementr
r
r�chain2�s���z'TestBasicOps.test_chain.<locals>.chain2rz�def�abcdef�rX�abcdrrs)�chainrer	r:r�r_)r-r�rnr
r
r�
test_chain�s�zTestBasicOps.test_chaincCs�|�tt�ddg��td��|�tt�dg��td��|�tt�dg��g�|�tdt�ddg��td��|�ttt�ddg��dS)	Nrzr�r�r�rXr�rrs)rer	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)
Nrzr�r�rl�bcdefr�rXr�rrsr�ri)�copy�deepcopy�
picklecopiersr�rer	rgr:r�r_r&rOr�rr)r-�operr`rSr
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
rrzr�)rlrmrn�drZ�f�ghi)r�rlrmrnr�rZr�)r�r_r��__setstate__�iterrer	�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)Nrzrr���cSr"rr
�rlr
r
rrT��z0TestBasicOps.test_combinations.<locals>.<lambda>� �ABCD���A�B�r��C�r��D�r�r��r�r��r�r�)r�r�r�r�r�rXrs�r�rrrs�rrrs�rrrs)r�r�r�c3s��t|��t��}||krdStt|��}t�fdd�|D��V	tt|��D]}|||||kr6nq(dS||d7<t|d|�D]}||dd||<qHt�fdd�|D��Vq")�%Pure python version shown in the docsNc3��|]}�|VqdSrr
�rUr��poolr
r�	<genexpr>���zHTestBasicOps.test_combinations.<locals>.combinations1.<locals>.<genexpr>rc3r�rr
r�r�r
rr��r���tuple�lenr	r&�reversed)r?rGr(�indicesr�jr
r�r�
combinations1�s$���z5TestBasicOps.test_combinations.<locals>.combinations1c3sR�t|��t��}tt|�|�D]}t|�t|�kr&t�fdd�|D��VqdS)r�c3r�rr
r�r�r
rr�r�zHTestBasicOps.test_combinations.<locals>.combinations2.<locals>.<genexpr>N)r�r��permutationsr&�sortedr	�r?rGr(r�r
r�r�
combinations2�����z5TestBasicOps.test_combinations.<locals>.combinations2c3sR�t|��t��}tt|�|�D]}tt|��|kr&t�fdd�|D��VqdS)zPure python version from cwr()c3r�rr
r�r�r
rr�	r�zHTestBasicOps.test_combinations.<locals>.combinations3.<locals>.<genexpr>N)r�r��combinations_with_replacementr&�setr�r
r�r�
combinations3r�z5TestBasicOps.test_combinations.<locals>.combinations3r|cS�g|]}d|d�qS�r}�r
�rUrr
r
rrV�z2TestBasicOps.test_combinations.<locals>.<listcomp>rc3��|]}|�vVqdSrr
rY��valuesr
rr�r�z1TestBasicOps.test_combinations.<locals>.<genexpr>c�g|]}|�vr|�qSr
r
rY�rnr
rrVr�)r�r_�combinationsrr�rer	rgr&r�rCr�r��
assertTrue�allrOr�rr)
r-�op�testIntermediater�r�r�r(rG�resultrSr
�rnr�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�abcdersr)rer�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)Nrzrrr�cSr"rr
r�r
r
rrT2r�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]}|||dkr3nq'dS||dg||||d�<t�fdd�|D��Vq!)r�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?rGr(r�rr
r�r�cwr1;s �
��z=TestBasicOps.test_combinations_with_replacement.<locals>.cwr1c3sT�t|��t��}tt|�|d�D]}t|�t|�kr't�fdd�|D��VqdS)r���repeatc3r�rr
r�r�r
rr�Sr�zPTestBasicOps.test_combinations_with_replacement.<locals>.cwr2.<locals>.<genexpr>N)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)rC)r(rGr
r
r�numcombsUs$zATestBasicOps.test_combinations_with_replacement.<locals>.numcombsr|cSr�r�r
r�r
r
rrV[r�zCTestBasicOps.test_combinations_with_replacement.<locals>.<listcomp>rcS�g|]\}}|�qSr
r
)rU�k�vr
r
rrVk�c3r�rr
rYr�r
rr�nr�zBTestBasicOps.test_combinations_with_replacement.<locals>.<genexpr>cr�r
r
rYr�r
rrVpr�)r�r�r_rr�rer	rgr&r�r�r�r�r��groupbyr�rOr�rr)
r-�cwrr�r�r�r�r�r(rGr��
regular_combs�norunsrSr
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�rer�r�r�r�r�r	)r-rr
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)Nrzrrr�r�rRrs)�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<||dkrr||dd�|||d�||d�<||||<qG||}||||||<||<t�fdd�|d|�D��VndS|sAdSdS)r�Nr���c3r�rr
r�r�r
rr��r�zHTestBasicOps.test_permutations.<locals>.permutations1.<locals>.<genexpr>rc3r�rr
r�r�r
rr��r�r�)r?rGr(r��cyclesrr�r
r�r�
permutations1�s*�$ ( �z5TestBasicOps.test_permutations.<locals>.permutations1c3sd�t|��t��}|dur|n|}tt|�|d�D]}tt|��|kr/t�fdd�|D��VqdS)r�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>.permutations2r|cSr�r�r
r�r
r
rrV�r�z2TestBasicOps.test_permutations.<locals>.<listcomp>rc3r�rr
rYr�r
rr��r�z1TestBasicOps.test_permutations.<locals>.<genexpr>r)r�r_r�rrer	r&r�rCr�r�r�r�rOr�rr)r-rrr(rGr��prSr
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�)rer�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)Nrt�ABCDEFGr~r�rrcS� g|]}t|�t|�kr|�qSr
�r�r	�rU�tr
r
rrV�� z3TestBasicOps.test_combinatorics.<locals>.<listcomp>c� g|]}tt|���kr|�qSr
�r�r�rrFr
rrV�rcSrr
rrr
r
rrV�rcrr
rrrFr
rrV�r)
r&r	r�r�r�r�rer�rCr�r��filter�__contains__)r-r(rRr@r�perm�combr
rFr�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�rrr�ACr�)rrrrrr�BC�'rtr�rrsr}cSs
t�|�Sr)r�r�r
r
rrT��
z,TestBasicOps.test_compress.<locals>.<lambda>cSs
t�|�Sr)r�r�r�r
r
rrT�r/�CEF�BCDEFr�)rer	�compressr�r�r�r&r�r_r�rg)r-r(r'r(r��result1�result2r�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)(Nrz��rlr�rmr�rnrrs)�rlrs�rmrX)rnr}rr:r;r)rlr)rmr���)rlr<)rmr�rXrlrMr}�
@)r=g@g@�
@�)r>y@��@��1.1z2.1z3.1r~r��zcount(3)zcount(4)���z	count(-9)i����g�$@zcount(10.25)g$@zcount(10.0)���r�	count(%r))rer�countr:r
r�r_�maxsizer	r&rr�reprrgrf�float�sys�__mod__r�r�rOr�rr�exc_info)r-�BIGINTrnr�r1�r2�valuerSr
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)2Nrzrrs)�rlr)rmr})rnr~)�start�stepr)rS)r7)rmr)rnr�rlrmr)rQ)rmrr9r)rQ)rmrs)rnrXr�rur�rMr}g�?)rr=g@r>)rr?y!@ �r@z.1z1.2z1.3r|�rvrAg@)rMg)@g.@zcount(3, 5)zcount(8, 5)rBz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)rCrDz
count(%r, %r))rerrEr�r_r:rFr&r	rrrGrgrfr�rHrIrOr�rr)r-rLrnrr�rMrNrSr
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)NrMrz�
abcabcabcar�r})
rrrrrrrrrr)rer:�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)NrzrlrM�
bcabcabcabr�
cabcabcabcr�c�g|]}t���qSr
�rgr�r�r
rrV�rz7TestBasicOps.test_cycle_copy_pickle.<locals>.<listcomp>rr��cdeabcdeabcdeabcdeabcr[r
r\r�r�r
rrV�rr|)rWrergr:r�r�r	r&rOr�rPrQrrr�)r-rSr`�_rr�r
r�r�test_cycle_copy_pickle}s:��


�z#TestBasicOps.test_cycle_copy_picklecCsFgd�}t|�dksJ�|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.r�rM)
rrsrrrsrrrsrr)r�rOrPrer:)r-�	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�defgrzrr��defgabcdefgabcdefgab�abcdefgrrr�r
)rWr�r	rer:r�r_r�)r-rnr
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��keyrzcSr"rr
rr
r
rrT�r�z+TestBasicOps.test_groupby.<locals>.<lambda>rM))rrMr�)r�rv)rr�rv)r�
rv)r��)rrurk)rsr��)rsrTrlcSrDrEr
rFr
r
rrT��rrrcSrr
r
�rUr�gr
r
rrVrz-TestBasicOps.test_groupby.<locals>.<listcomp>cSsg|]}|d�qSrdr
)rUrGr
r
rrVr�	AABBBAAAAr)r�r}�abracadabracSrr
r
rnr
r
rrV2r)rlrmrnr�rGcSs$g|]\}}tt|dd��r|�qSrr7rnr
r
rrV5�$)rlrmrGcS� g|]\}}tt|��|f�qSr
�r�r	rnr
r
rrV8r)�r}rl�rrm)rrn)rr��rrGcSrsr
rtrnr
r
rrV;rT)�reversers)rurwrvc@seZdZdS)z0TestBasicOps.test_groupby.<locals>.ExpectedErrorN)r2r3r4r
r
r
r�
ExpectedError?sryc3s�t|�D]}dVq��)N�yor%r'�ryr
r�
delayed_raiseAs�z0TestBasicOps.test_groupby.<locals>.delayed_raisecs�fdd�t||�D�S)Ncsg|]\}}�|��qSr
r
rn��funcr
rrVFr�z;TestBasicOps.test_groupby.<locals>.gulp.<locals>.<listcomp>)r)r?�keypr~r
r}r�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)r2r3r4r�r
r{r
r�DummyCmpN�r�r}cs �jdkr�jd8_|S��r�)�skip)�obj�ry�keyfuncr
rr�Ys
z*TestBasicOps.test_groupby.<locals>.keyfuncrd)rer	rr�r�r_�appendr&rOr�rPrQrHrKr�r�r
rgr��	Exceptionr�)r-rR�duprro�elemrS�ik�ig�keys�expectedkeysr`r^�g1�g2�g3rGr|r�r�r
r�r�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)
Nrt)rrrX�rrrrrrrrX)rrrXrtcSr"rr
rr
r
rrTlr�z*TestBasicOps.test_filter.<locals>.<lambda>cSr"rr
rr
r
rrTmr�r|rs)rer	r rr&�boolr:rEr�r_rgr�r�rOr�rPrQrr�r-�ansrnrSr
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)
Nrtr.r��rrrrX)rrsr}r|cSr"rr
rr
r
rrT�r�z/TestBasicOps.test_filterfalse.<locals>.<lambda>cSr"rr
rr
r
rrT�r�r|rsr)rer	�filterfalserr&r�r:rEr�r_rgrOr�rr�r-rSr
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
�rUr�yr
r
rrV�r�z)TestBasicOps.test_zip.<locals>.<listcomp>rzr6rtr�rscS�g|]}tt|���qSr
�r�r	�rU�pairr
r
rrV�r�r�cS�g|]}|�qSr
r
r�r
r
rrV��)	r
rErer	r&rr:r�r_)r-r�r
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)Nrzr�cSr�r
r
r�r
r
rrV�r�z5TestBasicOps.test_zip_tuple_reuse.<locals>.<listcomp>r6cSr�r
r
r�r
r
rrV�r�rcSr�r
r
r�r
r
rrV�r�cSr�r
r
r�r
r
rrV�r�r8r9)r	r�r�r
rer�r�r��dict�fromkeysr�rEr�r&rOr�rPrQrgrr)r-�idsr�rSr�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)NrzrtrA��i4i�i�ri�i�cs"g|]
�t�fdd��D���qS)cs$g|]}�t|�kr|�nd�qSr�r�)rU�argrr
rrV�rrz;TestBasicOps.test_ziplongest.<locals>.<listcomp>.<listcomp>�r�)rUrrrrV�s�z0TestBasicOps.test_ziplongest.<locals>.<listcomp>cSsg|]}tdd�|D���qS)css �|]}|dur
dp|VqdS)N�Xr
rYr
r
rr��s�z:TestBasicOps.test_ziplongest.<locals>.<listcomp>.<genexpr>r�rr
r
rrV�sr���	fillvaluersr�rb)zzip_longest('abc', fv=1)z3zip_longest('abc', fillvalue=1, bogus_keyword=None)zDid not raise Type in:  cSr�r
r�r�r
r
rrV�r�r�cSr�r
r
r�r
r
rrV�r�)rzrb)r&r�r�r�rer	�zip_longestr�r:rEr
r�r_�eval�globals�locals�fail)r-�target�stmtr
rr�test_ziplongest�sF

"(�
�"(����zTestBasicOps.test_ziplongestcCs^ttttdd���}|�t|�t|��tttttdd����}|�tt�	|��t|��dS)Nrzr�)
r	r�r�r�rer�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)Nrrzr��defghr�r�)r&rOr�rrr�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)Ncr�)z?TestBasicOps.test_zip_longest_bad_iterable.<locals>.BadIterablecr�rr
r,��	exceptionr
rr.�r$zHTestBasicOps.test_zip_longest_bad_iterable.<locals>.BadIterable.__iter__N)r2r3r4r.r
r�r
r�BadIterable�r�r�)r_r�r��assertIsr�)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�rrZ)r-r�rrZr
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�rZr,r
r
rr1s
z5TestBasicOps.test_bug_7244.<locals>.Repeater.__next__N)r2r3r4r�r.r1r
r
r
r�Repeater�sr�rrsrrXc	Ssdg}t||dd�D]&\}}t�d��t||f�Wd�n1s#wY|�||f�q	|S)Nrr��stdout)r�r�captured_output�printr�)rMrNr�rr�r
r
r�runs�z'TestBasicOps.test_bug_7244.<locals>.run)rrrr
rr�r)r0rer\r�rgr�)r-r�rMrNr�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�rlr{�rlrmr�)r�)rmrn)rnr�)r�rZr-rrzrMr>)rer	�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
r{r��rmrrs�)rrrr
r)rrrrrXr�r|rti��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�)rUr�r
r
rr�N��z>TestBasicOps.test_product.<locals>.product1.<locals>.<genexpr>cs��|]	\}}||VqdSrr
�rUr�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?sV�ttt|��|�dd�}gg}|D]��fdd�|D�}q|D]}t|�Vq!dS)z Pure python version used in docsr�rcs g|]}�D]}||g�qqSr
r
r�r�r
rrVcrz?TestBasicOps.test_product.<locals>.product2.<locals>.<listcomp>N)r	r�r�r�)rr�r�r�r@r
r�r�product2^s��z+TestBasicOps.test_product.<locals>.product2r�rzr)rlrmrnrdrhrir�csg|]}t����qSr
)�random�choice)rUr���argtypesr
rrVjsz-TestBasicOps.test_product.<locals>.<listcomp>r})r&rer	r�r�r�r�r_r�r�r��	randranger@r�r�)r-rr�rGr�r�r�expected_lenr
r�r�test_product8s:���"	�
�zTestBasicOps.test_productcCsH|�ttf��tdgdddi�Wd�dS1swYdS)Nr{r�r�i)r�r�r�r�r,r
r
r�test_product_overflowrs"�z"TestBasicOps.test_product_overflowc
Cr�)Nrzr�r)rer�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
r{r�r�rrsr�rr)	r&rer	r�r�r�rOr�rr)r-rr�rSr
r
r�test_product_pickling|s���z"TestBasicOps.test_product_picklingcCsLtdd�}|�d�|�t|�d�tddd�}|�d�|�tt|�dS)Nr)rs)r�)rrsr
)rrr�)r�r�rergr�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)Nrlrs)�object�times)rlrlrl))rrl)rrl)rrlrr<rXy�?zrepeat((1+0j))r}zrepeat((1+0j), 5)zrepeat((1+0j), 0)rMr�aar)rer	r�rr&r:r�r_rGrgr�r�rOr�rr)r-rGrnrSr
r
r�test_repeat�s0�
�zTestBasicOps.test_repeatcCs`|�ttdd��d�|�ttdd��d�|�ttddd��d�|�ttddd��d�dS)Nrlrzrepeat('a', 0)r��r�)rerGr�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)
Nrsrr|�rrr~rzr}r6rr7r8rMrX)rer	r�r<�powr&r#rEr:r�r_�negrgrrrr�r�rOr�rrr�r
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)Nrsrr|r�rXr}i�rXr}�extrarM)rer	�starmapr<r�r
r&r:rEr�r�r_rgrrrr�r�rOr�rrr�r
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)�rMr�rs�rMrsr��rMr�)rMrM�rMrs�r�r�)))rMr�rs)rMr�rs))rMr�)rMr�))r�)r�rMrrrsrX���rrrl�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-rr
r
rr�B�
z2TestBasicOps.test_islice.<locals>.IntLike.__init__cSs|jSrrr,r
r
r�	__index__Dsz3TestBasicOps.test_islice.<locals>.IntLike.__index__N)r2r3r4r�rr
r
r
r�IntLikeAsrr})rer	r8r&r�r�r_rr�rErFrgr�r�rOr�rr�weakref�ref�assertIsNotNoner�
gc_collect�assertIsNoner�)	r-r�tgtargsr`�rarnrS�wrrr
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�rrsr}r�rrXrtr~r.r�r�rM)rrrrrr�rrrr)rer	�	takewhilerNr�r_r<r�rgrrr�r0r�r�r&rOr�rr)r-r'rrSr
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�rrXrtr~r�r�rMr)rer	�	dropwhilerNr�r_r<r�rgrrr�r�r&rOr�rr)r-r'rSr
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�r}rrrsrrrzr�r��invalidrcS�g|]}t|��qSr
�r	r�r
r
rrV�rz)TestBasicOps.test_tee.<locals>.<listcomp>rM�	__class__r-�<r�)�teerer	r)rr&rgr��shuffler�r�r_rfrr�r�r�r�proxy�getattrrr	�ReferenceErrorr�r:r�rOr�rrr�)r-r(rlrmrr��order�lists�itsrOrnr�r��t1�t2�tnew�t3rr��long_ansrSr
r
r�test_teeqs� 
 
$<








�zTestBasicOps.test_teecCs0ttdd��\}}zt|�~WdS~~�)Ni-1)rr�r�)r-�forward�backwardr
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)�firstrg)r-r-r�r
rr1s
�z1TestBasicOps.test_tee_reenter.<locals>.I.__next__N)r2r3r4r-r.r1r
r�r
r�Isr.r)r�assertRaisesRegexr\rg)r-r.rlr
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,��finishrRr
rr1%sz4TestBasicOps.test_tee_concurrent.<locals>.I.__next__N)r2r3r4r.r1r
r3r
rr."�r.)r�rr)�	threading�Eventr�ThreadrgrRr2r/r\r��join)r-r.rlrm�threadr
r3r�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
rrTHr�z1TestBasicOps.test_StopIteration.<locals>.<lambda>cSr"rr
rr
r
rrTIr�)r�r0rgr
r�rWrr+r8rr�r r�r�rrr�)r-r�r�qr
r
r�test_StopIteration4s"�zTestBasicOps.test_StopIterationcC�6tdggd�}t|�t��|�t�t|���dSr;)r�rg�gc�collectr��
is_trackedr�r
r
r�test_combinations_result_gcKsz(TestBasicOps.test_combinations_result_gccCr>r;)r�rgr?r@r�rAr�r
r
r�,test_combinations_with_replacement_result_gcX�z9TestBasicOps.test_combinations_with_replacement_result_gccCr>r;)r�rgr?r@r�rAr�r
r
r�test_permutations_result_gc`rDz(TestBasicOps.test_permutations_result_gccCs4tdgg�}t|�t��|�t�t|���dSr)r�rgr?r@r�rAr�r
r
r�test_product_result_gchsz#TestBasicOps.test_product_result_gccCs*tgg�}t��|�t�t|���dSr)r�r?r@r�rArgr�r
r
r�test_zip_longest_result_gcps
z'TestBasicOps.test_zip_longest_result_gc)rXrN)?r2r3r4rrr�r�r�r�r�r�r�bigaddrspacetestr��impl_detailr�rr
rrrrr$r5rPrUrXr_rarer�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr(r+r0r;r=�cpython_onlyrBrCrErFrGr
r
r
rrWRs�
)#

P

L

?

!"07$$

*
(:


^	



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�TestExamplescCs |�ttgd���gd��dS�N�rrrsrXr}�rrsrtrMru)rer	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)NrMrNr)r&rOr�r�rer	rPrQrgr�r�)r-r'�accumulatedrSr`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_rergr&rOr�rPrQr	r�r�)r-r`rS�it_copyr
r
r�test_accumulate_reducible_none�sz+TestExamples.test_accumulate_reducible_nonecCs|�d�tdd��d�dS�Nr�r��DEFr%)rer9r�r,r
r
rr��szTestExamples.test_chaincCs |�d�t�ddg��d�dSrU)rer9r�r�r,r
r
rr��rOz%TestExamples.test_chain_from_iterablecCs<|�ttdd��gd��|�tttd�d��gd��dS)Nr�rr�rXrsr�)rer	r�r&r,r
r
rr��s��zTestExamples.test_combinationscC�|�ttdd��gd��dS)Nr�rr�)rer	r�r,r
r
rr�s�z/TestExamples.test_combinations_with_replacementcCs"|�ttdgd���td��dS)Nr%r&r))rer	r2r,r
r
rr5��"zTestExamples.test_compresscCs"|�tttd�d��gd��dS)NrMr})rMrhr�rirj)rer	r8rEr,r
r
rrP�rXzTestExamples.test_countcCs"|�tttd�d��td��dS)Nr�r��ABCDABCDABCD)rer	r8rWr,r
r
rrX�rXzTestExamples.test_cyclecCs&|�ttdd�gd���gd��dS)NcSrL�Nr}r
rr
r
rrT�rmz-TestExamples.test_dropwhile.<locals>.<lambda>�rrXrtrXr)rtrXr)rer	rr,r
r
rr��&zTestExamples.test_dropwhilecCsT|�dd�td�D�td��|�dd�td�D�td�td�td	�td
�g�dS)NcSrr
r
rnr
r
rrV�rz-TestExamples.test_groupby.<locals>.<listcomp>�AAAABBBCCDAABBB�ABCDABcSsg|]\}}t|��qSr
rrnr
r
rrV�r��
AAAABBBCCD�AAAA�BBB�CCr�)rerr	r,r
r
rr��s��zTestExamples.test_groupbycC�&|�ttdd�td���gd��dS)NcS�|dSrJr
rr
r
rrT�rmz*TestExamples.test_filter.<locals>.<lambda>rM)rrsr}r|r)rer	r r&r,r
r
rr��r\zTestExamples.test_filtercCrc)NcSrdrJr
rr
r
rrT�rmz/TestExamples.test_filterfalse.<locals>.<lambda>rM)rrrXrtr~)rer	r�r&r,r
r
rr��r\zTestExamples.test_filterfalsecCs |�tttdd��gd��dS)N)rrsrM)r}rrs�r�rrA)rer	r�r�r,r
r
rr��rOzTestExamples.test_mapcCst|�ttdd��td��|�ttddd��td��|�ttddd��td��|�ttdddd��td��dS)	Nrr�ABrX�CD�CDEFGr�ACEG)rer	r8r,r
r
rr�s"zTestExamples.test_islicecCs|�ttdd��ddg�dS)Nr��xy�r�r�r�r�)rer	r
r,r
r
rr���zTestExamples.test_zipcCs"|�ttdddd��gd��dS)Nr�rj�-r�)rkrl)r�rn)r�rn)rer	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 DCrs)r)rrr)rrr)rrr)rrr)rrr)rer	r�r�r��splitr&r,r
r
rr�s��zTestExamples.test_permutationscCsH|�ttdd��tttd�����|�tttd�dd��gd��dS)Nr�rjzAx Ay Bx By Cx Cy Dx Dyrrsr�)r�)rrr)rrr)rrr)rrrr*)rrrr)rer	r�r�r�rqr&r,r
r
rr��s��zTestExamples.test_productcCrW)NrMrs)rMrMrM)rer	r�r,r
r
rr��rmzTestExamples.test_repeatcCs"|�tttgd���gd��dS)N))rr})rsrr�re)rer	r�r�r,r
r
r�test_stapmap�rpzTestExamples.test_stapmapcCs&|�ttdd�gd���ddg�dS)NcSrLrZr
rr
r
rrT�rmz-TestExamples.test_takewhile.<locals>.<lambda>r[rrX)rer	rr,r
r
rr�r\zTestExamples.test_takewhileN)r2r3r4r�rQrTr�r�r�rr5rPrXrr�r�r�r�rr�rorr�r�rrrr
r
r
rrKxs0
rKc@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�)�slicerRrcrIrFrSr�r&rgr0r
�	enumerate)
r?rrRrRrcrSr`�nextirr�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)
NrrrfrXrgrhrrirMrsrr�)rer	r8r�r&rErg)r-r`rnr
r
r�test_islice_recipe�s  z1TestPurePythonRoughEquivalents.test_islice_recipeN)r2r3r4�staticmethodr8rwr
r
r
rrs�s
rsc@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)r�rg)r-�iterator�	containerr
r
r�	makecycles
zTestGC.makecyclecCs g}|�tdd|dg�|�dS�Nrrrs)r|r��r-rlr
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'r�z)TestGC.test_combinations_with_replacementcCsg}|�tdgd��|�dS)Nr%)rrrrrr)r|r2r~r
r
rr5+�zTestGC.test_compresscCs6g}tdtft|d��}|�t|d�|d��|�dS)N�Intrrr)rfr�r�r|rE)r-rlr�r
r
rrP/szTestGC.test_countcC�g}|�t|gd�|�dSrJ)r|rWr~r
r
rrX4r�zTestGC.test_cyclecCs g}|�ttd||g�|�dSrE)r|rr�r~r
r
rr8rzTestGC.test_dropwhilecCs$g}|�t|gddd��|�dS)NrcSr"rr
rr
r
rrT>r�z%TestGC.test_groupby.<locals>.<lambda>)r|rr~r
r
rr�<� zTestGC.test_groupbycCs>d}dd�}tt|�|d�D]\}}|j�dg��|�qdS)NrMcSr"rr
rr
r
rrTCr�z'TestGC.test_issue2246.<locals>.<lambda>rfr)rr&�__dict__�
setdefaultr�)r-r(r�rr�r
r
r�test_issue2246@s
�zTestGC.test_issue2246cC�$g}|�tdd�|gd�|�dS)NcS�dS)NTr
rr
r
rrTIr�z$TestGC.test_filter.<locals>.<lambda>r)r|r r~r
r
rr�Gr�zTestGC.test_filtercCsg}|�tdd�|�|�dS)NcSr�r,r
rr
r
rrTMr�z)TestGC.test_filterfalse.<locals>.<lambda>)r|r�r~r
r
rr�Kr�zTestGC.test_filterfalsecCs&g}|�t|gd|gd�|�dS)Nrrs)r|r
r~r
r
rr�Os"zTestGC.test_zipcCsPg}|�t|gd|gd�|�|dg}|�t|gd|gd|d�|�dS)Nrrsr�)r|r�)r-rlrmr
r
rroSs&zTestGC.test_zip_longestcCr�)NcSr"rr
rr
r
rrT[r�z!TestGC.test_map.<locals>.<lambda>r)r|r�r~r
r
rr�Yr�zTestGC.test_mapcCs g}|�t|gdd�|�dSrJ)r|r8r~r
r
rr]rzTestGC.test_islicecCr�rZ)r|r�r~r
r
rr�ar�zTestGC.test_pairwisecCr�r})r|r�r~r
r
rrer�zTestGC.test_permutationscCs$g}|�tdd|dgdd�|�dS)Nrrrsr�)r|r�r~r
r
rr�ir�zTestGC.test_productcCr�r)r|r�r~r
r
rr�mr�zTestGC.test_repeatcCs(g}|�tdd�||fgd�|�dS)NcWr"rr
�rr
r
rrTsr�z%TestGC.test_starmap.<locals>.<lambda>r)r|r�r~r
r
rr�qs$zTestGC.test_starmapcCs"g}|�ttdd||g�|�dS)Nrr)r|rr�r~r
r
rrur�zTestGC.test_takewhileN)r2r3r4r|r�r�r�r�rr5rPrXrr�r�r�r�r�ror�rr�rr�r�r�rr
r
r
rrys2ryccs�|D]}|VqdS)zRegular generatorNr
��seqnrr
r
r�Ryrr�c@r*)�GzSequence using __getitem__cCr�r�r��r-r�r
r
rr��rz
G.__init__cCs
|j|Srr�)r-rr
r
r�__getitem__�rz
G.__getitem__N)r2r3r4r5r�r�r
r
r
rr�~r6r�c@�(eZdZdZdd�Zdd�Zdd�ZdS)	r.z Sequence using iterator protocolcC�||_d|_dSrEr�r�r
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�r�r0�r-rr
r
rr1��z
I.__next__N�r2r3r4r5r�r.r1r
r
r
rr.��
r.c@r*)�Igz9Sequence using iterator protocol defined with a generatorcCr�rEr�r�r
r
rr��r�zIg.__init__ccs�|jD]}|VqdSrr�rr
r
rr.�s�
�zIg.__iter__N�r2r3r4r5r�r.r
r
r
rr���r�c@r*)r�z Missing __getitem__ and __iter__cCr�rEr�r�r
r
rr��r�z
X.__init__cCr�r;r�r�r
r
rr1�r�z
X.__next__N)r2r3r4r5r�r1r
r
r
rr��r�r�c@r*)�NzIterator missing __next__()cCr�rEr�r�r
r
rr��r�z
N.__init__cCr"rr
r,r
r
rr.�r$z
N.__iter__Nr�r
r
r
rr��r�r�c@r�)	�EzTest propagation of exceptionscCr�rEr�r�r
r
rr��r�z
E.__init__cCr"rr
r,r
r
rr.�r$z
E.__iter__cCsdddS)Nrsrr
r,r
r
rr1�rz
E.__next__Nr�r
r
r
rr��r�r�c@r�)	�SzTest immediate stopcC�dSrr
r�r
r
rr��r$z
S.__init__cCr"rr
r,r
r
rr.�r$z
S.__iter__cCrrr/r,r
r
rr1�r$z
S.__next__Nr�r
r
r
rr��s
r�cCsttdd�ttt|�����S)z Test multiple tiers of iteratorscSr"rr
rr
r
rrT�r�zL.<locals>.<lambda>)r�r�r�r�r�r�r
r
r�L�sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�TestVariousIteratorArgscCs�gd�}gd�}t|�}tttttfD]}|�tt||���|�q|�ttt	|���g�|�
ttt|��|�
ttt
|��|�
tttt|���dSrL)r�r�r.r�r�r�rer	r�r�r�r_r�r��ZeroDivisionErrorr�)r-rRrGr(ror
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�rA��dog333333�?r��r})r&r�r.r�r�r�r�rer	r�r�r_r�r�r�r��r-rRror
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�	Nr�r�rAr�r�r�r}r)r&r�r�r.r�r�r�r�rer	r2r�r�r_r�r�r�r�)r-rRr(ror
r
rr5�s(�z%TestVariousIteratorArgs.test_compresscCsZddtd�dtddd�fD]}|�ttt|��|�ttt|��|�ttt|��q
dSr�)r&r�r_r�r�r�r�r�)r-rRr
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)	Nr�r�rAr�r�r�r}rs)r&r�r.r�r�r�r�r�r	r8rWrer�r_r�r�r�r�)r-rRro�tgtlen�expected�actualr
r
rrX�s�z"TestVariousIteratorArgs.test_cyclecCs�td�td�td�dtddd�fD]=}ttttttfD]}|�dd	�t||��D�t	||���q|�
ttt|��|�
ttt
|��|�
tt	tt|���qdS)
NrMrrA�r|rhr�r�r}cSrr
r
)rUr�sbr
r
rrV�rz8TestVariousIteratorArgs.test_groupby.<locals>.<listcomp>)r&r�r.r�r�r�r�rerr	r�r_r�r�r�r�r�r
r
rr��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)
NrMrrAr�r�r�r}cS�g|]}t|�r|�qSr
)rr�r
r
rrVr�z7TestVariousIteratorArgs.test_filter.<locals>.<listcomp>)r&r�r.r�r�r�r�rer	r rr�r_r�r�r�r�r�r
r
rr���&��z#TestVariousIteratorArgs.test_filterc	Cr�)
NrMrrAr�r�r�r}cSr�r
)r!r�r
r
rrVr�z<TestVariousIteratorArgs.test_filterfalse.<locals>.<listcomp>)r&r�r.r�r�r�r�rer	r�rr�r_r�r�r�r�r�r
r
rr�r�z(TestVariousIteratorArgs.test_filterfalsec	Cs�ddtd�dtddd�fD]P}ttttttfD](}|�tt	||���t
||���|�tt	||�||���t
||�||���q|�tt	t
|��|�tt	t|��|�ttt	t|���q
dSr�)r&r�r.r�r�r�r�rer	r
rr�r_r�r�r�r�r�r
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
dSr�)r&r�r.r�r�r�r�rer	r�r
r�r_r�r�r�r�r�r
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)NrMrr�r�r�r�r}cSrr
)rr�r
r
rrV&rz4TestVariousIteratorArgs.test_map.<locals>.<listcomp>cS�g|]}||�qSr
r
r�r
r
rrV(r)r&r�r.r�r�r�r�rer	r�rr<r�r�r_r�r�r�r�r�r
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)N�12345r�rAr�r�r�r}rrrM)r&r�r.r�r�r�r�rer	r8r�r_r�r�r�r�r�r
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
dSr�)r&r�r.r�r�r�r�r	r
r�rer�r_r�r�r�r�)r-rRror9r�r�r
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)
NrMrr�r�r�r�r}cSr�r
r
r�r
r
rrVErz8TestVariousIteratorArgs.test_starmap.<locals>.<listcomp>)r&r�r.r�r�r�r�rrer	r�r<r�r�r_r�r�r�r�)r-rRro�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�NrMrrAr�r�r�r})r&r�r.r�r�r�r�rr�rer	rr�r_r�r�r�r��r-rRro�tgtr�r
r
rrJs&�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|���qdSr�)r&r�r.r�r�r�r�r!r�rer	rr�r_r�r�r�r�r�r
r
rrVs&�z&TestVariousIteratorArgs.test_dropwhilecCs�ddtd�dtddd�fD]L}ttttttfD]"}t||��\}}|�t	|�t	||���|�t	|�t	||���q|�
ttt|��|�
ttt
|��|�
tt	tt|��d�q
dS)	Nr�r�rAr�r�r�r}r)r&r�r.r�r�r�r�rrer	r�r_r�r�r�r�)r-rRro�it1�it2r
r
rr(bs�z TestVariousIteratorArgs.test_teeN)r2r3r4r�r�r5r�rXr�r�r�r�r�r�rr�r�rrr(r
r
r
rr��s$						
r�c@r�)�LengthTransparencycCsL|�t�tdd��d�|�t�tdd��d�|�t�td�d�d�dS)Nr�rr��rer<�length_hintr�r,r
r
rr�nszLengthTransparency.test_repeatcCsh|�t�tdd��d�|�t�tdd��d�|�t�tddd��d�|�t�tddd��d�dS)Nrrr�r�r�r,r
r
rr�ssz2LengthTransparency.test_repeat_with_negative_timesN)r2r3r4r�r�r
r
r
rr�lsr�c@s:eZdZdd�Zdd�Zejdd��Zdd�Zd	d
�Z	dS)�RegressionTestscs<dd�}�fdd�}g�|d|d�tt�}|��|�dS)NcsTdgf��fdd�	}t|�}t|�|dd�<t||�}t|gt|���t��dS)Nrcs|r
|dd�=�t���|Srr\)rOr-�r��zr
rro�s
z@RegressionTests.test_sf_793826.<locals>.mutatingtuple.<locals>.g)r	r�r
r�rg)�tuple1r��tuple2ro�items�genr
r�r�
mutatingtuple~s
z5RegressionTests.test_sf_793826.<locals>.mutatingtuplecs|att��dd�<dSr)�Tr	r��r-r
rr��sz)RegressionTests.test_sf_793826.<locals>.fr�)rXr}rt)r	r�re)r-r�r��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�r�)r��AssertionErrorr
��histr
r�gen1�s
�

z,RegressionTests.test_sf_950057.<locals>.gen1c3s ���d�dV��d�dS)NrsrrX)r�rr�r
r�gen2�s�
z,RegressionTests.test_sf_950057.<locals>.gen2FrrT)r�r�r	r�rerW)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
)rU�unusedr
r
rr��r�zERegressionTests.test_long_chain_of_empty_iterables.<locals>.<genexpr>i���)r�r�r&r�r0rgr�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)Nr}rtrrBr�r
rr��sz,RegressionTests.test_issue30347_1.<locals>.frM)rr&r	)r-r�rr
r�r�test_issue30347_1�s
�z!RegressionTests.test_issue30347_1csJG��fdd�d�}d�tttd�|��d�td�D]}t�d�qdS)Ncr1)z,RegressionTests.test_issue30347_2.<locals>.KcSr�rr
r�r
r
rr��r$z5RegressionTests.test_issue30347_2.<locals>.K.__init__cs�d7��dkr
t�d�dS)NrTr\)r-�other�rorr
rr��s
z3RegressionTests.test_issue30347_2.<locals>.K.__eq__N)r2r3r4r�r�r
r�r
r�K�r5r�rrMrr)rgrr&)r-r�r�r
r�r�test_issue30347_2�s	�z!RegressionTests.test_issue30347_2N)
r2r3r4r�r�r�skip_if_pgo_taskr�r�r�r
r
r
rr�ys
r�c@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)r2r3r4r�r
r�r
r�Subclass�sr�r)r�zkeyword argumentsr)r�r
r r�r�r�r�r8rrrWr2r_�assertNotInr)r-r��errr
r�r�test_keywords_in_subclass�s����z0SubclassWithKwargsTest.test_keywords_in_subclassN)r2r3r4r�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)N�3Pir{�12r)
rzrzrzrzrzrzrzrzrzrzrM)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�N�3Pnir�rsrMrX)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-rr�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)N�4Pnir�rXrsr�r}rM)rr�r�r�r�r&r�r
r
r�test_permutations_sizeof�s
�
�
��z#SizeofTest.test_permutations_sizeofN)
r2r3r4r�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�gettotalrefcountrr})rWr�ryr�r�r�rKrsr�r�run_unittest�hasattrrIr?r&r�r@r�r��run_doctest�modulesr2)�verbose�test_classesr?�countsrr
r
r�	test_main�
s �


r�__main__T)r�r)@�unittest�testr�	itertoolsr�decimalr�	fractionsrr<r�r�rO�	functoolsrrIr�r6r?�MAX_Py_ssize_trF�minsizerrrrrr!r#r)r+r:r@rCrHrKrNr&r�r��TestCaserWrKrsryr�r�r.r�r�r�r�r�r�r�r�r�r�rJr�r��__test__rr2r
r
r
r�<module>s�
�2n*i
	
	'
\&


�

Youez - 2016 - github.com/yon3zu
LinuXploit