
    <e-                     V   d dl Z d dlZd dlmZ  G d de          Z G d de          Z G d de          Z G d	 d
e          Z G d de	          Z
 G d de
          Z G d de	          Z G d de          Z G d de
          Z G d de	          Z G d dej                  Z G d de          Z G d de          Z G d dej                  Z G d d           Z G d! d"eej                  Z G d# d$eej                  Zed%k    r ej                     dS dS )&    N)supportc                       e Zd ZdS )PropertyBaseN__name__
__module____qualname__     )/usr/lib/python3.11/test/test_property.pyr   r              Dr   r   c                       e Zd ZdS )PropertyGetNr   r
   r   r   r   r      r   r   r   c                       e Zd ZdS )PropertySetNr   r
   r   r   r   r      r   r   r   c                       e Zd ZdS )PropertyDelNr   r
   r   r   r   r      r   r   r   c                   j    e Zd Zd Zed             Zej        d             Zej        d             ZdS )	BaseClassc                     d| _         d S )N   _spamselfs    r   __init__zBaseClass.__init__   s    


r   c                     | j         S )BaseClass.getterr   r   s    r   spamzBaseClass.spam        zr   c                     || _         d S Nr   r   values     r   r   zBaseClass.spam   s    


r   c                 
    | ` d S r"   r   r   s    r   r   zBaseClass.spam!   s    JJJr   N)r   r   r	   r   propertyr   setterdeleterr
   r   r   r   r      sx             X 
[  [ 
\  \  r   r   c                   x    e Zd Zej        j        d             Zej        d             Zej        d             ZdS )SubClassc                 *    t          | j                  )SubClass.getter)r   r   r   s    r   r   zSubClass.spam'   s     $*%%%r   c                 *    t          | j                  r"   )r   r   r#   s     r   r   zSubClass.spam,       $*%%%r   c                 *    t          | j                  r"   )r   r   r   s    r   r   zSubClass.spam0   r.   r   N)r   r   r	   r   r   getterr'   r(   r
   r   r   r*   r*   %   sm        ^& & & 
[& & [& 
\& & \& & &r   r*   c                   2    e Zd ZdZd Z eed          ZdS )PropertyDocBase   c                     | j         S r"   r   r   s    r   	_get_spamzPropertyDocBase._get_spam6   s
    zr   spam spam spamdocN)r   r   r	   r   r5   r&   r   r
   r   r   r2   r2   4   s7        E  8I#3444DDDr   r2   c                   8    e Zd Zej        j        d             ZdS )PropertyDocSubc                     | j         S )z*The decorator does not use this doc stringr   r   s    r   r   zPropertyDocSub.spam;   r    r   N)r   r   r	   r2   r   r0   r
   r   r   r:   r:   :   s4           !   r   r:   c                   8    e Zd Zej        j        d             ZdS )PropertySubNewGetterc                     dS )new docstringr   r
   r   s    r   r   zPropertySubNewGetter.spamA   	     qr   N)r   r   r	   r   r   r0   r
   r   r   r=   r=   @   s3        ^    r   r=   c                   D    e Zd Zed             Zej        d             ZdS )PropertyNewGetterc                     dS )zoriginal docstringr3   r
   r   s    r   r   zPropertyNewGetter.spamG   r@   r   c                     dS )r?      r
   r   s    r   r   zPropertyNewGetter.spamK   r@   r   N)r   r   r	   r&   r   r0   r
   r   r   rB   rB   F   sJ          X 
[  [  r   rB   c                      e Zd Zd Zd Z ej        ej        j	        dk    d          d             Z
 ej        ej        j	        dk    d          d             Zd Z ej        ej        j	        dk    d          d             Zd	 Z ej        ej        j	        dk    d          d
             Z ej        ej        j	        dk    d          d             Zej        d             Z ej        ej        j	        dk    d          d             Z ej        ej        j	        dk    d          d             Zd Zd ZdS )PropertyTestsc                 2   t                      }|                     |j        d           |                     |j        d           d|_        |                     |j        d           |                     |j        d           t	          |d           |                     t          |d                      |                     t          |d                      d|_        |                     |j        d           |                     |j        d           d S )Nr   
   r   r      )r   assertEqualr   r   delattr
assertTruehasattrr   bases     r   !test_property_decorator_baseclassz/PropertyTests.test_property_decorator_baseclassQ   s    {{A&&&Q'''	B'''R(((fGD&111222GD'222333	B'''R(((((r   c                     t                      }|                     t          t          |d           |                     t          t
          |dd            |                     t          t          |d           d S )Nr   )r*   assertRaisesr   getattrr   setattrr   rL   r   subs     r    test_property_decorator_subclassz.PropertyTests.test_property_decorator_subclass`   sa    jj+wV<<<+wVTBBB+wV<<<<<r      )Docstrings are omitted with -O2 and abovec                 l    t                      }|                     |j        j        j        d           d S )Nr,   )r*   rK   	__class__r   __doc__rV   s     r   $test_property_decorator_subclass_docz2PropertyTests.test_property_decorator_subclass_docg   s2     jj+35FGGGGGr   c                 l    t                      }|                     |j        j        j        d           d S )Nr   )r   rK   r\   r   r]   rO   s     r   %test_property_decorator_baseclass_docz3PropertyTests.test_property_decorator_baseclass_docm   s2     {{,46HIIIIIr   c                     t                      }t                      }|                     |j        j        j        d           |                     |j        j        j        d           d S )Nr6   )r2   r:   rK   r\   r   r]   )r   rP   rW   s      r   test_property_decorator_docz)PropertyTests.test_property_decorator_docs   s\      ,46FGGG+35EFFFFFr   c                 >   t                      }|                     |j        d           |                     |j        j        j        d           t                      }|                     |j        d           |                     |j        j        j        d           d S )Nr   r?   rE   )r=   rK   r   r\   r]   rB   )r   newgettersub	newgetters      r   !test_property_getter_doc_overridez/PropertyTests.test_property_getter_doc_overridey   s     ,--*A.../4<oNNN%''	+++,19?KKKKKr   c                 t   ddg dgddfD ]D G fddt                     }|                     |j        j        t	                               E G d d	t                     |                     t                    5   G fd
