Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_funcattrs.cpython-311.pyc
�

�Kep;���ddlZddlZddlZd�ZGd�dej��ZGd�de��ZGd�de��ZGd	�d
e��ZGd�de��Z	Gd
�de��Z
d�Zdd�ZGd�dej��Z
Gd�dej��ZGd�dej��Zedkrej��dSdS)�Nc���d���fd�S)Nc�&�Gd�d��}d�a|S)Nc��eZdZdS)�;global_function.<locals>.inner_function.<locals>.LocalClassN)�__name__�
__module__�__qualname__���=/usr/local/apps/python3/lib/python3.11/test/test_funcattrs.py�
LocalClassrs�������Drr
c��d�}|S)Nc��dS�Nr
r
rr�inner_function2z.inner_global_function.<locals>.inner_function2����rr
)rs r�inner_global_functionrs��
�
�
�"�"r)r)r
s r�inner_functionz'global_function.<locals>.inner_functionsA��	�	�	�	�	�	�	�	�	#�	#�	#��rc����Srr
�rs�r�<lambda>z!global_function.<locals>.<lambda>s���>�rr
rs@r�global_functionrs#������"�!�!�!�!rc��eZdZd�Zd�ZdS)�
FuncAttrsTestc�`�Gd�d��}d�}|��|_||_||_dS)Nc��eZdZd�ZdS)�FuncAttrsTest.setUp.<locals>.Fc��dSrr
��selfs r�az FuncAttrsTest.setUp.<locals>.F.arrN)rrr	r!r
rr�Frs#������
�
�
�
�
rr"c��dS)N�r
r
rr�bzFuncAttrsTest.setUp.<locals>.bs���1r)�fir"r%)r r"r%s   r�setUpzFuncAttrsTest.setUpsX��	�	�	�	�	�	�	�	�	�	�	��!�#�#����������rc���	t|||��|�d|�d|����n#|$rYnwxYw	t||��|�d|z��dS#|$rYdSwxYw)Nzshouldn't be able to set z to zshouldn't be able to del %s)�setattr�fail�delattr)r �obj�name�value�
exceptionss     r�cannot_set_attrzFuncAttrsTest.cannot_set_attrs���	K��C��u�%�%�%�
�I�I�I�T�T�T�5�5�I�J�J�J�J���	�	�	��D�	����	<��C�����
�I�I�3�d�:�;�;�;�;�;���	�	�	��D�D�	���s�/�7�7�A%�%A.�-A.N)rrr	r'r0r
rrrrs2���������<�<�<�<�<rrc�h�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�ZdS)�FunctionPropertiesTestc�P�|�|jjt��dSr)�assertEqualr%rrrs r�test_modulez"FunctionPropertiesTest.test_module/s#�������*�H�5�5�5�5�5rc���d|j_|�dt|j��d��d|jj_|�dt|jj��d��dS)N��
known_attrz+set attributes not in dir listing of methodzEset attribute on function implementations, should show up in next dir)r%r8�assertIn�dirr"r!r&rs r�test_dir_includes_correct_attrsz6FunctionPropertiesTest.test_dir_includes_correct_attrs2sx�������
�
�l�C���K�K�9�	;�	;�	;� ������
�
�l�C���	�N�N�5C�	D�	D�	D�	D�	Drc�B�d�}|�|j|��dS)Nc��dS)zmy docstringr$r
r
rr�	duplicatezJFunctionPropertiesTest.test_duplicate_function_equality.<locals>.duplicate=s���1r)�assertNotEqualr%)r r>s  r� test_duplicate_function_equalityz7FunctionPropertiesTest.test_duplicate_function_equality;s1��	�	�	�	
���D�F�I�.�.�.�.�.rc��d�}|�|��d��|jj|_|�|��d��dS)Nc��dSrr
r
rr�testz:FunctionPropertiesTest.test_copying___code__.<locals>.testC����rr$)r4r%�__code__)r rCs  r�test_copying___code__z,FunctionPropertiesTest.test_copying___code__BsT�������������&�&�&�����
���������#�#�#�#�#rc��|�|jjt����|�|jddt
tf��dS)N�__globals__�)�assertIsr%rH�globalsr0�AttributeError�	TypeErrorrs r�test___globals__z'FunctionPropertiesTest.test___globals__HsQ���
�
�d�f�(�'�)�)�4�4�4����T�V�]�A�,�i�8�	:�	:�	:�	:�	:rc�@�|�|jjt��|�|jddtt
f��d�}i}t
|��|j|��}|�|j|��|�|jt��|�	|d��d��|�	|i��tjd��}ddi}t|d�}t||��|�|d	j|��|�|d
j|��|�|d	jd|��|�
d|d
j��dS)N�__builtins__rIc� �t|��Sr)�len)�ss r�funcz6FunctionPropertiesTest.test___builtins__.<locals>.funcTs��C��F�F�]r�abcr$z\
            def func3(s): pass
            func4 = type(func3)(func3.__code__, {})
        �None)�typerP�func3�func4)rJr%rPr0rLrMrWrErHr4�textwrap�dedent�exec�assertNotIn)r rT�ns�func2�code�
safe_builtinss      r�test___builtins__z(FunctionPropertiesTest.test___builtins__Ms����
�
�d�f�)�<�8�8�8����T�V�^�Q�,�i�8�	:�	:�	:�
	#�"�"�
����T�
�
�4�=�"�-�-���
�
�e�'��,�,�,��
�
�e�(�,�7�7�7�	
�����u���q�)�)�)�����R� � � ��� �
�
�� ���
��M�
:�
:���T�2�����
�
�b��k�.�
�>�>�>��
�
�b��k�.�
�>�>�>��
�
�b��k�-�n�=�}�M�M�M������G��)@�A�A�A�A�Arc�&��d��fd�}|j}|�|t��|�t	|��d��|�|djjd��|�|d|t��dS)N�c�&��t���dSr��print�r!s�r�fz2FunctionPropertiesTest.test___closure__.<locals>.fn�����q�����r�r�cell�__closure__)	rm�assertIsInstance�tupler4rR�	__class__rr0rL�r ri�cr!s   @r�test___closure__z'FunctionPropertiesTest.test___closure__ls�����������
�M�����a��'�'�'�����Q����#�#�#�����1���0�&�9�9�9����Q�
�q�.�A�A�A�A�Arc��tjd��}|�|jd��tj��}d}|�t
|���5|jddd��dS#1swxYwYdS)Nrk�'shouldn't be able to read an empty cell)�msg)�types�CellTyper4�
cell_contents�assertRaises�
ValueError)r �cell_objrvs   r�
test_cell_newz$FunctionPropertiesTest.test_cell_newvs����>�!�$�$������/��3�3�3��>�#�#��7��
�
�
�z�s�
�
3�
3�	#�	#��"�"�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#�	#�	#s�!A6�6A:�=A:c����fd�}	|jdj|�d��n#t$rYnwxYwd�dS)Nc�&��t���dSrrfrhs�rriz1FunctionPropertiesTest.test_empty_cell.<locals>.f�rjrrrurd)rmryr*r{)r rir!s  @r�test_empty_cellz&FunctionPropertiesTest.test_empty_cellsm��������	A�
�M�!��*�*�
�I�I�?�@�@�@�@���	�	�	��D�	����
���s�0�
=�=c�\��d��fd�}|j}d|d_|�|djd��|�|��d��|��d��|d`	|dj|�d��n#t$rYnwxYw|�t��5|��ddd��n#1swxYwY|�t��5t���ddd��dS#1swxYwYdS)Nrdc����Srr
rhs�rriz/FunctionPropertiesTest.test_set_cell.<locals>.f�s����r�	rru)	rmryr4r*r{rz�	NameError�UnboundLocalErrorrgrqs   @r�
test_set_cellz$FunctionPropertiesTest.test_set_cell�s�����������
�M����!�������1��+�Q�/�/�/��������a� � � �����A����
�a�D��	A�
�a�D���
�I�I�?�@�@�@�@���	�	�	��D�	�����
�
�y�
)�
)�	�	�
�A�C�C�C�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�
�
�0�
1�
1�	�	��!�H�H�H�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s6�;
B�
B+�*B+�C�C#�&C#�D!�!D%�(D%c��|�|jjd��d|j_|�|jjd��d|j_|�|jjd��|�|jddt��d}t|dii��|�|jjjd��|�|jjddt��dS)	Nr%rr�drr7zdef f(): pass
f.__name__rPr!)	r4r%rr0rMr\r&r!rL)r rSs  r�
test___name__z$FunctionPropertiesTest.test___name__�s���������#�.�.�.�����������#�.�.�.�����������#�.�.�.����T�V�Z��I�>�>�>�
,���Q���$�%�%�%�������+�S�1�1�1����T�W�Y�
�C��H�H�H�H�Hrc�l�|�|jjd��|�tjjd��|�t
jd��|�t��jd��|�t����jd��|�t������jd��|�tjd��|�t
��jd��d	|j_|�|jjd	��d
|j_|�|jjd
��|�|jddt��dS)
NzFuncAttrsTest.setUp.<locals>.bzFuncAttrsTest.setUprz!global_function.<locals>.<lambda>z'global_function.<locals>.inner_functionrrz.inner_global_function.<locals>.inner_function2rrr�r	r7)	r4r%r	rr'rrr0rMrs r�test___qualname__z(FunctionPropertiesTest.test___qualname__�s��������,�.N�O�O�O�����,�9�;P�Q�Q�Q�����5�7H�I�I�I�����*�*�7�<�	>�	>�	>����*��*�*�,�,�9�B�	D�	D�	D����,�*��*�*�,�,�.�.�;�V�	X�	X�	X����.�;�=T�U�U�U����.�0�0�=�?o�p�p�p�!���������,�c�2�2�2�!���������,�c�2�2�2����T�V�^�Q�	�B�B�B�B�Brc����d\��d�}d�}�fd�}�fd�}��fd�}|||||fD]4}|�t|j��tj���5|�|��d��|�|��d��|j|_|�|j|j��|�|��d��	|j|_|�d	��n#t$rYnwxYw	|j|_|�d	��dS#t$rYdSwxYw)
N)r7�c��dSrr
r
rrr!z/FunctionPropertiesTest.test___code__.<locals>.a�rDrc��dS)Nrdr
r
rrr%z/FunctionPropertiesTest.test___code__.<locals>.b�s���rc����Srr
)�num_ones�rrrz/FunctionPropertiesTest.test___code__.<locals>.c������rc����Srr
)�num_twos�rr�z/FunctionPropertiesTest.test___code__.<locals>.d�r�rc�����fSrr
)r�r�s��r�ez/FunctionPropertiesTest.test___code__.<locals>.e�s
�����(�(rr7r�zC__code__ with different numbers of free vars should not be possible)r4rWrErw�CodeTyper*r{)	r r!r%rrr�r�rTr�r�s	       @@r�
test___code__z$FunctionPropertiesTest.test___code__�s����������
�
��������������(�(�(�(�(�(���1�a��O�	B�	B�D����T�$�-�0�0�%�.�A�A�A�A��������a� � � ��������a� � � ��Z��
������Q�Z�0�0�0��������a� � � �	)���A�J�
�I�I�(�
)�
)�
)�
)���	�	�	��D�	����
	)���A�J�
�I�I�(�
)�
)�
)�
)�
)���	�	�	��D�D�	���s$�!D�
D�D�D7�7
E�Ec��|�|jjd��|j`|�|jjd��dSr)r4r%�__defaults__rs r�test_blank_func_defaultsz/FunctionPropertiesTest.test_blank_func_defaults�sF�������,�d�3�3�3��F�������,�d�3�3�3�3�3rc��d�}dd�}|�|jd��|�|jd��d|_|�|jd��|�|��d��|�|d��d��|�|dd��d��|`|�|jd��	|��|�d	��dS#t$rYdSwxYw)
Nc��||zSrr
�r!r%s  r�
first_funczAFunctionPropertiesTest.test_func_default_args.<locals>.first_func�����Q�3�JrrkrIc��||zSrr
r�s  r�second_funczBFunctionPropertiesTest.test_func_default_args.<locals>.second_func�r�r)rkrIr$�r�zE__defaults__ does not update; deleting it does not remove requirement)r4r�r*rM)r r�r�s   r�test_func_default_argsz-FunctionPropertiesTest.test_func_default_args�sN��	�	�	�	�	�	�	�����0�$�7�7�7�����1�6�:�:�:�"(�
������0�&�9�9�9��������q�)�)�)������A����*�*�*������A�q�)�)�1�-�-�-��$�����1�4�8�8�8�	,��K�M�M�M�
�I�I�+�
,�
,�
,�
,�
,���	�	�	��D�D�	���s�
C<�<
D
�	D
N)rrr	r5r;r@rFrNrbrsr}r�r�r�r�r�r�r�r
rrr2r2-s������6�6�6�D�D�D�/�/�/�$�$�$�:�:�:�
B�B�B�>B�B�B�#�#�#�������(I�I�I� C�C�C�()�)�)�<4�4�4�
,�,�,�,�,rr2c�&�eZdZd�Zd�Zd�Zd�ZdS)�InstancemethodAttrTestc��|�|jjjj|j��|�|jjd|jt��dS)Nrp)r4r&r!�__self__rpr"r0rMrs r�test___class__z%InstancemethodAttrTest.test___class__�sJ��������+�5�t�v�>�>�>����T�W�Y��T�V�Y�G�G�G�G�Grc���|�|jjj|jj��|�|jjd|jjt��dS)N�__func__)r4r&r!r�r"r0rLrs r�
test___func__z$InstancemethodAttrTest.test___func__sK��������+�T�V�X�6�6�6����T�W�Y�
�D�F�H�n�M�M�M�M�Mrc��|�|jjj|j��|�|jjd|jt
��dS)Nr�)r4r&r!r�r0rLrs r�
test___self__z$InstancemethodAttrTest.test___self__sG��������+�T�W�5�5�5����T�W�Y�
�D�G�^�L�L�L�L�Lrc��tjt|j��|j_|�|j���t|j����	|jjj|�d��n#t$rYnwxYw|�|jjddt��dS)N�4using unknown attributes should raise AttributeError�unknown_attrrI)	rw�
MethodType�idr&r4r�r*rLr0rs r�test___func___non_methodz/InstancemethodAttrTest.test___func___non_method	s����%�b�$�'�2�2���
����������r�$�'�{�{�3�3�3�	N��G�J�#�#�
�I�I�L�M�M�M�M���	�	�	��D�	����
	
