a
    ze%                     @   s  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edkre  dS )     N)supportc                   @   s   e Zd ZdS )PropertyBaseN__name__
__module____qualname__ r   r   (/usr/lib/python3.9/test/test_property.pyr      s   r   c                   @   s   e Zd ZdS )PropertyGetNr   r   r   r   r	   r
      s   r
   c                   @   s   e Zd ZdS )PropertySetNr   r   r   r   r	   r      s   r   c                   @   s   e Zd ZdS )PropertyDelNr   r   r   r   r	   r      s   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   s
   d| _ d S )N   _spamselfr   r   r	   __init__   s    zBaseClass.__init__c                 C   s   | j S )BaseClass.getterr   r   r   r   r	   spam   s    zBaseClass.spamc                 C   s
   || _ d S Nr   r   valuer   r   r	   r      s    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   s   t | jdS )SubClass.getterN)r
   r   r   r   r   r	   r   '   s    zSubClass.spamc                 C   s   t | jd S r   )r   r   r   r   r   r	   r   ,   s    c                 C   s   t | jd S r   )r   r   r   r   r   r	   r   0   s    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   s   | j S r   r   r   r   r   r	   	_get_spam6   s    zPropertyDocBase._get_spamspam spam spamdocN)r   r   r   r   r!   r   r   r   r   r   r	   r   4   s   r   c                   @   s   e Zd Zejjdd ZdS )PropertyDocSubc                 C   s   | j S )z*The decorator does not use this doc stringr   r   r   r   r	   r   ;   s    zPropertyDocSub.spamN)r   r   r   r   r   r   r   r   r   r	   r%   :   s   r%   c                   @   s   e Zd Zejjdd ZdS )PropertySubNewGetterc                 C   s   dS )new docstringr   r   r   r   r   r	   r   A   s    zPropertySubNewGetter.spamN)r   r   r   r   r   r   r   r   r   r	   r&   @   s   r&   c                   @   s&   e Zd Zedd Zejdd ZdS )PropertyNewGetterc                 C   s   dS )zoriginal docstringr    r   r   r   r   r	   r   G   s    zPropertyNewGetter.spamc                 C   s   dS )r'      r   r   r   r   r	   r   K   s    N)r   r   r   r   r   r   r   r   r   r	   r(   F   s   
r(   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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   s   t  }| |jjjd d S )Nr   )r   r-   	__class__r   __doc__r6   r   r   r	   $test_property_decorator_subclass_docg   s    z2PropertyTests.test_property_decorator_subclass_docc                 C   s   t  }| |jjjd d S )Nr   )r   r-   r;   r   r<   r0   r   r   r	   %test_property_decorator_baseclass_docm   s    z3PropertyTests.test_property_decorator_baseclass_docc                 C   s4   t  }t }| |jjjd | |jjjd d S )Nr"   )r   r%   r-   r;   r   r<   )r   r1   r7   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   r'   r)   )r&   r-   r   r;   r<   r(   )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    n1 s0    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   s   d S r   r   r   r   r   r	   foo   s    IPropertyTests.test_property___isabstractmethod__descriptor.<locals>.C.fooNr   r   r   rD   __isabstractmethod__r   r   )valr   r	   C   s   rI   c                   @   s   e Zd Zdd ZeZdS )zKPropertyTests.test_property___isabstractmethod__descriptor.<locals>.NotBoolc                 S   s
   t  d S r   )
