B
    u9a4                @   s  d dl T d dlZd dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZ d dlmZmZmZ d dlmZ d dlZd dl Z G dd deZG d	d
 d
ejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZG dd dejZ G dd dejZ!G dd dejZ"G dd dejZ#G dd  d ejZ$G d!d" d"ejZ%G d#d$ d$ejZ&e'd%kre(  dS )&    )*N)Mock)	ClassVarAnyListUnionTupleDictGenericTypeVarOptional)dequeOrderedDict
namedtuple)total_orderingc               @   s   e Zd ZdS )CustomErrorN)__name__
__module____qualname__ r   r   &/usr/lib/python3.7/test_dataclasses.pyr      s    r   c               @   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#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d< Z d>d? Z!d@dA Z"dBdC Z#dDdE Z$dFdG Z%dHdI Z&dJdK Z'dLdM Z(dNdO Z)dPdQ Z*dRdS Z+dTdU Z,dVdW Z-dXdY Z.dZd[ Z/d\d] Z0d^d_ Z1d`da Z2dbdc Z3ddde Z4dfdg Z5dhdi Z6djdk Z7dldm Z8dndo Z9dpdq Z:drds Z;dtdu Z<dvdw Z=dxdy Z>dzd{ Z?d|d} Z@d~d ZAdd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdS )TestCasec             C   s0   t G dd d}| }| tt|d d S )Nc               @   s   e Zd ZdS )z"TestCase.test_no_fields.<locals>.CN)r   r   r   r   r   r   r   C   s   r   r   )	dataclassassertEquallenfields)selfr   or   r   r   test_no_fields   s    zTestCase.test_no_fieldsc             C   s0   t G dd d}| }| tt|d d S )Nc               @   s   e Zd ZdZdS )z6TestCase.test_no_fields_but_member_variable.<locals>.Cr   N)r   r   r   ir   r   r   r   r       s   r   r   )r   r   r   r   )r   r   r   r   r   r   "test_no_fields_but_member_variable   s    z+TestCase.test_no_fields_but_member_variablec             C   s,   t G dd d}|d}| |jd d S )Nc               @   s   e Zd ZU eed< dS )z-TestCase.test_one_field_no_default.<locals>.CxN)r   r   r   int__annotations__r   r   r   r   r   (   s   
r   *   )r   r   r"   )r   r   r   r   r   r   test_one_field_no_default'   s    z"TestCase.test_one_field_no_defaultc             C   s.   t G dd d}|dd}| |jd d S )Nc               @   s   e Zd ZU eed< dS )z*TestCase.test_named_init_params.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r   0   s   
r       )r"   )r   r   r"   )r   r   r   r   r   r   test_named_init_params/   s    
zTestCase.test_named_init_paramsc          	   C   s   t G dd d}|d}| |j|jfd | td t G dd d}W d Q R X | td, t G dd d}t G d	d d|}W d Q R X | td, t G d
d d}t G dd d|}W d Q R X d S )Nc               @   s"   e Zd ZU eed< dZeed< dS )z/TestCase.test_two_fields_one_default.<locals>.Cr"   r   yN)r   r   r   r#   r$   r)   r   r   r   r   r   8   s   
r      )r*   r   z1non-default argument 'y' follows default argumentc               @   s"   e Zd ZU dZeed< eed< dS )z/TestCase.test_two_fields_one_default.<locals>.Cr   r"   r)   N)r   r   r   r"   r#   r$   r   r   r   r   r   D   s   
c               @   s   e Zd ZU dZeed< dS )z/TestCase.test_two_fields_one_default.<locals>.Br   r"   N)r   r   r   r"   r#   r$   r   r   r   r   BM   s   
r+   c               @   s   e Zd ZU eed< dS )z/TestCase.test_two_fields_one_default.<locals>.Cr)   N)r   r   r   r#   r$   r   r   r   r   r   Q   s   
c               @   s   e Zd ZU eed< eed< dS )z/TestCase.test_two_fields_one_default.<locals>.Br"   r)   N)r   r   r   r#   r$   r   r   r   r   r+   Z   s   
c               @   s   e Zd ZU dZeed< dS )z/TestCase.test_two_fields_one_default.<locals>.Cr   r"   N)r   r   r   r"   r#   r$   r   r   r   r   r   _   s   
)r   r   r"   r)   assertRaisesRegex	TypeError)r   r   r   r+   r   r   r   test_two_fields_one_default7   s     z$TestCase.test_two_fields_one_defaultc          	   C   s   t ddG dd d}| t|dd t ddG dd d}| t|dtd | td	 t dd
G dd d}W d Q R X t dd
G dd d}| t|dtd | td	 t dd
G dd d}W d Q R X d S )NT)frozenc               @   s   e Zd ZU eed< dd ZdS )z'TestCase.test_overwrite_hash.<locals>.Cr"   c             S   s   dS )Ni-  r   )r   r   r   r   __hash__i   s    z0TestCase.test_overwrite_hash.<locals>.C.__hash__N)r   r   r   r#   r$   r0   r   r   r   r   r   f   s   
r   d   i-  c               @   s   e Zd ZU eed< dd ZdS )z'TestCase.test_overwrite_hash.<locals>.Cr"   c             S   s   dS )NFr   )r   otherr   r   r   __eq__r   s    z.TestCase.test_overwrite_hash.<locals>.C.__eq__N)r   r   r   r#   r$   r3   r   r   r   r   r   o   s   
)r1   z#Cannot overwrite attribute __hash__)unsafe_hashc               @   s   e Zd Zdd ZdS )z'TestCase.test_overwrite_hash.<locals>.Cc             S   s   d S )Nr   )r   r   r   r   r0   |   s    z0TestCase.test_overwrite_hash.<locals>.C.__hash__N)r   r   r   r0   r   r   r   r   r   z   s   c               @   s   e Zd ZU eed< dd ZdS )z'TestCase.test_overwrite_hash.<locals>.Cr"   c             S   s   d S )Nr   )r   r   r   r   r3      s    z.TestCase.test_overwrite_hash.<locals>.C.__eq__N)r   r   r   r#   r$   r3   r   r   r   r   r      s   

   )r5   c               @   s&   e Zd ZU eed< dd Zdd ZdS )z'TestCase.test_overwrite_hash.<locals>.Cr"   c             S   s   d S )Nr   )r   r   r   r   r3      s    z.TestCase.test_overwrite_hash.<locals>.C.__eq__c             S   s   d S )Nr   )r   r   r   r   r0      s    z0TestCase.test_overwrite_hash.<locals>.C.__hash__N)r   r   r   r#   r$   r3   r0   r   r   r   r   r      s   
)r   r   hashr,   r-   )r   r   r   r   r   test_overwrite_hashc   s    "	zTestCase.test_overwrite_hashc             C   sp   t G dd d}t G dd d|}| }| t|d | }| t|d |dd}| t|d	 d S )
Nc               @   s&   e Zd ZU dZeed< dZeed< dS )z=TestCase.test_overwrite_fields_in_derived_class.<locals>.Baseg      .@r"   r   r)   N)r   r   r   r"   r   r$   r)   r#   r   r   r   r   Base   s   
r8   c               @   s&   e Zd ZU dZeed< dZeed< dS )z;TestCase.test_overwrite_fields_in_derived_class.<locals>.C1r5   z   r"   N)r   r   r   r9   r#   r$   r"   r   r   r   r   C1   s   
r;   zJTestCase.test_overwrite_fields_in_derived_class.<locals>.Base(x=15.0, y=0)zLTestCase.test_overwrite_fields_in_derived_class.<locals>.C1(x=15, y=0, z=10)   )r"   zKTestCase.test_overwrite_fields_in_derived_class.<locals>.C1(x=5, y=0, z=10))r   r   repr)r   r8   r;   r   r   r   r   &test_overwrite_fields_in_derived_class   s    
z/TestCase.test_overwrite_fields_in_derived_classc             C   s   t G dd d}|d}| |jd t|j}tt|j}| 	d| t G dd d}t|j}tt|j}| d| d S )Nc               @   s   e Zd ZU eed< dS )z)TestCase.test_field_named_self.<locals>.Cr   N)r   r   r   strr$   r   r   r   r   r      s   
r   foor   c               @   s   e Zd ZU eed< dS )z)TestCase.test_field_named_self.<locals>.CZselfxN)r   r   r   r?   r$   r   r   r   r   r      s   
)
r   r   r   inspect	signature__init__nextiter
parametersassertNotEqual)r   r   cZsigfirstr   r   r   test_field_named_self   s    zTestCase.test_field_named_selfc             C   s,   t G dd d}|d}| |jd d S )Nc               @   s   e Zd ZU eed< dS )z+TestCase.test_field_named_object.<locals>.CobjectN)r   r   r   r?   r$   r   r   r   r   r      s   
r   r@   )r   r   rK   )r   r   rH   r   r   r   test_field_named_object   s    z TestCase.test_field_named_objectc             C   s2   t ddG dd d}|d}| |jd d S )NT)r/   c               @   s   e Zd ZU eed< dS )z2TestCase.test_field_named_object_frozen.<locals>.CrK   N)r   r   r   r?   r$   r   r   r   r   r      s   
r   r@   )r   r   rK   )r   r   rH   r   r   r   test_field_named_object_frozen   s    z'TestCase.test_field_named_object_frozenc                st   dddh t  fddtj D }dd |D }td|}|d	d |D  }x|D ]}| t||| qVW d S )
NNoneTrueFalsec             3   s$   | ]}| d s| kr|V  qdS )__N)
startswith).0b)
exclusionsr   r   	<genexpr>   s    z9TestCase.test_field_named_like_builtin.<locals>.<genexpr>c             S   s   g | ]}|t fqS r   )r?   )rS   namer   r   r   
<listcomp>   s    z:TestCase.test_field_named_like_builtin.<locals>.<listcomp>r   c             S   s   g | ]}|qS r   r   )rS   rW   r   r   r   rX      s    )sortedbuiltins__dict__keysmake_dataclassr   getattr)r   builtins_names
attributesr   rH   rW   r   )rU   r   test_field_named_like_builtin   s    


z&TestCase.test_field_named_like_builtinc                sx   dddh t  fddtj D }dd |D }td|d	d
}|dd |D  }x|D ]}| t||| qZW d S )NrN   rO   rP   c             3   s$   | ]}| d s| kr|V  qdS )rQ   N)rR   )rS   rT   )rU   r   r   rV      s    z@TestCase.test_field_named_like_builtin_frozen.<locals>.<genexpr>c             S   s   g | ]}|t fqS r   )r?   )rS   rW   r   r   r   rX      s    zATestCase.test_field_named_like_builtin_frozen.<locals>.<listcomp>r   T)r/   c             S   s   g | ]}|qS r   r   )rS   rW   r   r   r   rX      s    )rY   rZ   r[   r\   r]   r   r^   )r   r_   r`   r   rH   rW   r   )rU   r   $test_field_named_like_builtin_frozen   s    

z-TestCase.test_field_named_like_builtin_frozenc             C   s  t G dd d}t ddG dd d}x||gD ]}| j|d | | |  x|tdd	 d
d	 dd	 dd	 gD ]X\}}| j|d> | td|j d|j d || |  W d Q R X W d Q R X qxW W d Q R X q4W t ddG dd d}| | |  | | |  d S )Nc               @   s   e Zd ZdS )z)TestCase.test_0_field_compare.<locals>.C0N)r   r   r   r   r   r   r   C0   s   rc   F)orderc               @   s   e Zd ZdS )z)TestCase.test_0_field_compare.<locals>.C1N)r   r   r   r   r   r   r   r;      s   r;   )clsc             S   s   | |k S )Nr   )arT   r   r   r   <lambda>      z/TestCase.test_0_field_compare.<locals>.<lambda>c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg     rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg     rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg     rh   )idxz$not supported between instances of 'z' and ''Tc               @   s   e Zd ZdS )z(TestCase.test_0_field_compare.<locals>.CN)r   r   r   r   r   r   r   r     s   r   )	r   subTestr   	enumerater,   r-   r   assertLessEqualassertGreaterEqual)r   rc   r;   re   ri   fnr   r   r   r   test_0_field_compare   s     
4zTestCase.test_0_field_comparec             C   s  t G dd d}t ddG dd d}x||gD ]}| j|d | |d|d | |d	|d xtd
d dd dd dd gD ]\\}}| j|dB | td|j d|j d ||d	|d	 W d Q R X W d Q R X qW W d Q R X q4W t ddG dd d}| |d	|d | 	|d	|d | 	|d|d | 
|d|d	 | |d|d	 | |d|d d S )Nc               @   s   e Zd ZU eed< dS )z)TestCase.test_1_field_compare.<locals>.C0r"   N)r   r   r   r#   r$   r   r   r   r   rc     s   
rc   F)rd   c               @   s   e Zd ZU eed< dS )z)TestCase.test_1_field_compare.<locals>.C1r"   N)r   r   r   r#   r$   r   r   r   r   r;     s   
r;   )re      r   c             S   s   | |k S )Nr   )rf   rT   r   r   r   rg     rh   z/TestCase.test_1_field_compare.<locals>.<lambda>c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg      rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   !  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   "  rh   )ri   z$not supported between instances of 'z' and 'rj   Tc               @   s   e Zd ZU eed< dS )z(TestCase.test_1_field_compare.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r   (  s   
r   )r   rk   r   rG   rl   r,   r-   r   
assertLessrm   assertGreaterrn   )r   rc   r;   re   ri   ro   r   r   r   r   test_1_field_compare  s*    
8zTestCase.test_1_field_comparec             C   s  t G dd d}t ddG dd d}x||gD ]}| j|d | |dd|dd | |d	d
|d	d
 | |d	d|dd | |d	d|d	d	 xtdd dd dd dd gD ]`\}}| j|dF | td|j d|j d ||dd|dd W d Q R X W d Q R X qW W d Q R X q6W t ddG dd d}x\tdd dd dd gD ]>\}}| j|d" | ||dd|dd W d Q R X qrW xtdd dd dd gD ]v\}}| j|dZ | ||dd|dd	 | ||dd	|d	d | ||d	d|d	d	 W d Q R X qW xtdd dd dd gD ]v\}}| j|dZ | ||dd	|dd | ||d	d|dd	 | ||d	d	|d	d W d Q R X qfW d S ) Nc               @   s   e Zd ZU eed< eed< dS )z(TestCase.test_simple_compare.<locals>.C0r"   r)   N)r   r   r   r#   r$   r   r   r   r   rc   4  s   