���T�W�Z���N�K�K�K�K�Ks�*B�
B�BN)rrr	r�r�r�r�r
rrr�r��s^������H�H�H�N�N�N�M�M�M�
L�
L�
L�
L�
Lrr�c� �eZdZd�Zd�Zd�ZdS)�ArbitraryFunctionAttrTestc���d|j_|�|jjd��	d|jj_|�d��dS#t$rYdSwxYw)Nr7z0setting attributes on methods should raise error)r%r8r4r&r!r*rLrs r�
test_set_attrz'ArbitraryFunctionAttrTest.test_set_attrsx�����������*�A�.�.�.�	J�#$�D�G�I� �
�I�I�H�I�I�I�I�I���	�	�	��D�D�	���s�A�
A$�#A$c�b�	|j`|�d��dS#t$rYdSwxYw)Nz1deleting unknown attribute should raise TypeError)r%r�r*rLrs r�test_delete_unknown_attrz2ArbitraryFunctionAttrTest.test_delete_unknown_attr$sO��	K���#�
�I�I�I�J�J�J�J�J���	�	�	��D�D�	����� �
.�.c��|j|jjfD]/}	|j|�d��� #t
$rY�,wxYwdS)Nr�)r%r&r!�non_existent_attrr*rL)r rTs  r�test_unset_attrz)ArbitraryFunctionAttrTest.test_unset_attr,sx���V�T�W�Y�'�	,�	,�D�
,��&�&��	�	�+�,�,�,�,��"�
�
�
���
����	,�	,s�4�
A�AN)rrr	r�r�r�r
rrr�r�sG������J�J�J�K�K�K�,�,�,�,�,rr�c�,�eZdZd�Zd�Zd�Zd�Zd�ZdS)�FunctionDictsTestc���|�|jddt��ddlm}|ddi��}|�|jjjd|t��dS)N�__dict__r)�UserDictr8r7)r0r%rM�collectionsr�r&r!r�)r r�r�s   r�test_setting_dict_to_invalidz.FunctionDictsTest.test_setting_dict_to_invalid8sk�����T�V�Z��y�A�A�A�(�(�(�(�(�(��H�l�A�&�'�'�����T�W�Y�/��Q�	�J�J�J�J�Jrc�P�ddi}||j_|�||jj��||jj_|�||jjjj��|�||jjj��|�|jjd��|�|jjdd��|�|jjjjd��|�|jjjd��dS)Nr8r7)	r%r�rJr"r!r&r�r4r8)r r�s  r�test_setting_dict_to_validz,FunctionDictsTest.test_setting_dict_to_valid>s���
�1��������
�
�a����)�)�)�������
�
�a����+�4�5�5�5��
�
�a����+�,�,�,������*�A�.�.�.��������6��:�:�:�������+�6��:�:�:�������-�q�1�1�1�1�1rc�b�	|j`|�d��dS#t$rYdSwxYw)Nz3deleting function dictionary should raise TypeError)r%r�r*rMrs r�test_delete___dict__z&FunctionDictsTest.test_delete___dict__NsN��	M����
�I�I�K�L�L�L�L�L���	�	�	��D�D�	���r�c�F�|�|jji��dSr)r4r%r�rs r�test_unassigned_dictz&FunctionDictsTest.test_unassigned_dictVs"��������"�-�-�-�-�-rc�d�d}i}|||j<|�||j|��dS)NzSome string)r%r4)r r.r�s   r�test_func_as_dict_keyz'FunctionDictsTest.test_func_as_dict_keyYs9��������$�&�	�����4�6��E�*�*�*�*�*rN)rrr	r�r�r�r�r�r
rrr�r�7se������K�K�K�2�2�2� M�M�M�.�.�.�+�+�+�+�+rr�c��eZdZd�Zd�ZdS)�FunctionDocstringTestc�\�|�|jjd��d}||j_||jj_|�|jj|��|�|jjj|��|�|jjd|t��dS)NzA test method that does nothing�__doc__)r4r%r�r"r!r&r0rL)r �docstrs  r�test_set_docstring_attrz-FunctionDocstringTest.test_set_docstring_attras����������.�.�.�2������!������������0�0�0�������*�F�3�3�3����T�W�Y�	�6�>�J�J�J�J�Jrc�l�d|j_|j`|�|jjd��dS)Nz
The docstring)r%r�r4rs r�test_delete_docstringz+FunctionDocstringTest.test_delete_docstringjs2��(�����F�N��������.�.�.�.�.rN)rrr	r�r�r
rrr�r�`s5������K�K�K�/�/�/�/�/rr�c�,���fd�}|�|jdS)z)Create a cell containing the given value.c�&��t���dSrrfrhs�rrizcell.<locals>.fr����
�a�����rr�rm)r.rir!s  @rrlrlps.��������
�A��=���rTc�0���fd�}|sd�|jdS)zCreate an empty cell.c�&��t���dSrrfrhs�rrizempty_cell.<locals>.fyr�ri�rr�)�emptyrir!s  @r�
empty_cellr�ws8��������
�����=���rc��eZdZd�ZdS)�CellTestc��|�td��td��k��|�t��td��k��|�t��t��k��|�td��td��k��|�td��t��k��dS)NrIr$�saturdayi���gB�T)�
assertTruerlr�rs r�test_comparisonzCellTest.test_comparison�s���
	
����Q���$�q�'�'�)�*�*�*����
���t�J�'7�'7�7�8�8�8����
���
���4�5�5�5�����S�	�	�T�%�[�[�0�1�1�1�����T�
�
�Z�\�\�1�2�2�2�2�2rN)rrr	r�r
rrr�r��s#������	3�	3�	3�	3�	3rr�c��eZdZd�ZdS)�StaticMethodAttrsTestc��d�}t|��}|�|j|u��t|��}|�|j|u��dS)Nc��dSrr
r
rrriz4StaticMethodAttrsTest.test_func_attribute.<locals>.f�s���Dr)�classmethodr�r��staticmethod)r rirrrSs    r�test_func_attributez)StaticMethodAttrsTest.test_func_attribute�s_��	�	�	�
��N�N������
�a��(�(�(���O�O������
�a��(�(�(�(�(rN)rrr	r�r
rrr�r��s#������)�)�)�)�)rr�c��eZdZd�ZdS)�BuiltinFunctionPropertiesTestc�>�ddl}|�tjd��|�|jjd��|�tjjd��|�tjjd��|�tj	jd��|�tj	jd��|�gd�jjd	��|�d
dijjd��dS)
NrrR�timez
dict.fromkeyszfloat.__getformat__z
str.maketranszbytes.maketrans)rkrIr$zlist.append�foo�barzdict.pop)
r�r4rRr	�dict�fromkeys�float�
__getformat__�str�	maketrans�bytes�append�pop)r r�s  r�test_builtin__qualname__z6BuiltinFunctionPropertiesTest.test_builtin__qualname__�s������	
����)�5�1�1�1������/��8�8�8�	
�����3�_�E�E�E�����,�9�.�	0�	0�	0�	
�����3�_�E�E�E������5�7H�I�I�I�	
������)�6�
�F�F�F����%���+�8�*�E�E�E�E�ErN)rrr	r�r
rrr�r��s(������F�F�F�F�Frr��__main__)T)rZrw�unittestr�TestCaserr2r�r�r�r�rlr�r�r�r�r�mainr
rr�<module>r�s��������������
"�
"�
"�<�<�<�<�<�H�%�<�<�<�4K,�K,�K,�K,�K,�]�K,�K,�K,�\L�L�L�L�L�]�L�L�L�<,�,�,�,�,�
�,�,�,�<&+�&+�&+�&+�&+�
�&+�&+�&+�R
/�
/�
/�
/�
/�M�
/�
/�
/� ���	�	�	�	�
3�
3�
3�
3�
3�x� �
3�
3�
3�	)�	)�	)�	)�	)�H�-�	)�	)�	)�F�F�F�F�F�H�$5�F�F�F�2�z����H�M�O�O�O�O�O��r