https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/genshi/template/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/genshi/template/tests/__pycache__/eval.cpython-310.pyc
o

!�b��@s�ddlZddlZddlZddlZddlmZddlZddlmZddl	m
Z
ddlmZm
Z
mZmZmZddlmZmZmZGdd�dej�ZGd	d
�d
ej�Zdd�Zed
kr`ejdd�dSdS)�N)�mkstemp)�Markup)�Context)�
Expression�Suite�	Undefined�UndefinedError�	UNDEFINED)�BytesIO�
IS_PYTHON2�
wrapped_bytesc@sneZdZdd�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.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1d`da�Z2dbdc�Z3ddde�Z4e5j6dfkr�dgdh�Z7didj�Z8dkdl�Z9dmdn�Z:dodp�Z;dqdr�Z<dsdt�Z=dudv�Z>dwdx�Z?dydz�Z@d{d|�ZAd}d~�ZBdd��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�S)��ExpressionTestCasecCs,td�}|�|td��|�|td��dS�Nzx,yzy, x)r�assertEqual�assertNotEqual��self�expr�r�</usr/lib/python3/dist-packages/genshi/template/tests/eval.py�test_eqszExpressionTestCase.test_eqcCs<td�}|�t|�ttd���|�t|�ttd���dSr)rr�hashrrrrr�	test_hash#szExpressionTestCase.test_hashcCsVtd�}t�}t�||d�|�d�t�|�}|�i�dus!J�|j|jks)J�dS)N�1 < 2�rT)rr
�pickle�dump�seek�load�evaluate�code)rr�buf�	unpickledrrr�test_pickle(s

zExpressionTestCase.test_picklecCsh|�dtd��ddi��|�ttd��i��|�dtd��ddi��|�dtd��ddi��dS)N�bar�foo�id)rrrr&�rrrr�test_name_lookup1sz#ExpressionTestCase.test_name_lookupcCstd�}|�|�i�t�dS)Nr)rrrrrrrr�
test_builtins7�z ExpressionTestCase.test_builtinscCs�|�dtd��i��|�dtd��i��|�d�d�ttd���i��|�dtd��i��|�dtd��i��|�dtd��i��dS)	Nr%z"foo"z	"""foo"""�utf-8zb'foo'z	'''foo'''zu'foo'zr'foo')rrr�encoderr'rrr�test_str_literal;s�z#ExpressionTestCase.test_str_literalcCsvtd�}|�d|�i��td�}|�d|�i��ttd��}tr-|�d|�i��dS|�d�d�|�i��dS)Nuu'þ'�þzb'\xc3\xbe'r+)rrrrrr,rrrr�test_str_literal_non_asciiDsz-ExpressionTestCase.test_str_literal_non_asciicCs�|�dtd��i��tr|�dtd��i��|�dtd��i��tr0|�dtd��i��|�dtd	��i��|�dtd
��i��dS)N�*�42�42Lg�z�G��?z.42��07���0xF2�0XF2)rrrrr'rrr�test_num_literalSsz#ExpressionTestCase.test_num_literalcCs8|�itd��i��|�dditd��ddi��dS)Nz{}�keyTz{'key': value}�value�rrrr'rrr�test_dict_literal]s
�z$ExpressionTestCase.test_dict_literalcCsP|�gtd��i��|�gd�td��i��|�dgtd��ddi��dS)Nz[]��r�z	[1, 2, 3]Tz[value]r:r;r'rrr�test_list_literalbs
�z$ExpressionTestCase.test_list_literalcCsJ|�dtd��i��|�dtd��i��|�dtd��ddi��dS)	Nrz()r=z	(1, 2, 3))Tz(value,)r:Tr;r'rrr�test_tuple_literalhs
�z%ExpressionTestCase.test_tuple_literalcCs4|�dtd��i��|�dtd��ddi��dS)Nr>z+1z+x�xr;r'rrr�test_unaryop_posn�z#ExpressionTestCase.test_unaryop_poscC�4|�dtd��i��|�dtd��ddi��dS)N���z-1z-xrBr>r;r'rrr�test_unaryop_negrrDz#ExpressionTestCase.test_unaryop_negcCrE)NFznot Trueznot xrBTr;r'rrr�test_unaryop_notvrDz#ExpressionTestCase.test_unaryop_notcCrE)N���z~1z~xrBr>r;r'rrr�test_unaryop_invzrDz#ExpressionTestCase.test_unaryop_invcC�6|�dtd��i��|�dtd��ddd���dS)Nr?z2 + 1zx + yrr>�rB�yr;r'rrr�test_binop_add~� z!ExpressionTestCase.test_binop_addcCs6|�dtd��i��|�dtd��ddd���dS)Nr>�2 - 1�x - yrLr;r'rrr�test_binop_sub�rOz!ExpressionTestCase.test_binop_subcC�6|�dtd��i��|�dtd��ddd���dS)Nr>rPrQrrLr;r'rrrrR�rOcC�6|�dtd��i��|�dtd��ddd���dS)N�z2 * 2zx * yrrLr;r'rrr�test_binop_mul�rOz!ExpressionTestCase.test_binop_mulcCrT)NrUz2 ** 2zx ** yrrLr;r'rrr�test_binop_pow�rOz!ExpressionTestCase.test_binop_powcCrS)Nrz4 / 2zx / yrUrLr;r'rrr�test_binop_div�rOz!ExpressionTestCase.test_binop_divcCrK)Nr>z3 // 2zx // yr?rrLr;r'rrr�test_binop_floordiv�rOz&ExpressionTestCase.test_binop_floordivcCrK)Nr>z3 % 2zx % yr?rrLr;r'rrr�test_binop_mod�rOz!ExpressionTestCase.test_binop_modcCrS)Nrz1 & 0zx & yr>rLr;r'rrr�test_binop_and�rOz!ExpressionTestCase.test_binop_andcC�6|�dtd��i��|�dtd��ddd���dS)Nr>z1 | 0zx | yrrLr;r'rrr�
test_binop_or�rOz ExpressionTestCase.test_binop_orcCr\)Nr>z1 ^ 0zx ^ yrrLr;r'rrr�test_binop_xor�rOz!ExpressionTestCase.test_binop_xorcCrK)NTz1 in (1, 2, 3)zx in yr>r=rLr;r'rrr�test_binop_contains���z&ExpressionTestCase.test_binop_containscCrK)NTz4 not in (1, 2, 3)z
x not in yrUr=rLr;r'rrr�test_binop_not_contains�r`z*ExpressionTestCase.test_binop_not_containscCsh|�dtd��i��|�dtd��ddd���|�dtd��i��|�dtd��ddd���dS)	NTz1 is 1zx is yr>rLFz1 is 2rr;r'rrr�
test_binop_is�s z ExpressionTestCase.test_binop_iscCsh|�dtd��i��|�dtd��ddd���|�dtd��i��|�dtd��ddd���dS)	NTz
1 is not 2z
x is not yr>rrLFz
1 is not 1r;r'rrr�test_binop_is_not�s
��z$ExpressionTestCase.test_binop_is_notcCrS)NFzTrue and Falsezx and yTrLr;r'rrr�test_boolop_and�r`z"ExpressionTestCase.test_boolop_andcCr\)NTz
True or Falsezx or yFrLr;r'rrr�test_boolop_or�r`z!ExpressionTestCase.test_boolop_orcCrT)NTz1 == 1zx == yr>rLr;r'rrr�test_compare_eq�rOz"ExpressionTestCase.test_compare_eqcCsv|�dtd��i��|�dtd��ddd���tjdkr9|�dtd��i��|�dtd��ddd���dSdS)	NFz1 != 1zx != yr>rL�3z1 <> 1zx <> y)rrr�sys�versionr'rrr�test_compare_ne�s
 �z"ExpressionTestCase.test_compare_necCrK)NTrzx < yr>rrLr;r'rrr�test_compare_lt�rOz"ExpressionTestCase.test_compare_ltcCrT)NTz1 <= 1zx <= yr>rLr;r'rrr�test_compare_le�rOz"ExpressionTestCase.test_compare_lecCrK)NTz2 > 1zx > yrr>rLr;r'rrr�test_compare_gt�rOz"ExpressionTestCase.test_compare_gtcCrT)NTz1 >= 1zx >= yr>rLr;r'rrr�test_compare_ge�rOz"ExpressionTestCase.test_compare_gecCrK)NTz1 != 3 == 3zx != y == yr>r?rLr;r'rrr�test_compare_multi�r`z%ExpressionTestCase.test_compare_multicCsf|�dtd��ddd�i��ddi}|�dtd��|��ddtd�ii}|�dtd	��|��dS)
