a 4dg^`@sNddlZddlmZz ddlZWney6dZYn0ddlZddlZddlZddlZGdddej Z eGdddej Z Gdddej Z Gd d d e Z Gd d d e ZGd dde ZGddde ZddZddZGdddZeZeZGdddej ZdZdZddZddZGdd d ej Zed!krJedS)"N) cpython_onlyc@seZdZddZdS) FunctionCallscCs^tddg}|dt|}dd}|fi|}||t|t||dS)N)a)brc[s|SN)kwr r */usr/local/lib/python3.9/test/test_call.pyfnsz+FunctionCalls.test_kwargs_order..fn) collections OrderedDict move_to_endlistitemsZassertIsInstancedict assertEqual)selfZodexpectedr resr r r test_kwargs_orders   zFunctionCalls.test_kwargs_orderN)__name__ __module__ __qualname__rr r r r r src@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCS)DCFunctionCallsErrorMessagescCsd}|t|ijdS)Nz7__contains__\(\) takes exactly one argument \(0 given\)assertRaisesRegex TypeError __contains__rmsgr r r test_varargs0 sz)CFunctionCallsErrorMessages.test_varargs0cCsd}|t|ijdddS)Nz7__contains__\(\) takes exactly one argument \(2 given\)rrrr r r r test_varargs2$sz)CFunctionCallsErrorMessages.test_varargs2cCsd}|t|tjddddS)Nz@^from_bytes\(\) takes exactly 2 positional arguments \(3 given\)alittleF)rrint from_bytesr r r r test_varargs3(sz)CFunctionCallsErrorMessages.test_varargs3cCs,d}|t|ijd}|t|ijdS)Nz'get expected at least 1 argument, got 0zexpected 1 argument, got 0)rrget __delattr__r r r r test_varargs1min,sz,CFunctionCallsErrorMessages.test_varargs1mincCsd}|t|tdS)Nz,getattr expected at least 2 arguments, got 0rrgetattrr r r r test_varargs2min3sz,CFunctionCallsErrorMessages.test_varargs2mincCsd}|t|tdddS)Nz(input expected at most 1 argument, got 2rr)rrinputr r r r test_varargs1max7sz,CFunctionCallsErrorMessages.test_varargs1maxcCsd}|t|ijddddS)Nz'get expected at most 2 arguments, got 3rr)rrr)r r r r test_varargs2max;sz,CFunctionCallsErrorMessages.test_varargs2maxcCsd}|jt|ijdddS)N+__contains__\(\) takes no keyword argumentsrxrr r r r test_varargs1_kw?sz,CFunctionCallsErrorMessages.test_varargs1_kwcCsd}|jt|ijddddS)Nr3rr5yrr r r r test_varargs2_kwCsz,CFunctionCallsErrorMessages.test_varargs2_kwcCsd}|jt|tdddS)Nz#bool\(\) takes no keyword argumentsrr4)rrboolr r r r test_varargs3_kwGsz,CFunctionCallsErrorMessages.test_varargs3_kwcCsd}|jt|gjdddS)Nz-^list[.]index\(\) takes no keyword arguments$rr4)rrindexr r r r test_varargs4_kwKsz,CFunctionCallsErrorMessages.test_varargs4_kwcCsd}|jt|tdddS)Nz(^hasattr\(\) takes no keyword arguments$rr4)rrhasattrr r r r test_varargs5_kwOsz,CFunctionCallsErrorMessages.test_varargs5_kwcCsd}|jt|tdddS)Nz(^getattr\(\) takes no keyword arguments$rr4r,r r r r test_varargs6_kwSsz,CFunctionCallsErrorMessages.test_varargs6_kwcCsd}|jt|tdddS)Nz%^next\(\) takes no keyword arguments$rr4)rrnextr r r r test_varargs7_kwWsz,CFunctionCallsErrorMessages.test_varargs7_kwcCsd}|jt|tjdddS)Nz/^_struct[.]pack\(\) takes no keyword arguments$rr4)rrstructpackr r r r test_varargs8_kw[sz,CFunctionCallsErrorMessages.test_varargs8_kwcCsd}|jt|tjdddS)Nz4^_struct[.]pack_into\(\) takes no keyword arguments$rr4)rrrC pack_intor r r r test_varargs9_kw_sz,CFunctionCallsErrorMessages.test_varargs9_kwcCs d}|jt|tjdddS)Nz.^deque[.]index\(\) takes no keyword arguments$rr4)rrr dequer<r r r r test_varargs10_kwcsz-CFunctionCallsErrorMessages.test_varargs10_kwcCs&d}|jt|tjjtddddS)Nz.^Struct[.]pack\(\) takes no keyword arguments$rr4)rrrCStructrDr r r r test_varargs11_kwgsz-CFunctionCallsErrorMessages.test_varargs11_kwcCsd}|jt|ttddS)Nz-^staticmethod\(\) takes no keyword arguments$func)rr staticmethodidr r r r test_varargs12_kwksz-CFunctionCallsErrorMessages.test_varargs12_kwcCsd}|jt|ttddS)Nz,^classmethod\(\) takes no keyword arguments$rM)rr classmethodrPr r r r test_varargs13_kwosz-CFunctionCallsErrorMessages.test_varargs13_kwcCs d}|jt|tjdddddS)Nz:^product\(\) takes at most 1 keyword argument \(2 given\)$rrr)repeatfoo)rr itertoolsproductr r r r test_varargs14_kwss z-CFunctionCallsErrorMessages.test_varargs14_kwc Cs d}|jt|tddddddS)Nz?^ImportError\(\) takes at most 2 keyword arguments \(3 given\)$rrrr1)namepathrU)rr ImportErrorr r r r test_varargs15_kwxs z-CFunctionCallsErrorMessages.test_varargs15_kwc Cs d}|jt|tddddddS)Nz7^min\(\) takes at most 2 keyword arguments \(3 given\)$rrrr1)defaultkeyrU)rrminr r r r test_varargs16_kw}s z-CFunctionCallsErrorMessages.test_varargs16_kwc Cs$d}|jt|tddddddd dS) Nz9^print\(\) takes at most 4 keyword arguments \(5 given\)$rrrr1)sependfileflushrU)rrprintr r r r test_varargs17_kwsz-CFunctionCallsErrorMessages.test_varargs17_kwcCsd}|t|ijddS)Nz'keys\(\) takes no arguments \(1 given\)rrrkeysr r r r test_oldargs0_1sz+CFunctionCallsErrorMessages.test_oldargs0_1cCsd}|t|ijdddS)Nz'keys\(\) takes no arguments \(2 given\)rrrir r r r test_oldargs0_2sz+CFunctionCallsErrorMessages.test_oldargs0_2cCsd}|jt|ijdddS)N#keys\(\) takes no keyword argumentsrr4rir r r r test_oldargs0_1_kwsz.CFunctionCallsErrorMessages.test_oldargs0_1_kwcCsd}|jt|ijddddS)Nrmrr7rir r r r test_oldargs0_2_kwsz.CFunctionCallsErrorMessages.test_oldargs0_2_kwcCsd}|t|gjdS)Nz0count\(\) takes exactly one argument \(0 given\)rrcountr r r r test_oldargs1_0sz+CFunctionCallsErrorMessages.test_oldargs1_0cCsd}|t|gjdddS)Nz0count\(\) takes exactly one argument \(2 given\)rrrpr r r r test_oldargs1_2sz+CFunctionCallsErrorMessages.test_oldargs1_2cCsd}|jt|gjdddSN$count\(\) takes no keyword argumentsrr4rpr r r r test_oldargs1_0_kwsz.CFunctionCallsErrorMessages.test_oldargs1_0_kwcCsd}|jt|gjidddSrtrpr r r r test_oldargs1_1_kwsz.CFunctionCallsErrorMessages.test_oldargs1_1_kwcCsd}|jt|gjddddS)Nrurr7rpr r r r test_oldargs1_2_kwsz.CFunctionCallsErrorMessages.test_oldargs1_2_kwN)$rrrr"r#r(r+r.r0r2r6r9r;r=r?r@rBrErGrIrLrQrSrXr\r`rhrkrlrnrorrrsrvrwrxr r r r rsBrc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2S)3TestCallingConventionsaTest calling using various C calling conventions (METH_*) from Python Subclasses test several kinds of functions (module-level, methods, class methods static methods) using these attributes: obj: the object that contains tested functions (as attributes) expected_self: expected "self" argument to the C function The base class tests module-level functions. cCst|_|_dSr) _testcapiobj expected_selfrr r r setUpszTestCallingConventions.setUpcCs"||jddd|jdfdSNrrr1rrr1rr{ meth_varargsr|r}r r r test_varargssz#TestCallingConventions.test_varargscCs||jjd|jdfdSNrrr}r r r test_varargs_exts z'TestCallingConventions.test_varargs_extcsd}t|fdddS)Nz+meth_varargs\(\) takes no keyword argumentscsjjddSNr)k)r{rr r}r r z>TestCallingConventions.test_varargs_error_kw..rrr r r}r test_varargs_error_kwsz,TestCallingConventions.test_varargs_error_kwcCs.||jjddddd|jddddfdSNrrr1rarrrrrr{meth_varargs_keywordsr|r}r r r test_varargs_keywordssz,TestCallingConventions.test_varargs_keywordscCs6||jjddgiddd|jddddfdSrrr}r r r test_varargs_keywords_extsz0TestCallingConventions.test_varargs_keywords_extcCs||jd|jdfdSNrrr{meth_or|r}r r r test_oszTestCallingConventions.test_ocCs ||jjdg|jdfdSrrr}r r r test_o_extsz!TestCallingConventions.test_o_extcCsd}|t||jjdS)Nz1meth_o\(\) takes exactly one argument \(0 given\))rrr{rr r r r test_o_error_no_argsz*TestCallingConventions.test_o_error_no_argcsd}t|fdddS)Nz1meth_o\(\) takes exactly one argument \(2 given\)csjddSNrrr{rr r}r r rrz>TestCallingConventions.test_o_error_two_args..rr r r}r test_o_error_two_argssz,TestCallingConventions.test_o_error_two_argscsd}t|fdddS)Nz1meth_o\(\) takes exactly one argument \(3 given\)cs jjdSrrr r}r r rrz9TestCallingConventions.test_o_error_ext..rr r r}r test_o_error_extsz'TestCallingConventions.test_o_error_extcsd}t|fdddS)N%meth_o\(\) takes no keyword argumentscsjjddSrrr r}r r rrz8TestCallingConventions.test_o_error_kw..rr r r}r test_o_error_kwsz&TestCallingConventions.test_o_error_kwcsd}t|fdddS)NrcsjjddSrrr r}r r rrz.rr r r}r test_o_error_arg_kwsz*TestCallingConventions.test_o_error_arg_kwcCs||j|jdSrrr{ meth_noargsr|r}r r r test_noargssz"TestCallingConventions.test_noargscCs||jjg|jdSrrr}r r r test_noargs_extsz&TestCallingConventions.test_noargs_extcsd}t|fdddS)Nz.meth_noargs\(\) takes no arguments \(1 given\)cs jdSrr{rr r}r r rrz>TestCallingConventions.test_noargs_error_arg..rr r r}r test_noargs_error_argsz,TestCallingConventions.test_noargs_error_argcsd}t|fdddS)Nz.meth_noargs\(\) takes no arguments \(2 given\)csjddSrrr r}r r r rz?TestCallingConventions.test_noargs_error_arg2..rr r r}r test_noargs_error_arg2sz-TestCallingConventions.test_noargs_error_arg2csd}t|fdddS)Nz.meth_noargs\(\) takes no arguments \(3 given\)cs jjdSrrr r}r r rrz>TestCallingConventions.test_noargs_error_ext..rr r r}r test_noargs_error_ext sz,TestCallingConventions.test_noargs_error_extcsd}t|fdddS)Nz*meth_noargs\(\) takes no keyword argumentscsjjddSrrr r}r r rrz=TestCallingConventions.test_noargs_error_kw..rr r r}r test_noargs_error_kwsz+TestCallingConventions.test_noargs_error_kwcCs"||jddd|jdfdSrrr{ meth_fastcallr|r}r r r test_fastcallsz$TestCallingConventions.test_fastcallcCs||jjd|jdfdSrrr}r r r test_fastcall_exts z(TestCallingConventions.test_fastcall_extcsd}t|fdddS)Nz,meth_fastcall\(\) takes no keyword argumentscsjjddSr)r{rr r}r r r(rz?TestCallingConventions.test_fastcall_error_kw..rr r r}r test_fastcall_error_kw%sz-TestCallingConventions.test_fastcall_error_kwcCs.||jjddddd|jddddfdSrrr{meth_fastcall_keywordsr|r}r r r test_fastcall_keywords+sz-TestCallingConventions.test_fastcall_keywordscCs2||jjdiddd|jddddfdS)Nrr1rarrr}r r r test_fastcall_keywords_ext1sz1TestCallingConventions.test_fastcall_keywords_extN)rrr__doc__r~rrrrrrrrrrrrrrrrrrrrrrrr r r r rys2 ryc@seZdZdZddZdS)TestCallingConventionsInstancez?Test calling instance methods using various calling conventionscCst|_|_dSr)rz MethInstancer{r|r}r r r r~;sz$TestCallingConventionsInstance.setUpNrrrrr~r r r r r8src@seZdZdZddZdS)TestCallingConventionsClasszFastCallTests.test_fastcall_clearing_dict..IntWithDictrc[s ||_dSr)r)rrr r r __init__ szGFastCallTests.test_fastcall_clearing_dict..IntWithDict.__init__cSs|jtdS)Nr)rcleargcZcollectr}r r r __index__ s zHFastCallTests.test_fastcall_clearing_dict..IntWithDict.__index__N)rrr __slots__rrr r r r IntWithDictsr) dont_inheritpassrJexec)compiler)rrr5r r r test_fastcall_clearing_dicts z)FastCallTests.test_fastcall_clearing_dict)"rrrrrrrrrPYTHON_INSTANCErrrrrzrZ _instancerrr{r|extendrrrrrrrrrrrrr r r r rrs~               riicCs|Szsome docr r}r r r testfunctionsrcCs|Srr )rr r r r testfunction_kw src@s,eZdZddZddZddZddZd S) TestPEP590cCsddl}|dt}|ttjt@|tt j jt@|tt j jt@|ttjt@|t|jt@|t j jt@|t jjt@|t jjt@Gdddt j }||jt@dS)Nrrc@s eZdZdS)zDTestPEP590.test_method_descriptor_flag..MethodDescriptorHeapNrrrr r r r MethodDescriptorHeap6sr) functools lru_cacher assertFalsetyperepr __flags__Py_TPFLAGS_METHOD_DESCRIPTOR assertTruerappend__add__rzMethodDescriptorBaseMethodDescriptorDerivedMethodDescriptorNopGet)rrcachedrr r r test_method_descriptor_flag'sz&TestPEP590.test_method_descriptor_flagcCsn|tjjt@|tjjt@|tjjt@|tjjt@Gdddtj}||jt@dS)Nc@s eZdZdS)z=TestPEP590.test_vectorcall_flag..MethodDescriptorHeapNrr r r r rAsr) rrzrrPy_TPFLAGS_HAVE_VECTORCALLrrrMethodDescriptor2)rrr r r test_vectorcall_flag:s zTestPEP590.test_vectorcall_flagcCs(ttd}t}||||dS)Nrb)rrangerzrZassertIs)rrfr r r test_vectorcall_overrideEs z#TestPEP590.test_vectorcall_overridec sttdfidftjgdfidfgjdidftdgfddidftdidftdddidftdid ft did ft did fg }dd lm m }dd l m}dd lm}fdd}|D]f\}}}} |t|:|s|| ||||| ||||Wdq1s0YqGdddtj} Gdddtj} Gddd} Gddd| tj} |tjifdd idfijifdd idf| did f| didf| did fg7}|D]\}}}} |t||dd}|||d}||}|sH|| |||| ||d|| |||| |||| ||i||| |||||| ||i||| ||i|Wdn1s0YqdS)N*r)r$start)rr TF)rpyvectorcall_call) MethodType)partialcs&g||R}t|}|||Sr)rr)rNrrrrr r vectorcallgsz.TestPEP590.test_vectorcall..vectorcallc@s eZdZdS)z8TestPEP590.test_vectorcall..MethodDescriptorHeapNrr r r r rusrc@seZdZddZdS)z>TestPEP590.test_vectorcall..MethodDescriptorOverriddencSsdS)Nnewr )rnr r r __call__yszGTestPEP590.test_vectorcall..MethodDescriptorOverridden.__call__N)rrrrr r r r MethodDescriptorOverriddenxsrcseZdZfddZZS)z-TestPEP590.test_vectorcall..SuperBasecs tj|Srsuperrrr __class__r r r}sz6TestPEP590.test_vectorcall..SuperBase.__call__rrrr __classcell__r r rr SuperBase|srcseZdZfddZZS)z9TestPEP590.test_vectorcall..MethodDescriptorSupercs tj|Srrrrr r rszBTestPEP590.test_vectorcall..MethodDescriptorSuper.__call__rr r rr MethodDescriptorSupersrr^rr)lenrrrsumrrrzrrrrr typesr rr rstrrrupdate)rZcallsr r r r rNrrrrrrrZargs1methwrappedr r r rOsX       6    zTestPEP590.test_vectorcallN)rrrrrrrr r r r r%s  r__main__)ZunittestZ test.supportrrzr[rCr rVrZTestCaserrryrrrrrrrrobjectrrrrrrrrmainr r r r sB     &w