dt                     }|j        j         d d d            d S # 1 swxY w Y   d S )NTFr3    1c                   :    e Zd Zd Z e_         ee          ZdS )EPropertyTests.test_property___isabstractmethod__descriptor.<locals>.Cc                     d S r"   r
   r   s    r   foozIPropertyTests.test_property___isabstractmethod__descriptor.<locals>.C.foo       Dr   Nr   r   r	   rm   __isabstractmethod__r&   )vals   r   Crk      s3          +.(hsmmr   rr   c                       e Zd Zd ZeZdS )KPropertyTests.test_property___isabstractmethod__descriptor.<locals>.NotBoolc                     t                      r"   )
ValueErrorr   s    r   __bool__zTPropertyTests.test_property___isabstractmethod__descriptor.<locals>.NotBool.__bool__   s     ll"r   N)r   r   r	   rw   __len__r
   r   r   NotBoolrt      s"        # # #GGGr   ry   c                   J    e Zd Zd Z              e_         ee          ZdS )rk   c                     d S r"   r
   r   s    r   rm   zIPropertyTests.test_property___isabstractmethod__descriptor.<locals>.C.foo   rn   r   Nro   )ry   s   r   rr   zEPropertyTests.test_property___isabstractmethod__descriptor.<locals>.C   s9          +2799(hsmmr   )objectassertIsrm   rp   boolrS   rv   )r   rr   ry   rq   s     @@r   ,test_property___isabstractmethod__descriptorz:PropertyTests.test_property___isabstractmethod__descriptor   sa   %aS"c2 	A 	AC$ $ $ $ $ $ $F $ $ $
 MM!%4d3ii@@@@	 	 	 	 	f 	 	 	 z** 	' 	'$ $ $ $ $ $ $F $ $ $
 E&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   >"B--B14B1c                     t          d          }|                     |j        d           d|_        |                     |j        d           d S )Nbasicr7   extended)r&   rK   r]   )r   ps     r   "test_property_builtin_doc_writablez0PropertyTests.test_property_builtin_doc_writable   sQ     !!!G,,,	J/////r   c                      G d dt                     } |            }|                     |j        j        j        d           d|j        j        _        |                     |j        j        j        d           d S )Nc                   $    e Zd Zed             ZdS )OPropertyTests.test_property_decorator_doc_writable.<locals>.PropertyWritableDocc                     dS )Eggseggsr
   r   s    r   r   zTPropertyTests.test_property_decorator_doc_writable.<locals>.PropertyWritableDoc.spam   s	     vr   N)r   r   r	   r&   r   r
   r   r   PropertyWritableDocr      s-          X  r   r   r   Spam)r|   rK   r\   r   r]   )r   r   rW   s      r   $test_property_decorator_doc_writablez2PropertyTests.test_property_decorator_doc_writable   s    	 	 	 	 	& 	 	 	 "!##+3V<<<%+"+3V<<<<<r   c                    t          j        t          d          }t          dddd          } |            }t	          d          D ]}|                    dddd           |                      |            |z
  dd	           d S )