Nr0zfoo()r%cS�dS)Nr0rrrrr�<lambda>��z7ExpressionTestCase.test_call_function.<locals>.<lambda>r$�BARzfoo.upper()zlen(foo.bar))rrr�range�r�datarrr�test_call_function�s
z%ExpressionTestCase.test_call_functioncCs$|�dtd��dd�dd���dS)Nr0z
foo(x=bar)cS�|S�Nr�rBrrrrq�rrz7ExpressionTestCase.test_call_keywords.<locals>.<lambda>�r%r$r;r'rrr�test_call_keywords�s�z%ExpressionTestCase.test_call_keywordscCs&|�dtd��dd�dgd���dS)Nr0z	foo(*bar)cSrxryrrzrrrrq�rrz8ExpressionTestCase.test_call_star_args.<locals>.<lambda>r{r;r'rrr�test_call_star_args�s�z&ExpressionTestCase.test_call_star_argscCs0dd�}td�}|�d|�|ddid���dS)NcSrxryrrzrrrr%��z4ExpressionTestCase.test_call_dstar_args.<locals>.fooz
foo(**bar)r0rBr{�rrr)rr%rrrr�test_call_dstar_args�s z'ExpressionTestCase.test_call_dstar_argscCs2dtd�i}td�}|�ddgt|�|���dS)N�items�zfilter(lambda x: x > 2, items)r?rU)rtrr�listr�rrvrrrr�test_lambdaszExpressionTestCase.test_lambdacCs8tsdSdddgi}td�}|�dgt|�|���dS)Nr��r>r)rr>z#filter(lambda (x, y): x > y, items))rrrr�rr�rrr�test_lambda_tuple_args
z(ExpressionTestCase.test_lambda_tuple_argc	C��td�}|�ddg|�dtd�i��td�}|�gd�|�dtd�i��td�}|�gd	�|�td�d
d���td�}|�gd
�|�dtd
�td�gi��td�}|�gd�|�ddgddgd���dS)Nz[n for n in numbers if n < 2]rr>�numbersr�z+[(i, n + 1) for i, n in enumerate(numbers)]�)rr>r�)rr?)r?rU)rUr�z[offset + n for n in numbers]�rr?rUr��r�r��offsetz&[n for group in groups for n in group]�rr>rr>r�groupsr?z[(a, b) for a in x for b in y]�)�x0�y0)r��y1)�x1r�)r�r�r�r�r�r�rL�rrrrtrrrr�test_list_comprehension�$
�
�
�
�z*ExpressionTestCase.test_list_comprehensioncC�8ddd�ddd�g}td�}|�dg|�d|i��dS)N�ar>��namer:�brz&[i.name for i in items if i.value > 1]r�r�rr�rrrr�$test_list_comprehension_with_getattr"�z7ExpressionTestCase.test_list_comprehension_with_getattrcCr�)Nr�r>r�r�rz,[i['name'] for i in items if i['value'] > 1]r�rr�rrr�$test_list_comprehension_with_getitem'r�z7ExpressionTestCase.test_list_comprehension_with_getitemc	Cr�)Nz!list(n for n in numbers if n < 2)rr>r�r�z/list((i, n + 1) for i, n in enumerate(numbers))r�z!list(offset + n for n in numbers)r�rr�z*list(n for group in groups for n in group)r�r�r?z"list((a, b) for a in x for b in y)r�r�r�r�r�rLr�rrrr�test_generator_expression,r�z,ExpressionTestCase.test_generator_expressioncCr�)Nr�r>r�r�rz*list(i.name for i in items if i.value > 1)r�rr�rrr�&test_generator_expression_with_getattr@r�z9ExpressionTestCase.test_generator_expression_with_getattrcCr�)Nr�r>r�r�rz0list(i['name'] for i in items if i['value'] > 1)r�rr�rrr�&test_generator_expression_with_getitemEr�z9ExpressionTestCase.test_generator_expression_with_getitem)rr�cCs8td�}|�d|�ddi��|�d|�ddi��dS)Nz'T' if foo else 'F'�Tr%T�FFrrrrr�test_conditional_expressionKsz.ExpressionTestCase.test_conditional_expressionc	Cs.td�}|�ddg|�dttd��i��dS)Nznumbers[0:2]rr>r�r��rrrr�rtrrrr�
test_slicePs&zExpressionTestCase.test_slicecCs6td�}|�ttd��ddd��}|�ddg|�dS)Nznumbers[start:end]r�rr�r��start�endr>�rrr�rtr�rr�resrrr�test_slice_with_varsTsz'ExpressionTestCase.test_slice_with_varscC�2td�}|�dttd��i�}|�gd�|�dS)Nz
numbers[:]r�r��rr>rr?rUr�r�rrr�test_slice_copyY�z"ExpressionTestCase.test_slice_copycCs4td�}|�ttd��dd��}|�gd�|�dS)Nznumbers[::stride]r�r�r��stride�rrrUr�r�rrr�test_slice_stride^sz$ExpressionTestCase.test_slice_stridec	Cs,td�}|�dg|�dttd��i��dS)Nznumbers[-1:]rUr�r�r�rrrr�test_slice_negative_startcs$z,ExpressionTestCase.test_slice_negative_startcCr�)Nznumbers[:-1]r�r��rr>rr?r�r�rrr�test_slice_negative_endgr�z*ExpressionTestCase.test_slice_negative_endcCs.td�}|�dttd��i�}|�|d�dS)Nz
numbers[1]r�r�r>r�r�rrr�test_slice_constantlsz&ExpressionTestCase.test_slice_constantcCs8dd�}td�}|�ttd��|d��}|�|d�dS)NcSrp�Nrrrrrr�frr~z-ExpressionTestCase.test_slice_call.<locals>.fznumbers[f()]r��r�r�rr�)rr�rr�rrr�test_slice_callqsz"ExpressionTestCase.test_slice_callcCs0td�}|�ttd��dd��}|�|d�dS)Nz
numbers[v]r�r�r��vr�r�rrr�test_slice_namexsz"ExpressionTestCase.test_slice_namecCs@Gdd�d�}td�}|�ttd��|�d��}|�|d�dS)Nc@�eZdZdd�ZdS)z<ExpressionTestCase.test_slice_attribute.<locals>.ValueHoldercS�
d|_dS�Nr?�r:r'rrr�__init__�
zEExpressionTestCase.test_slice_attribute.<locals>.ValueHolder.__init__N��__name__�
__module__�__qualname__r�rrrr�ValueHolder~�r�znumbers[obj.value]r��r��objr?r�)rr�rr�rrr�test_slice_attribute}sz'ExpressionTestCase.test_slice_attributecCsHtddddd�}|�i�}t|t�sJ�|�d|j�|jtus"J�dS)N�nothing�
index.html�2�lenient��filename�lineno�lookup)rr�
isinstancerr�_name�_ownerr	)rr�retvalrrr�test_access_undefined�s�
z(ExpressionTestCase.test_access_undefinedcC�bGdd�dt�}|�}tddddd�}|�d|i�}t|t�s!J�|�d	|j�|j|us/J�dS)
Nc@r�)z<ExpressionTestCase.test_getattr_undefined.<locals>.SomethingcSrp�Nz<Something>rr'rrr�__repr__�r~zEExpressionTestCase.test_getattr_undefined.<locals>.Something.__repr__N�r�r�r�r�rrrr�	Something�r�r��
something.nilr�r�r�r��	something�nil��objectrrr�rrr�r��rr�r�rr�rrr�test_getattr_undefined���z)ExpressionTestCase.test_getattr_undefinedcCsHGdd�dt�}|�ttd�jd|�i�|�ttd�jd|�i�dS)Nc@s,eZdZdd�Zee�Zdd�Zee�ZdS)z<ExpressionTestCase.test_getattr_exception.<locals>.SomethingcS�t�ry��NotImplementedErrorr'rrr�prop_a�r~zCExpressionTestCase.test_getattr_exception.<locals>.Something.prop_acSr�ry)�AttributeErrorr'rrr�prop_b�r~zCExpressionTestCase.test_getattr_exception.<locals>.Something.prop_bN)r�r�r�r��propertyr�rrrrr��s
r�zs.prop_a�szs.prop_b)r��assertRaisesr�rrr��rr�rrr�test_getattr_exception�s��z)ExpressionTestCase.test_getattr_exceptioncCr�)
Nc@r�)zCExpressionTestCase.test_getitem_undefined_string.<locals>.SomethingcSrpr�rr'rrrr��r~zLExpressionTestCase.test_getitem_undefined_string.<locals>.Something.__repr__Nr�rrrrr��r�r��something["nil"]r�r�r�r�r�r�r�r�rrr�test_getitem_undefined_string�r�z0ExpressionTestCase.test_getitem_undefined_stringcCs.Gdd�dt�}|�ttd�jd|�i�dS)Nc@r�)z<ExpressionTestCase.test_getitem_exception.<locals>.SomethingcSr�ryr�)rr9rrr�__getitem__�r~zHExpressionTestCase.test_getitem_exception.<locals>.Something.__getitem__N)r�r�r�r�rrrrr��r�r�zs["foo"]r�)r�r�r�rrr�rrr�test_getitem_exception�s�z)ExpressionTestCase.test_getitem_exceptionc
Cs�tddddd�}z
|�i�|�d�WdStyi}zHt��\}}}|j}g}|jr7|j}|�|�|js,|�dt	|��|�d|d	j
jj�|�d|d	j
jj
�|�d|d	j�WYd}~dSd}~ww)
Nr�r�r��strictr��Expected UndefinedErrorz"nothing" not definedz<Expression 'nothing'>���)rr�failrrh�exc_info�tb_next�appendr�str�tb_frame�f_code�co_name�co_filename�	tb_lineno)rr�e�exc_type�	exc_value�
exc_traceback�frame�framesrrr�test_error_access_undefined�s0�

