Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_keywordonlyarg.cpython-34.pyc

�
g f��@sdZdZdZddlZddlmZdd�Zddd	d
�Zdd�Zd
d�Z	ddddd�Z
ddddd�Zdddd�Zdddd�Z
Gdd�d�ZGdd�dej�Zdd�Zed kre�ndS)!z?Unit tests for the keyword only argument specified in PEP 3102.z	Jiwon Seozseojiwon at gmail dot com�N)�run_unittestcOs|t|�t|j��S)N)�sum�values)Zpos_arg1�arg�kwarg�r�=/opt/alt/python34/lib64/python3.4/test/test_keywordonlyarg.py�posonly_sum	sr	�k1cCs||S)Nr)r
�k2rrr�keywordonly_sumsrcCs||S)Nr)r
rrrr�keywordonly_nodefaults_sum
sr
cKs||t|j��S)N)rr)r
rrrrr�keywordonly_and_kwarg_sumsrrcGs||||t|�S)N)r)�a�br
rrrrr�
mixedargs_sumsrcOs*||||t|�t|j��S)N)rr)rrr
rr�kwargsrrr�mixedargs_sum2sr�reverseFcGstt|�d|�S)Nr)�sorted�list)rZnumsrrr�sortnumsrcOstt|�d|�S)Nr)rr)rZwordsrrrr�	sortwordssrc@s:eZdZdddd�Zdd�Zdd�Zd	S)
�FoorrcCs||_||_dS)N)r
r)�selfr
rrrr�__init__s	zFoo.__init__cCs||_||_dS)N)r
r)r�p1r
rrrr�set s	zFoo.setcCs|j|jS)N)r
r)rrrrr#szFoo.sumN)�__name__�
__module__�__qualname__rrrrrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�KeywordOnlyArgTestCasecCs#dd�}|jt||�dS)NcSst|dd�dS)Nz<test>�single)�compile)�srrr�shouldRaiseSyntaxError(szNKeywordOnlyArgTestCase.assertRaisesSyntaxError.<locals>.shouldRaiseSyntaxError)�assertRaises�SyntaxError)rZcodestrr%rrr�assertRaisesSyntaxError'sz.KeywordOnlyArgTestCase.assertRaisesSyntaxErrorcCsl|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd�dS)	Nzdef f(p, *):
  pass
zdef f(p1, *, p1=100):
  pass
zdef f(p1, *k1, k1=100):
  pass
z!def f(p1, *, k1, k1=100):
  pass
zdef f(p1, *, **k1):
  pass
zdef f(p1, *, k1, **k1):
  pass
z!def f(p1, *, None, **k1):
  pass
z$def f(p, *, (k1, k2), **kw):
  pass
)r()rrrr�$testSyntaxErrorForFunctionDefinition,s






z;KeywordOnlyArgTestCase.testSyntaxErrorForFunctionDefinitioncCs�d}x"td�D]}|d|7}qW|d7}|j|�d}x"td�D]}|d|7}qUW|d7}|j|�d}x"td�D]}|d|7}q�W|d7}t|d	d
�dS)Nzdef f(�zi%d, z*, key=100):
 pass
zdef foo(i,*,zlastarg):
  pass
