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 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   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 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   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 r   r   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 r   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 Nr   r   r   r   r   r	   r   L   s    zPropertyNewGetter.spamc                 C   s   dS )N   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   r2   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   zSubClass.getter)r   r1   	__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   zBaseClass.getter)r   r1   r?   r   r@   r4   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#   r1   r?   r   r@   )r   r5   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   znew docstringr'   )r$   r1   r   r?   r   r@   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   rH   __isabstractmethod__r   r   )valr   r	   C   s   rM   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   rO   __len__r   r   r   r	   NotBool   s   rQ   c                       s$   e Zd Zdd Z  e_eeZdS )rG   c                 S   s   d S r   r   r   r   r   r	   rH      s    rI   NrJ   r   )rQ   r   r	   rM      s   )objectZassertIsr   rK   boolr7   rN   )r   rM   r   )rQ   rL   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   rU   c                   @   s   e Zd ZdS )z0PropertyTests.test_abstract_virtual.<locals>.AVPNr   r   r   r   r	   AVP   s   rV   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cyanrW   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   
rZ   rX   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   rW   r   r   r   r	   r)      s    z8PropertyTests.test_abstract_virtual.<locals>.Okay2.colorc                 S   s
   d| _ d S )NmagentarW   r   r   r   r	   r      s    z;PropertyTests.test_abstract_virtual.<locals>.Okay2.__init__NrY   r   r   r   r	   Okay2   s   
r\   r[   )r7   	TypeErrorr(   r-   AttributeErrorr)   r1   )r   rU   rV   rZ   r\   r   r   r	   test_abstract_virtual   s    $$z#PropertyTests.test_abstract_virtualN)r   r   r   r6   r<   unittestskipIfsysflagsoptimizerA   rB   rC   rD   rT   r_   r   r   r   r	   r.   a   s"   


r.   c                   @   s   e Zd ZdS )PropertySubNr   r   r   r   r	   re      s   re   c                   @   s   e Zd ZdZdS )PropertySubSlotsr   N)r   r   r   	__slots__r   r   r   r	   rf      s   rf   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 )PropertySubclassTestsr@   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 r&   r   r   r   r   r	   r      s    zKPropertySubclassTests.test_slots_docstring_copy_exception.<locals>.Foo.spam
N)r   r   r   rf   r   printr@   r   r   r   r	   Foo   s   
rk   zAttributeError not raised)rR   r^   	Exceptionr   rk   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 r&   r   r   r   r   r	   r      s    z;PropertySubclassTests.test_docstring_copy.<locals>.Foo.spamNr   r   r   re   r   r   r   r   r	   rk      s   rk   r   .spam wrapped in DynamicClassAttribute subclassrR   r1   r   r@   rm   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 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   re   r   r   r   r   r   r	   rk      s
   
rk   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 )Neggsr   r   r   r   r	   r     s    zWPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.FooSub.spamN)r   r   r   r   r   r   r   rk   r   r	   FooSub   s   
rv      rt   )rR   r1   r   r   r@   )r   rH   rv   Zfoosubr   ru   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 r&   r   r   r   r   r	   r     s    zNPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo.spamc                 S   s   dS Nr=   r   r   r   r   r	   r     s    N)r   r   r   re   r   r   r   r   r   r	   rk     s   
rk   r   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.spamNro   r   r   r   r	   FooBase  s   rz   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 ry   r   r   r   r   r	   r   #  s    zOPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2.spamN)r   r   r   r   r   r   r   rz   r   r	   Foo2!  s   
r|   rq   )r   rk   r|   r   r{   r	   &test_property_new_getter_new_docstring  s
    	z<PropertySubclassTests.test_property_new_getter_new_docstringN)r   r   r   r`   ra   r3   rf   rn   rb   rc   rd   rr   rx   r}   r   r   r   r	   rh      s    



 rh   __main__)r*   rb   r`   typesr   rl   r   r
   r   r   rR   r   r   r   r#   r$   r%   ABCMetar(   r-   ZTestCaser.   re   rf   rh   r   mainr   r   r   r	   <module>   s*   
g\