Ngettotalrefcountfgetfsetfdelr8   d   r   rI   )delta)r   get_attributesysr&   ranger   assertAlmostEqual)r   r   	fake_proprefs_beforeis        r   test_refleaks_in___init__z'PropertyTests.test_refleaks_in___init__   s    "06HIIVVVU;;	&&((s 	> 	>Avvvu====//11K?"MMMMMr   c                 V     G d d          }|                      |j        d           d S )Nc                   4    e Zd Zeed                         ZdS ),PropertyTests.test_class_property.<locals>.Ac                     d| j         z  S )NzA doc for %r)r   clss    r   r]   z4PropertyTests.test_class_property.<locals>.A.__doc__   s     &44r   N)r   r   r	   classmethodr&   r]   r
   r   r   Ar      s7        5 5 X [5 5 5r   r   zA doc for 'A'rK   r]   r   r   s     r   test_class_propertyz!PropertyTests.test_class_property   sJ    	5 	5 	5 	5 	5 	5 	5 	5
 	O44444r   c                 V     G d d          }|                      |j        d           d S )Nc                   8    e Zd ZdZeed                         ZdS )5PropertyTests.test_class_property_override.<locals>.AFirstc                     dS )NSecondr
   r   s    r   r]   z=PropertyTests.test_class_property_override.<locals>.A.__doc__   s	      xr   N)r   r   r	   r]   r   r&   r
   r   r   r   r      s<        K    X [     r   r   r   r   r   s     r   test_class_property_overridez*PropertyTests.test_class_property_override   sJ    	  	  	  	  	  	  	  	  	H-----r   c                     t                      }dD ]G}|                     t          d| d          5   |j        dg|z    d d d            n# 1 swxY w Y   Hd S )N)r   r3      z3^__set_name__\(\) takes 2 positional arguments but z were given$r   )r&   assertRaisesRegex	TypeError__set_name__)r   r   r   s      r   %test_property_set_name_incorrect_argsz3PropertyTests.test_property_set_name_incorrect_args   s    JJ 	+ 	+A''VqVVV  + + !q**	+ + + + + + + + + + + + + + +	+ 	+s   AA	A	c                      G d dt                     } G d d          }t                               |          }|                    |d           |                    d           }d S )Nc                       e Zd Zd ZdS )EPropertyTests.test_property_setname_on_property_subclass.<locals>.proc                     dS )Nabcdefr
   )typargskwargss      r   __new__zMPropertyTests.test_property_setname_on_property_subclass.<locals>.pro.__new__   s    xr   N)r   r   r	   r   r
   r   r   pror      s#                 r   r   c                       e Zd ZdS )CPropertyTests.test_property_setname_on_property_subclass.<locals>.ANr   r
   r   r   r   r      s        Dr   r   r3   c                     dS Nr3   r
   r   s    r   <lambda>zJPropertyTests.test_property_setname_on_property_subclass.<locals>.<lambda>   s    1 r   )r&   r   r   r0   )r   r   r   r   nps        r   *test_property_setname_on_property_subclassz8PropertyTests.test_property_setname_on_property_subclass   s    	  	  	  	  	 ( 	  	  	 	 	 	 	 	 	 	 	 S!!	q!XXnn%%r   N)r   r   r	   rQ   rX   unittestskipIfr   flagsoptimizer^   r`   rb   rf   r   r   r   r   refcount_testr   r   r   r   r   r
   r   r   rG   rG   P   sU       ) ) )= = = X_SY'1,@B BH HB BH X_SY'1,@B BJ JB BJG G G X_SY'1,@B BL LB BL' ' '. X_SY'1,@B B0 0B B0 X_SY'1,@B B= =B B= N N N X_SY'1,@B B5 5B B5 X_SY'1,@B B. .B B.+ + +& & & & &r   rG   c                       e Zd ZdZdS )PropertySubzThis is a subclass of propertyN)r   r   r	   r]   r
   r   r   r   r      s        ((((r   r   c                       e Zd ZdZdZdS )PropertySubSlotsz5This is a subclass of property that defines __slots__r
   N)r   r   r	   r]   	__slots__r
   r   r   r   r      s        ??IIIr   r   c                      e Zd Zd Z ej        ej        j        dk    d          d             Z	 ej        ej        j        dk    d          d             Z
 ej        ej        j        dk    d          d             ZdS )PropertySubclassTestsc                 j    	  G d dt                     }t          d          # t          $ r Y d S w xY w)Nc                   $    e Zd Zed             ZdS )FPropertySubclassTests.test_slots_docstring_copy_exception.<locals>.Fooc                     dS )z5Trying to copy this docstring will raise an exceptionr3   r
   r   s    r   r   zKPropertySubclassTests.test_slots_docstring_copy_exception.<locals>.Foo.spam   s	     1r   N)r   r   r	   r   r   r
   r   r   Foor      s.        !  "!  r   r   zAttributeError not raised)r|   	ExceptionAttributeErrorr   r   s     r   #test_slots_docstring_copy_exceptionz9PropertySubclassTests.test_slots_docstring_copy_exception   sf    		9    f    7888  	 	 	DD	s   $ 
22rY   rZ   c                 l     G d dt                     }|                     |j        j        d           d S )Nc                   $    e Zd Zed             ZdS )6PropertySubclassTests.test_docstring_copy.<locals>.Fooc                     dS )!spam wrapped in property subclassr3   r
   r   s    r   r   z;PropertySubclassTests.test_docstring_copy.<locals>.Foo.spam  	     qr   Nr   r   r	   r   r   r
   r   r   r   r     -          [  r   r   r   r|   rK   r   r]   r   s     r   test_docstring_copyz)PropertySubclassTests.test_docstring_copy  s[    	 	 	 	 	& 	 	 	
 	H/	1 	1 	1 	1 	1r   c                     G d dt                                  }|                     |j        d           d|_        |                     |j        d           |                     j        j        d            G fdd          } |            }|                     |j        d           d|_        |                     |j        d	           |                     |j        j        d           d S )
Nc                   J    e Zd Zd Zed             Zej        d             ZdS )OPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Fooc                     d| _         d S r   r   r   s    r   r   zXPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Foo.__init__  s    Q


r   c                     | j         S )r   r   r   s    r   r   zTPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Foo.spam  s     z!r   c                     || _         dS )zthis docstring is ignoredNr   r#   s     r   r   zTPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Foo.spam  s     #


r   N)r   r   r	   r   r   r   r'   r
   r   r   r   r     sS        ..." " [" [# # [# # #r   r   r3   rY   r   c                   :    e Zd Z j        j        d             ZdS )RPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.FooSubc                     d| _         dS )zanother ignored docstringr   Nr   r#   s     r   r   zWPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.FooSub.spam"  s     $


r   N)r   r   r	   r   r'   )r   s   r   FooSubr   !  s2        X_$ $ _$ $ $r   r      r   r   )r   rm   r   foosubr   s       @r   ,test_property_setter_copies_getter_docstringzBPropertySubclassTests.test_property_setter_copies_getter_docstring  s9   		# 		# 		# 		# 		#& 		# 		# 		# cee1%%%1%%%H/	1 	1 	1	$ 	$ 	$ 	$ 	$ 	$ 	$S 	$ 	$ 	$
 a(((f---K/	1 	1 	1 	1 	1r   c                      G d dt                     }|                     |j        j        d            G d dt                      G fdd          }|                     |j        j        d           d S )Nc                   D    e Zd Zed             Zej        d             ZdS )IPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Fooc                     dS za docstringr3   r
   r   s    r   r   zNPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo.spam3  r   r   c                     dS a new docstringrY   r
   r   s    r   r   zNPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo.spam7  r   r   N)r   r   r	   r   r   r0   r
   r   r   r   r   2  sJ          [ [  [  r   r   r   c                   $    e Zd Zed             ZdS )MPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.FooBasec                     dS r   r
   r   s    r   r   zRPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.FooBase.spam=  r   r   Nr   r
   r   r   FooBaser   <  r   r   r   c                   :    e Zd Z j        j        d             ZdS )JPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2c                     dS r   r
   r   s    r   r   zOPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2.spamB  r   r   N)r   r   r	   r   r0   )r   s   r   Foo2r   A  s4        \   !   r   r  r   )r   r   r  r   s      @r   &test_property_new_getter_new_docstringz<PropertySubclassTests.test_property_new_getter_new_docstring.  s    	 	 	 	 	& 	 	 	 	)+<===	 	 	 	 	f 	 	 	
	 	 	 	 	 	 	7 	 	 	
 	)+<=====r   N)r   r   r	   r   r   r   r   r   r   r   r   r  r
   r   r   r   r      s        
9 
9 
9 X_SY'1,@B B1 1B B1 X_SY'1,@B B1 1B B1> X_SY'1,@B B> >B B> > >r   r   c                   H    e Zd ZdZdZdZd Zed             Zd Z	d Z
d ZdS )_PropertyUnreachableAttributeNc                 6    | j                             |          S r"   )
msg_formatformat)r   msgs     r   _format_exc_msgz-_PropertyUnreachableAttribute._format_exc_msgN  s    %%c***r   c                 8    |                                  | _        d S r"   )r   objr   s    r   
setUpClassz(_PropertyUnreachableAttribute.setUpClassQ  s    ''))r   c                     |                      t          |                     d                    5  | j        j         d d d            d S # 1 swxY w Y   d S )Nzhas no getterr   r   r	  r  rm   r   s    r   test_get_propertyz/_PropertyUnreachableAttribute.test_get_propertyU  s    ##ND4H4H4Y4YZZ 	 	HLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   A		AAc                     |                      t          |                     d                    5  d | j        _        d d d            d S # 1 swxY w Y   d S )Nzhas no setterr  r   s    r   test_set_propertyz/_PropertyUnreachableAttribute.test_set_propertyY  s    ##ND4H4H4Y4YZZ 	  	 DHL	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 r  c                     |                      t          |                     d                    5  | j        `d d d            d S # 1 swxY w Y   d S )Nzhas no deleterr  r   s    r   test_del_propertyz/_PropertyUnreachableAttribute.test_del_property]  s    ##ND4H4HIY4Z4Z[[ 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAA)r   r   r	   r  r  r   r	  r   r  r  r  r  r
   r   r   r  r  I  sz        J
