a ze.6@sddlZddlZddZGdddejZGdddeZGdd d eZGd d d eZGd d d eZGdddeZ ddZ dddZ GdddejZ GdddejZ GdddejZedkredS)NcsddfddS)NcSsGddd}dda|S)Nc@s eZdZdS);global_function..inner_function..LocalClassN)__name__ __module__ __qualname__rrG/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_funcattrs.py LocalClasssrcSs dd}|S)NcSsdSNrrrrrinner_function2 s.inner_global_function..inner_function2r)r rrrinner_global_function sr )r )rrrrinner_functions'global_function..inner_functioncsSr rrr rr!global_function..rrrrrglobal_functions rc@seZdZddZddZdS) FuncAttrsTestcCs.Gddd}dd}||_||_||_dS)Nc@seZdZddZdS)zFuncAttrsTest.setUp..FcSsdSr rselfrrrasz FuncAttrsTest.setUp..F.aN)rrrrrrrrFsrcSsdSNrrrrrbsFuncAttrsTest.setUp..b)firr)rrrrrrsetUps FuncAttrsTest.setUpcCsjzt|||Wn|y"Yn0|d||fzt||Wn|yVYn0|d|dS)Nz!shouldn't be able to set %s to %rzshouldn't be able to del %s)setattrfaildelattr)robjnamevalue exceptionsrrrcannot_set_attrs  zFuncAttrsTest.cannot_set_attrN)rrrrr'rrrrrs rc@s|eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZdS)FunctionPropertiesTestcCs||jjtdSr ) assertEqualrrrrrrr test_module.sz"FunctionPropertiesTest.test_modulecCs@d|j_|dt|jdd|jj_|dt|jjddS)N known_attrz+set attributes not in dir listing of methodzEset attribute on function implementations, should show up in next dir)rr,ZassertIndirrrrrrrrtest_dir_includes_correct_attrs1s  z6FunctionPropertiesTest.test_dir_includes_correct_attrscCsdd}||j|dS)NcSsdSrrrrrr duplicate<szJFunctionPropertiesTest.test_duplicate_function_equality..duplicate)ZassertNotEqualr)rr/rrr test_duplicate_function_equality:sz7FunctionPropertiesTest.test_duplicate_function_equalitycCs2dd}||d|jj|_||ddS)NcSsdSr rrrrrtestBrz:FunctionPropertiesTest.test_copying___code__..testr)r)r__code__)rr1rrrtest_copying___code__As z,FunctionPropertiesTest.test_copying___code__cCs,||jjt||jddttfdS)N __globals__)assertIsrr4globalsr'AttributeError TypeErrorrrrrtest___globals__Gs z'FunctionPropertiesTest.test___globals__csZdfdd}|j}||t|t|d||djjd||d|tdS)N cs tdSr printrrrrfNrz2FunctionPropertiesTest.test___closure__..frcell __closure__) rBZassertIsInstancetupler)len __class__rr'r8rr?crr>rtest___closure__Ls  z'FunctionPropertiesTest.test___closure__cCs\td}||jdt}d}|jt|d|jWdn1sN0YdS)Nr@'shouldn't be able to read an empty cell)msg)typesCellTyper) cell_contents assertRaises ValueError)rZcell_objrJrrr test_cell_newVs  z$FunctionPropertiesTest.test_cell_newcsBfdd}z|jdjWnty.Yn 0|dddS)Ncs tdSr r<rr>rrr?`rz1FunctionPropertiesTest.test_empty_cell..frrIr;)rBrMrOr!)rr?rr>rtest_empty_cell_s   z&FunctionPropertiesTest.test_empty_cellcsdfdd}|j}d|d_||djd||d|d|d`z|djWntytYn 0|d|t|Wdn1s0Y|ttWdn1s0YdS)Nr;csSr rrr>rrr?krz/FunctionPropertiesTest.test_set_cell..f rrI) rBrMr)rOr!rN NameErrorUnboundLocalErrorr=rFrr>r test_set_cellis"      $ z$FunctionPropertiesTest.test_set_cellcCs||jjdd|j_||jjdd|j_||jjd||jddtd}t|dii||jjjd||jjddtdS) NrrGdrr+zdef f(): pass f.__name__ __builtins__r) r)rrr'r9execrrr8)rsrrr test___name__}sz$FunctionPropertiesTest.test___name__cCs||jjd|tjjd|tjd|tjd|tjd|tjd|tjd|tjdd |j_||jjd d |j_||jjd ||jd d tdS) Nrrrrrrr r rGrVrr+) r)rrrrrr r'r9rrrrtest___qualname__s&  z(FunctionPropertiesTest.test___qualname__csd\dd}dd}fdd}fdd }fd d }|||||fD]}|t|jtjqL||d ||d |j|_||j|j||d z |j|_WntyYn 0|dz |j|_WntyYn 0|ddS)N)r+cSsdSr rrrrrrrz/FunctionPropertiesTest.test___code__..acSsdS)Nr;rrrrrrrz/FunctionPropertiesTest.test___code__..bcsSr rr)num_onerrrGrz/FunctionPropertiesTest.test___code__..ccsSr rr)num_tworrrVrz/FunctionPropertiesTest.test___code__..dcsfSr rrr]r^rrerz/FunctionPropertiesTest.test___code__..er+r\zC__code__ with different numbers of free vars should not be possible)r)typer2rKCodeTyperOr!)rrrrGrVr`funcrr_r test___code__s.       z$FunctionPropertiesTest.test___code__cCs*||jjd|j`||jjddSr )r)r __defaults__rrrrtest_blank_func_defaultssz/FunctionPropertiesTest.test_blank_func_defaultscCsdd}d dd}||jd||jdd|_||jd||d||dd ||dd d |`||jdz |WntyYn 0|d dS) NcSs||Sr rrrrrr first_funcszAFunctionPropertiesTest.test_func_default_args..first_funcr@r5cSs||Sr rrgrrr second_funcszBFunctionPropertiesTest.test_func_default_args..second_func)r@r5rr\zE__defaults__ does not update; deleting it does not remove requirement)r@r5)r)rer9r!)rrhrirrrtest_func_default_argss    z-FunctionPropertiesTest.test_func_default_argsN)rrrr*r.r0r3r:rHrPrQrUrZr[rdrfrkrrrrr(,s    r(c@s,eZdZddZddZddZddZd S) InstancemethodAttrTestcCs0||jjjj|j||jjd|jtdS)NrE)r)rr__self__rErr'r9rrrrtest___class__sz%InstancemethodAttrTest.test___class__cCs2||jjj|jj||jjd|jjtdS)N__func__)r)rrrorr'r8rrrr test___func__sz$InstancemethodAttrTest.test___func__cCs.||jjj|j||jjd|jtdS)Nrm)r)rrrmr'r8rrrr test___self__sz$InstancemethodAttrTest.test___self__cCsntt|j|j_||jt|jz|jjjWntyJYn 0|d||jjddtdS)N4using unknown attributes should raise AttributeError unknown_attrr5) rK MethodTypeidrr)rsr8r!r'rrrrtest___func___non_methods  z/InstancemethodAttrTest.test___func___non_methodN)rrrrnrprqrvrrrrrlsrlc@s$eZdZddZddZddZdS)ArbitraryFunctionAttrTestcCsHd|j_||jjdzd|jj_Wnty8Yn 0|ddS)Nr+z0setting attributes on methods should raise error)rr,r)rrr8r!rrrr test_set_attrs z'ArbitraryFunctionAttrTest.test_set_attrcCs,z |j`WntyYn 0|ddS)Nz1deleting unknown attribute should raise TypeError)rrsr8r!rrrrtest_delete_unknown_attrs   z2ArbitraryFunctionAttrTest.test_delete_unknown_attrc Cs@|j|jjfD],}z |jWnty.Yq0|dqdS)Nrr)rrrZnon_existent_attrr8r!)rrcrrrtest_unset_attr s   z)ArbitraryFunctionAttrTest.test_unset_attrN)rrrrxryrzrrrrrws rwc@s4eZdZddZddZddZddZd d Zd S) FunctionDictsTestcCsD||jddtddlm}|ddi}||jjjd|tdS)N__dict__r)UserDictr,r+)r'rr9 collectionsr}rrro)rr}rVrrrtest_setting_dict_to_invalids  z.FunctionDictsTest.test_setting_dict_to_invalidcCsddi}||j_|||jj||jj_|||jjjj|||jjj||jjd||jjdd||jjjjd||jjjddS)Nr,r+) rr|r6rrrror)r,)rrVrrrtest_setting_dict_to_valids z,FunctionDictsTest.test_setting_dict_to_validcCs,z |j`WntyYn 0|ddS)Nz3deleting function dictionary should raise TypeError)rr|r9r!rrrrtest_delete___dict__.s   z&FunctionDictsTest.test_delete___dict__cCs||jjidSr )r)rr|rrrrtest_unassigned_dict6sz&FunctionDictsTest.test_unassigned_dictcCs(d}i}|||j<|||j|dS)Nz Some string)rr))rr%rVrrrtest_func_as_dict_key9s z'FunctionDictsTest.test_func_as_dict_keyN)rrrrrrrrrrrrr{s r{c@seZdZddZddZdS)FunctionDocstringTestcCs`||jjdd}||j_||jj_||jj|||jjj|||jjd|tdS)NzA test method that does nothing__doc__)r)rrrrrr'r8)rZdocstrrrrtest_set_docstring_attrAs z-FunctionDocstringTest.test_set_docstring_attrcCs"d|j_|j`||jjddS)Nz The docstring)rrr)rrrrtest_delete_docstringJsz+FunctionDocstringTest.test_delete_docstringN)rrrrrrrrrr@s rcsfdd}||jdS)Ncs tdSr r<rr>rrr?Rszcell..frrB)r%r?rr>rrAPs rATcsfdd}|sd|jdS)Ncs tdSr r<rr>rrr?Yszempty_cell..firr)emptyr?rr>r empty_cellWs rc@seZdZddZdS)CellTestcCsj|tdtdk|ttdk|ttk|tdtdk|tdtkdS)Nr5rZsaturdayigBT) assertTruerArrrrrtest_comparisonds zCellTest.test_comparisonN)rrrrrrrrrcsrc@seZdZddZdS)StaticMethodAttrsTestcCs<dd}t|}||j|ut|}||j|udS)NcSsdSr rrrrrr?rsz4StaticMethodAttrsTest.test_func_attribute..f) classmethodrro staticmethod)rr?rGrYrrrtest_func_attributeqs z)StaticMethodAttrsTest.test_func_attributeN)rrrrrrrrrpsrc@seZdZddZdS)BuiltinFunctionPropertiesTestcCsddl}|tjd||jjd|tjjd|tjjd|tj jd|t j jd|gdj jd |d d ij jd dS) NrrDtimez dict.fromkeyszfloat.__getformat__z str.maketranszbytes.maketrans)r@r5rz list.appendZfooZbarzdict.pop) rr)rDrdictfromkeysfloat __getformat__str maketransbytesappendpop)rrrrrtest_builtin__qualname__s z6BuiltinFunctionPropertiesTest.test_builtin__qualname__N)rrrrrrrrr|sr__main__)T)rKZunittestrZTestCaserr(rlrwr{rrArrrrrmainrrrrs  0)