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-1.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�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)Z	Factorialr)r@r&�r(r
r
r�factAsrBcC�|dS�Nrr
��rr
r
r�testRF�rGcCrC�Nrr
rEr
r
r�testR2IrHrJcC�|dkS)N�
r
rr
r
r�undertenLrHrMcCsg|]}|fdd��qS)cSst�t�||��Sr)�pickle�loads�dumps)�s�protor
r
r�<lambda>Osz<listcomp>.<lambda>r
)�.0rRr
r
r�
<listcomp>Os�rUc@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)NrLzinfinite recursion encounteredcsg|]	}�|�d��qS)rr
�rT�e)�expandrr
rrU`sz;TestBasicOps.pickletest.<locals>.expand.<locals>.<listcomp>)�RuntimeError�
isinstance�strr	r8�	TypeError)�itr�l�rZ�stoprrrZVs
�z'TestBasicOps.pickletest.<locals>.expandrN�r)rNrPrO�assertEqual�typer&�nextr0)r-�protocolr_rbr:�compare�dumpZi2�a�b�cZi3ZtookrZi4r
rar�
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)NrL)
rr��rL����$�-r>�abc)rj�abru��rorr)
r��	rxrwrrnrWrro)
rrrrrrrrrr)
rryrzrzrzrzrzrzrzrz)
r��i�i�rrrrr)�initial)rLrxr)rLrpr{�d)r~�n�s�t�)rdr	�
accumulater&�int�complexrr�map�assertRaisesr^�min�maxr<r=�chrrN�HIGHEST_PROTOCOLrm)r-�typrQrRr
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>.chain2ru�def�abcdef�rW�abcdrrn)�chainrdr	r:r�r^)r-r�rlr
r
r�
test_chain�s�zTestBasicOps.test_chaincCs�|�tt�ddg��td��|�tt�dg��td��|�tt�dg��g�|�tdt�ddg��td��|�ttt�ddg��dS)	Nrur�r�r�rWr�rrn)rdr	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)
Nrur�r�rjZbcdefr�rWr�rrnr�rh)�copy�deepcopy�
picklecopiersr�rdr	rfr:r�r^r&rNr�rm)r-Zoperr_rRr
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
rrur�)rjrkrl�drY�f�ghi)r�rjrkrlr�rYr�)r�r^r��__setstate__�iterrdr	�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)Nrurr���cSr"rr
�rjr
r
rrS��z0TestBasicOps.test_combinations.<locals>.<lambda>� �ABCD���A�B�r��C�r��D�r�r��r�r��r�r�)r�r�r�r�r�rWrn�r�rrrn�rrrn�rrrn)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
�rTr��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>.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?rFr(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>.combinations3rwcS�g|]}d|d�qS�rx�r
�rTrr
r
rrU�z2TestBasicOps.test_combinations.<locals>.<listcomp>rc3��|]}|�vVqdSrr
rX��valuesr
rr�r�z1TestBasicOps.test_combinations.<locals>.<genexpr>c�g|]}|�vr|�qSr
r
rX�rlr
rrUr�)r�r^�combinationsrr�rdr	rfr&r�rBr�r��
assertTrue�allrNr�rm)
r-�op�testIntermediater�r�r�r(rF�resultrRr
�rlr�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�abcdernr)rdr�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)Nrurrr�cSr"rr
r�r
r
rrS2r�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?rFr(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)rB)r(rFr
r
r�numcombsUs$zATestBasicOps.test_combinations_with_replacement.<locals>.numcombsrwcSr�r�r
r�r
r
rrU[r�zCTestBasicOps.test_combinations_with_replacement.<locals>.<listcomp>rcS�g|]\}}|�qSr
r
)rT�k�vr
r
rrUk�c3r�rr
rXr�r
rr�nr�zBTestBasicOps.test_combinations_with_replacement.<locals>.<genexpr>cr�r
r
rXr�r
rrUpr�)r�r�r^rr�rdr	rfr&r�r�r�r�r��groupbyr�rNr�rm)
r-�cwrr�r�r�r�r�r(rFr�Z
regular_combsZnorunsrRr
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�rdr�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)Nrurrr�r�rQrn)�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?rFr(r�Zcyclesrr�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>.permutations2rwcSr�r�r
r�r
r
rrU�r�z2TestBasicOps.test_permutations.<locals>.<listcomp>rc3r�rr
rXr�r
rr��r�z1TestBasicOps.test_permutations.<locals>.<genexpr>r)r�r^r�rrdr	r&r�rBr�r�r�r�rNr�rm)r-rr	r(rFr��prRr
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�)rdr�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)Nro�ABCDEFGryr�rrcS� g|]}t|�t|�kr|�qSr
�r�r	�rT�tr
r
rrU�� z3TestBasicOps.test_combinatorics.<locals>.<listcomp>c� g|]}tt|���kr|�qSr
�r�r�rrEr
rrU�rcSrr
rrr
r
rrU�rcrr
rrrEr
rrU�r)
r&r	r�r�r�r�rdr�rBr�r��filter�__contains__)r-r(rQr@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�'ror�rrnrxcSs
t�|�Sr)r�r�r
r
rrS��
z,TestBasicOps.test_compress.<locals>.<lambda>cSs
t�|�Sr)r�r�r�r
r
rrS�r#ZCEFZBCDEFr�)rdr	�compressr�r�r�r&r�r^r�rf)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)(Nru��rjr�rkr�rlrrn)�rjrn�rkrW)rlrxrr*r+r)rjr)rkr���)rjr,)rkr�rWrjrLrx�
@)r-g@g@�
@�)r.y@��@��1.1z2.1z3.1ryr��zcount(3)zcount(4)���z	count(-9)i����g�$@zcount(10.25)g$@zcount(10.0)���r�	count(%r))rdr�countr:r
r�r^�maxsizer	r&rr�reprrfre�float�sys�__mod__r�r�rNr�rm�exc_info)r-�BIGINTrlr�r1�r2�valuerRr
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)2Nrurrn)�rjr)rkrx)rlry)�start�stepr)rC)r')rkr)rlr�rjrkr)rA)rkrr)r)rA)rkrn)rlrWr�rpr~rLrxg�?)rr-g@r.)rr/y!@ �r0z.1z1.2z1.3rw�rqr1g@)rLg)@g.@zcount(3, 5)zcount(8, 5)r2z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)r3r4z
count(%r, %r))rdrr5r�r^r:r6r&r	rrr7rfrer�r8r9rNr�rm)r-r<rlrr�r=r>rRr
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)NrLruZ
abcabcabcar�rx)
rrrrrrrrrr)rdr:�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)NrurjrLZ
bcabcabcabrZ
cabcabcabcr�c�g|]}t���qSr
�rfr�r�r
rrU�r�z7TestBasicOps.test_cycle_copy_pickle.<locals>.<listcomp>rr�ZcdeabcdeabcdeabcdeabcrHr
rIr�r�r
rrU�r�rw)rFrdrfr:r�r�r	r&rNr�rOrPrmr�)r-rRr_�_r
r�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.rL)
rrnrrrnrrrnrr)rNrOrdr:)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�defgrurr�Zdefgabcdefgabcdefgab�abcdefgrrr�r
)rFr�r	rdr:r�r^r�)r-rlr
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��keyrucSr"rr
rr
r
rrS�r�z+TestBasicOps.test_groupby.<locals>.<lambda>rL))rrLr�)r�rq)rr�rq)r�
rq)r��)rrprU)rnr{�)rnrDrVcSrCrDr
rEr
r
rrS��rrrcSr�r
r
�rTr��gr
r
rrUr�z-TestBasicOps.test_groupby.<locals>.<listcomp>cSsg|]}|d�qSrcr
)rTrFr
r
rrUr�Z	AABBBAAAArz)r�rxZabracadabracSr�r
r
rXr
r
rrU2r�)rjrkrlr�rFcSs$g|]\}}tt|dd��r|�qSrr7rXr
r
rrU5�$)rjrkrFcS� g|]\}}tt|��|f�qSr
�r�r	rXr
r
rrU8r)�rxrj�rrk)rrl)rr��rrFcSr[r
r\rXr
r
rrU;rT)�reversern)r]r_r^c@seZdZdS)z0TestBasicOps.test_groupby.<locals>.ExpectedErrorN)r2r3r4r
r
r
r�
ExpectedError?srac3s�t|�D]}dVq��)NZyor%r'�rar
r�
delayed_raiseAs�z0TestBasicOps.test_groupby.<locals>.delayed_raisecs�fdd�t||�D�S)Ncsg|]\}}�|��qSr
r
rX��funcr
rrUFr�z;TestBasicOps.test_groupby.<locals>.gulp.<locals>.<listcomp>)r�)r?Zkeyprer
rdr�gulpEsz'TestBasicOps.test_groupby.<locals>.gulpc�eZdZ�fdd�ZdS)z+TestBasicOps.test_groupby.<locals>.DummyCmpc���rr
)r-�dstrbr
r�__eq__Or$z2TestBasicOps.test_groupby.<locals>.DummyCmp.__eq__N)r2r3r4rjr
rbr
r�DummyCmpN�rkrdcs �jdkr�jd8_|S��r�)�skip)�obj�ra�keyfuncr
rrpYs
z*TestBasicOps.test_groupby.<locals>.keyfuncrc)rdr	r�r�r�r^�appendr&rNr�rOrPrGrJr�r�r
rfr��	Exceptionrm)r-rQ�dupr�rY�elemrRZikZig�keysZexpectedkeysr_rJZg1Zg2Zg3rFrcrfrkr
ror�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)
Nro)rrrW�rrrrrrrrW)rrrWrocSr"rr
rr
r
rrSlr�z*TestBasicOps.test_filter.<locals>.<lambda>cSr"rr
rr
r
rrSmr�rwrn)rdr	rrr&�boolr:r5r�r^rfr�r�rNr�rOrPrm�r-�ansrlrRr
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)
Nror"rw�rrrrW)rrnrxrwcSr"rr
rr
r
rrS�r�z/TestBasicOps.test_filterfalse.<locals>.<lambda>cSr"rr
rr
r
rrS�r�rwrnr)rdr	�filterfalserr&rxr:r5r�r^rfrNr�rm�r-rRr
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
�rTr�yr
r
rrU�r�z)TestBasicOps.test_zip.<locals>.<listcomp>rur&ror�rncS�g|]}tt|���qSr
�r�r	�rTZpairr
r
rrU�r�r�cS�g|]}|�qSr
r
r�r
r
rrU��)	r
r5rdr	r&rr:r�r^)r-rzr
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)Nrur�cSr�r
r
r�r
r
rrU�r�z5TestBasicOps.test_zip_tuple_reuse.<locals>.<listcomp>r&cSr�r
r
r�r
r
rrU�r�rcSr�r
r
r�r
r
rrU�r�cSr�r
r
r�r
r
rrU�r�r(r))r	r�r�r
rdr�r�r��dict�fromkeysr�r5r�r&rNr�rOrPrfrm)r-�idsrzrRr�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)Nruror1��i4i�i�ri�i�cs"g|]
�t�fdd��D���qS)cs$g|]}�t|�kr|�nd�qSr�r�)rT�argrr
rrU�rZz;TestBasicOps.test_ziplongest.<locals>.<listcomp>.<listcomp>�r�)rTrrrrU�s�z0TestBasicOps.test_ziplongest.<locals>.<listcomp>cSsg|]}tdd�|D���qS)css �|]}|dur
dp|VqdS)N�Xr
rXr
r
rr��s�z:TestBasicOps.test_ziplongest.<locals>.<listcomp>.<genexpr>r�rr
r
rrU�sr���	fillvaluernr�rM)zzip_longest('abc', fv=1)z3zip_longest('abc', fillvalue=1, bogus_keyword=None)zDid not raise Type in:  cSr�r
r�r�r
r
rrU�r�r�cSr�r
r
r�r
r
rrU�r�)rurM)r&r�r�r�rdr	�zip_longestr�r:r5r
r�r^�eval�globals�localsZfail)r-�targetZstmtr
rr�test_ziplongest�sF

"(�
�"(����zTestBasicOps.test_ziplongestcCs^ttttdd���}|�t|�t|��tttttdd����}|�tt�	|��t|��dS)Nrur�)
r	r�r�r�rdr�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)Nrrur�Zdefghr�r�)r&rNr�rmr�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)Ncrg)z?TestBasicOps.test_zip_longest_bad_iterable.<locals>.BadIterablecrhrr
r,��	exceptionr
rr.�r$zHTestBasicOps.test_zip_longest_bad_iterable.<locals>.BadIterable.__iter__N)r2r3r4r.r
r�r
r�BadIterable�rlr�)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�rrY)r-r�rrYr
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�rYr,r
r
rr1s
z5TestBasicOps.test_bug_7244.<locals>.Repeater.__next__N)r2r3r4r�r.r1r
r
r
r�Repeater�sr�rrnrrWc	Ssdg}t||dd�D]&\}}t�d��t||f�Wd�n1s#wY|�||f�q	|S)Nrr��stdout)r�rZcaptured_output�printrq)r=r>r�rr�r
r
r�runs�z'TestBasicOps.test_bug_7244.<locals>.run)rrrrrr�r)r0rdr[r�rfr�)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�rjrv�rjrkr�)r�)rkrl)rlr�)r�rYr!rrurLr>)rdr	�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
rvr��rkrrn�)rrrrr)rrrrrWr�rwroi��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�)rTr�r
r
rr�N��z>TestBasicOps.test_product.<locals>.product1.<locals>.<genexpr>cs��|]	\}}||VqdSrr
�rTr�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
rrUcrz?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�rur)rjrkrlrNrRrSr~csg|]}t����qSr
)�random�choice)rTr���argtypesr
rrUjsz-TestBasicOps.test_product.<locals>.<listcomp>rx)r&rdr	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)Nrvr�r�i)r�r�r�r�r,r
r
r�test_product_overflowrs"�z"TestBasicOps.test_product_overflowc
Cr�)Nrur�r)rdr�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
rvr�r�rrnr�rr)	r&rdr	r�r�r�rNr�rm)r-rr�rRr
r
r�test_product_pickling|s���z"TestBasicOps.test_product_picklingcCsLtdd�}|�d�|�t|�d�tddd�}|�d�|�tt|�dS)Nr)rn)r�)rrnr
)rrr�)r�r�rdrfr�r0)r-r
r
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)Nrjrn)�object�times)rjrjrj))rrj)rrj)rrjrr,rWy�?zrepeat((1+0j))rxzrepeat((1+0j), 5)zrepeat((1+0j), 0)rLrZaar)rdr	r�rr&r:r�r^r7rfr�r�rNr�rm)r-rFrlrRr
r
r�test_repeat�s0�
�zTestBasicOps.test_repeatcCs`|�ttdd��d�|�ttdd��d�|�ttddd��d�|�ttddd��d�dS)Nrjrzrepeat('a', 0)r��r�)rdr7r�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)
Nrnrrw�rrryrurxr&rr'r(rLrW)rdr	r�r<�powr&r#r5r:r�r^�negrfrrrr�r�rNr�rmryr
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)Nrnrrwr�rWrxi�rWrx�extrarL)rdr	�starmapr<r�r
r&r:r5r�r�r^rfrrrr�r�rNr�rmryr
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)�rLr�rn�rLrnr��rLr�)rLrL�rLrn�r�r~)))rLrrn)rLr~rn))rLr)rLr~))r)r~rLrrrnrW���rrrj�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)r2r3r4r�r�r
r
r
r�IntLikeAsr�rx)rdr	r8r&r�r�r^rr�r5r6rfr�r�rNr�rm�weakref�refZassertIsNotNoner�
gc_collectZassertIsNoner�)	r-rZtgtargsr_ZrarlrR�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�rrnrxr�rrWroryr"r�r�rL)rrrrrr�rrrr)rdr	�	takewhilerMr�r^r<r�rfrrrxr0r�r�r&rNr�rm)r-rrrRr
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�rrWroryr�r�rLr)rdr	�	dropwhilerMr�r^r<r�rfrrr�r�r&rNr�rm)r-rrRr
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~rxrrrnrrrur�r��invalidrcS�g|]}t|��qSr
�r	r�r
r
rrU�r�z)TestBasicOps.test_tee.<locals>.<listcomp>rL�	__class__r!�<r�)�teerdr	r)rr&rfr��shufflerqr�r^rerr�r�r�r��proxy�getattrrr��ReferenceErrorr�r:r�rNr�rmr�)r-r(rjrkrr��orderZlistsZitsr?rlr�r��t1�t2ZtnewZt3r
rzZlong_ansrRr
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)�firstrf)r-r�r�r
rr1s
�z1TestBasicOps.test_tee_reenter.<locals>.I.__next__N)r2r3r4r�r.r1r
r�r
r�Isr�r�)r��assertRaisesRegexr[rf)r-r�rjr
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,�ZfinishrBr
rr1%sz4TestBasicOps.test_tee_concurrent.<locals>.I.__next__N)r2r3r4r.r1r
rr
rr�"�r�)r�rr�)�	threading�Eventr��ThreadrfrBr�r�r[r��join)r-r�rjrk�threadr
rr�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
rrSHr�z1TestBasicOps.test_StopIteration.<locals>.<lambda>cSr"rr
rr
r
rrSIr�)r�r0rfr
r�rFr�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�rf�gc�collectr��
is_trackedr�r
r
r�test_combinations_result_gcKsz(TestBasicOps.test_combinations_result_gccCr
r;)r�rfrrr�r
r�r
r
r�,test_combinations_with_replacement_result_gcX�z9TestBasicOps.test_combinations_with_replacement_result_gccCr
r;)r�rfrrr�r
r�r
r
r�test_permutations_result_gc`rz(TestBasicOps.test_permutations_result_gccCs4tdgg�}t|�t��|�t�t|���dSr)r�rfrrr�r
r�r
r
r�test_product_result_gchsz#TestBasicOps.test_product_result_gccCs*tgg�}t��|�t�t|���dSr)r�rrr�r
rfr�r
r
r�test_zip_longest_result_gcps
z'TestBasicOps.test_zip_longest_result_gc)rWrN)?r2r3r4rmr�r�r�r�r�r�rZbigaddrspacetestr�Zimpl_detailr�r�rrrrr
rr%r@rErGrKrLrOrvr{rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr	�cpython_onlyrrrrrr
r
r
rrVRs�
)#

P

L

?

!"07$$

*
(:


^	



rVc@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�rrrnrWrx�rrnrorLrp)rdr	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&rNr�r�rdr	rOrPrfr�r�)r-rZaccumulatedrRr_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_rdrfr&rNr�rOrPr	r�r�)r-r_rRZit_copyr
r
r�test_accumulate_reducible_none�sz+TestExamples.test_accumulate_reducible_nonecCs|�d�tdd��d�dS�Nr�r�ZDEFr)rdrr�r,r
r
rr��szTestExamples.test_chaincCs |�d�t�ddg��d�dSr)rdrr�r�r,r
r
rr��rz%TestExamples.test_chain_from_iterablecCs<|�ttdd��gd��|�tttd�d��gd��dS)Nr�rr�rWrnr�)rdr	r�r&r,r
r
rr��s��zTestExamples.test_combinationscC�|�ttdd��gd��dS)Nr�rr�)rdr	r�r,r
r
rr��s�z/TestExamples.test_combinations_with_replacementcCs"|�ttdgd���td��dS)Nrrr)rdr	r$r,r
r
rr%��"zTestExamples.test_compresscCs"|�tttd�d��gd��dS)NrLrx)rLrRr�rSrT)rdr	r8r5r,r
r
rr@�rzTestExamples.test_countcCs"|�tttd�d��td��dS)Nr�r�ZABCDABCDABCD)rdr	r8rFr,r
r
rrG�rzTestExamples.test_cyclecCs&|�ttdd�gd���gd��dS)NcSrK�Nrxr
rr
r
rrS�rWz-TestExamples.test_dropwhile.<locals>.<lambda>�rrWrorWr)rorWr)rdr	r�r,r
r
rr���&zTestExamples.test_dropwhilecCsT|�dd�td�D�td��|�dd�td�D�td�td�td	�td
�g�dS)NcSr�r
r
rXr
r
rrU�r�z-TestExamples.test_groupby.<locals>.<listcomp>ZAAAABBBCCDAABBBZABCDABcSsg|]\}}t|��qSr
r�rXr
r
rrU�r�Z
AAAABBBCCDZAAAAZBBBZCCr�)rdr�r	r,r
r
rrv�s��zTestExamples.test_groupbycC�&|�ttdd�td���gd��dS)NcS�|dSrIr
rr
r
rrS�rWz*TestExamples.test_filter.<locals>.<lambda>rL)rrnrxrwrz)rdr	rr&r,r
r
rr{�r"zTestExamples.test_filtercCr#)NcSr$rIr
rr
r
rrS�rWz/TestExamples.test_filterfalse.<locals>.<lambda>rL)rrrWrory)rdr	r}r&r,r
r
rr�r"zTestExamples.test_filterfalsecCs |�tttdd��gd��dS)N)rrnrL)rxrrn�r�rzr1)rdr	r�r�r,r
r
rr��rzTestExamples.test_mapcCst|�ttdd��td��|�ttddd��td��|�ttddd��td��|�ttdddd��td��dS)	Nrr�ABrW�CD�CDEFGr�ACEG)rdr	r8r,r
r
rr��s"zTestExamples.test_islicecCs|�ttdd��ddg�dS)Nr��xy�r�r�r�r�)rdr	r
r,r
r
rr���zTestExamples.test_zipcCs"|�ttdddd��gd��dS)Nr�r*�-r�)r+r,)r�r.)r�r.)rdr	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 DCrn)r)rrr)rrr)rrr)rrr)rrr)rdr	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 Dyrrnr�)r|)rrr)rrr)rrr)rrrr )rrrr�)rdr	r�r�r�r1r&r,r
r
rr��s��zTestExamples.test_productcCr)NrLrn)rLrLrL)rdr	r�r,r
r
rr��r-zTestExamples.test_repeatcCs"|�tttgd���gd��dS)N))rrx)rnrr�r%)rdr	r�r�r,r
r
r�test_stapmap�r0zTestExamples.test_stapmapcCs&|�ttdd�gd���ddg�dS)NcSrKr r
rr
r
rrS�rWz-TestExamples.test_takewhile.<locals>.<lambda>r!rrW)rdr	r�r,r
r
rr��r"zTestExamples.test_takewhileN)r2r3r4r�rrr�r�r�r�r%r@rGr�rvr{rr�r�r�r/rr�r�r2r�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�)�slicerBrbr9r6rCr�r&rfr0r
�	enumerate)
r?rrQrBrbrCr_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)
Nrrr&rWr'r(rr)rLrnrr�)rdr	r8r�r&r5rf)r-r_rlr
r
r�test_islice_recipe�s  z1TestPurePythonRoughEquivalents.test_islice_recipeN)r2r3r4�staticmethodr8r6r
r
r
rr3�s
r3c@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)rqrf)r-�iterator�	containerr
r
r�	makecycles
zTestGC.makecyclecCs g}|�tdd|dg�|�dS�Nrrrn)r;r��r-rjr
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_combinationscCrAr<)r;r�r=r
r
rr�'rBz)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)rer�r�r;r5)r-rjrDr
r
rr@/szTestGC.test_countcC�g}|�t|gd�|�dSrI)r;rFr=r
r
rrG4rCzTestGC.test_cyclecCs g}|�ttd||g�|�dSrD)r;r�rxr=r
r
rr�8r>zTestGC.test_dropwhilecCs$g}|�t|gddd��|�dS)NrcSr"rr
rr
r
rrS>r�z%TestGC.test_groupby.<locals>.<lambda>)r;r�r=r
r
rrv<� zTestGC.test_groupbycCs>d}dd�}tt|�|d�D]\}}|j�dg��|�qdS)NrLcSr"rr
rr
r
rrSCr�z'TestGC.test_issue2246.<locals>.<lambda>rPr)r�r&�__dict__�
setdefaultrq)r-r(rprr�r
r
r�test_issue2246@s
�zTestGC.test_issue2246cC�$g}|�tdd�|gd�|�dS)NcS�dS)NTr
rr
r
rrSIr�z$TestGC.test_filter.<locals>.<lambda>r)r;rr=r
r
rr{GrFzTestGC.test_filtercCsg}|�tdd�|�|�dS)NcSrKr�r
rr
r
rrSMr�z)TestGC.test_filterfalse.<locals>.<lambda>)r;r}r=r
r
rrKrCzTestGC.test_filterfalsecCs&g}|�t|gd|gd�|�dS)Nrrn)r;r
r=r
r
rr�Os"zTestGC.test_zipcCsPg}|�t|gd|gd�|�|dg}|�t|gd|gd|d�|�dS)Nrrnr�)r;r�)r-rjrkr
r
rr/Ss&zTestGC.test_zip_longestcCrJ)NcSr"rr
rr
r
rrS[r�z!TestGC.test_map.<locals>.<lambda>r)r;r�r=r
r
rr�YrFzTestGC.test_mapcCs g}|�t|gdd�|�dSrI)r;r8r=r
r
rr�]r>zTestGC.test_islicecCrEr )r;r�r=r
r
rr�arCzTestGC.test_pairwisecCrAr<)r;r�r=r
r
rrerBzTestGC.test_permutationscCs$g}|�tdd|dgdd�|�dS)Nrrrnr�)r;r�r=r
r
rr�irFzTestGC.test_productcCr?r)r;r�r=r
r
rr�mr@zTestGC.test_repeatcCs(g}|�tdd�||fgd�|�dS)NcWr"rr
�rr
r
rrSsr�z%TestGC.test_starmap.<locals>.<lambda>r)r;r�r=r
r
rr�qs$zTestGC.test_starmapcCs"g}|�ttdd||g�|�dS)Nrr)r;r�rxr=r
r
rr�urBzTestGC.test_takewhileN)r2r3r4r;r�r�r�r�r�r%r@rGr�rvrIr{rr�r/r�r�r�rr�r�r�r�r
r
r
rr8s2r8ccs�|D]}|VqdS)zRegular generatorNr
��seqnrr
r
r�RyrrOc@r*)�GzSequence using __getitem__cCr�r�rN�r-rNr
r
rr��r�z
G.__init__cCs
|j|SrrQ)r-rr
r
r�__getitem__�r�z
G.__getitem__N)r2r3r4r5r�rSr
r
r
rrP~r6rPc@�(eZdZdZdd�Zdd�Zdd�ZdS)	r�z Sequence using iterator protocolcC�||_d|_dSrDrMrRr
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�rNr0�r-r�r
r
rr1��z
I.__next__N�r2r3r4r5r�r.r1r
r
r
rr���
r�c@r*)�Igz9Sequence using iterator protocol defined with a generatorcCrUrDrMrRr
r
rr��rVzIg.__init__ccs�|jD]}|VqdSrrQr�r
r
rr.�s�
�zIg.__iter__N�r2r3r4r5r�r.r
r
r
rr]��r]c@r*)r�z Missing __getitem__ and __iter__cCrUrDrMrRr
r
rr��rVz
X.__init__cCrWr;rXrYr
r
rr1�rZz
X.__next__N)r2r3r4r5r�r1r
r
r
rr��r_r�c@r*)�NzIterator missing __next__()cCrUrDrMrRr
r
rr��rVz
N.__init__cCr"rr
r,r
r
rr.�r$z
N.__iter__Nr^r
r
r
rr`�r_r`c@rT)	�EzTest propagation of exceptionscCrUrDrMrRr
r
rr��rVz
E.__init__cCr"rr
r,r
r
rr.�r$z
E.__iter__cCsdddS)Nrnrr
r,r
r
rr1�rz
E.__next__Nr[r
r
r
rra�r\rac@rT)	�SzTest immediate stopcC�dSrr
rRr
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
rrb�s
rbcCsttdd�ttt|�����S)z Test multiple tiers of iteratorscSr"rr
rr
r
rrS�r�zL.<locals>.<lambda>)r�r�rOr]rPrQr
r
r�L�srdc@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�rPr�r]rdrOrdr	r�rbr�r^r�r`�ZeroDivisionErrorra)r-rQrFr(rYr
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�r1�Zdog333333�?r��rx)r&rPr�r]rbrdrOrdr	r�r�r^r�r`rfra�r-rQrYr
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�	Nrhr�r1rir�rjrxr)r&r�rPr�r]rbrdrOrdr	r$r�r�r^r�r`rfra)r-rQr(rYr
r
rr%�s(�z%TestVariousIteratorArgs.test_compresscCsZddtd�dtddd�fD]}|�ttt|��|�ttt|��|�ttt|��q
dSrg)r&r�r^r�r�r`rfra)r-rQr
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)	Nrhr�r1rir�rjrxrn)r&rPr�r]rbrdrOr�r	r8rFrdr�r^r�r`rfra)r-rQrYZtgtlen�expected�actualr
r
rrG�s�z"TestVariousIteratorArgs.test_cyclecCs�td�td�td�dtddd�fD]=}ttttttfD]}|�dd	�t||��D�t	||���q|�
ttt|��|�
ttt
|��|�
tt	tt|���qdS)
NrLrr1�rwrRr�rjrxcSr�r
r
)rTr�Zsbr
r
rrU�r�z8TestVariousIteratorArgs.test_groupby.<locals>.<listcomp>)r&rPr�r]rbrdrOrdr�r	r�r^r�r`rfrarkr
r
rrv�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)
NrLrr1ror�rjrxcS�g|]}t|�r|�qSr
)rr�r
r
rrUr�z7TestVariousIteratorArgs.test_filter.<locals>.<listcomp>)r&rPr�r]rbrdrOrdr	rrr�r^r�r`rfrarkr
r
rr{��&��z#TestVariousIteratorArgs.test_filterc	Crp)
NrLrr1ror�rjrxcSrqr
)r!r�r
r
rrUr�z<TestVariousIteratorArgs.test_filterfalse.<locals>.<listcomp>)r&rPr�r]rbrdrOrdr	r}rr�r^r�r`rfrarkr
r
rrrrz(TestVariousIteratorArgs.test_filterfalsec	Cs�ddtd�dtddd�fD]P}ttttttfD](}|�tt	||���t
||���|�tt	||�||���t
||�||���q|�tt	t
|��|�tt	t|��|�ttt	t|���q
dSrg)r&rPr�r]rbrdrOrdr	r
rr�r^r�r`rfrarkr
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
dSrg)r&rPr�r]rbrdrOrdr	r�r
r�r^r�r`rfrarkr
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)NrLrr~ror�r�rxcSr�r
)rr�r
r
rrU&r�z4TestVariousIteratorArgs.test_map.<locals>.<listcomp>cS�g|]}||�qSr
r
r�r
r
rrU(r�)r&rPr�r]rbrdrOrdr	r�rr<r�r�r^r�r`rfrarkr
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�r1rir�rjrxrrrL)r&rPr�r]rbrdrOrdr	r8r�r^r�r`rfrarkr
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
dSrl)r&rPr�r]rbrdrOr	r
r�rdr�r^r�r`rfra)r-rQrYr9rmrnr
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)
NrLrr~ror�r�rxcSrsr
r
r�r
r
rrUEr�z8TestVariousIteratorArgs.test_starmap.<locals>.<listcomp>)r&rPr�r]rbrdrOrrdr	r�r<r�r�r^r�r`rfra)r-rQrY�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�NrLrr1ror�rjrx)r&rPr�r]rbrdrOrrqrdr	r�r�r^r�r`rfra�r-rQrYZtgtrtr
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|���qdSru)r&rPr�r]rbrdrOr!rqrdr	r�r�r^r�r`rfrarvr
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)	Nrhr�r1rir�rjrxr)r&rPr�r]rbrdrOr�rdr	r�r^r�r`rfra)r-rQrYZit1Zit2r
r
rr�bs�z TestVariousIteratorArgs.test_teeN)r2r3r4r�r�r%r�rGrvr{rr�r�r�r�r�r�r�r�r�r
r
r
rre�s$						
rec@r�)�LengthTransparencycCsL|�t�tdd��d�|�t�tdd��d�|�t�td�d�d�dS)Nr�rr��rdr<�length_hintr�r,r
r
rr�nszLengthTransparency.test_repeatcCsh|�t�tdd��d�|�t�tdd��d�|�t�tddd��d�|�t�tddd��d�dS)Nrrr�r�rxr,r
r
rr�ssz2LengthTransparency.test_repeat_with_negative_timesN)r2r3r4r�r�r
r
r
rrwlsrwc@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���|SrrI)r?r��r��zr
rrY�s
z@RegressionTests.test_sf_793826.<locals>.mutatingtuple.<locals>.g)r	r�r
r�rf)Ztuple1r�Ztuple2rY�items�genr
r{r�
mutatingtuple~s
z5RegressionTests.test_sf_793826.<locals>.mutatingtuplecs|att��dd�<dSr)�Tr	rL�r�r
rr��sz)RegressionTests.test_sf_793826.<locals>.fr�)rWrxro)r	r�rd)r-rr��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�)rq�AssertionErrorr
�Zhistr
r�gen1�s
�

z,RegressionTests.test_sf_950057.<locals>.gen1c3s ���d�dV��d�dS)NrnrrW)rqrr�r
r�gen2�s�
z,RegressionTests.test_sf_950057.<locals>.gen2FrrT)r�r�r	r�rdrF)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
)rTZunusedr
r
rr��r�zERegressionTests.test_long_chain_of_empty_iterables.<locals>.<genexpr>i���)r�r�r&r�r0rfr�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)Nrxror�rAr�r
rr��sz,RegressionTests.test_issue30347_1.<locals>.frL)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>.KcSrcrr
rYr
r
rr��r$z5RegressionTests.test_issue30347_2.<locals>.K.__init__cs�d7��dkr
t�d�dS)NrTrI)r-�other�rYrr
rrj�s
z3RegressionTests.test_issue30347_2.<locals>.K.__eq__N)r2r3r4r�rjr
r�r
r�K�rr�rrLrr)rfr�r&)r-r�r�r
r�r�test_issue30347_2�s	�z!RegressionTests.test_issue30347_2N)
r2r3r4r�r�rZskip_if_pgo_taskr�r�r�r
r
r
rrzys
rzc@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
rr}r�r�r�r8r�r�rFr$r^ZassertNotInr)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)NZ3PirvZ12r)
rururururururururururL)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�rnrLrW)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�rWrnr�rxrL)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�gettotalrefcountrrx)rVrer8rzrwr�rr3r�rZrun_unittest�hasattrr9rr&r�rr�r�Zrun_doctest�modulesr2)�verboseZtest_classesr�countsrr
r
r�	test_main�
s �


r��__main__T)r�r)@Zunittest�testr�	itertoolsr�ZdecimalrZ	fractionsrr<r�r�rN�	functoolsrr9r�rrZMAX_Py_ssize_tr6Zminsizerrrrrr!r#r)r+r:r@rBrGrJrMr&r�r�ZTestCaserVrr3r8rOrPr�r]r�r`rarbrdrerwrzr�rr�r�Z__test__r�r2r
r
r
r�<module>s�
�2n*i
	
	'
\&