C
C+ + +   [           r   r  c                   ,    e Zd ZdZ G d d          ZdS )$PropertyUnreachableAttributeWithNamezI^property 'foo' of 'PropertyUnreachableAttributeWithName\.cls' object {}$c                   "    e Zd Z e            ZdS )(PropertyUnreachableAttributeWithName.clsN)r   r   r	   r&   rm   r
   r   r   r   r  e  s        hjjr   r   N)r   r   r	   r  r   r
   r   r   r  r  b  sA        ]J         r   r  c                   J    e Zd ZdZ G d d          Z e            e_        dS )"PropertyUnreachableAttributeNoNamezA^property of 'PropertyUnreachableAttributeNoName\.cls' object {}$c                       e Zd ZdS )&PropertyUnreachableAttributeNoName.clsNr   r
   r   r   r   r  l  s        r   r   N)r   r   r	   r  r   r&   rm   r
   r   r   r  r  i  sJ        UJ        hjjCGGGr   r  __main__)r   r   testr   r   r   r   r   r   r|   r   r*   r2   r:   r=   rB   TestCaserG   r&   r   r   r   r  r  r  r   mainr
   r   r   <module>r!     s=   


       	 	 	 	 	9 	 	 		 	 	 	 	, 	 	 		 	 	 	 	, 	 	 		 	 	 	 	, 	 	 	       "& & & & &y & & &5 5 5 5 5f 5 5 5    _       9          Y& Y& Y& Y& Y&H% Y& Y& Y&x) ) ) ) )( ) ) )    x   S> S> S> S> S>H- S> S> S>l       2    +H(J[       )FHY    zHMOOOOO r   