��� ��z.ExpressionTestCase.test_error_access_undefinedc

C��Gdd�dt�}tddddd�}z|�d|�i�|�d	�WdStym}zA|�d
t|��t��\}}}d}|j	}|j	rO|j	}|j
j}	|	j|krLn|j	s?|�d�|�d|	j
�|�d|j�WYd}~dSd}~ww)
Nc@r�)zBExpressionTestCase.test_error_getattr_undefined.<locals>.SomethingcSrpr�rr'rrrr��r~zKExpressionTestCase.test_error_getattr_undefined.<locals>.Something.__repr__Nr�rrrrr��r�r�r�r�r�r�r�r�r��%<Something> has no member named "nil"z<Expression 'something.nil'>�'never found the frame I was looking for�r�rrr�rrrrhrrrrrrr�
rr�rr	r
rr�
search_stringr
r rrr�test_error_getattr_undefined��.�
�
��z/ExpressionTestCase.test_error_getattr_undefinedc

Cr)
Nc@r�)zIExpressionTestCase.test_error_getitem_undefined_string.<locals>.SomethingcSrpr�rr'rrrr��r~zRExpressionTestCase.test_error_getitem_undefined_string.<locals>.Something.__repr__Nr�rrrrr��r�r�r�r�r�r�r�r�r�rz<Expression 'something["nil"]'>rrrrrr�#test_error_getitem_undefined_string�rz6ExpressionTestCase.test_error_getitem_undefined_stringcC�(tddid�}|�dtd��|��dS)N�some�thing)�dictzdict['some']�rrrrrurrr�!test_getitem_with_constant_string��z4ExpressionTestCase.test_getitem_with_constant_stringcCs�tdddddd�d�}|�dtd��|��|�dtd	��|��|�dtd
��|��|�dtd��|��|�dtd��|��dS)
Nr$�baz�quox�quooox�foobar)Tg@Nr0sfoo��valueszvalues[True]zvalues[2.5]z
values[42]zvalues[b"foo"]zvalues[None]rrurrr�test_getitem_with_simple_indexs
�z1ExpressionTestCase.test_getitem_with_simple_indexcCs>tgd�d�}|�dtd��|��|�dtd��|��dS)Nr=)r�r>zitems[0]r?z	items[-1]rrurrr�test_array_indicessz%ExpressionTestCase.test_array_indicescCsbGdd�dt�}|�dd�}|�dtd��|��|�dtd��|��|�dtd��|��dS)	Nc@seZdZdZdS)zCExpressionTestCase.test_item_access_for_attributes.<locals>.MyClass�BarN)r�r�r��myattrrrrr�MyClasssr*r))�miner9r(zmine.myattrzmine["myattr"]z	mine[key])r�rrr)rr*rvrrr�test_item_access_for_attributess
z2ExpressionTestCase.test_item_access_for_attributescCr)Nr%r$r$zvalues[str("foo")]rrurrr�test_function_in_item_accessrz/ExpressionTestCase.test_function_in_item_accessN)Or�r�r�rrr#r(r)r-r/r8r<r@rArCrGrHrJrNrRrVrWrXrYrZr[r]r^r_rarbrcrdrerfrjrkrlrmrnrorwr|r}r�r�r�r�r�r�r�r�r�rh�version_infor�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr&r'r,r-rrrrr
s�		


