B
    u9ay                  @   s6   d dl Z d dlZG dd dejZedkr2e  dS )    Nc               @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#S )$Testc             C   s:   G dd d}G dd d|}|  |j | |j d S )Nc                   s    e Zd ZdZ fddZ  ZS )z"Test.test_init_subclass.<locals>.AFc                s   t    d| _d S )NT)super__init_subclass__initialized)cls)	__class__ '/usr/lib/python3.7/test_subclassinit.pyr   
   s    
z4Test.test_init_subclass.<locals>.A.__init_subclass__)__name__
__module____qualname__r   r   __classcell__r   r   )r   r	   A   s   r   c               @   s   e Zd ZdS )z"Test.test_init_subclass.<locals>.BN)r
   r   r   r   r   r   r	   B   s   r   )assertFalser   
assertTrue)selfr   r   r   r   r	   test_init_subclass   s    zTest.test_init_subclassc             C   s<   G dd dt }G dd d|}| |j | |j d S )Nc                   s    e Zd ZdZ fddZ  ZS )z'Test.test_init_subclass_dict.<locals>.AFc                s   t    d| _d S )NT)r   r   r   )r   )r   r   r	   r      s    
z9Test.test_init_subclass_dict.<locals>.A.__init_subclass__)r
   r   r   r   r   r   r   r   )r   r	   r      s   r   c               @   s   e Zd ZdS )z'Test.test_init_subclass_dict.<locals>.BN)r
   r   r   r   r   r   r	   r      s   r   )dictr   r   r   )r   r   r   r   r   r	   test_init_subclass_dict   s    zTest.test_init_subclass_dictc             C   s:   G dd d}G dd d|dd}|  |jtdd d S )Nc               @   s   e Zd Zdd ZdS )z)Test.test_init_subclass_kwargs.<locals>.Ac             [   s
   || _ d S )N)kwargs)r   r   r   r   r	   r   $   s    z;Test.test_init_subclass_kwargs.<locals>.A.__init_subclass__N)r
   r   r   r   r   r   r   r	   r   #   s   r   c               @   s   e Zd ZdS )z)Test.test_init_subclass_kwargs.<locals>.BN)r
   r   r   r   r   r   r	   r   '   s   r      )x)assertEqualr   r   )r   r   r   r   r   r	   test_init_subclass_kwargs"   s    zTest.test_init_subclass_kwargsc          	   C   s8   G dd d}|  t G dd d|}W d Q R X d S )Nc               @   s   e Zd Zdd ZdS )z(Test.test_init_subclass_error.<locals>.Ac             S   s   t d S )N)RuntimeError)r   r   r   r	   r   .   s    z:Test.test_init_subclass_error.<locals>.A.__init_subclass__N)r
   r   r   r   r   r   r   r	   r   -   s   r   c               @   s   e Zd ZdS )z(Test.test_init_subclass_error.<locals>.BN)r
   r   r   r   r   r   r	   r   2   s   r   )assertRaisesr   )r   r   r   r   r   r	   test_init_subclass_error,   s    zTest.test_init_subclass_errorc          	   C   s8   G dd d}|  t G dd d|}W d Q R X d S )Nc               @   s   e Zd Zdd ZdS )z(Test.test_init_subclass_wrong.<locals>.Ac             S   s   d S )Nr   )r   Zwhateverr   r   r	   r   7   s    z:Test.test_init_subclass_wrong.<locals>.A.__init_subclass__N)r
   r   r   r   r   r   r   r	   r   6   s   r   c               @   s   e Zd ZdS )z(Test.test_init_subclass_wrong.<locals>.BN)r
   r   r   r   r   r   r	   r   ;   s   r   )r   	TypeError)r   r   r   r   r   r	   test_init_subclass_wrong5   s    zTest.test_init_subclass_wrongc             C   sN   G dd d}G dd d|}G dd d|}|  |j| |  |j| d S )Nc                   s   e Zd Z fddZ  ZS )z5Test.test_init_subclass_skipped.<locals>.BaseWithInitc                s   t  jf | | | _d S )N)r   r   r   )r   r   )r   r   r	   r   @   s    zGTest.test_init_subclass_skipped.<locals>.BaseWithInit.__init_subclass__)r
   r   r   r   r   r   r   )r   r	   BaseWithInit?   s   r    c               @   s   e Zd ZdS )z8Test.test_init_subclass_skipped.<locals>.BaseWithoutInitN)r
   r   r   r   r   r   r	   BaseWithoutInitD   s   r!   c               @   s   e Zd ZdS )z*Test.test_init_subclass_skipped.<locals>.AN)r
   r   r   r   r   r   r	   r   G   s   r   )assertIsr   )r   r    r!   r   r   r   r	   test_init_subclass_skipped>   s
    zTest.test_init_subclass_skippedc             C   s   G dd d}G dd d|}G dd d}G dd d|}G d	d
 d