rc   F)rd   c               @   s   e Zd ZU eed< eed< dS )z(TestCase.test_simple_compare.<locals>.C1r"   r)   N)r   r   r   r#   r$   r   r   r   r   r;   9  s   
r;   )re   r   rq      c             S   s   | |k S )Nr   )rf   rT   r   r   r   rg   D  rh   z.TestCase.test_simple_compare.<locals>.<lambda>c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   E  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   F  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   G  rh   )ri   z$not supported between instances of 'z' and 'rj   Tc               @   s   e Zd ZU eed< eed< dS )z'TestCase.test_simple_compare.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r   M  s   
r   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   R  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   S  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   T  rh   c             S   s   | |k S )Nr   )rf   rT   r   r   r   rg   X  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   Y  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   Z  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   `  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   a  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   b  rh   )	r   rk   r   rG   rl   r,   r-   r   
assertTrue)r   rc   r;   re   ri   ro   r   r   r   r   test_simple_compare2  sH    
<
,
,
zTestCase.test_simple_comparec             C   s   t G dd d}t G dd d|}x^tdd dfdd d	fgD ]>\}\}}| j|d
  | ||d|d| W d Q R X qDW xntdd dd dd dd gD ]J\}}| j|d
0 | td ||d|d W d Q R X W d Q R X qW d S )Nc               @   s   e Zd ZU eed< dS )z+TestCase.test_compare_subclasses.<locals>.Br    N)r   r   r   r#   r$   r   r   r   r   r+   k  s   
r+   c               @   s   e Zd ZdS )z+TestCase.test_compare_subclasses.<locals>.CN)r   r   r   r   r   r   r   r   o  s   r   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   s  rh   z2TestCase.test_compare_subclasses.<locals>.<lambda>Fc             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   t  rh   T)ri   r   c             S   s   | |k S )Nr   )rf   rT   r   r   r   rg   x  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   y  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   z  rh   c             S   s   | |kS )Nr   )rf   rT   r   r   r   rg   {  rh   z.not supported between instances of 'B' and 'C')r   rl   rk   r   r,   r-   )r   r+   r   ri   ro   expectedr   r   r   test_compare_subclassesh  s    (
z TestCase.test_compare_subclassesc             C   s  xdD ]\}}}| j ||df |dkrd| td  t||dG dd d}W d Q R X n"t||dG dd d}|dkr| d	|j | d
|j | d|j | d|j | d|j n|dkr | d	|j | d
|j | d|j | d|j | d|j nf|dkrr| d	|j | d
|j | d|j | d|j | d|j ndstd|W d Q R X qW d S )N))FFneither)FT	exception)TFeq_only)TTboth)eqrd   r{   z eq must be true if order is truec               @   s   e Zd ZdS )z!TestCase.test_eq_order.<locals>.CN)r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )z!TestCase.test_eq_order.<locals>.CN)r   r   r   r   r   r   r   r     s   rz   r3   __lt____le____gt____ge__r}   r|   Fzunknown result )rk   r,   
ValueErrorr   assertNotInr[   assertInAssertionError)r   r~   rd   resultr   r   r   r   test_eq_order  s2    (

zTestCase.test_eq_orderc          	   C   sF   t G dd d}| |djd | td |  W d Q R X d S )Nc               @   s   e Zd ZU e Zeed< dS )z)TestCase.test_field_no_default.<locals>.Cr"   N)r   r   r   fieldr"   r#   r$   r   r   r   r   r     s   
r   r<   z8__init__\(\) missing 1 required positional argument: 'x')r   r   r"   r,   r-   )r   r   r   r   r   test_field_no_default  s
    zTestCase.test_field_no_defaultc                sf   t   tG  fddd}| |j  |d}| |jd |`| |j  | | j  d S )Nc                   s    e Zd ZU e dZeed< dS )z&TestCase.test_field_default.<locals>.C)defaultr"   N)r   r   r   r   r"   rK   r$   r   )r   r   r   r     s   
r   r5   )rK   r   assertIsr"   r   )r   r   rH   r   )r   r   test_field_default  s    zTestCase.test_field_defaultc          	   C   sv   t G dd d}| t |  W d Q R X |d}| t|d t G dd d}|dd}| t|d d S )Nc               @   s    e Zd ZU eddZeed< dS )z$TestCase.test_not_in_repr.<locals>.CF)r=   r"   N)r   r   r   r   r"   r#   r$   r   r   r   r   r     s   
r   r5   z&TestCase.test_not_in_repr.<locals>.C()c               @   s(   e Zd ZU eddZeed< eed< dS )z$TestCase.test_not_in_repr.<locals>.CF)r=   r"   r)   N)r   r   r   r   r"   r#   r$   r   r   r   r   r     s   
   z*TestCase.test_not_in_repr.<locals>.C(y=20))r   assertRaisesr-   r   r=   )r   r   rH   r   r   r   test_not_in_repr  s    
