B
    18\#                 @   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   V/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/test_property.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   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 )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   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 )N)r   )r   r   r   r   	_get_spam6   s    zPropertyDocBase._get_spamz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 string)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 )z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 )znew docstring   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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   delattr
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   z)Docstrings are omitted with -O2 and abovec             C   s   t  }| |jjjd d S )NzSubClass.getter)r   r#   	__class__r   __doc__)r   r,   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   r0   )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 )Nzspam spam spam)r   r   r#   r/   r   r0   )r   r'   r,   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/   r0   r   )r   ZnewgettersubZ	newgetterr   r   r   !test_property_getter_doc_overridey   s    z/PropertyTests.test_property_getter_doc_overridec          	      s   xBddg dgddfD ],G fdddt }| |jjt qW G dd	 d	t  | t" G  fd
ddt }|jj 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   r7   __isabstractmethod__r   r   )valr   r   C   s   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   r<   __len__r   r   r   r   NotBool   s   r>   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   r7      s    zIPropertyTests.test_property___isabstractmethod__descriptor.<locals>.C.fooN)r   r   r   r7   r8   r   r   )r>   r   r   r:      s   )objectassertIsr7   r8   boolr)   r;   )r   r:   r   )r>   r9   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basic)r   Zextended)r   r#   r0   )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   rG   rE   ZSpam)r?   r#   r/   r   r0   )r   rG   r,   r   r   r   $test_property_decorator_doc_writable   s
    
z2PropertyTests.test_property_decorator_doc_writablec             C   s\   t td}tdddd}| }x tdD ]}|dddd q*W | j| | ddd	 d S )
Ngettotalrefcountfgetfsetfdelr   d   r   r!   )delta)r   get_attributesysr   ranger   assertAlmostEqual)r   rI   Z	fake_propZrefs_beforeir   r   r   test_refleaks_in___init__   s    z'PropertyTests.test_refleaks_in___init__N)r   r   r   r(   r-   unittestskipIfrP   flagsoptimizer1   r2   r3   r4   rB   rD   rH   r   refcount_testrT   r   r   r   r   r    P   s   	r    c               @   s   e Zd ZdZdS )PropertySubzThis is a subclass of propertyN)r   r   r   r0   r   r   r   r   rZ      s   rZ   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   r0   	__slots__r   r   r   r   r[      s   r[   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   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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   r[   r   r   r   r   r   Foo   s   r^   zAttributeError not raised)r?   AttributeError	Exception)r   r^   r   r   r   #test_slots_docstring_copy_exception   s
    z9PropertySubclassTests.test_slots_docstring_copy_exceptionr.   z)Docstrings are omitted with -O2 and abovec             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 )z!spam wrapped in property subclassr   r   )r   r   r   r   r      s    z;PropertySubclassTests.test_docstring_copy.<locals>.Foo.spamN)r   r   r   rZ   r   r   r   r   r   r^      s   r^   z!spam wrapped in property subclass)r?   r#   r   r0   )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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 )z!spam wrapped in property 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   rZ   r   r   r   r   r   r   r^      s   r^   r   r.   z!spam wrapped in property subclassc                   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 docstringrF   N)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   FooSub   s   rd      rF   )r?   r#   r   r0   )r   r7   rd   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 )za new docstringr.   r   )r   r   r   r   r     s    N)r   r   r   rZ   r   r   r   r   r   r   r^     s   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   rZ   r   r   r   r   r   FooBase  s   rg   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 )za new docstringr.   r   )r   r   r   r   r     s    zOPropertySubclassTests.test_property_new_getter_new_docstring.<locals>.Foo2.spamN)r   r   r   r   r   r   )rg   r   r   Foo2  s   rh   )r?   r#   r   r0   )r   r^   rh   r   )rg   r   &test_property_new_getter_new_docstring   s
    	z<PropertySubclassTests.test_property_new_getter_new_docstringN)r   r   r   ra   rU   rV   rP   rW   rX   rb   rf   ri   r   r   r   r   r]      s    r]   __main__)rP   rU   testr   r`   r   r	   r
   r   r?   r   r   r   r   r   r   TestCaser    r   rZ   r[   r]   r   mainr   r   r   r   <module>   s$   
lW
