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 Nr   r   r   r   r	   spam   s    zBaseClass.spamc                 C   s
   || _ d S r   r   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 r   )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 r   r   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 r   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 Nr   r   r   r   r   r	   r   G   s    zPropertyNewGetter.spamc                 C   s   dS )N   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 )NzSubClass.getter)r   r,   	__class__r   __doc__r5   r   r   r	   $test_property_decorator_subclass_docg   s    z2PropertyTests.test_property_decorator_subclass_docc                 C   s   t  }| |jjjd d S )NzBaseClass.getter)r   r,   r:   r   r;   r/   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   r0   r6   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   znew docstringr(   )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   rC   __isabstractmethod__r   r   )valr   r	   C   s   rH   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   rJ   __len__r   r   r   r	   NotBool   s   rL   c                       s$   e Zd Zdd Z  e_eeZdS )rB   c                 S   s   d S r   r   r   r   r   r	   rC      s    rD   NrE   r   )rL   r   r	   rH      s   )objectZassertIsrC   rF   boolr2   rI   )r   rH   r   )rL   rG   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 N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   rT   ZEggsZSpam)rM   r,   r:   r   r;   )r   rT   r6   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   rV   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eedd ZdS )z5PropertyTests.test_class_property_override.<locals>.Ac                 S   s   dS )NSecondr   r_   r   r   r	   r;      s    z=PropertyTests.test_class_property_override.<locals>.A.__doc__Nra   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   r1   r7   unittestskipIfr[   flagsoptimizer<   r=   r>   r?   rO   rQ   rU   r   Zrefcount_testr^   rf   rh   r   r   r   r	   r)   P   sD   






r)   c                   @   s   e Zd ZdS )PropertySubNr   r   r   r   r	   rm      s   rm   c                   @   s   e Zd ZdZdS )PropertySubSlotsr   N)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 r'   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)rM   AttributeError	Exceptionr   rq   r   r   r	   #test_slots_docstring_copy_exception   s
    z9PropertySubclassTests.test_slots_docstring_copy_exceptionr8   r9   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 r'   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   !spam wrapped in property subclassrM   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 r'   r   r   r   r   r	   r          zXPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Foo.__init__c                 S   s   | j S r   r   r   r   r   r	   r      s    zTPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.Foo.spamc                 S   s
   || _ d S r   r   r   r   r   r	   r      s    N)r   r   r   r   rm   r   r   r   r   r   r	   rq      s
   
rq   r   r8   rw   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 rR   r   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|      rS   rx   )r   rC   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 r'   r   r   r   r   r	   r     s    zNPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo.spamc                 S   s   dS Nr8   r   r   r   r   r	   r     s    N)r   r   r   rm   r   r   r   r   r   r	   rq     s   
rq   za new docstringc                   @   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.spamNrv   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   rM   r   r   r   r$   r%   r&   ZTestCaser)   r   rm   rn   rp   r   mainr   r   r   r	   <module>   s&   
 W