r
c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Ze
s6dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%dEdF�Z&dGdH�Z'dIdJ�Z(dKdL�Z)dMdN�Z*dOdP�Z+dQdR�Z,e-j.dSkr�dTdU�Z/dVdW�Z0dXdY�Z1dZd[�Z2d\d]�Z3d^d_�Z4d`da�Z5dbdc�Z6ddde�Z7dfdg�Z8dhdi�Z9djS)k�
SuiteTestCasecCsbtd�}t�}t�||d�|�d�t�|�}i}|�|�|�d|d�|j|jks/J�dS)N�foo = 42rrr0r%)	rr
rrrr�executerr )r�suiter!r"rvrrrr##s


zSuiteTestCase.test_picklecCs.td�}ddi}|�|�|�d|d�dS)Nzdata = []
bar = foo
r%r0r$�rr1r�rr2rvrrr�test_internal_shadowing.s
z%SuiteTestCase.test_internal_shadowingcC�*td�}i}|�|�|�d|d�dS)Nr0r0r%r3r4rrr�test_assign;s
zSuiteTestCase.test_assigncCs8td�}i}|�|�d|vsJ�|�d|d��dS)Nzdef donothing(): pass�	donothingr3r4rrr�test_defAs

zSuiteTestCase.test_defcCs<td�}ddi}|�|�d|vsJ�|�d|d��dS)Nz2
def donothing():
    if True:
        return foo