zTestCase.test_not_in_reprc             C   sp   t G dd d}| | |dd | |dd|dd | |d|dd | |dd|dd d S )	Nc               @   s.   e Zd ZU dZeed< edddZeed< dS )z'TestCase.test_not_in_compare.<locals>.Cr   r"   F   )comparer   r)   N)r   r   r   r"   r#   r$   r   r)   r   r   r   r   r     s   
r   r   r   rq   r5   r*   r   )r   r   rG   )r   r   r   r   r   test_not_in_compare  s
    zTestCase.test_not_in_comparec          
      s   xdD ]\ }| j  dz tddG  fddd}|dkr`| t|dtd	 n4|d
kr| t|dtd ndstd|W d Q R X qW d S )N))TFr   )TTr   )FFabsent)FTr   )NFr   )NTr   )r6   r   T)r4   c                   s$   e Zd ZU e ddZeed< dS )z)TestCase.test_hash_field_rules.<locals>.Cr<   )r   r6   r   r"   N)r   r   r   r   r"   r#   r$   r   )r   hash_r   r   r     s   
r   r   r<   )r<   r   r   Fzunknown result )rk   r   r   r6   r   )r   r   r   r   )r   r   r   test_hash_field_rules  s    zTestCase.test_hash_field_rulesc             C   sf   t G dd d}| d| j t G dd d}| d|dj | t|ddddd	 d S )
Nc               @   s    e Zd ZU eddZeed< dS )z.TestCase.test_init_false_no_default.<locals>.CF)initr"   N)r   r   r   r   r"   r#   r$   r   r   r   r   r     s   
r   r"   c               @   s@   e Zd ZU eed< dZeed< eddZeed< dZeed< d	S )
z.TestCase.test_init_false_no_default.<locals>.Cr"   r   r)   F)r   r9   r5   tN)	r   r   r   r#   r$   r)   r   r9   r   r   r   r   r   r     s   
r9   r   r<   r5   )r   r"   r)   )r   r   r[   r   vars)r   r   r   r   r   test_init_false_no_default  s
    z#TestCase.test_init_false_no_defaultc             C   sd  t G dd d}t|}| |t x,|D ]$}| t|t | |j|j	 q,W | 
t|d | 
|d jd | 
|d jt | t|d | |d j | |d j | 
|d jd | 
|d jt | t|d | |d j | |d j | 
|d jd	 | 
|d jt | t|d	 | |d j | |d j d S )
Nc               @   s<   e Zd ZU eed< edddZeed< eddZeed< dS )z%TestCase.test_class_marker.<locals>.Cr"   FN)r   r   r)   )r=   r9   )	r   r   r   r#   r$   r   r)   r?   r9   r   r   r   r   r     s   
r   r*   r   r"   rq   r)   ru   r9   )r   r   assertIsInstancetupler   typeZFieldr   rW   r$   r   r   r#   assertFalsehasattrrv   r   r=   r?   assertIsNoner^   )r   r   Z
the_fieldsfr   r   r   test_class_marker  s,    
zTestCase.test_class_markerc             C   s   t G dd d}t G dd d|}| dd t|D ddd	g t G d
d d|}| dd t|D dddg t G dd d|}| dd t|D ddddg d S )Nc               @   s2   e Zd ZU dZeed< dZeed< dZeed< dS )z$TestCase.test_field_order.<locals>.BzB:arf   zB:brT   zB:crH   N)r   r   r   rf   r?   r$   rT   rH   r   r   r   r   r+   0  s   
r+   c               @   s   e Zd ZU dZeed< dS )z$TestCase.test_field_order.<locals>.CzC:brT   N)r   r   r   rT   r?   r$   r   r   r   r   r   6  s   
r   c             S   s   g | ]}|j |jfqS r   )rW   r   )rS   r   r   r   r   rX   :  s    z-TestCase.test_field_order.<locals>.<listcomp>)rf   zB:a)rT   zC:b)rH   zB:cc               @   s   e Zd ZU dZeed< dS )z$TestCase.test_field_order.<locals>.DzD:crH   N)r   r   r   rH   r?   r$   r   r   r   r   D?  s   
r   c             S   s   g | ]}|j |jfqS r   )rW   r   )rS   r   r   r   r   rX   C  s    )rT   zB:b)rH   zD:cc               @   s&   e Zd ZU dZeed< dZeed< dS )z$TestCase.test_field_order.<locals>.EzE:arf   zE:ddN)r   r   r   rf   r?   r$   r   r   r   r   r   EH  s   
r   c             S   s   g | ]}|j |jfqS r   )rW   r   )rS   r   r   r   r   rX   M  s    )rf   zE:a)r   zE:d)r   r   r   )r   r+   r   r   r   r   r   r   test_field_order/  s(    zTestCase.test_field_orderc                s\   t   tG  fddd}| t|d | t|d | |j  | |jd d S )Nc                   sF   e Zd ZU eed< eddZeed<  Zeed< eddZ	eed< d	S )
z$TestCase.test_class_attrs.<locals>.Cr"   F)r=   r)   r9   r1   )r   r   N)
r   r   r   r#   r$   r   r)   r9   rK   r   r   )r   r   r   r   W  s   
r   r"   r)   r1   )rK   r   r   r   r   r9   r   r   )r   r   r   )r   r   test_class_attrsS  s    zTestCase.test_class_attrsc                s8  x0t g dgfti ddiftt tdgfgD ] \| jd | td d tG fddd}W d Q R X | td d tG fd	dd}W d Q R X G d
d d | td tG  fddd}W d Q R X tG fddd}tG  fddd}W d Q R X q.W d S )Nrq   r   )typzmutable default z for field x is not allowedc                   s   e Zd ZU  Zed< dS )z8TestCase.test_disallowed_mutable_defaults.<locals>.Pointr"   N)r   r   r   r"   r$   r   )emptyr   r   r   Pointn  s   
r   z for field y is not allowedc                   s   e Zd ZU  Zed< dS )z8TestCase.test_disallowed_mutable_defaults.<locals>.Pointr)   N)r   r   r   r)   r$   r   )	non_emptyr   r   r   r   w  s   
c               @   s   e Zd ZdS )z;TestCase.test_disallowed_mutable_defaults.<locals>.SubclassN)r   r   r   r   r   r   r   Subclass|  s    r   z7mutable default .*Subclass'> for field z is not allowedc                   s   e Zd ZU   Zed< dS )z8TestCase.test_disallowed_mutable_defaults.<locals>.Pointr9   N)r   r   r   r9   r$   r   )r   r   r   r   r     s   
c                   s    e Zd ZU   Ze  ed< dS )z4TestCase.test_disallowed_mutable_defaults.<locals>.Cr9   N)r   r   r   r9   r   r$   r   )r   r   r   r     s   
r   c                   s    e Zd ZU   Ze ed< dS )z4TestCase.test_disallowed_mutable_defaults.<locals>.Cr"   N)r   r   r   r"   r   r$   r   )r   r   r   r   r     s   
)listdictsetrk   r,   r   r   )r   r   r   r   )r   r   r   r   r    test_disallowed_mutable_defaultsc  s      """z)TestCase.test_disallowed_mutable_defaultsc                s   G dd d t G  fddd}  }||}||}| || |jjddg | || | |jjddg | |j|j d S )Nc               @   s   e Zd Zdd ZdS )z<TestCase.test_deliberately_mutable_defaults.<locals>.Mutablec             S   s
   g | _ d S )N)l)r   r   r   r   rC     s    zETestCase.test_deliberately_mutable_defaults.<locals>.Mutable.__init__N)r   r   r   rC   r   r   r   r   Mutable  s   r   c                   s   e Zd ZU  ed< dS )z6TestCase.test_deliberately_mutable_defaults.<locals>.Cr"   N)r   r   r   r$   r   )r   r   r   r     s   
r   rq   ru   )r   r   r"   r   extendr   )r   r   lstZo1Zo2r   )r   r   "test_deliberately_mutable_defaults  s    z+TestCase.test_deliberately_mutable_defaultsc             C   s*   t  G dd d}| |djd d S )Nc               @   s   e Zd ZU eed< dS )z#TestCase.test_no_options.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   r%   )r   r   r"   )r   r   r   r   r   test_no_options  s    zTestCase.test_no_optionsc             C   sR   t G dd d}| |ddd t G dd d}| |dd|dd d S )	Nc               @   s   e Zd ZU eed< eed< dS )z&TestCase.test_not_tuple.<locals>.Pointr"   r)   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   rq   ru   )rq   ru   c               @   s   e Zd ZU eed< eed< dS )z"TestCase.test_not_tuple.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   r*   )r   rG   )r   r   r   r   r   r   test_not_tuple  s    zTestCase.test_not_tuplec          	   C   s   t G dd d}t G dd d}| |ddd|ddd | |dd	dd
 | td |ddd\}}}W d Q R X t G dd d}| |ddd|  d S )Nc               @   s&   e Zd ZU eed< eed< eed< dS )z(TestCase.test_not_tuple.<locals>.Point3Dr"   r)   r9   N)r   r   r   r#   r$   r   r   r   r   Point3D  s   
r   c               @   s&   e Zd ZU eed< eed< eed< dS )z%TestCase.test_not_tuple.<locals>.DateZyearZmonthZdayN)r   r   r   r#   r$   r   r   r   r   Date  s   
r   i     r*   rq   ru   )rq   ru   r*   unpackr   r<   c               @   s2   e Zd ZU dZeed< dZeed< dZeed< dS )z*TestCase.test_not_tuple.<locals>.Point3Dv1r   r"   r)   r9   N)r   r   r   r"   r#   r$   r)   r9   r   r   r   r   	Point3Dv1  s   
r   r   )r   rG   r,   r-   )r   r   r   r"   r)   r9   r   r   r   r   r     s    c                sn   G dd d    fdd}t G  fddd}|| t dddG  fd	dd}|| d S )
Nc               @   s   e Zd ZdS )z-TestCase.test_function_annotations.<locals>.FN)r   r   r   r   r   r   r   F  s   r   c                s   | jd t  | jd t  | jd    | jd t  | jd t t| j}	|j
d  t|j }t|} |jd t|} |jd 	|jt  |jtjj  |jtjj t|} |jd 	|jt  |jtjj  |jtjj t|} |jd 	|j   |jtjj t|} |jd 	|jt  |jtjj tt| d S )Nr    jkr   r9   r   )r   r$   r#   r?   floatcomplexrA   rB   rC   r   Zreturn_annotationrE   rF   valuesrD   rW   Z
annotationr   Z	Parameterr   kindZPOSITIONAL_OR_KEYWORDr   StopIteration)re   rB   paramsZparam)r   r   r   r   validate_class  s:    z:TestCase.test_function_annotations.<locals>.validate_classc                   sP   e Zd ZU eed< eed< Z ed< eddZe	ed< eddd	Z
eed
< dS )z-TestCase.test_function_annotations.<locals>.Cr    r   r   N)r   r   y      @      @F)r   r   r9   )r   r   r   r#   r$   r?   r   r   r   r   r9   r   r   )r   r   r   r   r     s
   
r   T)r/   r4   c                   sP   e Zd ZU eed< eed< Z ed< eddZe	ed< eddd	Z
eed
< dS )z-TestCase.test_function_annotations.<locals>.Cr    r   r   N)r   r   y      @      @F)r   r   r9   )r   r   r   r#   r$   r?   r   r   r   r   r9   r   r   )r   r   r   r   r     s
   
)r   )r   r   r   r   )r   r   r   r   test_function_annotations  s    + z"TestCase.test_function_annotationsc          	   C   s   t G dd d}| td |  W d Q R X | d|j t G dd d}| td |  W d Q R X | d|j d S )Nc               @   s    e Zd ZU eedZeed< dS )z(TestCase.test_missing_default.<locals>.C)r   r"   N)r   r   r   r   MISSINGr"   r#   r$   r   r   r   r   r   $  s   
r   z3__init__\(\) missing 1 required positional argumentr"   c               @   s   e Zd ZU eed< dS )z(TestCase.test_missing_default.<locals>.Dr"   N)r   r   r   r#   r$   r   r   r   r   r   -  s   
r   )r   r,   r-   r   r[   )r   r   r   r   r   r   test_missing_default!  s    zTestCase.test_missing_defaultc          	   C   s   t G dd d}| td |  W d Q R X | d|j t G dd d}| td |  W d Q R X | d|j d S )Nc               @   s    e Zd ZU eedZeed< dS )z0TestCase.test_missing_default_factory.<locals>.C)default_factoryr"   N)r   r   r   r   r   r"   r#   r$   r   r   r   r   r   :  s   
r   z3__init__\(\) missing 1 required positional argumentr"   c               @   s"   e Zd ZU eeedZeed< dS )z0TestCase.test_missing_default_factory.<locals>.D)r   r   r"   N)r   r   r   r   r   r"   r#   r$   r   r   r   r   r   C  s   
r   )r   r,   r-   r   r[   )r   r   r   r   r   r   test_missing_default_factory6  s    z%TestCase.test_missing_default_factoryc             C   s   |  dtt d S )NzMISSING_TYPE object)r   r=   r   )r   r   r   r   test_missing_reprL  s    zTestCase.test_missing_reprc             C   sb   t G dd d}| t|jdg | |d d | |djd | |djd d S )Nc               @   s6   e Zd ZU eed< edddZeedddZdS )z7TestCase.test_dont_include_other_annotations.<locals>.Cr    )returnc             S   s   dS )Nr   r   )r   r   r   r   r@   S  s    z;TestCase.test_dont_include_other_annotations.<locals>.C.fooc             S   s   dS )Nr<   r   )r   r   r   r   barU  s    z;TestCase.test_dont_include_other_annotations.<locals>.C.barN)r   r   r   r#   r$   r@   propertyr   r   r   r   r   r   P  s   
r   r    r5   r   r<   )r   r   r   r$   r@   r   r    )r   r   r   r   r   #test_dont_include_other_annotationsO  s
    z,TestCase.test_dont_include_other_annotationsc          	   C   s   t G dd d}| t |  W d Q R X t G dd d}| t |  W d Q R X |d t ddG dd d}|  t G dd d}| | jd	 | |d
jd t ddG dd d}| t |  W d Q R X d S )Nc               @   s   e Zd Zdd ZdS )z"TestCase.test_post_init.<locals>.Cc             S   s
   t  d S )N)r   )r   r   r   r   __post_init__a  s    z0TestCase.test_post_init.<locals>.C.__post_init__N)r   r   r   r   r   r   r   r   r   _  s   r   c               @   s"   e Zd ZU dZeed< dd ZdS )z"TestCase.test_post_init.<locals>.Cr5   r    c             S   s   | j dkrt d S )Nr5   )r    r   )r   r   r   r   r   i  s    
z0TestCase.test_post_init.<locals>.C.__post_init__N)r   r   r   r    r#   r$   r   r   r   r   r   r   f  s   
r<   F)r   c               @   s   e Zd Zdd ZdS )z"TestCase.test_post_init.<locals>.Cc             S   s
   t  d S )N)r   )r   r   r   r   r   u  s    z0TestCase.test_post_init.<locals>.C.__post_init__N)r   r   r   r   r   r   r   r   r   s  s   c               @   s"   e Zd ZU dZeed< dd ZdS )z"TestCase.test_post_init.<locals>.Cr   r"   c             S   s   |  j d9  _ d S )Nru   )r"   )r   r   r   r   r   }  s    z0TestCase.test_post_init.<locals>.C.__post_init__N)r   r   r   r"   r#   r$   r   r   r   r   r   r   z  s   
r   ru   r   T)r/   c               @   s"   e Zd ZU dZeed< dd ZdS )z"TestCase.test_post_init.<locals>.Cr   r"   c             S   s   |  j d9  _ d S )Nru   )r"   )r   r   r   r   r     s    z0TestCase.test_post_init.<locals>.C.__post_init__N)r   r   r   r"   r#   r$   r   r   r   r   r   r     s   
)r   r   r   r   r"   FrozenInstanceError)r   r   r   r   r   test_post_init]  s    zTestCase.test_post_initc          	   C   s   G dd d}t G dd d|}| | jd t G dd d|}| t |  W d Q R X t G dd d|}| t |  W d Q R X d S )Nc               @   s   e Zd Zdd ZdS )z(TestCase.test_post_init_super.<locals>.Bc             S   s
   t  d S )N)r   )r   r   r   r   r     s    z6TestCase.test_post_init_super.<locals>.B.__post_init__N)r   r   r   r   r   r   r   r   r+     s   r+   c               @   s   e Zd Zdd ZdS )z(TestCase.test_post_init_super.<locals>.Cc             S   s
   d| _ d S )Nr<   )r"   )r   r   r   r   r     s    z6TestCase.test_post_init_super.<locals>.C.__post_init__N)r   r   r   r   r   r   r   r   r     s   r   r<   c                   s   e Zd Z fddZ  ZS )z(TestCase.test_post_init_super.<locals>.Cc                s   t    d S )N)superr   )r   )	__class__r   r   r     s    z6TestCase.test_post_init_super.<locals>.C.__post_init__)r   r   r   r   __classcell__r   r   )r   r   r     s   c               @   s   e Zd ZdS )z(TestCase.test_post_init_super.<locals>.CN)r   r   r   r   r   r   r   r     s   )r   r   r"   r   r   )r   r+   r   r   r   r   test_post_init_super  s    zTestCase.test_post_init_superc                sP   d t G  fddd}|   |dd}| |j|jfd |   d S )NFc                   s.   e Zd ZU eed< eed< e fddZdS )z/TestCase.test_post_init_staticmethod.<locals>.Cr"   r)   c                  s   d d S )NTr   r   )flagr   r   r     s    z=TestCase.test_post_init_staticmethod.<locals>.C.__post_init__N)r   r   r   r#   r$   staticmethodr   r   )r   r   r   r     s   
r   r*   r   )r*   r   )r   r   r   r"   r)   rv   )r   r   rH   r   )r   r   test_post_init_staticmethod  s    	

z$TestCase.test_post_init_staticmethodc             C   sL   t G dd d}| |j |dd}| |j|jfd | |j d S )Nc               @   s.   e Zd ZU dZeed< eed< edd ZdS )z.TestCase.test_post_init_classmethod.<locals>.CFr"   r)   c             S   s
   d| _ d S )NT)r   )re   r   r   r   r     s    z<TestCase.test_post_init_classmethod.<locals>.C.__post_init__N)r   r   r   r   r#   r$   classmethodr   r   r   r   r   r     s   
r   r*   r   )r*   r   )r   r   r   r   r"   r)   rv   )r   r   rH   r   r   r   test_post_init_classmethod  s
    	
z#TestCase.test_post_init_classmethodc             C   s   t G dd d}|d}| t|d | tt|d | t|jd | |jd | |jd | |jd	 | |j	d
 | jd7  _| |jd |d}| |j
|jfd | |jd | |jd | |jd	 | |j	d
 d S )Nc               @   s^   e Zd ZU eed< dZeed< dZee ed< dZee ed< dZ	ee ed	< d
Z
eed< dS )z"TestCase.test_class_var.<locals>.Cr"   r5   r)   i  r9   i  wi  r   i  sN)r   r   r   r#   r$   r)   r9   r   r   r   r   r   r   r   r   r     s   
r   r<   z-TestCase.test_class_var.<locals>.C(x=5, y=10)ru   r   i  i  i  i  rq   i  r   )r   r5   )r   r   r=   r   r   r$   r9   r   r   r   r"   r)   )r   r   rH   r   r   r   test_class_var  s"    	zTestCase.test_class_varc             C   s$   t G dd d}| d|j d S )Nc               @   s   e Zd ZU ee ed< dS )z-TestCase.test_class_var_no_default.<locals>.Cr"   N)r   r   r   r   r#   r$   r   r   r   r   r     s   
r   r"   )r   r   r[   )r   r   r   r   r   test_class_var_no_default  s    z"TestCase.test_class_var_no_defaultc          	   C   s<   |  td& tG dd d}| d|j W d Q R X d S )Nzcannot have a default factoryc               @   s$   e Zd ZU eedZee ed< dS )z2TestCase.test_class_var_default_factory.<locals>.C)r   r"   N)r   r   r   r   r#   r"   r   r$   r   r   r   r   r     s   
r   r"   )r,   r-   r   r   r[   )r   r   r   r   r   test_class_var_default_factory  s    z'TestCase.test_class_var_default_factoryc             C   sD   t G dd d}| |jd t G dd d}| |jd d S )Nc               @   s   e Zd ZU dZee ed< dS )z/TestCase.test_class_var_with_default.<locals>.Cr5   r"   N)r   r   r   r"   r   r#   r$   r   r   r   r   r     s   
r   r5   c               @   s$   e Zd ZU eddZee ed< dS )z/TestCase.test_class_var_with_default.<locals>.Cr5   )r   r"   N)r   r   r   r   r"   r   r#   r$   r   r   r   r   r      s   
)r   r   r"   )r   r   r   r   r   test_class_var_with_default  s    z$TestCase.test_class_var_with_defaultc             C   s   t ddG dd d}|d}| t|dd | tt|d | t|jd | |jd | |jd	 | |jd
 | jd7  _| |jd |d}| |j	|j
fd | |jd | |jd	 | |jd
 d S )NT)r/   c               @   sR   e Zd ZU eed< dZeed< dZee ed< dZee ed< dZ	ee ed	< d
S )z)TestCase.test_class_var_frozen.<locals>.Cr"   r5   r)   i  r9   i  r   i  r   N)
r   r   r   r#   r$   r)   r9   r   r   r   r   r   r   r   r     s
   
r   r<   z4TestCase.test_class_var_frozen.<locals>.C(x=5, y=10)ru   i  i  i  rq   i  r   )r   r5   )r   r   r=   r   r   r$   r9   r   r   r"   r)   )r   r   rH   r   r   r   test_class_var_frozen  s    zTestCase.test_class_var_frozenc             C   s$   t G dd d}| d|j d S )Nc               @   s   e Zd ZU ee ed< dS )z,TestCase.test_init_var_no_default.<locals>.Cr"   N)r   r   r   InitVarr#   r$   r   r   r   r   r   "  s   
r   r"   )r   r   r[   )r   r   r   r   r   test_init_var_no_default   s    z!TestCase.test_init_var_no_defaultc          	   C   s<   |  td& tG dd d}| d|j W d Q R X d S )Nzcannot have a default factoryc               @   s$   e Zd ZU eedZee ed< dS )z1TestCase.test_init_var_default_factory.<locals>.C)r   r"   N)r   r   r   r   r#   r"   r   r$   r   r   r   r   r   -  s   
r   r"   )r,   r-   r   r   r[   )r   r   r   r   r   test_init_var_default_factory(  s    z&TestCase.test_init_var_default_factoryc             C   sD   t G dd d}| |jd t G dd d}| |jd d S )Nc               @   s   e Zd ZU dZee ed< dS )z.TestCase.test_init_var_with_default.<locals>.Cr5   r"   N)r   r   r   r"   r   r#   r$   r   r   r   r   r   5  s   
r   r5   c               @   s$   e Zd ZU eddZee ed< dS )z.TestCase.test_init_var_with_default.<locals>.Cr5   )r   r"   N)r   r   r   r   r"   r   r#   r$   r   r   r   r   r   :  s   
)r   r   r"   )r   r   r   r   r   test_init_var_with_default3  s    z#TestCase.test_init_var_with_defaultc             C   s.   t G dd d}|dd}| |jd d S )Nc               @   s2   e Zd ZU dZeed< dZee ed< dd ZdS )z!TestCase.test_init_var.<locals>.CNr"   
init_paramc             S   s   | j d kr|d | _ d S )Nru   )r"   )r   r   r   r   r   r   E  s    
z/TestCase.test_init_var.<locals>.C.__post_init__)	r   r   r   r"   r#   r$   r   r   r   r   r   r   r   r   @  s   
r   r5   )r   r   )r   r   r"   )r   r   rH   r   r   r   test_init_var?  s    	
zTestCase.test_init_varc             C   sl   t G dd d}|dd}| t|ddi t G dd d|}|ddd	d
}| t|ddd d S )Nc               @   s"   e Zd ZU eed< ee ed< dS )z0TestCase.test_init_var_inheritance.<locals>.Baser"   	init_baseN)r   r   r   r#   r$   r   r   r   r   r   r8   P  s   
r8   r   r5   r"   c               @   s*   e Zd ZU eed< ee ed< dd ZdS )z-TestCase.test_init_var_inheritance.<locals>.Cr)   init_derivedc             S   s   | j | | _ | j| | _d S )N)r"   r)   )r   r   r   r   r   r   r   _  s    z;TestCase.test_init_var_inheritance.<locals>.C.__post_init__N)r   r   r   r#   r$   r   r   r   r   r   r   r   Z  s   
r      2   3      e   )r"   r)   )r   r   r   )r   r8   rT   r   rH   r   r   r   test_init_var_inheritanceL  s    
z"TestCase.test_init_var_inheritancec                s  t G dd d}|d}|d}| |jd | |jg  | || | |j|j | t|ddgddgf g  t G  fddd}|d}|d}| |jd | |jg  | || | |j|j | t|ddgddgf t G dd d}| t| d | | jg  t d	d
G dd d}| t| g f | t| td t G dd d}| t| g f t G dd d}| | |dg d S )Nc               @   s(   e Zd ZU eed< eedZeed< dS )z(TestCase.test_default_factory.<locals>.Cr"   )r   r)   N)r   r   r   r#   r$   r   r   r)   r   r   r   r   r   h  s   
r   r*   r<   rq   c                   s0   e Zd ZU eed< e fdddZeed< dS )z(TestCase.test_default_factory.<locals>.Cr"   c                  s    S )Nr   r   )r   r   r   rg   z  rh   z1TestCase.test_default_factory.<locals>.C.<lambda>)r   r)   N)r   r   r   r#   r$   r   r)   r   r   )r   r   r   r   w  s   
c               @   s"   e Zd ZU eeddZeed< dS )z(TestCase.test_default_factory.<locals>.CF)r   r=   r"   N)r   r   r   r   r   r"   r$   r   r   r   r   r     s   
z*TestCase.test_default_factory.<locals>.C()T)r4   c               @   s"   e Zd ZU eeddZeed< dS )z(TestCase.test_default_factory.<locals>.CF)r   r6   r"   N)r   r   r   r   r   r"   r$   r   r   r   r   r     s   
r   c               @   s"   e Zd ZU eeddZeed< dS )z(TestCase.test_default_factory.<locals>.CF)r   r   r"   N)r   r   r   r   r   r"   r$   r   r   r   r   r     s   
c               @   s"   e Zd ZU eeddZeed< dS )z(TestCase.test_default_factory.<locals>.CF)r   r   r"   N)r   r   r   r   r   r"   r$   r   r   r   r   r     s   
)	r   r   r"   r)   assertIsNotastupler   r=   r6   )r   r   Zc0c1r   )r   r   test_default_factoryf  s6    zTestCase.test_default_factoryc                sL   t   tG  fddd}| j |  jd | j |  jd d S )Nc                   s"   e Zd ZU e ddZeed< dS )z5TestCase.test_default_factory_with_no_init.<locals>.CF)r   r   r"   N)r   r   r   r   r"   r   r$   r   )factoryr   r   r     s   
r   rq   ru   )r   r   r"   r   
call_count)r   r   r   )r   r   !test_default_factory_with_no_init  s    z*TestCase.test_default_factory_with_no_initc                sl   t   tG  fddd}| j |  jd | |djd |  jd | j |  jd d S )Nc                   s    e Zd ZU e dZeed< dS )zBTestCase.test_default_factory_not_called_if_value_given.<locals>.C)r   r"   N)r   r   r   r   r"   r#   r$   r   )r   r   r   r     s   
r   rq   r5   ru   )r   r   r"   r   r   )r   r   r   )r   r   .test_default_factory_not_called_if_value_given  s    z7TestCase.test_default_factory_not_called_if_value_givenc             C   s~   t G dd d}t G dd d|}| | ji  | | ji  | | jd t G dd d|}| | ji  d S )Nc               @   s    e Zd ZU eedZeed< dS )z2TestCase.test_default_factory_derived.<locals>.Foo)r   r"   N)r   r   r   r   r   r"   r$   r   r   r   r   Foo  s   
r   c               @   s   e Zd ZU dZeed< dS )z2TestCase.test_default_factory_derived.<locals>.Barrq   r)   N)r   r   r   r)   r#   r$   r   r   r   r   Bar  s   
r   rq   c               @   s   e Zd ZdS )z2TestCase.test_default_factory_derived.<locals>.BazN)r   r   r   r   r   r   r   Baz  s   r   )r   r   r"   r)   )r   r   r   r   r   r   r   test_default_factory_derived  s    z%TestCase.test_default_factory_derivedc          	   C   s   t G dd d}G dd d|}t G dd d|}|dd}| |j|jfd	 | td
 |j W d Q R X G dd d|}|dd}| |j|jfd d S )Nc               @   s   e Zd ZU eed< dS )z3TestCase.test_intermediate_non_dataclass.<locals>.Ar"   N)r   r   r   r#   r$   r   r   r   r   A  s   
r   c               @   s   e Zd ZU eed< dS )z3TestCase.test_intermediate_non_dataclass.<locals>.Br)   N)r   r   r   r#   r$   r   r   r   r   r+     s   
r+   c               @   s   e Zd ZU eed< dS )z3TestCase.test_intermediate_non_dataclass.<locals>.Cr9   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   rq   r*   )rq   r*   zobject has no attributec               @   s   e Zd ZU eed< dS )z3TestCase.test_intermediate_non_dataclass.<locals>.Dr   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   r   r<   )r   r<   )r   r   r"   r9   r,   AttributeErrorr)   )r   r   r+   r   rH   r   r   r   r   r   test_intermediate_non_dataclass  s    

z(TestCase.test_intermediate_non_dataclassc          	   C   s.   |  td tG dd d}W d Q R X d S )Nzcannot have a default factoryc               @   s$   e Zd ZU eedZee ed< dS )z1TestCase.test_classvar_default_factory.<locals>.C)r   r"   N)r   r   r   r   r#   r"   r   r$   r   r   r   r   r     s   
r   )r,   r-   r   )r   r   r   r   r   test_classvar_default_factory  s    z&TestCase.test_classvar_default_factoryc                s   G dd d}|  td |  tt |  t| |  t|  tG dd d tG  fddd} d}||d	}| t  | t| |  t|j | t|j |  t|j d S )
Nc               @   s   e Zd ZdS )z0TestCase.test_is_dataclass.<locals>.NotDataClassN)r   r   r   r   r   r   r   NotDataClass  s   r  r   c               @   s   e Zd ZU eed< dS )z%TestCase.test_is_dataclass.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   c                   s   e Zd ZU  ed< eed< dS )z%TestCase.test_is_dataclass.<locals>.Dr   eN)r   r   r   r$   r#   r   )r   r   r   r     s   
r   r5   r   )r   Zis_dataclassr#   r   rv   r"   r   r  )r   r  r   rH   r   r   )r   r   test_is_dataclass  s    
zTestCase.test_is_dataclassc             C   s0   t G dd d}| t|t|dd d S )Nc               @   s   e Zd ZU eed< eed< dS )z:TestCase.test_helper_fields_with_class_instance.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r   r     s   
r   r   g        )r   r   r   )r   r   r   r   r   &test_helper_fields_with_class_instance  s    z/TestCase.test_helper_fields_with_class_instancec          	   C   st   |  td td W d Q R X G dd d}|  td t| W d Q R X |  td t|  W d Q R X d S )Nzdataclass type or instancer   c               @   s   e Zd ZdS )z0TestCase.test_helper_fields_exception.<locals>.CN)r   r   r   r   r   r   r   r   !  s    r   )r,   r-   r   )r   r   r   r   r   test_helper_fields_exception  s    z%TestCase.test_helper_fields_exceptionc             C   s   t G dd d}|dd}| t|ddd | t|t| | t|t| d|_| t|ddd | tt|t d S )Nc               @   s   e Zd ZU eed< eed< dS )z&TestCase.test_helper_asdict.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r   )  s   
r   rq   ru   )r"   r)   r%   )r   r   asdictr   r"   r   r   r   )r   r   rH   r   r   r   test_helper_asdict'  s    
zTestCase.test_helper_asdictc          	   C   sV   t G dd d}| td t| W d Q R X | td tt W d Q R X d S )Nc               @   s   e Zd ZU eed< eed< dS )z8TestCase.test_helper_asdict_raises_on_classes.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r   8  s   
r   zdataclass instance)r   r,   r-   r  r#   )r   r   r   r   r   $test_helper_asdict_raises_on_classes6  s
    z-TestCase.test_helper_asdict_raises_on_classesc             C   sx   t G dd d}g }|d|}t|}| |d | | |d | |d}t|}|d d | |jg  d S )Nc               @   s,   e Zd ZU eed< eedZee ed< dS )z2TestCase.test_helper_asdict_copy_values.<locals>.Cr"   )r   r)   N)	r   r   r   r#   r$   r   r   r)   r   r   r   r   r   r   B  s   
r   rq   r)   )r   r  r   r   appendr)   )r   r   initialrH   r   r   r   r   test_helper_asdict_copy_valuesA  s    
z'TestCase.test_helper_asdict_copy_valuesc                s   t G dd d t G  fddd}|d dd}t|}| |ddddd	 | t|t| d
|j_| t|ddd
dd	 d S )Nc               @   s   e Zd ZU eed< eed< dS )z2TestCase.test_helper_asdict_nested.<locals>.UserIdtokengroupN)r   r   r   r#   r$   r   r   r   r   UserIdQ  s   
r  c                   s   e Zd ZU eed<  ed< dS )z0TestCase.test_helper_asdict_nested.<locals>.UserrW   idN)r   r   r   r?   r$   r   )r  r   r   UserU  s   
r  Joe{   rq   )r  r  )rW   r  ru   )r   r  r   r   r  r  )r   r  ur   r   )r  r   test_helper_asdict_nestedP  s    z"TestCase.test_helper_asdict_nestedc       	         s  t G dd d t G  fddd}t G  fddd}t G  fddd} d	d
} dd}|d||g}|d||f}|d||d}| t|dd	d
ddddgd | t|dd	d
ddddfd | t|dd	d
dddddd d S )Nc               @   s   e Zd ZU eed< eed< dS )z<TestCase.test_helper_asdict_builtin_containers.<locals>.UserrW   r  N)r   r   r   r?   r$   r#   r   r   r   r   r  b  s   
r  c                   s"   e Zd ZU eed< e  ed< dS )zATestCase.test_helper_asdict_builtin_containers.<locals>.GroupListr  usersN)r   r   r   r#   r$   r   r   )r  r   r   	GroupListf  s   
r  c                   s&   e Zd ZU eed< e df ed< dS )zBTestCase.test_helper_asdict_builtin_containers.<locals>.GroupTupler  .r  N)r   r   r   r#   r$   r   r   )r  r   r   
GroupTuplej  s   
r  c                   s&   e Zd ZU eed< ee f ed< dS )zATestCase.test_helper_asdict_builtin_containers.<locals>.GroupDictr  r  N)r   r   r   r#   r$   r	   r?   r   )r  r   r   	GroupDictn  s   
r  Alicerq   Bobru   r   )rI   second)rW   r  )r  r  )r   r   r  )	r   r  r  r  rf   rT   glgtgdr   )r  r   %test_helper_asdict_builtin_containersa  s    

z.TestCase.test_helper_asdict_builtin_containersc                sx   t G dd d t G  fddd}| t| dgdddgii | t| ddiddddiii d S )	Nc               @   s   e Zd ZU eed< dS )z=TestCase.test_helper_asdict_builtin_containers.<locals>.Childr   N)r   r   r   rK   r$   r   r   r   r   Child  s   
r!  c                   s   e Zd ZU  ed< dS )z>TestCase.test_helper_asdict_builtin_containers.<locals>.ParentchildN)r   r   r   r$   r   )r!  r   r   Parent  s   
r#  rq   r"  r   ru   )r   r   r  )r   r#  r   )r!  r   r   ~  s    $c             C   s   t G dd d}|dd}t|td}| |tddg | |t|td d|_t|td}| |td	dg | t|t d S )
Nc               @   s   e Zd ZU eed< eed< dS )z.TestCase.test_helper_asdict_factory.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   rq   ru   )dict_factory)r"   rq   )r)   ru   r%   )r"   r%   )r   r  r   r   r   r"   r   r   )r   r   rH   r   r   r   r   test_helper_asdict_factory  s    
z#TestCase.test_helper_asdict_factoryc                s   t dd tG  fddd}|d d|d dd	d
d}t|}| |d dd dd	d
ddd t|td}| |d dd dd	d
ddd | t|t | t|d d t d S )NTza b cc                   s   e Zd ZU eed<  ed< dS )z1TestCase.test_helper_asdict_namedtuple.<locals>.Cr"   r)   N)r   r   r   r?   r$   r   )r&  r   r   r     s   
r   outerrq   innerr         ru   )r"   r)   )r$  r)   )r   r   r  r   r   r   r   )r   r   rH   r   r   )r&  r   test_helper_asdict_namedtuple  s"    
 z&TestCase.test_helper_asdict_namedtuplec             C   sN   t G dd d}tdd}||ddi}| t|d|dddii d S )	Nc               @   s   e Zd ZU eed< dS )z5TestCase.test_helper_asdict_namedtuple_key.<locals>.Cr   N)r   r   r   r   r$   r   r   r   r   r     s   
r   r&  rf   zan ar   r   )rf   )r   r   r   r  )r   r   r&  rH   r   r   r   !test_helper_asdict_namedtuple_key  s    
z*TestCase.test_helper_asdict_namedtuple_keyc                s   G dd dt dd tG  fddd} d}||}t|}| |d dd	i | |d | | |d  d d S )
Nc               @   s   e Zd Zdd ZdS )z9TestCase.test_helper_asdict_namedtuple_derived.<locals>.Tc             S   s   | j S )N)rf   )r   r   r   r   my_a  s    z>TestCase.test_helper_asdict_namedtuple_derived.<locals>.T.my_aN)r   r   r   r-  r   r   r   r   r&    s   r&  ZTbaserf   c                   s   e Zd ZU  ed< dS )z9TestCase.test_helper_asdict_namedtuple_derived.<locals>.Cr   N)r   r   r   r$   r   )r&  r   r   r     s   
r   r   r   )rf   )r   r   r  r   r   r-  )r   r   r   rH   r   r   )r&  r   %test_helper_asdict_namedtuple_derived  s    z.TestCase.test_helper_asdict_namedtuple_derivedc             C   s   t G dd d}|d}| t|d | t|t| | t|t| d|_| t|d | tt|t d S )Nc               @   s"   e Zd ZU eed< dZeed< dS )z'TestCase.test_helper_astuple.<locals>.Cr"   r   r)   N)r   r   r   r#   r$   r)   r   r   r   r   r     s   
r   rq   )rq   r   r%   )rq   r%   )r   r   r   r   r)   r   r   r   )r   r   rH   r   r   r   test_helper_astuple  s    zTestCase.test_helper_astuplec          	   C   sV   t G dd d}| td t| W d Q R X | td tt W d Q R X d S )Nc               @   s   e Zd ZU eed< eed< dS )z9TestCase.test_helper_astuple_raises_on_classes.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   zdataclass instance)r   r,   r-   r   r#   )r   r   r   r   r   %test_helper_astuple_raises_on_classes  s
    z.TestCase.test_helper_astuple_raises_on_classesc             C   sx   t G dd d}g }|d|}t|}| |d | | |d | |d}t|}|d d | |jg  d S )Nc               @   s,   e Zd ZU eed< eedZee ed< dS )z3TestCase.test_helper_astuple_copy_values.<locals>.Cr"   )r   r)   N)	r   r   r   r#   r$   r   r   r)   r   r   r   r   r   r     s   
r   rq   )r   r   r   r   r
  r)   )r   r   r  rH   r   r   r   r   test_helper_astuple_copy_values  s    
z(TestCase.test_helper_astuple_copy_valuesc                s|   t G dd d t G  fddd}|d dd}t|}| |d | t|t| d	|j_| t|d
 d S )Nc               @   s   e Zd ZU eed< eed< dS )z3TestCase.test_helper_astuple_nested.<locals>.UserIdr  r  N)r   r   r   r#   r$   r   r   r   r   r    s   
r  c                   s   e Zd ZU eed<  ed< dS )z1TestCase.test_helper_astuple_nested.<locals>.UserrW   r  N)r   r   r   r?   r$   r   )r  r   r   r    s   
r  r  r  rq   )r  )r  rq   ru   )r  )r  ru   )r   r   r   r   r  r  )r   r  r  r   r   )r  r   test_helper_astuple_nested  s    z#TestCase.test_helper_astuple_nestedc       	         s   t G dd d t G  fddd}t G  fddd}t G  fddd} d	d
} dd}|d||g}|d||f}|d||d}| t|dddgf | t|d | t|ddddf d S )Nc               @   s   e Zd ZU eed< eed< dS )z=TestCase.test_helper_astuple_builtin_containers.<locals>.UserrW   r  N)r   r   r   r?   r$   r#   r   r   r   r   r    s   
r  c                   s"   e Zd ZU eed< e  ed< dS )zBTestCase.test_helper_astuple_builtin_containers.<locals>.GroupListr  r  N)r   r   r   r#   r$   r   r   )r  r   r   r    s   
r  c                   s&   e Zd ZU eed< e df ed< dS )zCTestCase.test_helper_astuple_builtin_containers.<locals>.GroupTupler  .r  N)r   r   r   r#   r$   r   r   )r  r   r   r    s   
r  c                   s&   e Zd ZU eed< ee f ed< dS )zBTestCase.test_helper_astuple_builtin_containers.<locals>.GroupDictr  r  N)r   r   r   r#   r$   r	   r?   r   )r  r   r   r    s   
r  r  rq   r  ru   r   )rI   r  )r  rq   )r  ru   )r   ))r  rq   )r  ru   )r   r   r   )	r   r  r  r  rf   rT   r  r  r  r   )r  r   &test_helper_astuple_builtin_containers  s    

z/TestCase.test_helper_astuple_builtin_containersc                sp   t G dd d t G  fddd}| t| dgdgff | t| ddiddiff d S )Nc               @   s   e Zd ZU eed< dS )z>TestCase.test_helper_astuple_builtin_containers.<locals>.Childr   N)r   r   r   rK   r$   r   r   r   r   r!  ,  s   
r!  c                   s   e Zd ZU  ed< dS )z?TestCase.test_helper_astuple_builtin_containers.<locals>.Parentr"  N)r   r   r   r$   r   )r!  r   r   r#  0  s   
r#  rq   ru   )r   r   r   )r   r#  r   )r!  r   r3  +  s     c                s   t G dd d}tdd  fdd}|dd}t||d	}| | dd | |t||d	 d
|_t||d	}| | d
d | t|  d S )Nc               @   s   e Zd ZU eed< eed< dS )z/TestCase.test_helper_astuple_factory.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r   8  s   
r   NTzx yc                s    |  S )Nr   )r   )r4  r   r   nt=  s    z0TestCase.test_helper_astuple_factory.<locals>.ntrq   ru   )tuple_factoryr%   )r   r   r   r   r   r"   r   r   )r   r   r5  rH   r   r   )r4  r   test_helper_astuple_factory7  s    

z$TestCase.test_helper_astuple_factoryc                s   t dd tG  fddd}|d d|d dd	d
d}t|}| |d dddf t|td}| |d dd dd	d
gdg d S )Nr&  za b cc                   s   e Zd ZU eed<  ed< dS )z2TestCase.test_helper_astuple_namedtuple.<locals>.Cr"   r)   N)r   r   r   r?   r$   r   )r&  r   r   r   J  s   
r   r'  rq   r(  r   r)  r*  ru   )r(  )r   r)  r*  )r6  )r   r   r   r   r   )r   r   rH   r   r   )r&  r   test_helper_astuple_namedtupleH  s    
 z'TestCase.test_helper_astuple_namedtuplec             C   sN   dt t di}tdd|}t|}| || | t|ddddd d S )Nr$   )r"   r)   r   r   rq   ru   )r#   r   r   r   r  )r   cls_dictre   cls1r   r   r   test_dynamic_class_creationW  s
    z$TestCase.test_dynamic_class_creationc             C   sT   t t dtddd}tdd|}t|}| || | t|dddd d S )N)r"   r)   r<   )r   )r$   r)   r   r   rq   )r#   r   r   r   r   r  )r   r9  re   r:  r   r   r   'test_dynamic_class_creation_using_fieldd  s    z0TestCase.test_dynamic_class_creation_using_fieldc                s   t G dd d}g   fdd}||_|dd}| d d  | d d  | d	g f d
  | dg f d  | d  | d d  d S )Nc               @   sj   e Zd ZU eed< e Zeed< eeddZeed< eedZ	eed< eddd	Z
eed
< dZeed< dS )z&TestCase.test_init_in_order.<locals>.Crf   rT   F)r   r   rH   )r   r   r   )r   r   r  r   N)r   r   r   r#   r$   r   rT   r   rH   r   r  r   r   r   r   r   r   s  s   
r   c                s     ||f d S )N)r
  )r   rW   value)callsr   r   setattr}  s    z,TestCase.test_init_in_order.<locals>.setattrr   rq   )rf   r   )rT   rq   rH   ru   r   r*   )r  r   )r   r   r   )r   __setattr__r   r   )r   r   r?  rH   r   )r>  r   test_init_in_orderr  s    	
zTestCase.test_init_in_orderc             C   s   t G dd d}|d}| d|j | d|j | d|j | d|j | |jd | d	|j | |jd | d|j | |jd | d|j | |jg  | d|j | |j	g  | d|j | d	|j | |jd d S )
Nc               @   s\   e Zd ZU eed< eeddZeed< eedZeed< edddZ	eed	< d
Z
eed< dS )z'TestCase.test_items_in_dicts.<locals>.Crf   F)r   r   rT   )r   rH   r   )r   r   r   r   r  N)r   r   r   r#   r$   r   r   rT   rH   r   r  r   r   r   r   r     s
   
r   r   rf   rT   rH   r   r   r  )
r   r   r[   r   r   r   r  rf   rT   rH   )r   r   rH   r   r   r   test_items_in_dicts  s$    zTestCase.test_items_in_dictsc             C   s*   t G dd d}| |djd d S )Nc               @   s"   e Zd ZU eed< edd ZdS )z:TestCase.test_alternate_classmethod_constructor.<locals>.Cr"   c             S   s   d}| |S )Nr   r   )re   filenameZvalue_in_filer   r   r   	from_file  s    zDTestCase.test_alternate_classmethod_constructor.<locals>.C.from_fileN)r   r   r   r#   r$   r   rD  r   r   r   r   r     s   
r   rC  r   )r   r   rD  r"   )r   r   r   r   r   &test_alternate_classmethod_constructor  s    
z/TestCase.test_alternate_classmethod_constructorc          	   C   sn   t G dd d}| t|d j | tt|d jd | td dt|d jd< W d Q R X d S )Nc               @   s   e Zd ZU eed< dS )z/TestCase.test_field_metadata_default.<locals>.Cr    N)r   r   r   r#   r$   r   r   r   r   r     s   
r   r   z does not support item assignmentr*   test)r   r   r   metadatar   r   r,   r-   )r   r   r   r   r   test_field_metadata_default  s    z$TestCase.test_field_metadata_defaultc          	      s  |  t tG dd d}W d Q R X i  tG  fddd}| t|d j | tt|d jd d d< | tt|d jd | t|d jd d | td dt|d jd	< W d Q R X d
ddd tG  fddd}| tt|d jd | t|d jd	 d
 | t|d jd d | t|d jd d d d< | tt|d jd | t|d jd d |  t	 t|d jd  W d Q R X | td dt|d jd	< W d Q R X d S )Nc               @   s    e Zd ZU eddZeed< dS )z/TestCase.test_field_metadata_mapping.<locals>.Cr   )rG  r    N)r   r   r   r   r    r#   r$   r   r   r   r   r     s   
r   c                   s    e Zd ZU e dZeed< dS )z/TestCase.test_field_metadata_mapping.<locals>.C)rG  r    N)r   r   r   r   r    r#   r$   r   )r   r   r   r     s   
r   rq   r@   z does not support item assignmentr*   rF  r5   Z42Zthree)rF  r   r*   c                   s    e Zd ZU e dZeed< dS )z/TestCase.test_field_metadata_mapping.<locals>.C)rG  r    N)r   r   r   r   r    r#   r$   r   )r   r   r   r     s   
r   r   Zbaz)
r   r-   r   r   r   rG  r   r   r,   KeyError)r   r   r   )r   r   test_field_metadata_mapping  s4    z$TestCase.test_field_metadata_mappingc          	      s   G dd d t G  fddd}| tt|d jd | t|d jd d | t t|d jd	  W d Q R X | t|d jd
 d d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )zDTestCase.test_field_metadata_custom_mapping.<locals>.SimpleNameSpacec             [   s   | j | d S )N)r[   update)r   kwr   r   r   rC     s    zMTestCase.test_field_metadata_custom_mapping.<locals>.SimpleNameSpace.__init__c             S   s   |dkrdS t | |S )Nxyzzyplugh)r^   )r   itemr   r   r   __getitem__  s    zPTestCase.test_field_metadata_custom_mapping.<locals>.SimpleNameSpace.__getitem__c             S   s
   | j  S )N)r[   __len__)r   r   r   r   rQ    s    zLTestCase.test_field_metadata_custom_mapping.<locals>.SimpleNameSpace.__len__N)r   r   r   rC   rP  rQ  r   r   r   r   SimpleNameSpace  s   rR  c                   s&   e Zd ZU e dddZeed< dS )z6TestCase.test_field_metadata_custom_mapping.<locals>.Cr5   )rf   )rG  r    N)r   r   r   r   r    r#   r$   r   )rR  r   r   r     s   
r   r   rq   rf   r5   rT   rM  rN  )r   r   r   r   rG  r   r   )r   r   r   )rR  r   "test_field_metadata_custom_mapping  s    z+TestCase.test_field_metadata_custom_mappingc                sX   t d tG  fdddt  }|d}| |jd | |jd t|t  }d S )Nr&  c                   s"   e Zd ZU  ed< dZeed< dS )z5TestCase.test_generic_dataclasses.<locals>.LabeledBoxcontentz	<unknown>labelN)r   r   r   r$   rU  r?   r   )r&  r   r   
LabeledBox
  s   
rV  r%   z	<unknown>)r   r   r
   r   rT  rU  r   r#   )r   rV  ZboxAliasr   )r&  r   test_generic_dataclasses  s    z!TestCase.test_generic_dataclassesc                s   t d t dtG  fdddt f }tG dd d|tf }|t }|ddd	}| t|d
 G dd d|tf }|t }|dd}| | d d S )NSr&  c                   s   e Zd ZU ed<  ed< dS )z-TestCase.test_generic_extending.<locals>.Baser"   r)   N)r   r   r   r$   r   )rY  r&  r   r   r8     s   
r8   c               @   s   e Zd ZU eed< dS )z4TestCase.test_generic_extending.<locals>.DataDerivedZ	new_fieldN)r   r   r   r?   r$   r   r   r   r   DataDerived  s   
rZ  r   test1test2)r   r[  r\  c               @   s   e Zd Zdd ZdS )z7TestCase.test_generic_extending.<locals>.NonDataDerivedc             S   s   | j S )N)r)   )r   r   r   r   
new_method'  s    zBTestCase.test_generic_extending.<locals>.NonDataDerived.new_methodN)r   r   r   r]  r   r   r   r   NonDataDerived&  s   r^  r5   g      ?)	r   r   r
   r#   r?   r   r   r   r]  )r   r8   rZ  rW  rH   r^  r   )rY  r&  r   test_generic_extending  s    
zTestCase.test_generic_extendingc                s   t d tG  fdddt  }tdd fdt  d fg|t t  fddid	}| |t d
djd  | |t d
ddjd | |t d
ddj	d |  }| |t d
dj
d
 | |j||ttf d S )Nr&  c                   s   e Zd ZU  ed< dS )z-TestCase.test_generic_dynamic.<locals>.Parentr"   N)r   r   r   r$   r   )r&  r   r   r#  0  s   
r#  r!  r)   r9   r2   r%   )bases	namespacerq   ru   r*   )r   r   r
   r]   r   r#   r   r9   r   r2   r"   __mro__rK   )r   r#  r!  rW  r   )r&  r   test_generic_dynamic-  s    zTestCase.test_generic_dynamicc             C   s,  t G dd dat G dd dat G dd datd}d|_tdtddtd|tdtddd	d
gg}x|D ]}xttjd D ]}| j||d| t	t
||}| |j|j | |j|j | || d|_t	t
||}| |j|j | |j|j W d Q R X qW qxW d S )Nc               @   s"   e Zd ZU eed< dZeed< dS )Pr"   r   r)   N)r   r   r   r#   r$   r)   r   r   r   r   rd  @  s   
rd  c               @   s*   e Zd ZU eed< edddZeed< dS )Qr"   r   F)r   r   r)   N)r   r   r   r#   r$   r   r)   r   r   r   r   re  D  s   
re  c               @   s,   e Zd ZU eed< eedZee ed< dS )Rr"   )r   r)   N)	r   r   r   r#   r$   r   r   r)   r   r   r   r   r   rf  H  s   
rf  rq   ru   r*   r   )sampleprotor%   )r   rd  re  rf  r)   rangepickleZHIGHEST_PROTOCOLrk   loadsdumpsr   r"   r   )r   qZsamplesrg  rh  Z
new_sampleZanother_new_sampler   r   r   test_dataclassses_pickleable>  s"    .
z%TestCase.test_dataclassses_pickleableN)Yr   r   r   r   r!   r&   r(   r.   r7   r>   rJ   rL   rM   ra   rb   rp   rt   rw   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r	  r  r  r   r%  r+  r,  r.  r/  r0  r1  r2  r3  r7  r8  r;  r<  rA  rB  rE  rH  rJ  rS  rX  r_  rc  rn  r   r   r   r   r      s   ,5!6(!$-F/9
!+r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )TestFieldNoAnnotationc          	   C   s.   |  td tG dd d}W d Q R X d S )Nz)'f' is a field but has no type annotationc               @   s   e Zd Ze ZdS )z>TestFieldNoAnnotation.test_field_without_annotation.<locals>.CN)r   r   r   r   r   r   r   r   r   r   `  s   r   )r,   r-   r   )r   r   r   r   r   test_field_without_annotation]  s    z3TestFieldNoAnnotation.test_field_without_annotationc          	   C   sB   t G dd d}| td t G dd d|}W d Q R X d S )Nc               @   s   e Zd ZU eed< dS )zUTestFieldNoAnnotation.test_field_without_annotation_but_annotation_in_base.<locals>.Br   N)r   r   r   r#   r$   r   r   r   r   r+   e  s   
r+   z)'f' is a field but has no type annotationc               @   s   e Zd Ze ZdS )zUTestFieldNoAnnotation.test_field_without_annotation_but_annotation_in_base.<locals>.CN)r   r   r   r   r   r   r   r   r   r   m  s   r   )r   r,   r-   )r   r+   r   r   r   r   4test_field_without_annotation_but_annotation_in_based  s
    zJTestFieldNoAnnotation.test_field_without_annotation_but_annotation_in_basec          	   C   s>   G dd d}|  td tG dd d|}W d Q R X d S )Nc               @   s   e Zd ZU eed< dS )zcTestFieldNoAnnotation.test_field_without_annotation_but_annotation_in_base_not_dataclass.<locals>.Br   N)r   r   r   r#   r$   r   r   r   r   r+   s  s   
