a
    zeC&                     @   sF  d dl Z 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dZG dd de jd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rBe  dS )%    N)DynamicClassAttributec                   @   s   e Zd ZdS )PropertyBaseN__name__
__module____qualname__ r   r   5/usr/lib/python3.9/test/test_dynamicclassattribute.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   r   r   setterdeleterr   r   r   r	   r      s   

r   c                   @   s@   e Zd Zejd Zejdd Zejdd Zejdd ZdS )SubClassr   c                 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   3   s    N)	r   r   r   r   __dict__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_spam9   s    zPropertyDocBase._get_spamspam spam spam)docN)r   r   r   r   r!   r   r   r   r   r   r	   r   7   s   r   c                   @   s$   e Zd Zejd Zejdd ZdS )PropertyDocSubr   c                 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	   r$   =   s   
r$   c                   @   s$   e Zd Zejd Zejdd ZdS )PropertySubNewGetterr   c                 C   s   dS )new docstringr   r   r   r   r   r	   r   F   s    zPropertySubNewGetter.spamN)r   r   r   r   r   r   r   r   r   r   r	   r%   D   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   L   s    zPropertyNewGetter.spamc                 C   s   dS )r&      r   r   r   r   r	   r   P   s    N)r   r   r   r   r   r   r   r   r   r	   r'   K   s   
r'   c                   @   s   e Zd Zeejdd ZdS ) ClassWithAbstractVirtualPropertyc                   C   s   d S r   r   r   r   r   r	   colorV   s    z&ClassWithAbstractVirtualProperty.colorN)r   r   r   r   abcabstractmethodr*   r   r   r   r	   r)   U   s   r)   )	metaclassc                   @   s   e Zd Zejedd ZdS ) ClassWithPropertyAbstractVirtualc                   C   s   d S r   r   r   r   r   r	   r*   \   s    z&ClassWithPropertyAbstractVirtual.colorN)r   r   r   r+   r,   r   r*   r   r   r   r	   r.   [   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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_baseclassb   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   r3   r   subr   r   r	    test_property_decorator_subclassq   s    z.PropertyTests.test_property_decorator_subclass   )Docstrings are omitted with -O2 and abovec                 C   s    t  }| |jjd jd d S )Nr   r   )r   r2   	__class__r   __doc__r;   r   r   r	   $test_property_decorator_subclass_docx   s    z2PropertyTests.test_property_decorator_subclass_docc                 C   s    t  }| |jjd jd d S )Nr   r   )r   r2   r@   r   rA   r5   r   r   r	   %test_property_decorator_baseclass_doc~   s    z3PropertyTests.test_property_decorator_baseclass_docc                 C   s<   t  }t }| |jjd jd | |jjd jd d S )Nr   r"   )r   r$   r2   r@   r   rA   )r   r6   r<   r   r   r	   test_property_decorator_doc   s    z)PropertyTests.test_property_decorator_docc                 C   sX   t  }| |jd | |jjd jd t }| |jd | |jjd jd d S )Nr   r   r&   r(   )r%   r2   r   r@   r   rA   r'   )r   ZnewgettersubZ	newgetterr   r   r	   !test_property_getter_doc_override   s    z/PropertyTests.test_property_getter_doc_overridec                    s   ddg dgddfD ]0G fdddt }| |jd jt qG d	d
 d
t  | t$ G  fdddt }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   rI   __isabstractmethod__r   r   )valr   r	   C   s   rN   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   rP   __len__r   r   r   r	   NotBool   s   rR   c                       s$   e Zd Zdd Z  e_eeZdS )rH   c                 S   s   d S r   r   r   r   r   r	   rI      s    rJ   NrK   r   )rR   r   r	   rN      s   )objectZassertIsr   rL   boolr8   rO   )r   rN   r   )rR   rM   r	   ,test_property___isabstractmethod__descriptor   s    z:PropertyTests.test_property___isabstractmethod__descriptorc                 C   s   |  tt |  tt G dd dt}|  t| G dd dt}|  t| G dd dt}|  t |j W d    n1 s0    Y  | | jd G dd	 d	t}|  t |j W d    n1 s0    Y  | | jd
 d S )Nc                   @   s   e Zd ZdS )z0PropertyTests.test_abstract_virtual.<locals>.APVNr   r   r   r   r	   APV   s   rV   c                   @   s   e Zd ZdS )z0PropertyTests.test_abstract_virtual.<locals>.AVPNr   r   r   r   r	   AVP   s   rW   c                   @   s    e Zd Zedd Zdd ZdS )z2PropertyTests.test_abstract_virtual.<locals>.Okay1c                 S   s   | j S r   Z_colorr   r   r   r	   r*      s    z8PropertyTests.test_abstract_virtual.<locals>.Okay1.colorc                 S   s
   d| _ d S )NcyanrX   r   r   r   r	   r      s    z;PropertyTests.test_abstract_virtual.<locals>.Okay1.__init__Nr   r   r   r   r*   r   r   r   r   r	   Okay1   s   