r%r$r8r3r4rrr�!test_def_with_multiple_statementsHs

z/SuiteTestCase.test_def_with_multiple_statementscC�.td�}i}|�|�|�ddg|d�dS)Nzl
values = []
def add(value):
    if value not in values:
        values.append(value)
add('foo')
add('bar')
r%r$r%r3r4rrr�test_def_using_nonlocalS�
z%SuiteTestCase.test_def_using_nonlocalcC�:td�}i}|�|�|�d|d�|�d|d�dS)NzY
def difference(v1, v2=10):
    return v1 - v2
x = difference(20, 19)
y = difference(20)
r>rB�
rMr3r4rrr�test_def_some_defaults`�

z$SuiteTestCase.test_def_some_defaultscCsJtd�}i}|�|�|�d|d�|�d|d�|�d|d�dS)Nzn
def difference(v1=100, v2=10):
    return v1 - v2
x = difference(20, 19)
y = difference(20)
z = difference()
r>rBr?rM�Z�zr3r4rrr�test_def_all_defaultsls
z#SuiteTestCase.test_def_all_defaultscCr6)Nzj
def mysum(*others):
    rv = 0
    for n in others:
        rv = rv + n
    return rv
x = mysum(1, 2, 3)
r�rBr3r4rrr�test_def_varargzs
zSuiteTestCase.test_def_varargcCs2td�}i}|�|�|�ddgt|d��dS)Nz^
def smash(**kw):
    return [''.join(i) for i in kw.items()]
x = smash(foo='abc', bar='def')
�bardef�fooabcrB)rr1r�sortedr4rrr�test_def_kwargs�s
zSuiteTestCase.test_def_kwargscCr6)Nz8
def kwonly(*args, k):
    return k
x = kwonly(k="foo")
r%rBr3r4rrr�test_def_kwonlyarg��
z SuiteTestCase.test_def_kwonlyargcCr>)NzK
def kwonly(*args, k="bar"):
    return k
x = kwonly(k="foo")
y = kwonly()
r%rBr$rMr3r4rrr�test_def_kwonlyarg_with_default�rAz-SuiteTestCase.test_def_kwonlyarg_with_defaultcCr;)Nz�
def doit():
    values = []
    def add(value):
        if value not in values:
            values.append(value)
    add('foo')
    add('bar')
    return values
x = doit()
r%r$rBr3r4rrr�test_def_nested�s
zSuiteTestCase.test_def_nestedcCr6)Nzl
def lower(fun):
    return lambda: fun().lower()

@lower
def say_hi():
    return 'Hi!'

result = say_hi()
zhi!�resultr3r4rrr�test_def_with_decorator�s

z%SuiteTestCase.test_def_with_decoratorcCs&td�}i}|�|�d|vsJ�dS)Nzfoo = 42
del foo
r%�rr1r4rrr�test_delete�s
zSuiteTestCase.test_deletecC�&td�}i}|�|�d|vsJ�dS)Nzclass plain(object): pass�plainrPr4rrr�
test_class��
zSuiteTestCase.test_classcCs.td�}i}|�|�|�dt|d��dS)Nz�
def create():
    class Foobar(object):
        def __str__(self):
            return 'foobar'
    return Foobar()
x = create()
r#rB)rr1rrr4rrr�test_class_in_def�r=zSuiteTestCase.test_class_in_defcCrR)Nz7class plain(object):
    def donothing():
        pass
rSrPr4rrr�test_class_with_methods�s
z%SuiteTestCase.test_class_with_methodscCrR)Nzfrom itertools import repeat�repeatrPr4rrr�test_import�rUzSuiteTestCase.test_importcCs(td�}t�}|�|�d|vsJ�dS)Nzfrom itertools import *rX)rrr1r4rrr�test_import_star�s
zSuiteTestCase.test_import_starcCsBtd�}t�}|�|�d|vsJ�|�gd�t|d���dS)NzDdef fun():
    from itertools import repeat
    return repeat(1, 3)
rX)r>r>r>�fun)rrr1rr�r4rrr�test_import_in_def�s

z SuiteTestCase.test_import_in_defcCs.td�}i}|�|�|�gd�|d�dS)Nz-x = []
for i in range(3):
    x.append(i**2)
)rr>rUrBr3r4rrr�test_fors
zSuiteTestCase.test_forcCs8td�}i}|�|�d|vsJ�|�d|d��dS)NzVdef loop():
    for i in range(10):
        if i == 5:
            break
    return i
�loopr�r3r4rrr�test_for_in_def
s

zSuiteTestCase.test_for_in_defcC�.td�}ddi}|�|�|�d|d�dS)Nzif foo == 42:
    x = True
r%r0TrBr3r4rrr�test_ifs
zSuiteTestCase.test_ifcCstd�}|�t|ji�dS)Nzraise NotImplementedError)rr�r�r1�rr2rrr�
test_raiseszSuiteTestCase.test_raisecC�*td�}i}|�|�|�d|d�dS)NzXtry:
    import somemod
except ImportError:
    somemod = None
else:
    somemod.dosth()�somemodr3r4rrr�test_try_except"s
zSuiteTestCase.test_try_exceptcCrd)Nz%try:
    x = 2
finally:
    x = None
rBr3r4rrr�test_finally-rKzSuiteTestCase.test_finallycCr`)Nz>x = 0
while x < 5:
    x += step
    if x == 4:
        break
