o
    HXhi-                     @   sN  d dl Z d dlZd dlmZ G dd deZG dd deZG dd deZG d	d
 d
eZG dd de	Z
G dd de
ZG dd de	ZG dd deZG dd de
ZG dd de	ZG dd dejZG dd deZG dd deZG dd dejZG dd  d ZG d!d" d"eejZG d#d$ d$eejZed%kre  dS dS )&    N)supportc                   @      e Zd ZdS )PropertyBaseN__name__
__module____qualname__ r	   r	   </opt/python-3.10.19/usr/lib/python3.10/test/test_property.pyr          r   c                   @   r   )PropertyGetNr   r	   r	   r	   r
   r      r   r   c                   @   r   )PropertySetNr   r	   r	   r	   r
   r      r   r   c                   @   r   )PropertyDelNr   r	   r	   r	   r
   r      r   r   c                   @   s<   e Zd Zdd Zedd Zejdd Zejdd ZdS )	BaseClassc                 C   
   d| _ d S )N   _spamselfr	   r	   r
   __init__   s   
zBaseClass.__init__c                 C      | j S )BaseClass.getterr   r   r	   r	   r
   spam      zBaseClass.spamc                 C   s
   || _ d S Nr   r   valuer	   r	   r
   r         
c                 C   s   | ` d S r   r   r   r	   r	   r
   r   !   s   N)r   r   r   r   propertyr   setterdeleterr	   r	   r	   r
   r      s    

r   c                   @   s8   e Zd Zejjdd Zejdd Zejdd ZdS )SubClassc                 C   
   t | j)SubClass.getter)r   r   r   r	   r	   r
   r   '      
zSubClass.spamc                 C   r#   r   )r   r   r   r	   r	   r
   r   ,   r   c                 C   r#   r   )r   r   r   r	   r	   r
   r   0   r   N)r   r   r   r   r   getterr    r!   r	   r	   r	   r
   r"   %   s    

r"   c                   @   s$   e Zd ZdZdd ZeeddZdS )PropertyDocBase   c                 C   r   r   r   r   r	   r	   r
   	_get_spam6      zPropertyDocBase._get_spamspam spam spamdocN)r   r   r   r   r)   r   r   r	   r	   r	   r
   r'   4   s    r'   c                   @      e Zd Zejjdd ZdS )PropertyDocSubc                 C   r   )z*The decorator does not use this doc stringr   r   r	   r	   r
   r   ;   r   zPropertyDocSub.spamN)r   r   r   r'   r   r&   r	   r	   r	   r
   r/   :       r/   c                   @   r.   )PropertySubNewGetterc                 C      dS )new docstringr   r	   r   r	   r	   r
   r   A      zPropertySubNewGetter.spamN)r   r   r   r   r   r&   r	   r	   r	   r
   r1   @   r0   r1   c                   @   &   e Zd Zedd Zejdd ZdS )PropertyNewGetterc                 C   r2   )zoriginal docstringr(   r	   r   r	   r	   r
   r   G   r4   zPropertyNewGetter.spamc                 C   r2   )r3      r	   r   r	   r	   r
   r   K   r4   N)r   r   r   r   r   r&   r	   r	   r	   r
   r6   F   
    
r6   c                   @   s  e Zd Zdd Zdd Zeejj	dkddd Z
eejj	dkdd	d
 Zdd Zeejj	dkddd Zdd Zeejj	dkddd Zeejj	dkddd Zejdd Zeejj	dkddd Zeejj	dkddd Zdd Zdd ZdS ) PropertyTestsc                 C   s   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   delattrZ
assertTruehasattrr   baser	   r	   r
   !test_property_decorator_baseclassQ   s   
z/PropertyTests.test_property_decorator_baseclassc                 C   s<   t  }| tt|d | tt|dd  | tt|d d S )Nr   )r"   assertRaisesr   getattrr   setattrr   r=   r   subr	   r	   r
    test_property_decorator_subclass`   s   z.PropertyTests.test_property_decorator_subclass   )Docstrings are omitted with -O2 and abovec                 C      t  }| |jjjd d S )Nr$   )r"   r<   	__class__r   __doc__rE   r	   r	   r
   $test_property_decorator_subclass_docg      z2PropertyTests.test_property_decorator_subclass_docc                 C   rJ   )Nr   )r   r<   rK   r   rL   r?   r	   r	   r
   %test_property_decorator_baseclass_docm   rN   z3PropertyTests.test_property_decorator_baseclass_docc                 C   s4   t  }t }| |jjjd | |jjjd d S )Nr+   )r'   r/   r<   rK   r   rL   )r   r@   rF   r	   r	   r
   test_property_decorator_docs   s   z)PropertyTests.test_property_decorator_docc                 C   sP   t  }| |jd | |jjjd t }| |jd | |jjjd d S )Nr   r3   r7   )r1   r<   r   rK   rL   r6   )r   ZnewgettersubZ	newgetterr	   r	   r
   !test_property_getter_doc_overridey   s   z/PropertyTests.test_property_getter_doc_overridec                    s   ddg dgddfD ]G fdddt }| |jjt q	G dd	 d	t  | t G  fd
