B
    u9aC&                 @   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   0/usr/lib/python3.7/test_dynamicclassattribute.pyr   	   s   r   c               @   s   e Zd ZdS )PropertyGetN)r   r   r   r   r   r   r   r	      s   r	   c               @   s   e Zd ZdS )PropertySetN)r   r   r   r   r   r   r   r
      s   r
   c               @   s   e Zd ZdS )PropertyDelN)r   r   r   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 )zBaseClass.getter)r   )r   r   r   r   spam   s    zBaseClass.spamc             C   s
   || _ d S )N)r   )r   valuer   r   r   r      s    c             C   s   | ` d S )N)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 )zSubClass.getterN)r	   r   )r   r   r   r   r   *   s    zSubClass.spamc             C   s   t | jd S )N)r
   r   )r   r   r   r   r   r   /   s    c             C   s   t | jd S )N)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 )N)r   )r   r   r   r   	_get_spam9   s    zPropertyDocBase._get_spamz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 string)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 )z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 )znew docstring   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 )Nr   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 )Nr   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   r*   )r   subr   r   r    test_property_decorator_subclassq   s    z.PropertyTests.test_property_decorator_subclass   z)Docstrings are omitted with -O2 and abovec             C   s    t  }| |jjd jd d S )Nr   zSubClass.getter)r   r)   	__class__r   __doc__)r   r1   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   r)   r4   r   r5   )r   r,   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   zspam spam spam)r   r   r)   r4   r   r5   )r   r,   r1   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   r)   r   r4   r   r5   r   )r   ZnewgettersubZ	newgetterr   r   r   !test_property_getter_doc_override   s    z/PropertyTests.test_property_getter_doc_overridec          	      s   xFddg dgddfD ]0G fdddt }| |jd jt qW G d	d
 d
t  | t G  fdddt }W d Q R X d S )NTFr    1c                   s"   e Zd Zdd Z e_eeZdS )zEPropertyTests.test_property___isabstractmethod__descriptor.<locals>.Cc             S   s   d S )Nr   )r   r   r   r   foo   s    zIPropertyTests.test_property___isabstractmethod__descriptor.<locals>.C.fooN)r   r   r   r<   __isabstractmethod__r   r   )valr   r   C   s   r?   r<   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 )N)
ValueError)r   r   r   r   __bool__   s    zTPropertyTests.test_property___isabstractmethod__descriptor.<locals>.NotBool.__bool__N)r   r   r   rA   __len__r   r   r   r   NotBool   s   rC   c                   s$   e Zd Zdd Z  e_eeZdS )zEPropertyTests.test_property___isabstractmethod__descriptor.<locals>.Cc             S   s   d S )Nr   )r   r   r   r   r<      s    zIPropertyTests.test_property___isabstractmethod__descriptor.<locals>.C.fooN)r   r   r   r<   r=   r   r   )rC   r   r   r?      s   )objectZassertIsr   r=   boolr.   r@   )r   r?   r   )rC   r>   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 Q R X | | jd G dd	 d	t}|  t |j W d Q R X | | jd
 d S )Nc               @   s   e Zd ZdS )z0PropertyTests.test_abstract_virtual.<locals>.APVN)r   r   r   r   r   r   r   APV   s   rG   c               @   s   e Zd ZdS )z0PropertyTests.test_abstract_virtual.<locals>.AVPN)r   r   r   r   r   r   r   AVP   s   rH   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 )N)_color)r   r   r   r   r!      s    z8PropertyTests.test_abstract_virtual.<locals>.Okay1.colorc             S   s
   d| _ d S )Ncyan)rI   )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   rK   rJ   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 )N)rI   )r   r   r   r   r!      s    z8PropertyTests.test_abstract_virtual.<locals>.Okay2.colorc             S   s
   d| _ d S )Nmagenta)rI   )r   r   r   r   r      s    z;PropertyTests.test_abstract_virtual.<locals>.Okay2.__init__N)r   r   r   r   r!   r   r   r   r   r   Okay2   s   rM   rL   )r.   	TypeErrorr    r%   AttributeErrorr!   r)   )r   rG   rH   rK   rM   r   r   r   test_abstract_virtual   s    z#PropertyTests.test_abstract_virtualN)r   r   r   r-   r2   unittestskipIfsysflagsoptimizer6   r7   r8   r9   rF   rP   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   r5   r   r   r   r   rV      s   rV   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   r5   	__slots__r   r   r   r   rW      s   rW   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 )PropertySubclassTestsr5   z9__doc__ is already present, __slots__ will have no effectc             C   s6   yG dd dt }W n tk
r(   Y n
X 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   rW   r   printr5   r   r   r   r   Foo   s   r\   zAttributeError not raised)rD   rO   	Exception)r   r\   r   r   r   #test_slots_docstring_copy_exception   s
    z9PropertySubclassTests.test_slots_docstring_copy_exceptionr3   z)Docstrings are omitted with -O2 and abovec             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 )z.spam wrapped in DynamicClassAttribute subclassr   r   )r   r   r   r   r      s    z;PropertySubclassTests.test_docstring_copy.<locals>.Foo.spamN)r   r   r   rV   r   r   r   r   r   r\      s   r\   r   z.spam wrapped in DynamicClassAttribute subclass)rD   r)   r   r5   )r   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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 )z.spam wrapped in DynamicClassAttribute subclass)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 ignoredN)r   )r   r   r   r   r   r      s    N)r   r   r   r   rV   r   r   r   r   r   r   r\      s   r\   r   r3   r   z.spam wrapped in DynamicClassAttribute subclassc                   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eggsN)r   )r   r   r   r   r   r     s    zWPropertySubclassTests.test_property_setter_copies_getter_docstring.<locals>.FooSub.spamN)r   r   r   r   r   r   r   )r\   r   r   FooSub   s   
rb      ra   )rD   r)   r   r   r5   )r   r<   rb   Zfoosubr   )r\   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 )za new docstringr3   r   )r   r   r   r   r     s    N)r   r   r   rV   r   r   r   r   r   r   r\     s   r\   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 )za docstringr   r   )r   r   r   r   r     s    zRPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.FooBase.spamN)r   r   r   rV   r   r   r   r   r   FooBase  s   re   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 )za new docstringr3   r   )r   r   r   r   r   #  s    zOPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2.spamN)r   r   r   r   r   r   r   )re   r   r   Foo2!  s   
rf   )rD   r)   r   r5   )r   r\   rf   r   )re   r   &test_property_new_getter_new_docstring  s
    	z<PropertySubclassTests.test_property_new_getter_new_docstringN)r   r   r   rQ   rR   r+   rW   r^   rS   rT   rU   r_   rd   rg   r   r   r   r   rY      s   !rY   __main__)r"   rS   rQ   typesr   r]   r   r	   r
   r   rD   r   r   r   r   r   r   ABCMetar    r%   ZTestCaser&   rV   rW   rY   r   mainr   r   r   r   <module>   s*   
g\