�steprrUrBr3r4rrr�test_while_break7s
zSuiteTestCase.test_while_breakcC�2td�}ddi}|�d|i�|�d|d�dS)Nzd['k'] += 42�kr>�d�+r3�rr2rlrrr�#test_augmented_attribute_assignmentB�z1SuiteTestCase.test_augmented_attribute_assignmentcCstd��i�dS)Nzx = 1; x += 42; assert x == 43rPr'rrr�test_local_augmented_assignHsz)SuiteTestCase.test_local_augmented_assigncC�&i}td��|�|�d|d�dS)Nz6def foo():
    i = 1
    i += 1
    return i
x = foo()rrBr3�rrlrrr�test_augmented_assign_in_defKsz*SuiteTestCase.test_augmented_assign_in_defcCrr)NzQdef foo():
    i = 0
    for n in range(5):
        i += n
    return i
x = foo()r?rBr3rsrrr�$test_augmented_assign_in_loop_in_defTsz2SuiteTestCase.test_augmented_assign_in_loop_in_defcCrj)Nz)[d['k']] = 'foo',; assert d['k'] == 'foo'rkr$rlr%r3rnrrr�test_assign_in_list^rpz!SuiteTestCase.test_assign_in_listcCstd�}|�dddii�dS)Nz&x = 1; exec(d['k']); assert x == 42, xrlrkzx = 42rPrbrrr�	test_execdr*zSuiteTestCase.test_execcCstd�}|�ddi�dS)Nz)
def f():
    return v