r+   z)'f' is a field but has no type annotationc               @   s   e Zd Ze ZdS )zcTestFieldNoAnnotation.test_field_without_annotation_but_annotation_in_base_not_dataclass.<locals>.CN)r   r   r   r   r   r   r   r   r   r   z  s   r   )r,   r-   r   )r   r+   r   r   r   r   Btest_field_without_annotation_but_annotation_in_base_not_dataclassq  s
    zXTestFieldNoAnnotation.test_field_without_annotation_but_annotation_in_base_not_dataclassN)r   r   r   rp  rq  rr  r   r   r   r   ro  \  s   ro  c               @   sl   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S )TestDocStringc             C   s    |  |dd|dd d S )N  )r   replace)r   rf   rT   r   r   r   assertDocStrEqual  s    zTestDocString.assertDocStrEqualc             C   s$   t G dd d}| |jd d S )Nc               @   s   e Zd ZU dZeed< dS )z?TestDocString.test_existing_docstring_not_overridden.<locals>.CzLorem ipsumr"   N)r   r   r   __doc__r#   r$   r   r   r   r   r     s   
r   zLorem ipsum)r   r   rx  )r   r   r   r   r   &test_existing_docstring_not_overridden  s    z4TestDocString.test_existing_docstring_not_overriddenc             C   s$   t G dd d}| |jd d S )Nc               @   s   e Zd ZdS )z1TestDocString.test_docstring_no_fields.<locals>.CN)r   r   r   r   r   r   r   r     s   r   zC())r   rw  rx  )r   r   r   r   r   test_docstring_no_fields  s    z&TestDocString.test_docstring_no_fieldsc             C   s$   t G dd d}| |jd d S )Nc               @   s   e Zd ZU eed< dS )z1TestDocString.test_docstring_one_field.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   zC(x:int))r   rw  rx  )r   r   r   r   r   test_docstring_one_field  s    z&TestDocString.test_docstring_one_fieldc             C   s$   t G dd d}| |jd d S )Nc               @   s   e Zd ZU eed< eed< dS )z2TestDocString.test_docstring_two_fields.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   zC(x:int, y:int))r   rw  rx  )r   r   r   r   r   test_docstring_two_fields  s    z'TestDocString.test_docstring_two_fieldsc             C   s$   t G dd d}| |jd d S )Nc               @   s&   e Zd ZU eed< eed< eed< dS )z4TestDocString.test_docstring_three_fields.<locals>.Cr"   r)   r9   N)r   r   r   r#   r$   r?   r   r   r   r   r     s   
r   zC(x:int, y:int, z:str))r   rw  rx  )r   r   r   r   r   test_docstring_three_fields  s    z)TestDocString.test_docstring_three_fieldsc             C   s$   t G dd d}| |jd d S )Nc               @   s   e Zd ZU dZeed< dS )z>TestDocString.test_docstring_one_field_with_default.<locals>.Cr*   r"   N)r   r   r   r"   r#   r$   r   r   r   r   r     s   
r   z
C(x:int=3))r   rw  rx  )r   r   r   r   r   %test_docstring_one_field_with_default  s    z3TestDocString.test_docstring_one_field_with_defaultc             C   s$   t G dd d}| |jd d S )Nc               @   s&   e Zd ZU dZeeedf ed< dS )zCTestDocString.test_docstring_one_field_with_default_none.<locals>.CNr"   )r   r   r   r"   r   r#   r   r$   r   r   r   r   r     s   
r   zC(x:Union[int, NoneType]=None))r   rw  rx  )r   r   r   r   r   *test_docstring_one_field_with_default_none  s    z8TestDocString.test_docstring_one_field_with_default_nonec             C   s$   t G dd d}| |jd d S )Nc               @   s   e Zd ZU ee ed< dS )z2TestDocString.test_docstring_list_field.<locals>.Cr"   N)r   r   r   r   r#   r$   r   r   r   r   r     s   
r   zC(x:List[int]))r   rw  rx  )r   r   r   r   r   test_docstring_list_field  s    z'TestDocString.test_docstring_list_fieldc             C   s$   t G dd d}| |jd d S )Nc               @   s$   e Zd ZU eedZee ed< dS )zGTestDocString.test_docstring_list_field_with_default_factory.<locals>.C)r   r"   N)	r   r   r   r   r   r"   r   r#   r$   r   r   r   r   r     s   
r   zC(x:List[int]=<factory>))r   rw  rx  )r   r   r   r   r   .test_docstring_list_field_with_default_factory  s    z<TestDocString.test_docstring_list_field_with_default_factoryc             C   s$   t G dd d}| |jd d S )Nc               @   s   e Zd ZU eed< dS )z3TestDocString.test_docstring_deque_field.<locals>.Cr"   N)r   r   r   r   r$   r   r   r   r   r     s   
r   zC(x:collections.deque))r   rw  rx  )r   r   r   r   r   test_docstring_deque_field  s    z(TestDocString.test_docstring_deque_fieldc             C   s$   t G dd d}| |jd d S )Nc               @   s    e Zd ZU eedZeed< dS )zHTestDocString.test_docstring_deque_field_with_default_factory.<locals>.C)r   r"   N)r   r   r   r   r   r"   r$   r   r   r   r   r     s   
r   z C(x:collections.deque=<factory>))r   rw  rx  )r   r   r   r   r   /test_docstring_deque_field_with_default_factory  s    z=TestDocString.test_docstring_deque_field_with_default_factoryN)r   r   r   rw  ry  rz  r{  r|  r}  r~  r  r  r  r  r  r   r   r   r   rs    s   	rs  c               @   s$   e Zd Zdd Zdd Zdd ZdS )TestInitc             C   s   G dd d}t G dd d|}|d}| |jd | dt| t ddG d	d d|}| }| |jd | |jd
 d S )Nc               @   s   e Zd Zdd ZdS )z&TestInit.test_base_has_init.<locals>.Bc             S   s
   d| _ d S )Nr1   )r9   )r   r   r   r   rC     s    z/TestInit.test_base_has_init.<locals>.B.__init__N)r   r   r   rC   r   r   r   r   r+     s   r+   c               @   s   e Zd ZU dZeed< dS )z&TestInit.test_base_has_init.<locals>.Cr   r"   N)r   r   r   r"   r#   r$   r   r   r   r   r     s   