ValueErrorr   r   r   r	   __bool__   s    zTPropertyTests.test_property___isabstractmethod__descriptor.<locals>.NotBool.__bool__N)r   r   r   rK   __len__r   r   r   r	   NotBool   s   rM   c                       s$   e Zd Zdd Z  e_eeZdS )rC   c                 S   s   d S r   r   r   r   r   r	   rD      s    rE   NrF   r   )rM   r   r	   rI      s   )objectZassertIsrD   rG   boolr3   rJ   )r   rI   r   )rM   rH   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-   r<   )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                   @   s   e Zd Zedd ZdS )zOPropertyTests.test_property_decorator_doc_writable.<locals>.PropertyWritableDocc                 S   s   dS )Eggseggsr   r   r   r   r	   r      s    zTPropertyTests.test_property_decorator_doc_writable.<locals>.PropertyWritableDoc.spamN)r   r   r   r   r   r   r   r   r	   PropertyWritableDoc   s   rU   rS   ZSpam)rN   r-   r;   r   r<   )r   rU   r7   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   rW   Z	fake_propZrefs_beforeir   r   r	   test_refleaks_in___init__   s    z'PropertyTests.test_refleaks_in___init__c                 C   s    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	   r<      s    z4PropertyTests.test_class_property.<locals>.A.__doc__N)r   r   r   classmethodr   r<   r   r   r   r	   A   s   rc   zA doc for 'A'r-   r<   r   rc   r   r   r	   test_class_property   s    z!PropertyTests.test_class_propertyc                 C   s    G dd d}|  |jd d S )Nc                   @   s    e Zd ZdZeedd ZdS )z5PropertyTests.test_class_property_override.<locals>.AZFirstc                 S   s   dS )NSecondr   r`   r   r   r	   r<      s    z=PropertyTests.test_class_property_override.<locals>.A.__doc__N)r   r   r   r<   rb   r   r   r   r   r	   rc      s   rc   rg   rd   re   r   r   r	   test_class_property_override   s    z*PropertyTests.test_class_property_overrideN)r   r   r   r2   r8   unittestskipIfr\   flagsoptimizer=   r>   r?   r@   rP   rR   rV   r   Zrefcount_testr_   rf   rh   r   r   r   r	   r*   P   sD   






r*   c                   @   s   e Zd ZdZdS )PropertySubzThis is a subclass of propertyN)r   r   r   r<   r   r   r   r	   rm      s   rm   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   r<   	__slots__r   r   r   r	   rn      s   rn   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   s4   zG dd dt }W n ty&   Y n
0 tdd S )Nc                   @   s   e Zd Zedd ZdS )zFPropertySubclassTests.test_slots_docstring_copy_exception.<locals>.Fooc                 S   s   dS )z5Trying to copy this docstring will raise an exceptionr    r   r   r   r   r	   r      s    zKPropertySubclassTests.test_slots_docstring_copy_exception.<locals>.Foo.spamN)r   r   r   rn   r   r   r   r   r	   Foo   s   rq   zAttributeError not raised)rN   AttributeError	Exceptionr   rq   r   r   r	   #test_slots_docstring_copy_exception   s
    z9PropertySubclassTests.test_slots_docstring_copy_exceptionr9   r:   c                 C   s$   G dd dt }| |jjd d S )Nc                   @   s   e Zd Zedd ZdS )z6PropertySubclassTests.test_docstring_copy.<locals>.Fooc                 S   s   dS )!spam wrapped in property subclassr    r   r   r   r   r	   r      s    z;PropertySubclassTests.test_docstring_copy.<locals>.Foo.spamNr   r   r   rm   r   r   r   r   r	   rq      s   rq   rv   rN   r-   r   r<   rt   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   s
   d| _ d S )Nr    r   r   r   r   r	   r          zXPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Foo.__init__c                 S   s   | j S )rv   r   r   r   r   r	   r      s    zTPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Foo.spamc                 S   s
   || _ dS )zthis docstring is ignoredNr   r   r   r   r	   r      s    N)r   r   r   r   rm   r   r   r   r   r   r	   rq      s
   
rq   r    r9   rv   c                       s   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 docstringrT   Nr   r   r   r   r	   r     s    zWPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.FooSub.spamN)r   r   r   r   r   r   rq   r   r	   FooSub  s   r|      rT   rx   )r   rD   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                   @   s&   e Zd Zedd Zejdd ZdS )zIPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Fooc                 S   s   dS za docstringr    r   r   r   r   r	   r     s    zNPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo.spamc                 S   s   dS a new docstringr9   r   r   r   r   r	   r     s    N)r   r   r   rm   r   r   r   r   r   r	   rq     s   
rq   r   c                   @   s   e Zd Zedd ZdS )zMPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.FooBasec                 S   s   dS r   r   r   r   r   r	   r   "  s    zRPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.FooBase.spamNrw   r   r   r   r	   FooBase!  s   r   c                       s   e Zd Z jjdd ZdS )zJPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2c                 S   s   dS r   r   r   r   r   r	   r   '  s    zOPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2.spamN)r   r   r   r   r   r   r   r   r	   Foo2&  s   r   rx   )r   rq   r   r   r   r	   &test_property_new_getter_new_docstring  s
    	z<PropertySubclassTests.test_property_new_getter_new_docstringN)r   r   r   ru   ri   rj   r\   rk   rl   ry   r~   r   r   r   r   r	   rp      s   


rp   __main__)r\   ri   testr   rs   r   r
   r   r   rN   r   r   r   r%   r&   r(   ZTestCaser*   r   rm   rn   rp   r   mainr   r   r   r	   <module>   s&   
 W