assert f() == 42
r�r0rPrbrrr�test_returnhszSuiteTestCase.test_returncCs2td�}dii}|�|�|�d|dd�dS)Nzd['k'] = 'foo'rlr%rkr3r4rrr�test_assign_to_dict_itemqs
z&SuiteTestCase.test_assign_to_dict_itemcCsBGdd�dt�}|�}td�}d|i}|�|�|�d|j�dS)Nc@seZdZdS)z9SuiteTestCase.test_assign_to_attribute.<locals>.SomethingN)r�r�r�rrrrr�xsr�zobj.attr = 'foo'r�r%)r�rr1r�attr)rr�r�r2rvrrr�test_assign_to_attributews
z&SuiteTestCase.test_assign_to_attributecCs<Gdd�dt�}|�}td��d|i�|�t|d��dS)Nc@r�)z-SuiteTestCase.test_delattr.<locals>.SomethingcSr�)Nr%)rzr'rrrr��r�z6SuiteTestCase.test_delattr.<locals>.Something.__init__Nr�rrrrr��r�r�zdel obj.attrr�rz)r�rr1�assertFalse�hasattr)rr�r�rrr�test_delattrszSuiteTestCase.test_delattrcCs*ddi}td��d|i�|�d|�dS)Nrkr%z
del d['k']rl)rr1�assertNotInrsrrr�test_delitem�szSuiteTestCase.test_delitemc	Cs~t�\}}t�|d�}z-|�d�|�d�|��d|i}td�}|�|�|�ddg|d�Wt�	|�dSt�	|�w)	N�wzfoo
bar
r�pathz{from __future__ import with_statement
lines = []
with open(path) as file:
    for line in file:
        lines.append(line)
�foo
zbar
�lines�
r�os�fdopen�writer�closerr1r�remove�r�fdr�r�rlr2rrr�test_with_statement�s



z!SuiteTestCase.test_with_statementcCs.i}td�}|�|�|�gd�|d�dS)Na
results = []
def counter(maximum):
    i = 0
    while i < maximum:
        val = (yield i)
        if val is not None:
            i = val
        else:
            i += 1