r   r5   r9   F)r   c               @   s   e Zd ZU dZeed< dS )z&TestInit.test_base_has_init.<locals>.Cr5   r"   N)r   r   r   r"   r#   r$   r   r   r   r   r     s   
r1   )r   r   r"   r   r   r9   )r   r+   r   rH   r   r   r   test_base_has_init  s    	zTestInit.test_base_has_initc             C   sT   t dd G dd d}| | jd t dd G dd d}| | jd d S )NF)r   c               @   s   e Zd ZU dZeed< dS )z TestInit.test_no_init.<locals>.Cr   r    N)r   r   r   r    r#   r$   r   r   r   r   r     s   
r   r   c               @   s"   e Zd ZU dZeed< dd ZdS )z TestInit.test_no_init.<locals>.Cru   r    c             S   s
   d| _ d S )Nr*   )r    )r   r   r   r   rC     s    z)TestInit.test_no_init.<locals>.C.__init__N)r   r   r   r    r#   r$   rC   r   r   r   r   r     s   
r*   )r   r   r    )r   r   r   r   r   test_no_init  s    

zTestInit.test_no_initc             C   s|   t G dd d}| |djd t ddG dd d}| |djd	 t d
dG dd d}| |djd d S )Nc               @   s   e Zd ZU eed< dd ZdS )z)TestInit.test_overwriting_init.<locals>.Cr"   c             S   s   d| | _ d S )Nru   )r"   )r   r"   r   r   r   rC     s    z2TestInit.test_overwriting_init.<locals>.C.__init__N)r   r   r   r#   r$   rC   r   r   r   r   r     s   
r   r*   r   T)r   c               @   s   e Zd ZU eed< dd ZdS )z)TestInit.test_overwriting_init.<locals>.Cr"   c             S   s   d| | _ d S )Nru   )r"   )r   r"   r   r   r   rC     s    z2TestInit.test_overwriting_init.<locals>.C.__init__N)r   r   r   r#   r$   rC   r   r   r   r   r     s   
r      Fc               @   s   e Zd ZU eed< dd ZdS )z)TestInit.test_overwriting_init.<locals>.Cr"   c             S   s   d| | _ d S )Nru   )r"   )r   r"   r   r   r   rC     s    z2TestInit.test_overwriting_init.<locals>.C.__init__N)r   r   r   r#   r$   rC   r   r   r   r   r     s   
r<   r5   )r   r   r"   )r   r   r   r   r   test_overwriting_init   s    zTestInit.test_overwriting_initN)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dd ZdS )TestReprc             C   s   t G dd d}t G dd d|}|d}| t|d t G dd d|}| t| d	 t G d
d d}| t|dd | t| d d S )Nc               @   s   e Zd ZU eed< dS )zTestRepr.test_repr.<locals>.Br"   N)r   r   r   r#   r$   r   r   r   r   r+     s   
r+   c               @   s   e Zd ZU dZeed< dS )zTestRepr.test_repr.<locals>.Cr5   r)   N)r   r   r   r)   r#   r$   r   r   r   r   r      s   
r   r   z(TestRepr.test_repr.<locals>.C(x=4, y=10)c               @   s   e Zd ZU dZeed< dS )zTestRepr.test_repr.<locals>.Dr   r"   N)r   r   r   r"   r#   r$   r   r   r   r   r   '  s   
r   z)TestRepr.test_repr.<locals>.D(x=20, y=10)c               @   s0   e Zd ZeG dd dZeG dd dZdS )zTestRepr.test_repr.<locals>.Cc               @   s   e Zd ZU eed< dS )zTestRepr.test_repr.<locals>.C.Dr    N)r   r   r   r#   r$   r   r   r   r   r   .  s   
r   c               @   s   e Zd ZdS )zTestRepr.test_repr.<locals>.C.EN)r   r   r   r   r   r   r   r   1  s   r   N)r   r   r   r   r   r   r   r   r   r   r   ,  s   r   z$TestRepr.test_repr.<locals>.C.D(i=0)z!TestRepr.test_repr.<locals>.C.E())r   r   r=   r   r   )r   r+   r   r   r   r   r   r   	test_repr  s    zTestRepr.test_reprc             C   sb   t ddG dd d}| t dt|d t ddG dd d}| t|dd d S )	NF)r=   c               @   s   e Zd ZU eed< dS )z TestRepr.test_no_repr.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r   9  s   
r   z+.TestRepr.test_no_repr.<locals>.C object atr*   c               @   s   e Zd ZU eed< dd ZdS )z TestRepr.test_no_repr.<locals>.Cr"   c             S   s   dS )NzC-classr   )r   r   r   r   __repr__C  s    z)TestRepr.test_no_repr.<locals>.C.__repr__N)r   r   r   r#   r$   r  r   r   r   r   r   @  s   
zC-class)r   r   r   r=   r   )r   r   r   r   r   test_no_repr7  s
    zTestRepr.test_no_reprc             C   s   t G dd d}| t|dd t ddG dd d}| t|dd t ddG d	d d}| t|dd d S )