r[   rY   c                   @   s    e Zd Zedd Zdd ZdS )z2PropertyTests.test_abstract_virtual.<locals>.Okay2c                 S   s   | j S r   rX   r   r   r   r	   r*      s    z8PropertyTests.test_abstract_virtual.<locals>.Okay2.colorc                 S   s
   d| _ d S )NmagentarX   r   r   r   r	   r      s    z;PropertyTests.test_abstract_virtual.<locals>.Okay2.__init__NrZ   r   r   r   r	   Okay2   s   
r]   r\   )r8   	TypeErrorr)   r.   AttributeErrorr*   r2   )r   rV   rW   r[   r]   r   r   r	   test_abstract_virtual   s    $$z#PropertyTests.test_abstract_virtualN)r   r   r   r7   r=   unittestskipIfsysflagsoptimizerB   rC   rD   rE   rU   r`   r   r   r   r	   r/   a   s"   


r/   c                   @   s   e Zd ZdZdS )PropertySubz+This is a subclass of DynamicClassAttributeN)r   r   r   rA   r   r   r   r	   rf      s   rf   c                   @   s   e Zd ZdZdZdS )PropertySubSlotszBThis is a subclass of DynamicClassAttribute that defines __slots__r   N)r   r   r   rA   	__slots__r   r   r   r	   rg      s   rg   c                   @   sz   e Zd Zeeedd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 )PropertySubclassTestsrA   z9__doc__ is already present, __slots__ will have no effectc                 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edej 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.spam
N)r   r   r   rg   r   printrA   r   r   r   r	   Foo   s   
rl   zAttributeError not raised)rS   r_   	Exceptionr   rl   r   r   r	   #test_slots_docstring_copy_exception   s
    z9PropertySubclassTests.test_slots_docstring_copy_exceptionr>   r?   c                 C   s(   G dd dt }| |jd 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 DynamicClassAttribute subclassr    r   r   r   r   r	   r      s    z;PropertySubclassTests.test_docstring_copy.<locals>.Foo.spamNr   r   r   rf   r   r   r   r   r	   rl      s   rl   r   rp   rS   r2   r   rA   rn   r   r   r	   test_docstring_copy   s
    
z)PropertySubclassTests.test_docstring_copyc                    s   G dd dt    }| |jd d|_| |jd |  jd jd G  fddd }| }| |jd d	|_| |jd
 | |jd 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 )rp   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   rf   r   r   r   r   r   r	   rl      s
   
rl   r    r>   r   rp   c                       s$   e Zd Z jd Zejdd ZdS )zRPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.FooSubr   c                 S   s
   d| _ dS )zanother ignored docstringeggsNr   r   r   r   r	   r     s    zWPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.FooSub.spamN)r   r   r   r   r   r   r   rl   r   r	   FooSub   s   
rw      ru   )rS   r2   r   r   rA   )r   rI   rw   Zfoosubr   rv   r	   ,test_property_setter_copies_getter_docstring   s$    


zBPropertySubclassTests.test_property_setter_copies_getter_docstringc                    s`   G dd dt }| |jd jd G dd dt  G  fddd }| |jd 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 docstringr>   r   r   r   r   r	   r     s    N)r   r   r   rf   r   r   r   r   r   r	   rl     s   
rl   r   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 rz   r   r   r   r   r	   r     s    zRPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.FooBase.spamNrq   r   r   r   r	   FooBase  s   r}   c                       s$   e Zd Z jd Zejdd ZdS )zJPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2r   c                 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   r	   Foo2!  s   
r   rr   )r   rl   r   r   r~   r	   &test_property_new_getter_new_docstring  s
    	z<PropertySubclassTests.test_property_new_getter_new_docstringN)r   r   r   ra   rb   r4   rg   ro   rc   rd   re   rs   ry   r   r   r   r   r	   ri      s    



 ri   __main__)r+   rc   ra   typesr   rm   r   r
   r   r   rS   r   r   r   r$   r%   r'   ABCMetar)   r.   ZTestCaser/   rf   rg   ri   r   mainr   r   r   r	   <module>   s*   
g\