it = counter(5)
results.append(next(it))
results.append(it.send(3))
results.append(next(it))
)rr?rU�resultsr3)rrlr2rrr�test_yield_expression�s
z#SuiteTestCase.test_yield_expression)r?r?c	Cs~t�\}}t�|d�}z-|�d�|�d�|��d|i}td�}|�|�|�ddg|d�Wt�	|�dSt�	|�w)Nr�r�rr�z�from __future__ import with_statement
lines = []
with open(path) as file1, open(path) as file2:
    for line in file1:
        lines.append(line)
    for line in file2:
        lines.append(line)
r�r�r�rrr�'test_with_statement_with_multiple_items�s



z5SuiteTestCase.test_with_statement_with_multiple_itemscCs6td�}dgd�i}|�|�|�ddg|d�dS)Nzx = numbers[0:2]r�r�rr>rBr3r4rrrr���
zSuiteTestCase.test_slicecCs:td�}gd�ddd�}|�|�|�ddg|d�dS)Nzx = numbers[start:end]r�rrr�r>rBr3r4rrrr��s
z"SuiteTestCase.test_slice_with_varscCs6td�}dgd�i}|�|�|�gd�|d�dS)Nzx = numbers[:]r�r�rBr3r4rrrr��r�zSuiteTestCase.test_slice_copycC�8td�}gd�dd�}|�|�|�gd�|d�dS)Nzx = numbers[::stride]r�rr�r�rBr3r4rrrr���
zSuiteTestCase.test_slice_stridecCs6td�}gd�dd�}|�|�|�dg|d�dS)Nzx = numbers[-1:]r�rr�rUrBr3r4rrrr��s
z'SuiteTestCase.test_slice_negative_startcCr�)Nzx = numbers[:-1]r�rr�r�rBr3r4rrrr��r�z%SuiteTestCase.test_slice_negative_endcCs2td�}dgd�i}|�|�|�d|d�dS)Nzx = numbers[1]r�r�r>rBr3r4rrrr��s
z!SuiteTestCase.test_slice_constantcCs<dd�}td�}gd�|d�}|�|�|�d|d�dS)NcSrpr�rrrrrr��r~z(SuiteTestCase.test_slice_call.<locals>.fzx = numbers[f()]r�r�rrBr3)rr�r2rvrrrr��s

zSuiteTestCase.test_slice_callcCs4td�}gd�dd�}|�|�|�d|d�dS)Nzx = numbers[v]r�rr�rBr3r4rrrr��s
zSuiteTestCase.test_slice_namecCsDGdd�d�}td�}gd�|�d�}|�|�|�d|d�dS)Nc@r�)z7SuiteTestCase.test_slice_attribute.<locals>.ValueHoldercSr�r�r�r'rrrr�r�z@SuiteTestCase.test_slice_attribute.<locals>.ValueHolder.__init__Nr�rrrrr�r�r�zx = numbers[obj.value]r�r�r?rBr3)rr�r2rvrrrr�s

z"SuiteTestCase.test_slice_attributeN):r�r�r�r#r5r7r9r:r<r@rDrErIrrJrLrMrOrQrTrVrWrYrZr\r]r_rarcrfrgrirorqrtrurvrwrxryr{r~r�r�r�rhr.r�r�r�r�r�r�r�r�r�r�r�rrrrr/!sn





	
	
	
	
r/cCsBt��}|�t�tj��|�t�td��|�t�t	d��|S)N�test)
�unittest�	TestSuite�addTest�doctest�DocTestSuiterr��	makeSuiter
r/)r2rrrr2
s
r2�__main__)�defaultTest)r�r�rrh�tempfilerr��genshi.corer�genshi.template.baser�genshi.template.evalrrrrr	�
genshi.compatr
rr�TestCaser
r/r2r��mainrrrr�<module>s.
	o�

https://t.me/RX1948 - 2025