ddt }|jj W d    d S 1 sGw   Y  d S )NTFr(    1c                       s"   e Zd Zdd Z e_eeZdS )EPropertyTests.test_property___isabstractmethod__descriptor.<locals>.Cc                 S      d S r   r	   r   r	   r	   r
   foo      IPropertyTests.test_property___isabstractmethod__descriptor.<locals>.C.fooNr   r   r   rV   __isabstractmethod__r   r	   )valr	   r
   C   s    r\   c                   @   s   e Zd Zdd ZeZdS )zKPropertyTests.test_property___isabstractmethod__descriptor.<locals>.NotBoolc                 S   s   t  r   )
ValueErrorr   r	   r	   r
   __bool__   r*   zTPropertyTests.test_property___isabstractmethod__descriptor.<locals>.NotBool.__bool__N)r   r   r   r^   __len__r	   r	   r	   r
   NotBool   s    r`   c                       s$   e Zd Zdd Z  e_eeZdS )rT   c                 S   rU   r   r	   r   r	   r	   r
   rV      rW   rX   NrY   r	   )r`   r	   r
   r\      s    )objectZassertIsrV   rZ   boolrB   r]   )r   r\   r	   )r`   r[   r
   ,test_property___isabstractmethod__descriptor   s   
"z:PropertyTests.test_property___isabstractmethod__descriptorc                 C   s0   t dd}| |jd d|_| |jd d S )NZbasicr,   Zextended)r   r<   rL   )r   pr	   r	   r
   "test_property_builtin_doc_writable   s   
z0PropertyTests.test_property_builtin_doc_writablec                 C   sH   G dd dt }| }| |jjjd d|jj_| |jjjd d S )Nc                   @      e Zd Zedd ZdS )zOPropertyTests.test_property_decorator_doc_writable.<locals>.PropertyWritableDocc                 S   r2   )Eggseggsr	   r   r	   r	   r
   r      r4   zTPropertyTests.test_property_decorator_doc_writable.<locals>.PropertyWritableDoc.spamN)r   r   r   r   r   r	   r	   r	   r
   PropertyWritableDoc   s    ri   rg   ZSpam)ra   r<   rK   r   rL   )r   ri   rF   r	   r	   r
   $test_property_decorator_doc_writable   s
   
z2PropertyTests.test_property_decorator_doc_writablec                 C   sX   t td}tdddd}| }tdD ]
}|dddd q| j| | ddd	 d S )
Ngettotalrefcountfgetfsetfdelr-   d   r   r:   )Zdelta)r   Zget_attributesysr   ranger   ZassertAlmostEqual)r   rk   Z	fake_propZrefs_beforeir	   r	   r
   test_refleaks_in___init__   s   z'PropertyTests.test_refleaks_in___init__c                 C       G dd d}|  |jd d S )Nc                   @   s   e Zd Zeedd ZdS )z,PropertyTests.test_class_property.<locals>.Ac                 S   s
   d| j  S )NzA doc for %r)r   clsr	   r	   r
   rL      r%   z4PropertyTests.test_class_property.<locals>.A.__doc__N)r   r   r   classmethodr   rL   r	   r	   r	   r
   A   s    rx   zA doc for 'A'r<   rL   r   rx   r	   r	   r
   test_class_property   s   z!PropertyTests.test_class_propertyc                 C   rt   )Nc                   @   s    e Zd ZdZeedd ZdS )z5PropertyTests.test_class_property_override.<locals>.AZFirstc                 S   r2   )NSecondr	   ru   r	   r	   r
   rL      r4   z=PropertyTests.test_class_property_override.<locals>.A.__doc__N)r   r   r   rL   rw   r   r	   r	   r	   r
   rx      s
    rx   r|   ry   rz   r	   r	   r
   test_class_property_override   s   z*PropertyTests.test_class_property_overridec              	   C   sX   t  }dD ]$}| td| d |jdg|   W d    n1 s$w   Y  qd S )N)r   r(      z3^__set_name__\(\) takes 2 positional arguments but z were given$r   )r   assertRaisesRegex	TypeError__set_name__)r   rd   rr   r	   r	   r
   %test_property_set_name_incorrect_args   s   
z3PropertyTests.test_property_set_name_incorrect_argsc                 C   sF   G dd dt }G dd d}t |}||d |dd }d S )Nc                   @   s   e Zd Zdd ZdS )zEPropertyTests.test_property_setname_on_property_subclass.<locals>.proc                 _   r2   )NZabcdefr	   )typargskwargsr	   r	   r
   __new__   rW   zMPropertyTests.test_property_setname_on_property_subclass.<locals>.pro.__new__N)r   r   r   r   r	   r	   r	   r
   pro   s    r   c                   @   r   )zCPropertyTests.test_property_setname_on_property_subclass.<locals>.ANr   r	   r	   r	   r
   rx      r   rx   r(   c                 S   r2   Nr(   r	   r   r	   r	   r
   <lambda>   s    zJPropertyTests.test_property_setname_on_property_subclass.<locals>.<lambda>)r   r   r   r&   )r   r   rx   rd   Znpr	   r	   r
   *test_property_setname_on_property_subclass   s
   
z8PropertyTests.test_property_setname_on_property_subclassN)r   r   r   rA   rG   unittestskipIfrp   flagsoptimizerM   rO   rP   rQ   rc   re   rj   r   Zrefcount_testrs   r{   r}   r   r   r	   r	   r	   r
   r9   P   sJ    







	
r9   c                   @   s   e Zd ZdZdS )PropertySubzThis is a subclass of propertyN)r   r   r   rL   r	   r	   r	   r
   r      s    r   c                   @   s   e Zd ZdZdZdS )PropertySubSlotsz5This is a subclass of property that defines __slots__r	   N)r   r   r   rL   	__slots__r	   r	   r	   r
   r      s    r   c                   @   sh   e Zd Zdd Zeejjdkddd Z	eejjdkddd Z
eejjdkdd	d
 ZdS )PropertySubclassTestsc                 C   s0   zG dd dt }W td ty   Y d S w )Nc                   @   rf   )zFPropertySubclassTests.test_slots_docstring_copy_exception.<locals>.Fooc                 S   r2   )z5Trying to copy this docstring will raise an exceptionr(   r	   r   r	   r	   r
   r      r4   zKPropertySubclassTests.test_slots_docstring_copy_exception.<locals>.Foo.spamN)r   r   r   r   r   r	   r	   r	   r
   Foo       r   zAttributeError not raised)ra   AttributeError	Exceptionr   r   r	   r	   r
   #test_slots_docstring_copy_exception   s   z9PropertySubclassTests.test_slots_docstring_copy_exceptionrH   rI   c                 C   s$   G dd dt }| |jjd d S )Nc                   @   rf   )z6PropertySubclassTests.test_docstring_copy.<locals>.Fooc                 S   r2   )!spam wrapped in property subclassr(   r	   r   r	   r	   r
   r     r4   z;PropertySubclassTests.test_docstring_copy.<locals>.Foo.spamNr   r   r   r   r   r	   r	   r	   r
   r     r   r   r   ra   r<   r   rL   r   r	   r	   r
   test_docstring_copy  s
   z)PropertySubclassTests.test_docstring_copyc                    s   G dd dt    }| |jd d|_| |jd |  jjd G  fddd }| }| |jd d|_| |jd	 | |jjd d S )
Nc                   @   s.   e Zd Zdd Zedd Zejdd ZdS )zOPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Fooc                 S   r   r   r   r   r	   r	   r
   r     s   
 zXPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Foo.__init__c                 S   r   )r   r   r   r	   r	   r
   r     r   zTPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Foo.spamc                 S   s
   || _ dS )zthis docstring is ignoredNr   r   r	   r	   r
   r     r%   N)r   r   r   r   r   r   r    r	   r	   r	   r
   r     s    
r   r(   rH   r   c                          e Zd Z jjdd ZdS )zRPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.FooSubc                 S   s
   d| _ dS )zanother ignored docstringrh   Nr   r   r	   r	   r
   r   "  r%   zWPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.FooSub.spamN)r   r   r   r   r    r	   r   r	   r
   FooSub!  r0   r      rh   r   )r   rV   r   Zfoosubr	   r   r
   ,test_property_setter_copies_getter_docstring  s$   
zBPropertySubclassTests.test_property_setter_copies_getter_docstringc                    sX   G dd dt }| |jjd G dd dt  G  fddd }| |jjd d S )Nc                   @   r5   )zIPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Fooc                 S   r2   za docstringr(   r	   r   r	   r	   r
   r   3  r4   zNPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo.spamc                 S   r2   a new docstringrH   r	   r   r	   r	   r
   r   7  r4   N)r   r   r   r   r   r&   r	   r	   r	   r
   r   2  r8   r   r   c                   @   rf   )zMPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.FooBasec                 S   r2   r   r	   r   r	   r	   r
   r   =  r4   zRPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.FooBase.spamNr   r	   r	   r	   r
   FooBase<  r   r   c                       r   )zJPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2c                 S   r2   r   r	   r   r	   r	   r
   r   B  r4   zOPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2.spamN)r   r   r   r   r&   r	   r   r	   r
   Foo2A  r0   r   r   )r   r   r   r	   r   r
   &test_property_new_getter_new_docstring.  s
   	z<PropertySubclassTests.test_property_new_getter_new_docstringN)r   r   r   r   r   r   rp   r   r   r   r   r   r	   r	   r	   r
   r      s    


r   c                   @   sD   e Zd ZdZdZdZdd Zedd Zdd Z	dd	 Z
d
d ZdS )_PropertyUnreachableAttributeNc                 C   s   | j |S r   )
msg_formatformat)r   msgr	   r	   r
   _format_exc_msgN  s   z-_PropertyUnreachableAttribute._format_exc_msgc                 C   s   |   | _d S r   )rv   objru   r	   r	   r
   
setUpClassQ  s   z(_PropertyUnreachableAttribute.setUpClassc                 C   s@   |  t| d | jj W d    d S 1 sw   Y  d S )Nzunreadable attributer   r   r   r   rV   r   r	   r	   r
   test_get_propertyU     
"z/_PropertyUnreachableAttribute.test_get_propertyc                 C   s@   |  t| d d | j_W d    d S 1 sw   Y  d S )Nzcan't set attributer   r   r	   r	   r
   test_set_propertyY  r   z/_PropertyUnreachableAttribute.test_set_propertyc                 C   s>   |  t| d | j`W d    d S 1 sw   Y  d S )Nzcan't delete attributer   r   r	   r	   r
   test_del_property]  s   "z/_PropertyUnreachableAttribute.test_del_property)r   r   r   r   r   rv   r   rw   r   r   r   r   r	   r	   r	   r
   r   I  s    
r   c                   @   s   e Zd ZdZG dd dZdS )$PropertyUnreachableAttributeWithNamez
^{} 'foo'$c                   @   s   e Zd Ze ZdS )z(PropertyUnreachableAttributeWithName.clsN)r   r   r   r   rV   r	   r	   r	   r
   rv   e  s    
rv   N)r   r   r   r   rv   r	   r	   r	   r
   r   b  s    r   c                   @   s&   e Zd ZdZG dd dZe e_dS )"PropertyUnreachableAttributeNoNamez^{}$c                   @   r   )z&PropertyUnreachableAttributeNoName.clsNr   r	   r	   r	   r
   rv   l  r   rv   N)r   r   r   r   rv   r   rV   r	   r	   r	   r
   r   i  s    r   __main__)rp   r   testr   r   r   r   r   r   ra   r   r"   r'   r/   r1   r6   ZTestCaser9   r   r   r   r   r   r   r   r   mainr	   r	   r	   r
   <module>   s0   
 V	