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)rrrrrrrrFsrcSsdS)NrrrrrbsFuncAttrsTest.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)NcSsdS)z my docstringrrrrrr 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__)rr0rrrtest_copying___code__As z,FunctionPropertiesTest.test_copying___code__cCs,||jjt||jddttfdS)N __globals__)assertIsrr3globalsr&AttributeError TypeErrorrrrrtest___globals__Gs z'FunctionPropertiesTest.test___globals__csZdfdd}|j}||t|t|d||djjd||d|tdS)N cs tdSr printrrrrfNrz2FunctionPropertiesTest.test___closure__..frcell __closure__) rAZassertIsInstancetupler(len __class__rr&r7rr>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_objrIrrr test_cell_newVs  z$FunctionPropertiesTest.test_cell_newcsBfdd}z|jdjWnty.Yn 0|dddS)Ncs tdSr r;rr=rrr>`rz1FunctionPropertiesTest.test_empty_cell..frrHr:)rArLrNr )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 rrH) rArLr(rNr rM NameErrorUnboundLocalErrorr<rErr=r test_set_cellis"      $ z$FunctionPropertiesTest.test_set_cellcCs||jjdd|j_||jjdd|j_||jjd||jddtd}t|dii||jjjd||jjddtdS) NrrFdrr*zdef f(): pass f.__name__ __builtins__r) r(rrr&r8execrrr7)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 rFrUrr*) r(rrrrrr r&r8rrrrtest___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_onerrrFrz/FunctionPropertiesTest.test___code__..ccsSr rr)num_tworrrUrz/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(typer1rJCodeTyperNr )rrrrFrUr_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?r4cSs||Sr rrfrrr second_funcszBFunctionPropertiesTest.test_func_default_args..second_func)r?r4rr[zE__defaults__ does not update; deleting it does not remove requirement)r?r4)r(rdr8r )rrgrhrrrtest_func_default_argss    z-FunctionPropertiesTest.test_func_default_argsN)rrrr)r-r/r2r9rGrOrPrTrYrZrcrerjrrrrr',s    r'c@s,eZdZddZddZddZddZd S) InstancemethodAttrTestcCs0||jjjj|j||jjd|jtdS)NrD)r(rr__self__rDrr&r8rrrrtest___class__sz%InstancemethodAttrTest.test___class__cCs2||jjj|jj||jjd|jjtdS)N__func__)r(rrrnrr&r7rrrr test___func__sz$InstancemethodAttrTest.test___func__cCs.||jjj|j||jjd|jtdS)Nrl)r(rrrlr&r7rrrr test___self__sz$InstancemethodAttrTest.test___self__cCsntt|j|j_||jt|jz|jjjWntyJYn 0|d||jjddtdS)N4using unknown attributes should raise AttributeError unknown_attrr4) rJ MethodTypeidrr(rrr7r r&rrrrtest___func___non_methods  z/InstancemethodAttrTest.test___func___non_methodN)rrrrmrorprurrrrrksrkc@s$eZdZddZddZddZdS)ArbitraryFunctionAttrTestcCsHd|j_||jjdzd|jj_Wnty8Yn 0|ddS)Nr*z0setting attributes on methods should raise error)rr+r(rrr7r rrrr test_set_attrs z'ArbitraryFunctionAttrTest.test_set_attrcCs,z |j`WntyYn 0|ddS)Nz1deleting unknown attribute should raise TypeError)rrrr7r rrrrtest_delete_unknown_attrs   z2ArbitraryFunctionAttrTest.test_delete_unknown_attrc Cs@|j|jjfD],}z |jWnty.Yq0|dqdS)Nrq)rrrZnon_existent_attrr7r )rrbrrrtest_unset_attr s   z)ArbitraryFunctionAttrTest.test_unset_attrN)rrrrwrxryrrrrrvs rvc@s4eZdZddZddZddZddZd d Zd S) FunctionDictsTestcCsD||jddtddlm}|ddi}||jjjd|tdS)N__dict__r)UserDictr+r*)r&rr8 collectionsr|rrrn)rr|rUrrrtest_setting_dict_to_invalids  z.FunctionDictsTest.test_setting_dict_to_invalidcCsddi}||j_|||jj||jj_|||jjjj|||jjj||jjd||jjdd||jjjjd||jjjddS)Nr+r*) rr{r5rrrrnr(r+)rrUrrrtest_setting_dict_to_valids z,FunctionDictsTest.test_setting_dict_to_validcCs,z |j`WntyYn 0|ddS)Nz3deleting function dictionary should raise TypeError)rr{r8r 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$rUrrrtest_func_as_dict_key9s z'FunctionDictsTest.test_func_as_dict_keyN)rrrr~rrrrrrrrrzs rzc@seZdZddZddZdS)FunctionDocstringTestcCs`||jjdd}||j_||jj_||jj|||jjj|||jjd|tdS)NzA test method that does nothing__doc__)r(rrrrrr&r7)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)z)Create a cell containing the given value.cs tdSr r;rr=rrr>Rszcell..frrA)r$r>rr=rr@Ps r@Tcsfdd}|sd|jdS)zCreate an empty cell.cs tdSr r;rr=rrr>Yszempty_cell..firr)emptyr>rr=r empty_cellWs rc@seZdZddZdS)CellTestcCsj|tdtdk|ttdk|ttk|tdtdk|tdtkdS)Nr4rZsaturdayigBT) assertTruer@rrrrrtest_comparisonds zCellTest.test_comparisonN)rrrrrrrrrcsrc@seZdZddZdS)StaticMethodAttrsTestcCs<dd}t|}||j|ut|}||j|udS)NcSsdSr rrrrrr>rsz4StaticMethodAttrsTest.test_func_attribute..f) classmethodrrn staticmethod)rr>rFrXrrrtest_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) NrrCtimez dict.fromkeyszfloat.__getformat__z str.maketranszbytes.maketrans)r?r4rz list.appendZfooZbarzdict.pop) rr(rCrdictfromkeysfloat __getformat__str maketransbytesappendpop)rrrrrtest_builtin__qualname__s z6BuiltinFunctionPropertiesTest.test_builtin__qualname__N)rrrrrrrrr|sr__main__)T)rJZunittestrZTestCaserr'rkrvrzrr@rrrrrmainrrrrs  0)