|||dd}|  |jddg |  |jg  |  |jg  d S )Nc                   s   e Zd Z fddZ  ZS )z-Test.test_init_subclass_diamond.<locals>.Basec                s   t  jf | g | _d S )N)r   r   calls)r   r   )r   r   r	   r   O   s    z?Test.test_init_subclass_diamond.<locals>.Base.__init_subclass__)r
   r   r   r   r   r   r   )r   r	   BaseN   s   r%   c               @   s   e Zd ZdS )z-Test.test_init_subclass_diamond.<locals>.LeftN)r
   r   r   r   r   r   r	   LeftS   s   r&   c                   s   e Zd Z fddZ  ZS )z/Test.test_init_subclass_diamond.<locals>.Middlec                s"   t  jf | |  j|g7  _d S )N)r   r   r$   )r   middler   )r   r   r	   r   W   s    zATest.test_init_subclass_diamond.<locals>.Middle.__init_subclass__)r
   r   r   r   r   r   r   )r   r	   MiddleV   s   r(   c                   s   e Zd Zd fdd	Z  ZS )z.Test.test_init_subclass_diamond.<locals>.Rightrightc                s"   t  jf | |  j|g7  _d S )N)r   r   r$   )r   r)   r   )r   r   r	   r   \   s    z@Test.test_init_subclass_diamond.<locals>.Right.__init_subclass__)r)   )r
   r   r   r   r   r   r   )r   r	   Right[   s   r*   c               @   s   e Zd ZdS )z*Test.test_init_subclass_diamond.<locals>.AN)r
   r   r   r   r   r   r	   r   `   s   r   r'   )r'   r)   )r   r$   )r   r%   r&   r(   r*   r   r   r   r	   test_init_subclass_diamondM   s    zTest.test_init_subclass_diamondc                sD   G dd d G  fddd}|  |jjd | |jj| d S )Nc               @   s   e Zd Zdd ZdS )z&Test.test_set_name.<locals>.Descriptorc             S   s   || _ || _d S )N)ownername)r   r,   r-   r   r   r	   __set_name__i   s    z3Test.test_set_name.<locals>.Descriptor.__set_name__N)r
   r   r   r.   r   r   r   r	   
Descriptorh   s   r/   c                   s   e Zd Z  ZdS )zTest.test_set_name.<locals>.AN)r
   r   r   dr   )r/   r   r	   r   m   s   r   r0   )r   r0   r-   r"   r,   )r   r   r   )r/   r	   test_set_nameg   s    zTest.test_set_namec                sH   G fdddt }G dd d G  fddd|d}|d d S )	Nc                   s   e Zd Z fddZ  ZS )z*Test.test_set_name_metaclass.<locals>.Metac                s6   t  | |||}|jjd |jj| dS )Nr0   r   )r   __new__r   r0   r-   r"   r,   )r   r-   basesnsret)r   r   r   r	   r2   u   s    z2Test.test_set_name_metaclass.<locals>.Meta.__new__)r
   r   r   r2   r   r   )r   )r   r	   Metat   s   r6   c               @   s   e Zd Zdd ZdS )z0Test.test_set_name_metaclass.<locals>.Descriptorc             S   s   || _ || _d S )N)r,   r-   )r   r,   r-   r   r   r	   r.   |   s    z=Test.test_set_name_metaclass.<locals>.Descriptor.__set_name__N)r
   r   r   r.   r   r   r   r	   r/   {   s   r/   c                   s   e Zd Z  ZdS )z'Test.test_set_name_metaclass.<locals>.AN)r
   r   r   r0   r   )r/   r   r	   r      s   r   )	metaclassr   )typer   )r   r6   r   r   )r/   r   r	   test_set_name_metaclasss   s    zTest.test_set_name_metaclassc          	      s~   G dd d |  t}G  fddd}W d Q R X |j}| t|d | t|d | t|d | |jt d S )Nc               @   s   e Zd Zdd ZdS )z,Test.test_set_name_error.<locals>.Descriptorc             S   s   dd  d S )N   r   r   )r   r,   r-   r   r   r	   r.      s    z9Test.test_set_name_error.<locals>.Descriptor.__set_name__N)r
   r   r   r.   r   r   r   r	   r/      s   r/   c                   s   e Zd Z  ZdS )z0Test.test_set_name_error.<locals>.NotGoingToWorkN)r
   r   r   attrr   )r/   r   r	   NotGoingToWork   s   r<   z\bNotGoingToWork\bz\battr\bz\bDescriptor\b)r   r   	exceptionassertRegexstrassertIsInstance	__cause__ZeroDivisionError)r   cmr<   excr   )r/   r	   test_set_name_error   s    zTest.test_set_name_errorc          	      s~   G dd d |  t}G  fddd}W d Q R X |j}| t|d | t|d | t|d | |jt d S )Nc               @   s   e Zd Zdd ZdS )z,Test.test_set_name_wrong.<locals>.Descriptorc             S   s   d S )Nr   )r   r   r   r	   r.      s    z9Test.test_set_name_wrong.<locals>.Descriptor.__set_name__N)r
   r   r   r.   r   r   r   r	   r/      s   r/   c                   s   e Zd Z  ZdS )z0Test.test_set_name_wrong.<locals>.NotGoingToWorkN)r
   r   r   r;   r   )r/   r   r	   r<      s   r<   z\bNotGoingToWork\bz\battr\bz\bDescriptor\b)r   r   r=   r>   r?   r@   rA   r   )r   rC   r<   rD   r   )r/   r	   test_set_name_wrong   s    zTest.test_set_name_wrongc                s:   g G fddd G  fddd}|  dd d S )Nc                   s   e Zd Z fddZdS )z0Test.test_set_name_lookup.<locals>.NonDescriptorc                s     | d S )N)append)r   r-   )resolvedr   r	   __getattr__   s    z<Test.test_set_name_lookup.<locals>.NonDescriptor.__getattr__N)r
   r   r   rI   r   )rH   r   r	   NonDescriptor   s   rJ   c                   s   e Zd Z  ZdS )z$Test.test_set_name_lookup.<locals>.AN)r
   r   r   r0   r   )rJ   r   r	   r      s   r   r.   z*__set_name__ is looked up in instance dict)ZassertNotIn)r   r   r   )rJ   rH   r	   test_set_name_lookup   s
    zTest.test_set_name_lookupc                s   G dd d G dd dt }G dd d}G  fddd||d	}| |j| | |jd
 | |j| | |jd
 d S )Nc               @   s   e Zd Zdd ZdS )z4Test.test_set_name_init_subclass.<locals>.Descriptorc             S   s   || _ || _d S )N)r,   r-   )r   r,   r-   r   r   r	   r.      s    zATest.test_set_name_init_subclass.<locals>.Descriptor.__set_name__N)r
   r   r   r.   r   r   r   r	   r/      s   r/   c                   s   e Zd Z fddZ  ZS )z.Test.test_set_name_init_subclass.<locals>.Metac                s&   t  | |||}|j|_|j|_|S )N)r   r2   r,   
meta_ownerr-   Z	meta_name)r   r-   r3   r4   r   )r   r   r	   r2      s    z6Test.test_set_name_init_subclass.<locals>.Meta.__new__)r
   r   r   r2   r   r   r   )r   r	   r6      s   r6   c               @   s   e Zd Zdd ZdS )z+Test.test_set_name_init_subclass.<locals>.Ac             S   s   | j j| _| j j| _d S )N)r0   r,   r-   )r   r   r   r	   r      s    
z=Test.test_set_name_init_subclass.<locals>.A.__init_subclass__N)r
   r   r   r   r   r   r   r	   r      s   r   c                   s   e Zd Z  ZdS )z+Test.test_set_name_init_subclass.<locals>.BN)r
   r   r   r0   r   )r/   r   r	   r      s   r   )r7   r0   )r8   r"   r,   r   r-   rL   )r   r6   r   r   r   )r/   r	   test_set_name_init_subclass   s    z Test.test_set_name_init_subclassc                sB   g G fddd G  fddd}|  ddddd	g d S )
Nc                   s   e Zd Z fddZdS )z5Test.test_set_name_modifying_dict.<locals>.Descriptorc                s   t ||d d   | d S )Nr   )setattrrG   )r   r,   r-   )notifiedr   r	   r.      s    zBTest.test_set_name_modifying_dict.<locals>.Descriptor.__set_name__N)r
   r   r   r.   r   )rO   r   r	   r/      s   r/   c                   s*   e Zd Z  Z  Z  Z  Z  ZdS )z,Test.test_set_name_modifying_dict.<locals>.AN)r
   r   r   abcr0   er   )r/   r   r	   r      s
   r   rP   rQ   rR   r0   rS   )ZassertCountEqual)r   r   r   )r/   rO   r	   test_set_name_modifying_dict   s    z!Test.test_set_name_modifying_dictc          	   C   s   G dd dt }| t G dd d|dd}W d Q R X | t tdtft|dd W d Q R X tdtft|dd G dd dt }| t G dd d|dd}W d Q R X G d	d dt }G d
d d|dd}| |j	d d S )Nc               @   s   e Zd ZdS )z Test.test_errors.<locals>.MyMetaN)r
   r   r   r   r   r   r	   MyMeta   s   rU   c               @   s   e Zd ZdS )z!Test.test_errors.<locals>.MyClassN)r
   r   r   r   r   r   r	   MyClass   s   rV   r:   )r7   otherargc                   s   e Zd Z fddZ  ZS )z Test.test_errors.<locals>.MyMetac                s   t  ||| d S )N)r   __init__)r   r-   r3   	namespacerW   )r   r   r	   rX      s    z)Test.test_errors.<locals>.MyMeta.__init__)r
   r   r   rX   r   r   r   )r   r	   rU      s   c               @   s   e Zd ZdS )z!Test.test_errors.<locals>.MyClassN)r
   r   r   r   r   r   r	   rV      s   c                   s(   e Zd Z fddZ fddZ  ZS )z Test.test_errors.<locals>.MyMetac                s   t  | |||S )N)r   r2   )r   r-   r3   rY   rW   )r   r   r	   r2      s    z(Test.test_errors.<locals>.MyMeta.__new__c                s   t  ||| || _d S )N)r   rX   rW   )r   r-   r3   rY   rW   )r   r   r	   rX      s    z)Test.test_errors.<locals>.MyMeta.__init__)r
   r   r   r2   rX   r   r   r   )r   r	   rU      s   c               @   s   e Zd ZdS )z!Test.test_errors.<locals>.MyClassN)r
   r   r   r   r   r   r	   rV      s   )
r8   r   r   types	new_classobjectr   prepare_classr   rW   )r   rU   rV   r   r   r	   test_errors   s    

zTest.test_errorsc          	   C   sn   G dd dt }| t G dd d|d}W d Q R X G dd dt }G dd d|dd	}| |jd d S )
Nc                   s   e Zd Z fddZ  ZS )z/Test.test_errors_changed_pep487.<locals>.MyMetac                s   t  j| |||dS )N)r-   r3   r   )r   r2   )r   r-   r3   rY   )r   r   r	   r2      s    z7Test.test_errors_changed_pep487.<locals>.MyMeta.__new__)r
   r   r   r2   r   r   r   )r   r	   rU      s   rU   c               @   s   e Zd ZdS )z0Test.test_errors_changed_pep487.<locals>.MyClassN)r
   r   r   r   r   r   r	   rV     s   rV   )r7   c                   s   e Zd Z fddZ  ZS )z/Test.test_errors_changed_pep487.<locals>.MyMetac                s   t  | |||}||_|S )N)r   r2   rW   )r   r-   r3   rY   rW   r   )r   r   r	   r2     s    z7Test.test_errors_changed_pep487.<locals>.MyMeta.__new__)r
   r   r   r2   r   r   r   )r   r	   rU     s   c               @   s   e Zd ZdS )z0Test.test_errors_changed_pep487.<locals>.MyClassN)r
   r   r   r   r   r   r	   rV     s   r:   )r7   rW   )r8   r   r   r   rW   )r   rU   rV   r   r   r	   test_errors_changed_pep487   s    zTest.test_errors_changed_pep487c          	   C   sR   t dtfi }| |t  | |jd | t t dtfi d W d Q R X d S )NZNewClass)r-   r3   r   )r8   r\   r@   r   r
   r   r   )r   tr   r   r	   	test_type  s
    zTest.test_typeN)r
   r   r   r   r   r   r   r   r#   r+   r1   r9   rE   rF   rK   rM   rT   r^   r_   ra   r   r   r   r	   r      s"   
		#r   __main__)rZ   ZunittestZTestCaser   r
   mainr   r   r   r	   <module>   s     