z
def f(i,*,�z<test>r")�ranger(r#)rZfundef�iZfundef2Zfundef3rrr�testSyntaxForManyArguments6s




z1KeywordOnlyArgTestCase.testSyntaxForManyArgumentscCs`ddddd�}|jt��}|ddd�WdQXd}|jt|j�|�dS)N�ccSsdS)Nr)rrr/rrr�fKszCKeywordOnlyArgTestCase.testTooManyPositionalErrorMessage.<locals>.f���z;f() takes from 1 to 2 positional arguments but 3 were given)r&�	TypeError�assertEqual�str�	exception)rr0�excZexpectedrrr�!testTooManyPositionalErrorMessageJs
z8KeywordOnlyArgTestCase.testTooManyPositionalErrorMessagecCs|jd�|jd�dS)Nz
f(p, k=1, p2)zf(p, k1=50, *(1,2), k1=100))r()rrrr�testSyntaxErrorForFunctionCallRs
z5KeywordOnlyArgTestCase.testSyntaxErrorForFunctionCallcCs�|jttf�|jttf�|jttf�y$tdddd�|jd�Wntk
rqYnXytdd�|jd�Wntk
r�YnXdS)Nr�dZnon_existing_arg��zshould raise TypeErrorr2)r&r4rr
r�fail)rrrr�2testRaiseErrorFuncallWithUnexpectedKeywordArgumentVs


zIKeywordOnlyArgTestCase.testRaiseErrorFuncallWithUnexpectedKeywordArgumentcCs�|jdtd��|jdtdidd6��|jdtdd��|jdtddidd6��|jdtdd��|jdtdddd��|jdtdddd��|jdtddddd	d��|jd tddddidd
6dd6��|jd!tddd��|jd#tdddd��|jd&tdddddd��|jd*tddddddd��|jd+tddd��|jd-tdddd��|jd0tdddddd��|jd4tddddddd��|jd9tdddddddd	d
��|jd>tdddddidd6d
d	6��|jdtdd�j��|jd?tdddd�j��|jdddgtddd��|jdddgtddddd��|jd
ddgt	d
dd��|jddd
gt	d
dddd��|jddd
gt	d
dddddd��dS)@Nr1r2�2r3��4rr
Zk3rr��rTr/�ignorer3r3rC)r2r3r3rC�
)r2r3r3r3r3rCr3rCrEr3r3rCr3rCrEr3rCrE�r3r3rCr3rCrEr3rCrErFr3rCrErF�r3rCrErFrGr3)
r5r	rrrrrrrr)rrrr�testFunctionCalles> #%	%(%(	%	*%%+%+z'KeywordOnlyArgTestCase.testFunctionCallcCs�ddddd�}|jd|jj�|jidd6|j�idd6|_y!|ddd�|jd	�Wntk
r�YnXdS)
NrrcSs||||S)Nr)rZp2r
rrrr�foo�sz2KeywordOnlyArgTestCase.testKwDefaults.<locals>.foor2r
r1rEz&__kwdefaults__ is not properly changed)r5�__code__�co_kwonlyargcount�__kwdefaults__r=r4)rrIrrr�testKwDefaults�s
z%KeywordOnlyArgTestCase.testKwDefaultscCs�Gdd�d�}|j|�jdddd�d�|j|j|�dddd�d�|jt|jdddd�dS)	Nc@s(eZdZdddddd�ZdS)z;KeywordOnlyArgTestCase.test_kwonly_methods.<locals>.Exampler
r1rr2cSs
||fS)Nr)rr
rrrrr0�sz=KeywordOnlyArgTestCase.test_kwonly_methods.<locals>.Example.fN)rrr r0rrrr�Example�srNr
r1rr2)r1r2)r1r2)r5r0r&r4)rrNrrr�test_kwonly_methods�s%(z*KeywordOnlyArgTestCase.test_kwonly_methodscCsdtdd�dS)Nr
cSsdS)Nr)r
rrr�<lambda>�sz8KeywordOnlyArgTestCase.test_issue13343.<locals>.<lambda>)�unittest)rrrr�test_issue13343�sz&KeywordOnlyArgTestCase.test_issue13343cCs0Gdd�d�}|j|�j�d�dS)Nc@s"eZdZdddd�ZdS)z/KeywordOnlyArgTestCase.test_mangling.<locals>.X�_X__a�*cSs|S)Nr)rrSrrrr0�sz1KeywordOnlyArgTestCase.test_mangling.<locals>.X.fN)rrr r0rrrr�X�srUrT)r5r0)rrUrrr�
test_mangling�sz$KeywordOnlyArgTestCase.test_manglingcCs�d}|jt��%}|tdtdtdd�}WdQX|jt|j�d�|jt��%}|tdtdtdd�}WdQX|jt|j�d�dS)	NrT�y�zcSsdS)Nr)�v�xrWrXrrrr0�sz?KeywordOnlyArgTestCase.test_default_evaluation_order.<locals>.fzname 'b' is not definedcSsdS)Nr)rYrZrWrXrrrrP�szFKeywordOnlyArgTestCase.test_default_evaluation_order.<locals>.<lambda>)r&�	NameErrorrr/�dr5r6r7)rr�errr0rrr�test_default_evaluation_order�s$$z4KeywordOnlyArgTestCase.test_default_evaluation_orderN)rrr r(r)r.r9r:r>rHrMrOrRrVr^rrrrr!&s
(
	r!cCstt�dS)N)rr!rrrr�	test_main�sr_�__main__)�__doc__�
__author__Z	__email__rQZtest.supportrr	rr
rrrrrrZTestCaser!r_rrrrr�<module>s"