Nc               @   s   e Zd ZU eed< dd ZdS )z)TestRepr.test_overwriting_repr.<locals>.Cr"   c             S   s   dS )Nr"   r   )r   r   r   r   r  N  s    z2TestRepr.test_overwriting_repr.<locals>.C.__repr__N)r   r   r   r#   r$   r  r   r   r   r   r   K  s   
r   r   r"   T)r=   c               @   s   e Zd ZU eed< dd ZdS )z)TestRepr.test_overwriting_repr.<locals>.Cr"   c             S   s   dS )Nr"   r   )r   r   r   r   r  U  s    z2TestRepr.test_overwriting_repr.<locals>.C.__repr__N)r   r   r   r#   r$   r  r   r   r   r   r   R  s   
Fc               @   s   e Zd ZU eed< dd ZdS )z)TestRepr.test_overwriting_repr.<locals>.Cr"   c             S   s   dS )Nr"   r   )r   r   r   r   r  \  s    z2TestRepr.test_overwriting_repr.<locals>.C.__repr__N)r   r   r   r#   r$   r  r   r   r   r   r   Y  s   
)r   r   r=   )r   r   r   r   r   test_overwriting_reprG  s    zTestRepr.test_overwriting_reprN)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dS )TestEqc             C   sl   t ddG dd d}| |d|d |d}| || t ddG dd d}| |dd d S )	NF)r~   c               @   s   e Zd ZU eed< dS )zTestEq.test_no_eq.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r   d  s   
r   r   r*   c               @   s   e Zd ZU eed< dd ZdS )zTestEq.test_no_eq.<locals>.Cr"   c             S   s   |dkS )Nr5   r   )r   r2   r   r   r   r3   o  s    z#TestEq.test_no_eq.<locals>.C.__eq__N)r   r   r   r#   r$   r3   r   r   r   r   r   l  s   
r5   )r   rG   r   )r   r   rH   r   r   r   
test_no_eqb  s    zTestEq.test_no_eqc             C   s   t G dd d}| |dd | |dd t ddG dd d}| |dd | |dd t d	dG d
d d}| |dd | |dd d S )Nc               @   s   e Zd ZU eed< dd ZdS )z%TestEq.test_overwriting_eq.<locals>.Cr"   c             S   s   |dkS )Nr*   r   )r   r2   r   r   r   r3   z  s    z,TestEq.test_overwriting_eq.<locals>.C.__eq__N)r   r   r   r#   r$   r3   r   r   r   r   r   w  s   
r   rq   r*   T)r~   c               @   s   e Zd ZU eed< dd ZdS )z%TestEq.test_overwriting_eq.<locals>.Cr"   c             S   s   |dkS )Nr   r   )r   r2   r   r   r   r3     s    z,TestEq.test_overwriting_eq.<locals>.C.__eq__N)r   r   r   r#   r$   r3   r   r   r   r   r     s   
r   Fc               @   s   e Zd ZU eed< dd ZdS )z%TestEq.test_overwriting_eq.<locals>.Cr"   c             S   s   |dkS )Nr<   r   )r   r2   r   r   r   r3     s    z,TestEq.test_overwriting_eq.<locals>.C.__eq__N)r   r   r   r#   r$   r3   r   r   r   r   r     s   
r<   )r   r   rG   )r   r   r   r   r   test_overwriting_eqs  s    zTestEq.test_overwriting_eqN)r   r   r   r  r  r   r   r   r   r  a  s   r  c               @   s$   e Zd Zdd Zdd Zdd ZdS )TestOrderingc             C   sZ   t tG dd d}| |dd | |dd | |dd | |dd d S )Nc               @   s   e Zd ZU eed< dd ZdS )z5TestOrdering.test_functools_total_ordering.<locals>.Cr"   c             S   s
   | j |kS )N)r"   )r   r2   r   r   r   r     s    z<TestOrdering.test_functools_total_ordering.<locals>.C.__lt__N)r   r   r   r#   r$   r   r   r   r   r   r     s   
r   r   rq   )r   r   rr   rm   rs   rn   )r   r   r   r   r   test_functools_total_ordering  s    z*TestOrdering.test_functools_total_orderingc             C   s   t ddG dd d}| d|j | d|j | d|j | d|j t ddG d	d d}| d|j | d|j | d|j d S )
NF)rd   c               @   s   e Zd ZU eed< dS )z%TestOrdering.test_no_order.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   r   r   r   r   c               @   s   e Zd ZU eed< dd ZdS )z%TestOrdering.test_no_order.<locals>.Cr"   c             S   s   dS )NFr   )r   r2   r   r   r   r     s    z,TestOrdering.test_no_order.<locals>.C.__lt__N)r   r   r   r#   r$   r   r   r   r   r   r     s   
)r   r   r[   )r   r   r   r   r   test_no_order  s    zTestOrdering.test_no_orderc          	   C   s   |  td tddG dd d}W d Q R X |  td tddG dd d}W d Q R X |  td tddG d	d d}W d Q R X |  td
 tddG dd d}W d Q R X d S )NzACannot overwrite attribute __lt__.*using functools.total_orderingT)rd   c               @   s   e Zd ZU eed< dd ZdS )z.TestOrdering.test_overwriting_order.<locals>.Cr"   c             S   s   d S )Nr   )r   r   r   r   r     s    z5TestOrdering.test_overwriting_order.<locals>.C.__lt__N)r   r   r   r#   r$   r   r   r   r   r   r     s   
r   zACannot overwrite attribute __le__.*using functools.total_orderingc               @   s   e Zd ZU eed< dd ZdS )z.TestOrdering.test_overwriting_order.<locals>.Cr"   c             S   s   d S )Nr   )r   r   r   r   r     s    z5TestOrdering.test_overwriting_order.<locals>.C.__le__N)r   r   r   r#   r$   r   r   r   r   r   r     s   
zACannot overwrite attribute __gt__.*using functools.total_orderingc               @   s   e Zd ZU eed< dd ZdS )z.TestOrdering.test_overwriting_order.<locals>.Cr"   c             S   s   d S )Nr   )r   r   r   r   r     s    z5TestOrdering.test_overwriting_order.<locals>.C.__gt__N)r   r   r   r#   r$   r   r   r   r   r   r     s   
zACannot overwrite attribute __ge__.*using functools.total_orderingc               @   s   e Zd ZU eed< dd ZdS )z.TestOrdering.test_overwriting_order.<locals>.Cr"   c             S   s   d S )Nr   )r   r   r   r   r     s    z5TestOrdering.test_overwriting_order.<locals>.C.__ge__N)r   r   r   r#   r$   r   r   r   r   r   r     s   
)r,   r-   r   )r   r   r   r   r   test_overwriting_order  s    """z#TestOrdering.test_overwriting_orderN)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dd Zdd Zd	d
 Zdd ZdS )TestHashc             C   s6   t ddG dd d}| t|ddtd d S )NT)r4   c               @   s   e Zd ZU eed< eed< dS )z$TestHash.test_unsafe_hash.<locals>.Cr"   r)   N)r   r   r   r#   r$   r?   r   r   r   r   r     s   
r   rq   r@   )rq   r@   )r   r   r6   )r   r   r   r   r   test_unsafe_hash  s    zTestHash.test_unsafe_hashc       	   	      s   dd } fdd}xt ddddd	d
ddgdD ]r\}\}}}}}|||||d| |||||d| ||||||||d| ||||||||d| q0W d S )Nc             S   s   | d krd S | rdS dS )N)r*   r   r   )r=  r   r   r   non_bool  s
    z*TestHash.test_hash_rules.<locals>.non_boolc          
      s2   j | |||d |dkr\|r@t|||dG dd d}nt|||dG dd d}|dkr d|j  |jd  n|d	kr|s d|j n|d
krȈ d|j  |jd  n\|dkr|st t	d" t|||dG dd d}W d Q R X nds$td|W d Q R X d S )N)caser4   r~   r/   r{   )r4   r~   r/   c               @   s   e Zd Zdd ZdS )z1TestHash.test_hash_rules.<locals>.test.<locals>.Cc             S   s   dS )Nr   r   )r   r   r   r   r0     s    z:TestHash.test_hash_rules.<locals>.test.<locals>.C.__hash__N)r   r   r   r0   r   r   r   r   r     s   r   c               @   s   e Zd ZdS )z1TestHash.test_hash_rules.<locals>.test.<locals>.CN)r   r   r   r   r   r   r   r     s   ro   r0   ru  nonez#Cannot overwrite attribute __hash__c               @   s   e Zd Zdd ZdS )z1TestHash.test_hash_rules.<locals>.test.<locals>.Cc             S   s   dS )Nr   r   )r   r   r   r   r0   	  s    z:TestHash.test_hash_rules.<locals>.test.<locals>.C.__hash__N)r   r   r   r0   r   r   r   r   r   	  s   Fzunknown result )
rk   r   r   r[   ZassertIsNotNoner   r   r   r,   r-   )r  r4   r~   r/   Z	with_hashr   r   )r   r   r   rF    s(    

(z&TestHash.test_hash_rules.<locals>.test)FFFru  ru  )FFTru  ru  )FTFr  ru  )FTTro   ru  )TFFro   r{   )TFTro   r{   )TTFro   r{   )TTTro   r{   rq   FT)rl   )	r   r  rF  r  r4   r~   r/   Zres_no_defined_hashZres_defined_hashr   )r   r   test_hash_rules  s     1zTestHash.test_hash_rulesc             C   s   t G dd d}| |d|d | |d|d t ddG dd d}| |d|d | t|dt|d t ddd	G d
d d}| |d|d | |d|d | t|dt|d d S )Nc               @   s   e Zd ZU eed< dd ZdS )z TestHash.test_eq_only.<locals>.Cr    c             S   s   | j |j kS )N)r    )r   r2   r   r   r   r3   ;	  s    z'TestHash.test_eq_only.<locals>.C.__eq__N)r   r   r   r#   r$   r3   r   r   r   r   r   8	  s   
r   rq   r   T)r4   c               @   s   e Zd ZU eed< dd ZdS )z TestHash.test_eq_only.<locals>.Cr    c             S   s   | j |j kS )N)r    )r   r2   r   r   r   r3   E	  s    z'TestHash.test_eq_only.<locals>.C.__eq__N)r   r   r   r#   r$   r3   r   r   r   r   r   B	  s   
g      ?)r4   r~   c               @   s   e Zd ZU eed< dd ZdS )z TestHash.test_eq_only.<locals>.Cr    c             S   s   | j dko| j |j kS )Nr*   )r    )r   r2   r   r   r   r3   O	  s    z'TestHash.test_eq_only.<locals>.C.__eq__N)r   r   r   r#   r$   r3   r   r   r   r   r   L	  s   
r*   )r   r   rG   r6   )r   r   r   r   r   test_eq_only2	  s    zTestHash.test_eq_onlyc             C   s`   t ddG dd d}| t| td t ddG dd d}| t| td d S )NT)r/   c               @   s   e Zd ZdS )z%TestHash.test_0_field_hash.<locals>.CN)r   r   r   r   r   r   r   r   V	  s   r   r   )r4   c               @   s   e Zd ZdS )z%TestHash.test_0_field_hash.<locals>.CN)r   r   r   r   r   r   r   r   [	  s   )r   r   r6   )r   r   r   r   r   test_0_field_hashU	  s    zTestHash.test_0_field_hashc             C   s   t ddG dd d}| t|dtd | t|dtd t dd	G d
d d}| t|dtd | t|dtd d S )NT)r/   c               @   s   e Zd ZU eed< dS )z%TestHash.test_1_field_hash.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r   a	  s   
r   r   )r   r%   )r%   )r4   c               @   s   e Zd ZU eed< dS )z%TestHash.test_1_field_hash.<locals>.Cr"   N)r   r   r   r#   r$   r   r   r   r   r   g	  s   
)r   r   r6   )r   r   r   r   r   test_1_field_hash`	  s    zTestHash.test_1_field_hashc             C   s:  G dd d}x$d d t dfd d |dfd dt dfd d|dfd dt dfd d|dfdd t dfdd |dfddt dfdd|dfddt dfdd|dfdd t dfdd |dfddt dfdd|dfddt dfdd|dfgD ]f\}}}}| j||||d	@ |d kr|d krtG d
d d|}nh|d kr>t|dG dd d|}nB|d krdt|dG dd d|}nt||dG dd d|}|dkr|d}| td t| W d Q R X nt|dkr| t|dd nT|dkr| |jt j n8|dkr| t|dtd nds(t	d|W d Q R X qW d S )Nc               @   s   e Zd Zdd ZdS )z(TestHash.test_hash_no_args.<locals>.Basec             S   s   dS )Ni-  r   )r   r   r   r   r0   t	  s    z1TestHash.test_hash_no_args.<locals>.Base.__hash__N)r   r   r   r0   r   r   r   r   r8   s	  s   r8   Z
unhashableFrK   baseTr   )r/   r~   r  rx   c               @   s   e Zd ZU eed< dS )z%TestHash.test_hash_no_args.<locals>.Cr    N)r   r   r   r#   r$   r   r   r   r   r   	  s   
r   )r~   c               @   s   e Zd ZU eed< dS )z%TestHash.test_hash_no_args.<locals>.Cr    N)r   r   r   r#   r$   r   r   r   r   r   	  s   
)r/   c               @   s   e Zd ZU eed< dS )z%TestHash.test_hash_no_args.<locals>.Cr    N)r   r   r   r#   r$   r   r   r   r   r   	  s   
)r/   r~   c               @   s   e Zd ZU eed< dS )z%TestHash.test_hash_no_args.<locals>.Cr    N)r   r   r   r#   r$   r   r   r   r   r   	  s   
r5   zunhashable typei-  r%   )r%   zunknown value for expected=)
rK   rk   r   r,   r-   r6   r   r   r0   r   )r   r8   r/   r~   r  rx   r   rH   r   r   r   test_hash_no_argsm	  sV    

























zTestHash.test_hash_no_argsN)	r   r   r   r  r  r  r  r  r  r   r   r   r   r    s   N#r  c               @   sL   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S )
TestFrozenc          	   C   s\   t ddG dd d}|d}| |jd | t d|_W d Q R X | |jd d S )NT)r/   c               @   s   e Zd ZU eed< dS )z!TestFrozen.test_frozen.<locals>.Cr    N)r   r   r   r#   r$   r   r   r   r   r   	  s   
r   r5   r<   )r   r   r    r   r   )r   r   rH   r   r   r   test_frozen	  s    zTestFrozen.test_frozenc          	   C   s   t ddG dd d}t ddG dd d|}|dd}| t d	|_W d Q R X | t d
|_W d Q R X | |jd | |jd d S )NT)r/   c               @   s   e Zd ZU eed< dS )z"TestFrozen.test_inherit.<locals>.Cr    N)r   r   r   r#   r$   r   r   r   r   r   	  s   
r   c               @   s   e Zd ZU eed< dS )z"TestFrozen.test_inherit.<locals>.Dr   N)r   r   r   r#   r$   r   r   r   r   r   	  s   
r   r   r5   r<   r   )r   r   r   r    r   r   )r   r   r   r   r   r   r   test_inherit	  s    
zTestFrozen.test_inheritc             C   s   xdD ]z}| j |dd tddG dd d}|rFG dd d|}n|}| td	 tG d
d d|}W d Q R X W d Q R X qW d S )N)TF)intermediate_classT)r/   c               @   s   e Zd ZU eed< dS )z8TestFrozen.test_inherit_nonfrozen_from_frozen.<locals>.Cr    N)r   r   r   r#   r$   r   r   r   r   r   	  s   
r   c               @   s   e Zd ZdS )z8TestFrozen.test_inherit_nonfrozen_from_frozen.<locals>.IN)r   r   r   r   r   r   r   I	  s    r  z5cannot inherit non-frozen dataclass from a frozen onec               @   s   e Zd ZdS )z8TestFrozen.test_inherit_nonfrozen_from_frozen.<locals>.DN)r   r   r   r   r   r   r   r   	  s   r   )rk   r   r,   r-   )r   r  r   r  r   r   r   r   "test_inherit_nonfrozen_from_frozen	  s    
z-TestFrozen.test_inherit_nonfrozen_from_frozenc             C   s   xdD ]z}| j |dd tG dd d}|r@G dd d|}n|}| td  tdd	G d
d d|}W d Q R X W d Q R X qW d S )N)TF)r  c               @   s   e Zd ZU eed< dS )z8TestFrozen.test_inherit_frozen_from_nonfrozen.<locals>.Cr    N)r   r   r   r#   r$   r   r   r   r   r   	  s   
r   c               @   s   e Zd ZdS )z8TestFrozen.test_inherit_frozen_from_nonfrozen.<locals>.IN)r   r   r   r   r   r   r   r  	  s    r  z5cannot inherit frozen dataclass from a non-frozen oneT)r/   c               @   s   e Zd ZdS )z8TestFrozen.test_inherit_frozen_from_nonfrozen.<locals>.DN)r   r   r   r   r   r   r   r   	  s   r   )rk   r   r,   r-   )r   r  r   r  r   r   r   r   "test_inherit_frozen_from_nonfrozen	  s    
z-TestFrozen.test_inherit_frozen_from_nonfrozenc          
   C   s   xdD ]}| j |dH G dd d}|r<G dd d|}n|}tddG d	d
 d
|}W d Q R X |d}| t d|_W d Q R X qW d S )N)TF)r  c               @   s   e Zd ZdS )z4TestFrozen.test_inherit_from_normal_class.<locals>.CN)r   r   r   r   r   r   r   r   	  s   r   c               @   s   e Zd ZdS )z4TestFrozen.test_inherit_from_normal_class.<locals>.IN)r   r   r   r   r   r   r   r  
  s    r  T)r/   c               @   s   e Zd ZU eed< dS )z4TestFrozen.test_inherit_from_normal_class.<locals>.Dr    N)r   r   r   r#   r$   r   r   r   r   r   
  s   
r   r5   r<   )rk   r   r   r   r    )r   r  r   r  r   r   r   r   r   test_inherit_from_normal_class	  s    
z)TestFrozen.test_inherit_from_normal_classc          	   C   s   t ddG dd d}G dd d|}|d}| |jd | |jd d|_| t d	|_W d Q R X | t d	|_W d Q R X | |jd | |jd | |jd d S )
NT)r/   c               @   s"   e Zd ZU eed< dZeed< dS )z4TestFrozen.test_non_frozen_normal_derived.<locals>.Dr"   r5   r)   N)r   r   r   r#   r$   r)   r   r   r   r   r   
  s   
r   c               @   s   e Zd ZdS )z4TestFrozen.test_non_frozen_normal_derived.<locals>.SN)r   r   r   r   r   r   r   rY  
  s   rY  r*   r5   r<   )r   r   r"   r)   cachedr   r   )r   r   rY  r   r   r   r   test_non_frozen_normal_derived
  s    z)TestFrozen.test_non_frozen_normal_derivedc          	   C   s   |  td tddG dd d}W d Q R X |  td tddG dd d}W d Q R X tddG d	d d}| |d
jd d S )Nz&Cannot overwrite attribute __setattr__T)r/   c               @   s   e Zd ZU eed< dd ZdS )z-TestFrozen.test_overwriting_frozen.<locals>.Cr"   c             S   s   d S )Nr   )r   r   r   r   r@  .
  s    z9TestFrozen.test_overwriting_frozen.<locals>.C.__setattr__N)r   r   r   r#   r$   r@  r   r   r   r   r   +
  s   
r   z&Cannot overwrite attribute __delattr__c               @   s   e Zd ZU eed< dd ZdS )z-TestFrozen.test_overwriting_frozen.<locals>.Cr"   c             S   s   d S )Nr   )r   r   r   r   __delattr__6
  s    z9TestFrozen.test_overwriting_frozen.<locals>.C.__delattr__N)r   r   r   r#   r$   r  r   r   r   r   r   3
  s   
Fc               @   s   e Zd ZU eed< dd ZdS )z-TestFrozen.test_overwriting_frozen.<locals>.Cr"   c             S   s   |d | j d< d S )Nru   r"   )r[   )r   rW   r=  r   r   r   r@  <
  s    z9TestFrozen.test_overwriting_frozen.<locals>.C.__setattr__N)r   r   r   r#   r$   r@  r   r   r   r   r   9
  s   
r5   r   )r,   r-   r   r   r"   )r   r   r   r   r   test_overwriting_frozen'
  s    ""z"TestFrozen.test_overwriting_frozenc          	   C   sL   t ddG dd d}t|d | td t|i  W d Q R X d S )NT)r/   c               @   s   e Zd ZU eed< dS )z&TestFrozen.test_frozen_hash.<locals>.Cr"   N)r   r   r   r   r$   r   r   r   r   r   A
  s   
r   r*   zunhashable type)r   r6   r,   r-   )r   r   r   r   r   test_frozen_hash@
  s    zTestFrozen.test_frozen_hashN)r   r   r   r  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dS )	TestSlotsc          	   C   s|   t G dd d}| td |  W d Q R X |d}| |jd d|_| |jd | td d|_W d Q R X d S )Nc               @   s   e Zd ZU dZeed< dS )z TestSlots.test_simple.<locals>.C)r"   r"   N)r   r   r   	__slots__r   r$   r   r   r   r   r   P
  s   
r   z8__init__\(\) missing 1 required positional argument: 'x'r5   r<   z'C' object has no attribute 'y')r   r,   r-   r   r"   r   r)   )r   r   rH   r   r   r   test_simpleO
  s    zTestSlots.test_simplec             C   sN   t G dd d}t G dd d|}|dd}| |j|jfd d|_d S )	Nc               @   s   e Zd ZU dZeed< dS )z0TestSlots.test_derived_added_field.<locals>.Base)r"   r"   N)r   r   r   r  r   r$   r   r   r   r   r8   h
  s   
r8   c               @   s   e Zd ZU eed< eed< dS )z3TestSlots.test_derived_added_field.<locals>.Derivedr"   r)   N)r   r   r   r#   r$   r   r   r   r   Derivedm
  s   
r  rq   ru   )rq   ru   r5   )r   r   r"   r)   r9   )r   r8   r  r   r   r   r   test_derived_added_fieldf
  s    
z"TestSlots.test_derived_added_fieldN)r   r   r   r  r  r   r   r   r   r  N
  s   r  c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestDescriptorsc                sn   G dd d t G  fddd}| |jjd t G  fddd}| |jjd | | jd d S )Nc               @   s   e Zd Zdd Zdd ZdS )z(TestDescriptors.test_set_name.<locals>.Dc             S   s   |d | _ d S )Nr"   )rW   )r   ownerrW   r   r   r   __set_name__~
  s    z5TestDescriptors.test_set_name.<locals>.D.__set_name__c             S   s   |d k	rdS | S )Nrq   r   )r   instancer  r   r   r   __get__
  s    z0TestDescriptors.test_set_name.<locals>.D.__get__N)r   r   r   r  r  r   r   r   r   r   }
  s   r   c                   s   e Zd ZU   Zeed< dS )z(TestDescriptors.test_set_name.<locals>.CrH   N)r   r   r   rH   r#   r$   r   )r   r   r   r   
  s   
r   cxc                   s$   e Zd ZU e  ddZeed< dS )z(TestDescriptors.test_set_name.<locals>.CF)r   r   rH   N)r   r   r   r   rH   r#   r$   r   )r   r   r   r   
  s   
rq   )r   r   rH   rW   )r   r   r   )r   r   test_set_namey
  s    
zTestDescriptors.test_set_namec                s8   G dd d t G  fddd}| |jjd d S )Nc               @   s   e Zd Zdd ZdS )z.TestDescriptors.test_non_descriptor.<locals>.Dc             S   s   |d | _ d S )Nr"   )rW   )r   r  rW   r   r   r   r  
  s    z;TestDescriptors.test_non_descriptor.<locals>.D.__set_name__N)r   r   r   r  r   r   r   r   r   
  s   r   c                   s$   e Zd ZU e  ddZeed< dS )z.TestDescriptors.test_non_descriptor.<locals>.CF)r   r   rH   N)r   r   r   r   rH   r#   r$   r   )r   r   r   r   
  s   
r   r  )r   r   rH   rW   )r   r   r   )r   r   test_non_descriptor
  s    z#TestDescriptors.test_non_descriptorc                sF   G dd d}|  t   _tG  fddd}|  jjd d S )Nc               @   s   e Zd ZdS )z2TestDescriptors.test_lookup_on_instance.<locals>.DN)r   r   r   r   r   r   r   r   
  s   r   c                   s"   e Zd ZU e ddZeed< dS )z2TestDescriptors.test_lookup_on_instance.<locals>.CF)r   r   r    N)r   r   r   r   r    r#   r$   r   )r   r   r   r   
  s   
r   r   )r   r  r   r   r   )r   r   r   r   )r   r   test_lookup_on_instance
  s
    z'TestDescriptors.test_lookup_on_instancec                s@   G dd d t   _tG  fddd}|  jjd d S )Nc               @   s   e Zd ZdS )z/TestDescriptors.test_lookup_on_class.<locals>.DN)r   r   r   r   r   r   r   r   
  s   r   c                   s$   e Zd ZU e  ddZeed< dS )z/TestDescriptors.test_lookup_on_class.<locals>.CF)r   r   r    N)r   r   r   r   r    r#   r$   r   )r   r   r   r   
  s   
r   rq   )r   r  r   r   r   )r   r   r   )r   r   test_lookup_on_class
  s    z$TestDescriptors.test_lookup_on_classN)r   r   r   r  r  r  r  r   r   r   r   r  x
  s   r  c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestStringAnnotationsc          
      sT   xNdD ]F | j  d0 tG  fddd}|  | d|j W d Q R X qW d S )N)zClassVar[int]zClassVar [int] ClassVar [int]r   z
 ClassVar ztyping.ClassVar[int]ztyping.ClassVar[str]z typing.ClassVar[str]ztyping .ClassVar[str]ztyping. ClassVar[str]ztyping.ClassVar [str]ztyping.ClassVar [ str]ztyping.ClassVar.[int]ztyping.ClassVar+)typestrc                   s   e Zd ZU  ed< dS )z.TestStringAnnotations.test_classvar.<locals>.Cr"   N)r   r   r   r$   r   )r  r   r   r   
  s   
r   r"   )rk   r   r   r[   )r   r   r   )r  r   test_classvar
  s
    
z#TestStringAnnotations.test_classvarc          
      sR   xLdD ]D | j  d. tG  fddd}| |djd W d Q R X qW d S )N)
CVz
t.ClassVarzt.ClassVar[int]ztyping..ClassVar[int]ZClassvarzClassvar[int]ztyping.ClassVarx[int]ztypong.ClassVar[int]zdataclasses.ClassVar[int]ztypingxClassVar[str])r  c                   s   e Zd ZU  ed< dS )z3TestStringAnnotations.test_isnt_classvar.<locals>.Cr"   N)r   r   r   r$   r   )r  r   r   r   
  s   
r   r5   )rk   r   r   r"   )r   r   r   )r  r   test_isnt_classvar
  s    
z(TestStringAnnotations.test_isnt_classvarc                sb   x\dD ]T | j  d> tG  fddd}| td |dj W d Q R X W d Q R X qW d S )N)zInitVar[int]zInitVar [int] InitVar [int]r   z	 InitVar zdataclasses.InitVar[int]zdataclasses.InitVar[str]z dataclasses.InitVar[str]zdataclasses .InitVar[str]zdataclasses. InitVar[str]zdataclasses.InitVar [str]zdataclasses.InitVar [ str]zdataclasses.InitVar.[int]zdataclasses.InitVar+)r  c                   s   e Zd ZU  ed< dS )z-TestStringAnnotations.test_initvar.<locals>.Cr"   N)r   r   r   r$   r   )r  r   r   r     s   
r   zobject has no attribute 'x'rq   )rk   r   r,   r   r"   )r   r   r   )r  r   test_initvar
  s    
z"TestStringAnnotations.test_initvarc          
      sR   xLdD ]D | j  d. tG  fddd}| |djd W d Q R X qW d S )N)IVz
dc.InitVarzxdataclasses.xInitVarztyping.xInitVar[int])r  c                   s   e Zd ZU  ed< dS )z2TestStringAnnotations.test_isnt_initvar.<locals>.Cr"   N)r   r   r   r$   r   )r  r   r   r     s   
r   r5   )rk   r   r   r"   )r   r   r   )r  r   test_isnt_initvar  s    
z'TestStringAnnotations.test_isnt_initvarc             C   s  ddl m} ddl m} ddl m} ddl m} x||||fD ]}| j|d |jrb|d}n| }| |j	d |
dd	d
dd}xNdD ]F}| j|d0 | td| d t|| W d Q R X W d Q R X qW |jr| d|j | |jd n| d|j W d Q R X q>W d S )Nr   )dataclass_module_1)dataclass_module_1_str)dataclass_module_2)dataclass_module_2_str)mr5   r   rq   ru   r*   r   )Ziv0Ziv1Ziv2Ziv3)
field_namezobject has no attribute 'rj   not_iv4)rF  r  r  r  r  rk   ZUSING_STRINGSr  r   Zcv0r  r,   r   r^   r   r[   r  r   )r   r  r  r  r  r  rH   r  r   r   r   !test_classvar_module_level_import&  s(    
"z7TestStringAnnotations.test_classvar_module_level_importN)r   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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 )TestMakeDataclassc             C   sZ   t ddtfdttddfgddd id	}|d
}| |j|jfd | | d d S )Nr   r"   r)   r<   )r   add_onec             S   s
   | j d S )Nrq   )r"   )r   r   r   r   rg   U  rh   z/TestMakeDataclass.test_simple.<locals>.<lambda>)ra  r5   )r5   r<   r   )r]   r#   r   r   r"   r)   r  )r   r   rH   r   r   r   r  Q  s    zTestMakeDataclass.test_simplec             C   s6   i }t ddtfdttddfg|d}| |i  d S )Nr   r"   r)   r<   )r   )ra  )r]   r#   r   r   )r   nsr   r   r   r   test_no_mutate_namespace[  s    z*TestMakeDataclass.test_no_mutate_namespacec             C   sd   G dd d}G dd d}t ddtfg||fd}|d}| || | || | || d S )	Nc               @   s   e Zd ZdS )z*TestMakeDataclass.test_base.<locals>.Base1N)r   r   r   r   r   r   r   Base1e  s   r  c               @   s   e Zd ZdS )z*TestMakeDataclass.test_base.<locals>.Base2N)r   r   r   r   r   r   r   Base2g  s   r  r   r"   )r`  ru   )r]   r#   r   )r   r  r  r   rH   r   r   r   	test_based  s    zTestMakeDataclass.test_basec          	   C   s   t G dd d}G dd d}tddtfg||fd}| td |d	}W d Q R X |d
d	}| || | || | || | |j|jfd d S )Nc               @   s   e Zd ZU eed< dS )z4TestMakeDataclass.test_base_dataclass.<locals>.Base1r"   N)r   r   r   r#   r$   r   r   r   r   r  r  s   
r  c               @   s   e Zd ZdS )z4TestMakeDataclass.test_base_dataclass.<locals>.Base2N)r   r   r   r   r   r   r   r  u  s   r  r   r)   )r`  zrequired positionalru   rq   )rq   ru   )	r   r]   r#   r,   r-   r   r   r"   r)   )r   r  r  r   rH   r   r   r   test_base_dataclassq  s    
z%TestMakeDataclass.test_base_dataclassc             C   s`   dd }t ddtfdtt fgd|id}|dd	}| t|dd
i | tt|d d S )Nc             S   s   |  j |9  _ d S )N)r"   )r   r)   r   r   r   	post_init  s    z2TestMakeDataclass.test_init_var.<locals>.post_initr   r"   r)   r   )ra  ru   r*   r   rq   )r]   r#   r   r   r   r   r   )r   r  r   rH   r   r   r   r     s    
zTestMakeDataclass.test_init_varc          	   C   s~   t ddtfdtt dfdtt tddfg}|d}| t|ddi | tt|d | |jd | |j	d d S )	Nr   r"   r)   r5   r9   r   )r   rq   )
r]   r#   r   r   r   r   r   r   r)   r9   )r   r   rH   r   r   r   r     s    z TestMakeDataclass.test_class_varc          	   C   s|   t ddtfdtt dfdtt tddfgdd	}| d
t| | dt| | td t dg dd}W d Q R X d S )Nr   r"   r)   r5   r9   r   )r   F)r   rC   r  zunexpected keyword argument)Zxxinit)	r]   r#   r   r   r   r   r   r,   r-   )r   r   r   r   r   test_other_params  s    z#TestMakeDataclass.test_other_paramsc             C   s   t ddddg}|ddd}| t|dddd | |jd	d	d	d t dddtfdg}|ddd}| t|dddd | |jd	td	d d S )
Nr   r"   r)   r9   rq   ru   r*   )r"   r)   r9   z
typing.Any)r]   r   r   r$   r#   )r   r   rH   r   r   r   test_no_types  s    


zTestMakeDataclass.test_no_typesc             C   s   xJdD ]B}| j |d, | td tdd|g W d Q R X W d Q R X qW xRtdd gD ]B}| j |d, | td tdd|g W d Q R X W d Q R X qZW d S )	N)r   )rq   ru   r*   r   )	bad_fieldzInvalid field: r   rf   c             S   s   | S )Nr   )r"   r   r   r   rg     rh   zCTestMakeDataclass.test_invalid_type_specification.<locals>.<lambda>zhas no len\(\))rk   r,   r-   r]   r   )r   r  r   r   r   test_invalid_type_specification  s    
&z1TestMakeDataclass.test_invalid_type_specificationc             C   sR   xLdD ]D}| j |d. | td td|d|g W d Q R X W d Q R X qW d S )N)rf   Zab)r   zField name duplicatedr   rf   )rk   r,   r-   r]   )r   r   r   r   r   test_duplicate_field_names  s    
z,TestMakeDataclass.test_duplicate_field_namesc             C   s   xdD ]}| j |dv | td tdd|g W d Q R X | td td|g W d Q R X | td td|dg W d Q R X W d Q R X qW d S )N)forasyncawaitas)r   zmust not be keywordsr   rf   )rk   r,   r-   r]   )r   r   r   r   r   test_keyword_field_names  s    
z*TestMakeDataclass.test_keyword_field_namesc             C   s   xdD ]}| j |dv | td tdd|g W d Q R X | td td|g W d Q R X | td td|dg W d Q R X W d Q R X qW d S )N)z()zx,yr   z2@3ru  zlittle johnny tables)r   zmust be valid identifersr   rf   )rk   r,   r-   r]   )r   r   r   r   r   test_non_identifier_field_names  s    
z1TestMakeDataclass.test_non_identifier_field_namesc             C   s   t dddddg d S )Nr   _Z_aZa_aZa_)r]   )r   r   r   r   test_underscore_field_names  s    z-TestMakeDataclass.test_underscore_field_namesc          
   C   sF   x@dD ]8}| j |d" t|ddg}| |j| W d Q R X qW d S )N)z()zx,yr   z2@3ru  )	classnamerf   rT   )rk   r]   r   r   )r   r  r   r   r   r   test_funny_class_names_names  s    
z.TestMakeDataclass.test_funny_class_names_namesN)r   r   r   r  r  r  r  r   r   r  r  r  r  r  r  r  r  r   r   r   r   r  P  s   
	

r  c               @   st   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S )TestReplacec             C   sN   t ddG dd d}|dd}t|dd}| |jd | |jd d S )	NT)r/   c               @   s   e Zd ZU eed< eed< dS )zTestReplace.test.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r     s   
r   rq   ru   r*   )r"   )r   rv  r   r"   r)   )r   r   rH   r   r   r   r   rF    s
    
zTestReplace.testc          	   C   s
  t ddG dd d}|dd}t|dd}| |j|j|j|jfd	 | |j|j|j|jfd
 | td t|dddd W d Q R X | td" t|dd t|dddd W d Q R X | t	d d|_W d Q R X | t
d t|ddd}W d Q R X d S )NT)r/   c               @   sF   e Zd ZU eed< eed< edddZeed< edddZeed< d	S )
z"TestReplace.test_frozen.<locals>.Cr"   r)   Fr5   )r   r   r9   r1   r   N)r   r   r   r#   r$   r   r9   r   r   r   r   r   r     s   
r   rq   ru   r*   )r"   )rq   ru   r5   r1   )r*   ru   r5   r1   z
init=Falser   r   )r"   r9   r   )r9   zcannot assign to field 'x'z3__init__\(\) got an unexpected keyword argument 'a'r<   )r"   rf   )r   rv  r   r"   r)   r9   r   r,   r   r   r-   )r   r   rH   r   r   r   r   r     s    
zTestReplace.test_frozenc          	   C   sJ   t ddG dd d}|dd}| td t|dd	}W d Q R X d S )
NT)r/   c               @   s   e Zd ZU eed< eed< dS )z.TestReplace.test_invalid_field_name.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r   !  s   
r   rq   ru   z3__init__\(\) got an unexpected keyword argument 'z'r*   )r9   )r   r,   r-   rv  )r   r   rH   r   r   r   r   test_invalid_field_name   s    
z#TestReplace.test_invalid_field_namec          	   C   sd   t ddG dd d}| td t|dd W d Q R X | td tddd W d Q R X d S )	NT)r/   c               @   s   e Zd ZU eed< eed< dS )z*TestReplace.test_invalid_object.<locals>.Cr"   r)   N)r   r   r   r#   r$   r   r   r   r   r   ,  s   
r   zdataclass instancer*   )r"   r   )r   r,   r-   rv  )r   r   r   r   r   test_invalid_object+  s
    zTestReplace.test_invalid_objectc          	   C   s   t G dd d}|d}d|_t|dd}| |j|jfd | td t|d	d
d W d Q R X | td t|d
d W d Q R X d S )Nc               @   s*   e Zd ZU eed< edddZeed< dS )z#TestReplace.test_no_init.<locals>.Cr"   Fr5   )r   r   r)   N)r   r   r   r#   r$   r   r)   r   r   r   r   r   8  s   
r   rq   r   r<   )r"   )r<   r5   z
init=Falseru      )r"   r)   )r)   )r   r)   rv  r   r"   r,   r   )r   r   rH   r   r   r   r   r  7  s    zTestReplace.test_no_initc          	   C   st   t G dd d}|d}|d}| |j|j | |jd | td t|dd W d Q R X t|d	d
 d S )Nc               @   s&   e Zd ZU eed< dZee ed< dS )z$TestReplace.test_classvar.<locals>.Cr"   i  r)   N)r   r   r   r#   r$   r)   r   r   r   r   r   r   L  s   
r   rq   ru   i  z3__init__\(\) got an unexpected keyword argument 'y'r  )r)   r<   )r"   )r   r   r)   r   r,   r-   rv  )r   r   rH   r   r   r   r   r  K  s    zTestReplace.test_classvarc          	   C   sn   t G dd d}|dd}| |jd | td t|dd W d Q R X t|ddd	}| |jd
 d S )Nc               @   s*   e Zd ZU eed< ee ed< dd ZdS )z0TestReplace.test_initvar_is_specified.<locals>.Cr"   r)   c             S   s   |  j |9  _ d S )N)r"   )r   r)   r   r   r   r   d  s    z>TestReplace.test_initvar_is_specified.<locals>.C.__post_init__N)r   r   r   r#   r$   r   r   r   r   r   r   r   _  s   
r   rq   r5   z,InitVar 'y' must be specified with replace()r*   )r"   r<   )r"   r)   r:   )r   r   r"   r,   r   rv  )r   r   rH   r   r   r   test_initvar_is_specified^  s    
z%TestReplace.test_initvar_is_specifiedc             C   s4   t G dd d}|d }||_| t|d d S )Nc               @   s   e Zd ZU ded< dS )z*TestReplace.test_recursive_repr.<locals>.Cr   r   N)r   r   r   r$   r   r   r   r   r   p  s   
r   z1TestReplace.test_recursive_repr.<locals>.C(f=...))r   r   r   r=   )r   r   rH   r   r   r   test_recursive_repro  s    zTestReplace.test_recursive_reprc             C   s<   t G dd d}|d d }||_||_| t|d d S )Nc               @   s   e Zd ZU ded< ded< dS )z4TestReplace.test_recursive_repr_two_attrs.<locals>.Cr   r   gN)r   r   r   r$   r   r   r   r   r   y  s   
r   zBTestReplace.test_recursive_repr_two_attrs.<locals>.C(f=..., g=...))r   r   r  r   r=   )r   r   rH   r   r   r   test_recursive_repr_two_attrsx  s
    
z)TestReplace.test_recursive_repr_two_attrsc             C   sT   t G dd d}t G dd d}|d }|d }||_||_| t|d d S )Nc               @   s   e Zd ZU ded< dS )z6TestReplace.test_recursive_repr_indirection.<locals>.Cr   r   N)r   r   r   r$   r   r   r   r   r     s   
r   c               @   s   e Zd ZU ded< dS )z6TestReplace.test_recursive_repr_indirection.<locals>.Dr   r   N)r   r   r   r$   r   r   r   r   r     s   
r   zwTestReplace.test_recursive_repr_indirection.<locals>.C(f=TestReplace.test_recursive_repr_indirection.<locals>.D(f=...)))r   r   r   r=   )r   r   r   rH   r   r   r   r   test_recursive_repr_indirection  s    z+TestReplace.test_recursive_repr_indirectionc             C   st   t G dd d}t G dd d}t G dd d}|d }|d }|d }||_||_||_| t|d d S )Nc               @   s   e Zd ZU ded< dS )z:TestReplace.test_recursive_repr_indirection_two.<locals>.Cr   r   N)r   r   r   r$   r   r   r   r   r     s   
r   c               @   s   e Zd ZU ded< dS )z:TestReplace.test_recursive_repr_indirection_two.<locals>.Dr   r   N)r   r   r   r$   r   r   r   r   r     s   
r   c               @   s   e Zd ZU ded< dS )z:TestReplace.test_recursive_repr_indirection_two.<locals>.Er   r   N)r   r   r   r$   r   r   r   r   r     s   
r   zTestReplace.test_recursive_repr_indirection_two.<locals>.C(f=TestReplace.test_recursive_repr_indirection_two.<locals>.D(f=TestReplace.test_recursive_repr_indirection_two.<locals>.E(f=...))))r   r   r   r=   )r   r   r   r   rH   r   r  r   r   r   #test_recursive_repr_indirection_two  s    z/TestReplace.test_recursive_repr_indirection_twoc             C   s<   t G dd d}|d d }||_||_| t|d d S )Nc               @   s   e Zd ZU ded< ded< dS )z4TestReplace.test_recursive_repr_two_attrs.<locals>.Cr   r   r  N)r   r   r   r$   r   r   r   r   r     s   
r   zBTestReplace.test_recursive_repr_two_attrs.<locals>.C(f=..., g=...))r   r   r  r   r=   )r   r   rH   r   r   r   r    s
    
c             C   s6   t G dd d}|d d}||_| t|d d S )Nc               @   s   e Zd ZU ded< eed< dS )z5TestReplace.test_recursive_repr_misc_attrs.<locals>.Cr   r   r  N)r   r   r   r$   r#   r   r   r   r   r     s   
r   rq   zATestReplace.test_recursive_repr_misc_attrs.<locals>.C(f=..., g=1))r   r   r   r=   )r   r   rH   r   r   r   test_recursive_repr_misc_attrs  s    
z*TestReplace.test_recursive_repr_misc_attrsN)r   r   r   rF  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s    	r  __main__))Zdataclassesrj  rA   rZ   ZunittestZunittest.mockr   typingr   r   r   r   r   r	   r
   r   r   collectionsr   r   r   	functoolsr   	Exceptionr   r   ro  rs  r  r  r  r  r  r  r  r  r  r  r  r   mainr   r   r   r   <module>   s\   ,              T#YBG/L ] *H  % `
