B
    u9a(g                 @   s   d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZ ddlZeeee	fZe
efZee ZG dd dejZdd Zedkre  dS )	zUnit tests for the copy module.    N)leltgegteqnec               @   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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"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2dadb Z3dcdd Z4dedf Z5dgdh Z6didj Z7dkdl Z8dmdn Z9dodp Z:dqdr Z;dsdt Z<dudv Z=dwdx Z>dydz Z?d{d| Z@d}d~ ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdS )TestCopyc             C   s&   |  tjtj | ttjt d S )N)assertIscopyErrorerrorZ
assertTrue
issubclass	Exception)self r   /usr/lib/python3.7/test_copy.pytest_exceptions   s    zTestCopy.test_exceptionsc             C   s   d}t  |}| || d S )N*   )r
   assertEqual)r   xyr   r   r   test_copy_basic   s    
zTestCopy.test_copy_basicc                sJ   G  fdddt   d}t|}| |j|j | |j|j d S )Nc                   s    e Zd Zdd Z fddZdS )z"TestCopy.test_copy_copy.<locals>.Cc             S   s
   || _ d S )N)foo)r   r   r   r   r   __init__    s    z+TestCopy.test_copy_copy.<locals>.C.__init__c                s
    | j S )N)r   )r   )Cr   r   __copy__"   s    z+TestCopy.test_copy_copy.<locals>.C.__copy__N)__name__
__module____qualname__r   r   r   )r   r   r   r      s   r   r   )objectr
   r   	__class__r   )r   r   r   r   )r   r   test_copy_copy   s
    
zTestCopy.test_copy_copyc                sP   G dd dt   fdd} d}| ttj| t |  t|}d S )Nc               @   s   e Zd Zdd ZdS )z&TestCopy.test_copy_registry.<locals>.Cc             S   s   t | }||_|S )N)r   __new__r   )clsr   objr   r   r   r"   +   s    
z.TestCopy.test_copy_registry.<locals>.C.__new__N)r   r   r   r"   r   r   r   r   r   *   s   r   c                s    | j ffS )N)r   )r$   )r   r   r   pickle_C/   s    z-TestCopy.test_copy_registry.<locals>.pickle_Cr   )r   assertRaises	TypeErrorr
   copyregpickle)r   r%   r   r   r   )r   r   test_copy_registry)   s    zTestCopy.test_copy_registryc                sF   G  fdddt }g  | }t|}| || |  dg d S )Nc                   s    e Zd Z fddZdd ZdS )z'TestCopy.test_copy_reduce_ex.<locals>.Cc                s     d dS )N    )append)r   proto)cr   r   __reduce_ex__8   s    
z5TestCopy.test_copy_reduce_ex.<locals>.C.__reduce_ex__c             S   s   |  d d S )Nzshouldn't call this)fail)r   r   r   r   
__reduce__;   s    z2TestCopy.test_copy_reduce_ex.<locals>.C.__reduce__N)r   r   r   r0   r2   r   )r/   r   r   r   7   s   r   r+   )r   r
   r	   r   )r   r   r   r   r   )r/   r   test_copy_reduce_ex6   s    
zTestCopy.test_copy_reduce_exc                sF   G  fdddt }g  | }t|}| || |  dg d S )Nc                   s   e Zd Z fddZdS )z$TestCopy.test_copy_reduce.<locals>.Cc                s     d dS )Nr+   r,   )r-   )r   )r/   r   r   r2   E   s    
z/TestCopy.test_copy_reduce.<locals>.C.__reduce__N)r   r   r   r2   r   )r/   r   r   r   D   s   r   r+   )r   r
   r	   r   )r   r   r   r   r   )r/   r   test_copy_reduceC   s    
zTestCopy.test_copy_reducec             C   s,   G dd dt }| }| tjtj| d S )Nc               @   s   e Zd Zdd ZdS )z"TestCopy.test_copy_cant.<locals>.Cc             S   s   | drt|t| |S )N__reduce)
startswithAttributeErrorr   __getattribute__)r   namer   r   r   r8   P   s    
z3TestCopy.test_copy_cant.<locals>.C.__getattribute__N)r   r   r   r8   r   r   r   r   r   O   s   r   )r   r&   r
   r   )r   r   r   r   r   r   test_copy_cantN   s    zTestCopy.test_copy_cantc             C   s   G dd d}G dd dt }dd }G dd dtjd	}d d
tddd dddddd|jdttdtdtddd||t|g}x|D ]}| 	t

|| qW d S )Nc               @   s   e Zd ZdS )z*TestCopy.test_copy_atomic.<locals>.ClassicN)r   r   r   r   r   r   r   ClassicZ   s   r;   c               @   s   e Zd ZdS )z+TestCopy.test_copy_atomic.<locals>.NewStyleN)r   r   r   r   r   r   r   NewStyle\   s   r<   c               S   s   d S )Nr   r   r   r   r   f^   s    z$TestCopy.test_copy_atomic.<locals>.fc               @   s   e Zd ZdS )z0TestCopy.test_copy_atomic.<locals>.WithMetaclassN)r   r   r   r   r   r   r   WithMetaclass`   s   r>   )	metaclass.r      d   gQ	@TFy              ?hellou   helloሴs   world   
   r+   )r   abcABCMetaNotImplemented__code__bytesrangeslicemaxr	   r
   )r   r;   r<   r=   r>   testsr   r   r   r   test_copy_atomicY   s    
zTestCopy.test_copy_atomicc             C   sV   dddg}t  |}| || | || g }t  |}| || | || d S )Nr+   r@      )r
   r   assertIsNot)r   r   r   r   r   r   test_copy_listj   s    


zTestCopy.test_copy_listc             C   sN   d}|  t|| d}|  t|| dddg f}|  t|| d S )N)r+   r@   rO   r   r+   r@   rO   )r	   r
   )r   r   r   r   r   test_copy_tuplet   s    zTestCopy.test_copy_tuplec             C   sV   ddd}t  |}| || | || i }t  |}| || | || d S )Nr+   r@   )r   bar)r
   r   rP   )r   r   r   r   r   r   test_copy_dict|   s    


zTestCopy.test_copy_dictc             C   sX   dddh}t  |}| || | || t }t  |}| || | || d S )Nr+   r@   rO   )r
   r   rP   set)r   r   r   r   r   r   test_copy_set   s    


zTestCopy.test_copy_setc             C   s<   t dddh}| t|| t  }| t|| d S )Nr+   r@   rO   )	frozensetr	   r
   )r   r   r   r   r   test_copy_frozenset   s    zTestCopy.test_copy_frozensetc             C   sV   t d}t|}| || | || t  }t|}| || | || d S )Ns   abc)	bytearrayr
   r   rP   )r   r   r   r   r   r   test_copy_bytearray   s    

zTestCopy.test_copy_bytearrayc             C   s,   G dd d}|d}|  t|| d S )Nc               @   s   e Zd Zdd Zdd ZdS )z*TestCopy.test_copy_inst_vanilla.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r      s    z3TestCopy.test_copy_inst_vanilla.<locals>.C.__init__c             S   s   | j |j kS )N)r   )r   otherr   r   r   __eq__   s    z1TestCopy.test_copy_inst_vanilla.<locals>.C.__eq__N)r   r   r   r   r\   r   r   r   r   r      s   r   r   )r   r
   )r   r   r   r   r   r   test_copy_inst_vanilla   s    zTestCopy.test_copy_inst_vanillac                s0   G  fddd  d}|  t|| d S )Nc                   s(   e Zd Zdd Z fddZdd ZdS )z'TestCopy.test_copy_inst_copy.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r      s    z0TestCopy.test_copy_inst_copy.<locals>.C.__init__c                s
    | j S )N)r   )r   )r   r   r   r      s    z0TestCopy.test_copy_inst_copy.<locals>.C.__copy__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\      s    z.TestCopy.test_copy_inst_copy.<locals>.C.__eq__N)r   r   r   r   r   r\   r   )r   r   r   r      s   r   r   )r   r
   )r   r   r   )r   r   test_copy_inst_copy   s    zTestCopy.test_copy_inst_copyc             C   s,   G dd d}|d}|  t|| d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z.TestCopy.test_copy_inst_getinitargs.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r      s    z7TestCopy.test_copy_inst_getinitargs.<locals>.C.__init__c             S   s   | j fS )N)r   )r   r   r   r   __getinitargs__   s    z>TestCopy.test_copy_inst_getinitargs.<locals>.C.__getinitargs__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\      s    z5TestCopy.test_copy_inst_getinitargs.<locals>.C.__eq__N)r   r   r   r   r_   r\   r   r   r   r   r      s   r   r   )r   r
   )r   r   r   r   r   r   test_copy_inst_getinitargs   s    z#TestCopy.test_copy_inst_getinitargsc             C   sZ   G dd dt }|d}t|}| || | || | || | |j|j d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z-TestCopy.test_copy_inst_getnewargs.<locals>.Cc             S   s   t | }||_|S )N)intr"   r   )r#   r   r   r   r   r   r"      s    
z5TestCopy.test_copy_inst_getnewargs.<locals>.C.__new__c             S   s   | j fS )N)r   )r   r   r   r   __getnewargs__   s    z<TestCopy.test_copy_inst_getnewargs.<locals>.C.__getnewargs__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\      s    z4TestCopy.test_copy_inst_getnewargs.<locals>.C.__eq__N)r   r   r   r"   rb   r\   r   r   r   r   r      s   r   r   )ra   r
   assertIsInstancer   rP   r   )r   r   r   r   r   r   r   test_copy_inst_getnewargs   s    	
z"TestCopy.test_copy_inst_getnewargsc             C   s\   G dd dt }|dd}t|}| || | || | || | |j|j d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z0TestCopy.test_copy_inst_getnewargs_ex.<locals>.Cc            S   s   t | }||_|S )N)ra   r"   r   )r#   r   r   r   r   r   r"      s    
z8TestCopy.test_copy_inst_getnewargs_ex.<locals>.C.__new__c             S   s   dd| j ifS )Nr   r   )r   )r   r   r   r   __getnewargs_ex__   s    zBTestCopy.test_copy_inst_getnewargs_ex.<locals>.C.__getnewargs_ex__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\      s    z7TestCopy.test_copy_inst_getnewargs_ex.<locals>.C.__eq__N)r   r   r   r"   re   r\   r   r   r   r   r      s   r   r   )r   )ra   r
   rc   r   rP   r   )r   r   r   r   r   r   r   test_copy_inst_getnewargs_ex   s    	

z%TestCopy.test_copy_inst_getnewargs_exc             C   s,   G dd d}|d}|  t|| d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z+TestCopy.test_copy_inst_getstate.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r      s    z4TestCopy.test_copy_inst_getstate.<locals>.C.__init__c             S   s
   d| j iS )Nr   )r   )r   r   r   r   __getstate__   s    z8TestCopy.test_copy_inst_getstate.<locals>.C.__getstate__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\      s    z2TestCopy.test_copy_inst_getstate.<locals>.C.__eq__N)r   r   r   r   rg   r\   r   r   r   r   r      s   r   r   )r   r
   )r   r   r   r   r   r   test_copy_inst_getstate   s    z TestCopy.test_copy_inst_getstatec             C   s,   G dd d}|d}|  t|| d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z+TestCopy.test_copy_inst_setstate.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r      s    z4TestCopy.test_copy_inst_setstate.<locals>.C.__init__c             S   s   |d | _ d S )Nr   )r   )r   stater   r   r   __setstate__   s    z8TestCopy.test_copy_inst_setstate.<locals>.C.__setstate__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\      s    z2TestCopy.test_copy_inst_setstate.<locals>.C.__eq__N)r   r   r   r   rj   r\   r   r   r   r   r      s   r   r   )r   r
   )r   r   r   r   r   r   test_copy_inst_setstate   s    z TestCopy.test_copy_inst_setstatec             C   sF   G dd d}|d}|  t|| |d}|  t|| d S )Nc               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
z4TestCopy.test_copy_inst_getstate_setstate.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r      s    z=TestCopy.test_copy_inst_getstate_setstate.<locals>.C.__init__c             S   s   | j S )N)r   )r   r   r   r   rg      s    zATestCopy.test_copy_inst_getstate_setstate.<locals>.C.__getstate__c             S   s
   || _ d S )N)r   )r   ri   r   r   r   rj      s    zATestCopy.test_copy_inst_getstate_setstate.<locals>.C.__setstate__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\      s    z;TestCopy.test_copy_inst_getstate_setstate.<locals>.C.__eq__N)r   r   r   r   rg   rj   r\   r   r   r   r   r      s   r   r   g        )r   r
   )r   r   r   r   r   r    test_copy_inst_getstate_setstate   s
    	z)TestCopy.test_copy_inst_getstate_setstatec             C   s   d}t |}| || d S )Nr   )r
   deepcopyr   )r   r   r   r   r   r   test_deepcopy_basic	  s    
zTestCopy.test_deepcopy_basicc             C   sZ   g }||g}t |}| || | || | |d |d  | |d |d  d S )Nr   r+   )r
   rm   r   rP   r	   )r   r   r   r   r   r   test_deepcopy_memo  s    
zTestCopy.test_deepcopy_memoc             C   s8   G dd dt }G dd d|d}| t|| d S )Nc               @   s   e Zd ZdS )z/TestCopy.test_deepcopy_issubclass.<locals>.MetaN)r   r   r   r   r   r   r   Meta  s   rp   c               @   s   e Zd ZdS )z,TestCopy.test_deepcopy_issubclass.<locals>.CN)r   r   r   r   r   r   r   r      s   r   )r?   )typer   r
   rm   )r   rp   r   r   r   r   test_deepcopy_issubclass  s    z!TestCopy.test_deepcopy_issubclassc                sJ   G  fdddt   d}t|}| |j|j | |j|j d S )Nc                   s"   e Zd Zdd Zd fdd	ZdS )z*TestCopy.test_deepcopy_deepcopy.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r   &  s    z3TestCopy.test_deepcopy_deepcopy.<locals>.C.__init__Nc                s
    | j S )N)r   )r   memo)r   r   r   __deepcopy__(  s    z7TestCopy.test_deepcopy_deepcopy.<locals>.C.__deepcopy__)N)r   r   r   r   rt   r   )r   r   r   r   %  s   r   r   )r   r
   rm   r   r    r   )r   r   r   r   )r   r   test_deepcopy_deepcopy$  s
    
zTestCopy.test_deepcopy_deepcopyc                sP   G dd dt   fdd} d}| ttj| t |  t|}d S )Nc               @   s   e Zd Zdd ZdS )z*TestCopy.test_deepcopy_registry.<locals>.Cc             S   s   t | }||_|S )N)r   r"   r   )r#   r   r$   r   r   r   r"   1  s    
z2TestCopy.test_deepcopy_registry.<locals>.C.__new__N)r   r   r   r"   r   r   r   r   r   0  s   r   c                s    | j ffS )N)r   )r$   )r   r   r   r%   5  s    z1TestCopy.test_deepcopy_registry.<locals>.pickle_Cr   )r   r&   r'   r
   rm   r(   r)   )r   r%   r   r   r   )r   r   test_deepcopy_registry/  s    zTestCopy.test_deepcopy_registryc                sF   G  fdddt }g  | }t|}| || |  dg d S )Nc                   s    e Zd Z fddZdd ZdS )z+TestCopy.test_deepcopy_reduce_ex.<locals>.Cc                s     d dS )Nr+   r,   )r-   )r   r.   )r/   r   r   r0   >  s    
z9TestCopy.test_deepcopy_reduce_ex.<locals>.C.__reduce_ex__c             S   s   |  d d S )Nzshouldn't call this)r1   )r   r   r   r   r2   A  s    z6TestCopy.test_deepcopy_reduce_ex.<locals>.C.__reduce__N)r   r   r   r0   r2   r   )r/   r   r   r   =  s   r   r+   )r   r
   rm   r	   r   )r   r   r   r   r   )r/   r   test_deepcopy_reduce_ex<  s    
z TestCopy.test_deepcopy_reduce_exc                sF   G  fdddt }g  | }t|}| || |  dg d S )Nc                   s   e Zd Z fddZdS )z(TestCopy.test_deepcopy_reduce.<locals>.Cc                s     d dS )Nr+   r,   )r-   )r   )r/   r   r   r2   K  s    
z3TestCopy.test_deepcopy_reduce.<locals>.C.__reduce__N)r   r   r   r2   r   )r/   r   r   r   J  s   r   r+   )r   r
   rm   r	   r   )r   r   r   r   r   )r/   r   test_deepcopy_reduceI  s    
zTestCopy.test_deepcopy_reducec             C   s,   G dd dt }| }| tjtj| d S )Nc               @   s   e Zd Zdd ZdS )z&TestCopy.test_deepcopy_cant.<locals>.Cc             S   s   | drt|t| |S )Nr5   )r6   r7   r   r8   )r   r9   r   r   r   r8   V  s    
z7TestCopy.test_deepcopy_cant.<locals>.C.__getattribute__N)r   r   r   r8   r   r   r   r   r   U  s   r   )r   r&   r
   r   rm   )r   r   r   r   r   r   test_deepcopy_cantT  s    zTestCopy.test_deepcopy_cantc             C   sn   G dd d}G dd dt }dd }d ddd	 d
ddddd|j||tg}x|D ]}| t|| qPW d S )Nc               @   s   e Zd ZdS )z.TestCopy.test_deepcopy_atomic.<locals>.ClassicN)r   r   r   r   r   r   r   r;   `  s   r;   c               @   s   e Zd ZdS )z/TestCopy.test_deepcopy_atomic.<locals>.NewStyleN)r   r   r   r   r   r   r   r<   b  s   r<   c               S   s   d S )Nr   r   r   r   r   r=   d  s    z(TestCopy.test_deepcopy_atomic.<locals>.fr   r@   rA   gQ	@TFy              ?rB   u   helloሴ)r   rH   rL   r	   r
   rm   )r   r;   r<   r=   rM   r   r   r   r   test_deepcopy_atomic_  s    

zTestCopy.test_deepcopy_atomicc             C   sF   ddgdg}t |}| || | || | |d |d  d S )Nr+   r@   rO   r   )r
   rm   r   rP   )r   r   r   r   r   r   test_deepcopy_listl  s
    
zTestCopy.test_deepcopy_listc             C   sf   g }| | t|}xtD ]}| t||| qW | || | |d | | t	|d d S )Nr   r+   )
r-   r
   rm   comparisonsr&   RecursionErrorrP   r	   r   len)r   r   r   opr   r   r   test_deepcopy_reflexive_lists  s    


z%TestCopy.test_deepcopy_reflexive_listc             C   s   d}t |}| || d S )Nr   )r
   rm   r	   )r   r   r   r   r   r   test_deepcopy_empty_tuple}  s    
z"TestCopy.test_deepcopy_empty_tuplec             C   sF   ddgdf}t |}| || | || | |d |d  d S )Nr+   r@   rO   r   )r
   rm   r   rP   )r   r   r   r   r   r   test_deepcopy_tuple  s
    
zTestCopy.test_deepcopy_tuplec             C   s   d}t |}| || d S )N))r+   r@   rO   )r
   rm   r	   )r   r   r   r   r   r   !test_deepcopy_tuple_of_immutables  s    
z*TestCopy.test_deepcopy_tuple_of_immutablesc             C   st   g f}|d  | t|}xtD ]}| t||| q$W | || | |d |d  | |d d | d S )Nr   )r-   r
   rm   r|   r&   r}   rP   r	   )r   r   r   r   r   r   r   test_deepcopy_reflexive_tuple  s    

z&TestCopy.test_deepcopy_reflexive_tuplec             C   sH   ddgdd}t |}| || | || | |d |d  d S )Nr+   r@   rO   )r   rS   r   )r
   rm   r   rP   )r   r   r   r   r   r   test_deepcopy_dict  s
    
zTestCopy.test_deepcopy_dictc             C   s   i }||d< t |}xtD ]}| t||| qW xtD ]}| t||| q:W | || | |d | | 	t
|d d S )Nr   r+   )r
   rm   order_comparisonsr&   r'   equality_comparisonsr}   rP   r	   r   r~   )r   r   r   r   r   r   r   test_deepcopy_reflexive_dict  s    


z%TestCopy.test_deepcopy_reflexive_dictc             C   s0   i }g }t ||}| |t| d | d S )Nr   )r
   rm   r	   id)r   rs   r   r   r   r   r   test_deepcopy_keepalive  s    z TestCopy.test_deepcopy_keepalivec             C   sn   i }ddddg}t ||}| || | t|d i }dg}t ||}| || | t|d d S )Nr+   r@   rO      )r+   r@   )r
   rm   r   r~   )r   rs   r   r   r   r   r   !test_deepcopy_dont_memo_immutable  s    z*TestCopy.test_deepcopy_dont_memo_immutablec             C   sB   G dd d}|dg}t |}| || | |j|j d S )Nc               @   s   e Zd Zdd Zdd ZdS )z.TestCopy.test_deepcopy_inst_vanilla.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z7TestCopy.test_deepcopy_inst_vanilla.<locals>.C.__init__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\     s    z5TestCopy.test_deepcopy_inst_vanilla.<locals>.C.__eq__N)r   r   r   r   r\   r   r   r   r   r     s   r   r   )r
   rm   r   rP   r   )r   r   r   r   r   r   r   test_deepcopy_inst_vanilla  s
    

z#TestCopy.test_deepcopy_inst_vanillac                sR   G  fddd  dg}t |}| || | || | |j|j d S )Nc                   s(   e Zd Zdd Z fddZdd ZdS )z/TestCopy.test_deepcopy_inst_deepcopy.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z8TestCopy.test_deepcopy_inst_deepcopy.<locals>.C.__init__c                s    t | j|S )N)r
   rm   r   )r   rs   )r   r   r   rt     s    z<TestCopy.test_deepcopy_inst_deepcopy.<locals>.C.__deepcopy__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\     s    z6TestCopy.test_deepcopy_inst_deepcopy.<locals>.C.__eq__N)r   r   r   r   rt   r\   r   )r   r   r   r     s   r   r   )r
   rm   r   rP   r   )r   r   r   r   )r   r   test_deepcopy_inst_deepcopy  s    

z$TestCopy.test_deepcopy_inst_deepcopyc             C   sN   G dd d}|dg}t |}| || | || | |j|j d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z2TestCopy.test_deepcopy_inst_getinitargs.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z;TestCopy.test_deepcopy_inst_getinitargs.<locals>.C.__init__c             S   s   | j fS )N)r   )r   r   r   r   r_     s    zBTestCopy.test_deepcopy_inst_getinitargs.<locals>.C.__getinitargs__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\     s    z9TestCopy.test_deepcopy_inst_getinitargs.<locals>.C.__eq__N)r   r   r   r   r_   r\   r   r   r   r   r     s   r   r   )r
   rm   r   rP   r   )r   r   r   r   r   r   r   test_deepcopy_inst_getinitargs  s    

z'TestCopy.test_deepcopy_inst_getinitargsc             C   sl   G dd dt }|dg}t|}| || | || | || | |j|j | |j|j d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z1TestCopy.test_deepcopy_inst_getnewargs.<locals>.Cc             S   s   t | }||_|S )N)ra   r"   r   )r#   r   r   r   r   r   r"     s    
z9TestCopy.test_deepcopy_inst_getnewargs.<locals>.C.__new__c             S   s   | j fS )N)r   )r   r   r   r   rb     s    z@TestCopy.test_deepcopy_inst_getnewargs.<locals>.C.__getnewargs__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\     s    z8TestCopy.test_deepcopy_inst_getnewargs.<locals>.C.__eq__N)r   r   r   r"   rb   r\   r   r   r   r   r     s   r   r   )ra   r
   rm   rc   r   rP   r   )r   r   r   r   r   r   r   test_deepcopy_inst_getnewargs  s    	

z&TestCopy.test_deepcopy_inst_getnewargsc             C   sn   G dd dt }|dgd}t|}| || | || | || | |j|j | |j|j d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z4TestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.Cc            S   s   t | }||_|S )N)ra   r"   r   )r#   r   r   r   r   r   r"     s    
z<TestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.C.__new__c             S   s   dd| j ifS )Nr   r   )r   )r   r   r   r   re     s    zFTestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.C.__getnewargs_ex__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\     s    z;TestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.C.__eq__N)r   r   r   r"   re   r\   r   r   r   r   r     s   r   r   )r   )ra   r
   rm   rc   r   rP   r   )r   r   r   r   r   r   r    test_deepcopy_inst_getnewargs_ex  s    	
z)TestCopy.test_deepcopy_inst_getnewargs_exc             C   sN   G dd d}|dg}t |}| || | || | |j|j d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z/TestCopy.test_deepcopy_inst_getstate.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z8TestCopy.test_deepcopy_inst_getstate.<locals>.C.__init__c             S   s
   d| j iS )Nr   )r   )r   r   r   r   rg     s    z<TestCopy.test_deepcopy_inst_getstate.<locals>.C.__getstate__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\     s    z6TestCopy.test_deepcopy_inst_getstate.<locals>.C.__eq__N)r   r   r   r   rg   r\   r   r   r   r   r     s   r   r   )r
   rm   r   rP   r   )r   r   r   r   r   r   r   test_deepcopy_inst_getstate  s    

z$TestCopy.test_deepcopy_inst_getstatec             C   sN   G dd d}|dg}t |}| || | || | |j|j d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z/TestCopy.test_deepcopy_inst_setstate.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r     s    z8TestCopy.test_deepcopy_inst_setstate.<locals>.C.__init__c             S   s   |d | _ d S )Nr   )r   )r   ri   r   r   r   rj     s    z<TestCopy.test_deepcopy_inst_setstate.<locals>.C.__setstate__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\     s    z6TestCopy.test_deepcopy_inst_setstate.<locals>.C.__eq__N)r   r   r   r   rj   r\   r   r   r   r   r     s   r   r   )r
   rm   r   rP   r   )r   r   r   r   r   r   r   test_deepcopy_inst_setstate  s    

z$TestCopy.test_deepcopy_inst_setstatec             C   s   G dd d}|dg}t |}| || | || | |j|j |g }t |}| || | || | |j|j d S )Nc               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
z8TestCopy.test_deepcopy_inst_getstate_setstate.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r   )  s    zATestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__init__c             S   s   | j S )N)r   )r   r   r   r   rg   +  s    zETestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__getstate__c             S   s
   || _ d S )N)r   )r   ri   r   r   r   rj   -  s    zETestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__setstate__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\   /  s    z?TestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__eq__N)r   r   r   r   rg   rj   r\   r   r   r   r   r   (  s   r   r   )r
   rm   r   rP   r   )r   r   r   r   r   r   r   $test_deepcopy_inst_getstate_setstate'  s    	


z-TestCopy.test_deepcopy_inst_getstate_setstatec             C   sB   G dd d}| }||_ t|}| || | |j | d S )Nc               @   s   e Zd ZdS )z0TestCopy.test_deepcopy_reflexive_inst.<locals>.CN)r   r   r   r   r   r   r   r   >  s   r   )r   r
   rm   rP   r	   )r   r   r   r   r   r   r   test_deepcopy_reflexive_inst=  s    
z%TestCopy.test_deepcopy_reflexive_instc             C   sp   G dd dt }t|d}t|}| || | || | |j|j | |j|j | |j| d S )Nc               @   s   e Zd ZdS )z'TestCopy.test_deepcopy_range.<locals>.IN)r   r   r   r   r   r   r   IG  s   r   rD   )ra   rJ   r
   rm   rP   r   stoprc   )r   r   r   r   r   r   r   test_deepcopy_rangeF  s    
zTestCopy.test_deepcopy_rangec             C   sF   G dd dt }| }t|}| || t|}| || d S )Nc               @   s   e Zd Zdd ZdS )z+TestCopy.test_reconstruct_string.<locals>.Cc             S   s   dS )Nr,   r   )r   r   r   r   r2   U  s    z6TestCopy.test_reconstruct_string.<locals>.C.__reduce__N)r   r   r   r2   r   r   r   r   r   T  s   r   )r   r
   r	   rm   )r   r   r   r   r   r   r   test_reconstruct_stringS  s    

z TestCopy.test_reconstruct_stringc                sX   G  fdddt    }d|_t|}| |j|j t|}| |j|j d S )Nc                   s   e Zd Z fddZdS )z,TestCopy.test_reconstruct_nostate.<locals>.Cc                s    dfS )Nr   r   )r   )r   r   r   r2   _  s    z7TestCopy.test_reconstruct_nostate.<locals>.C.__reduce__N)r   r   r   r2   r   )r   r   r   r   ^  s   r   r   )r   r   r
   r	   r    rm   )r   r   r   r   )r   r   test_reconstruct_nostate]  s    

z!TestCopy.test_reconstruct_nostatec                sb   G  fdddt    }dg|_t|}| || t|}| || | |j|j d S )Nc                   s    e Zd Z fddZdd ZdS )z*TestCopy.test_reconstruct_state.<locals>.Cc                s    d| j fS )Nr   )__dict__)r   )r   r   r   r2   j  s    z5TestCopy.test_reconstruct_state.<locals>.C.__reduce__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\   l  s    z1TestCopy.test_reconstruct_state.<locals>.C.__eq__N)r   r   r   r2   r\   r   )r   r   r   r   i  s   r   r   )r   r   r
   r   rm   rP   )r   r   r   r   )r   r   test_reconstruct_stateh  s    

zTestCopy.test_reconstruct_statec                sb   G  fdddt    }dg|_t|}| || t|}| || | |j|j d S )Nc                   s(   e Zd Z fddZdd Zdd ZdS )z3TestCopy.test_reconstruct_state_setstate.<locals>.Cc                s    d| j fS )Nr   )r   )r   )r   r   r   r2   x  s    z>TestCopy.test_reconstruct_state_setstate.<locals>.C.__reduce__c             S   s   | j | d S )N)r   update)r   ri   r   r   r   rj   z  s    z@TestCopy.test_reconstruct_state_setstate.<locals>.C.__setstate__c             S   s   | j |j kS )N)r   )r   r[   r   r   r   r\   |  s    z:TestCopy.test_reconstruct_state_setstate.<locals>.C.__eq__N)r   r   r   r2   rj   r\   r   )r   r   r   r   w  s   r   r   )r   r   r
   r   rm   rP   )r   r   r   r   )r   r   test_reconstruct_state_setstatev  s    

z(TestCopy.test_reconstruct_state_setstatec             C   sD   G dd dt }| }||_t|}| || | |j| d S )Nc               @   s   e Zd ZdS )z.TestCopy.test_reconstruct_reflexive.<locals>.CN)r   r   r   r   r   r   r   r     s   r   )r   r   r
   rm   rP   r	   )r   r   r   r   r   r   r   test_reconstruct_reflexive  s    
z#TestCopy.test_reconstruct_reflexivec                s   G  fdddt   ddgdg}t|}| || | || | |d |d  t|}| || | || | |d |d  d S )Nc                   s    e Zd Z fddZdd ZdS )z&TestCopy.test_reduce_4tuple.<locals>.Cc                s    d| j t| fS )Nr   )r   iter)r   )r   r   r   r2     s    z1TestCopy.test_reduce_4tuple.<locals>.C.__reduce__c             S   s   t | t |ko| j|jkS )N)listr   )r   r[   r   r   r   r\     s    z-TestCopy.test_reduce_4tuple.<locals>.C.__eq__N)r   r   r   r2   r\   r   )r   r   r   r     s   r   r+   r@   rO   r   )r   r
   r   rP   r	   rm   )r   r   r   r   )r   r   test_reduce_4tuple  s    

zTestCopy.test_reduce_4tuplec                s   G  fdddt   dddgfdg}t|}| || | || | |d |d  t|}| || | || | |d |d  d S )Nc                   s    e Zd Z fddZdd ZdS )z&TestCopy.test_reduce_5tuple.<locals>.Cc                s    d| j d |  fS )Nr   )r   items)r   )r   r   r   r2     s    z1TestCopy.test_reduce_5tuple.<locals>.C.__reduce__c             S   s   t | t |ko| j|jkS )N)dictr   )r   r[   r   r   r   r\     s    z-TestCopy.test_reduce_5tuple.<locals>.C.__eq__N)r   r   r   r2   r\   r   )r   r   r   r     s   r   r   r+   r@   )rS   rO   )r   r
   r   rP   r	   rm   )r   r   r   r   )r   r   test_reduce_5tuple  s    

zTestCopy.test_reduce_5tuplec             C   s<   G dd dt }| }dg|_t|}| |j|j d S )Nc               @   s   e Zd ZdgZdS )z#TestCopy.test_copy_slots.<locals>.Cr   N)r   r   r   	__slots__r   r   r   r   r     s   r   r   )r   r   r
   r	   )r   r   r   r   r   r   r   test_copy_slots  s
    
zTestCopy.test_copy_slotsc             C   sL   G dd dt }| }dg|_t|}| |j|j | |j|j d S )Nc               @   s   e Zd ZdgZdS )z'TestCopy.test_deepcopy_slots.<locals>.Cr   N)r   r   r   r   r   r   r   r   r     s   r   r   )r   r   r
   rm   r   rP   )r   r   r   r   r   r   r   test_deepcopy_slots  s    
zTestCopy.test_deepcopy_slotsc             C   sx   G dd dt }|ddid}t|}| || | |j|j | || d|d< | || | |j|j d S )Nc                   s*   e Zd Zd fdd	Z fddZ  ZS )z/TestCopy.test_deepcopy_dict_subclass.<locals>.CNc                s&   |si }t | | _t | d S )N)r   keys_keyssuperr   )r   d)r    r   r   r     s    z8TestCopy.test_deepcopy_dict_subclass.<locals>.C.__init__c                s(   t  || || jkr$| j| d S )N)r   __setitem__r   r-   )r   keyitem)r    r   r   r     s    
z;TestCopy.test_deepcopy_dict_subclass.<locals>.C.__setitem__)N)r   r   r   r   r   __classcell__r   r   )r    r   r     s   r   r   r   )r   r+   rS   )r   r
   rm   r   r   rP   assertNotEqual)r   r   r   r   r   r   r   test_deepcopy_dict_subclass  s    

z$TestCopy.test_deepcopy_dict_subclassc             C   s   G dd dt }|ddgdg}ddg|_t|}| t |t | | |j|j | |d |d  | |j|j d S )	Nc               @   s   e Zd ZdS )z+TestCopy.test_copy_list_subclass.<locals>.CN)r   r   r   r   r   r   r   r     s   r   r+   r@   rO   r      r   )r   r   r
   r   r	   )r   r   r   r   r   r   r   test_copy_list_subclass  s    

z TestCopy.test_copy_list_subclassc             C   s   G dd dt }|ddgdg}ddg|_t|}| t |t | | |j|j | |d |d  | |j|j d S )	Nc               @   s   e Zd ZdS )z/TestCopy.test_deepcopy_list_subclass.<locals>.CN)r   r   r   r   r   r   r   r     s   r   r+   r@   rO   r   r   r   )r   r   r
   rm   r   rP   )r   r   r   r   r   r   r   test_deepcopy_list_subclass  s    

z$TestCopy.test_deepcopy_list_subclassc             C   sL   G dd dt }|dddg}| t |d t|}| t |d d S )Nc               @   s   e Zd ZdS )z,TestCopy.test_copy_tuple_subclass.<locals>.CN)r   r   r   r   r   r   r   r     s   r   r+   r@   rO   )r+   r@   rO   )tupler   r
   )r   r   r   r   r   r   r   test_copy_tuple_subclass  s
    
z!TestCopy.test_copy_tuple_subclassc             C   s~   G dd dt }|ddgdg}| t |ddgdf t|}| t |ddgdf | || | |d |d  d S )Nc               @   s   e Zd ZdS )z0TestCopy.test_deepcopy_tuple_subclass.<locals>.CN)r   r   r   r   r   r   r   r     s   r   r+   r@   rO   r   )r   r   r
   rm   rP   )r   r   r   r   r   r   r   test_deepcopy_tuple_subclass  s    
z%TestCopy.test_deepcopy_tuple_subclassc             C   s&   G dd dt }| ttj|  d S )Nc               @   s   e Zd Zdd ZdS )z-TestCopy.test_getstate_exc.<locals>.EvilStatec             S   s   t dd S )Nzain't got no stickin' state)
ValueError)r   r   r   r   rg     s    z:TestCopy.test_getstate_exc.<locals>.EvilState.__getstate__N)r   r   r   rg   r   r   r   r   	EvilState  s   r   )r   r&   r   r
   )r   r   r   r   r   test_getstate_exc   s    zTestCopy.test_getstate_excc             C   sJ   |  ttt dd }|  t|| dd }|  t|| d S )Nc             S   s   | | S )Nr   )r   r   r   r   r   r         z(TestCopy.test_copy_function.<locals>.fooc               S   s   d S )Nr   r   r   r   r   <lambda>
  r   z-TestCopy.test_copy_function.<locals>.<lambda>)r   r
   
global_foo)r   r   rS   r   r   r   test_copy_function  s
    zTestCopy.test_copy_functionc             C   sJ   |  ttt dd }|  t|| dd }|  t|| d S )Nc             S   s   | | S )Nr   )r   r   r   r   r   r     r   z,TestCopy.test_deepcopy_function.<locals>.fooc               S   s   d S )Nr   r   r   r   r   r     r   z1TestCopy.test_deepcopy_function.<locals>.<lambda>)r   r
   rm   r   )r   r   rS   r   r   r   test_deepcopy_function  s
    zTestCopy.test_deepcopy_functionc             C   sN   G dd dt }| }t|}||}| || ~||}| || d S )Nc               @   s   e Zd ZdS )z"TestCopy._check_weakref.<locals>.CN)r   r   r   r   r   r   r   r     s   r   )r   weakrefrefr	   )r   Z_copyr   r$   r   r   r   r   r   _check_weakref  s    
zTestCopy._check_weakrefc             C   s   |  tj d S )N)r   r
   )r   r   r   r   test_copy_weakref  s    zTestCopy.test_copy_weakrefc             C   s   |  tj d S )N)r   r
   rm   )r   r   r   r   test_deepcopy_weakref"  s    zTestCopy.test_deepcopy_weakrefc       
         s   G dd dt   fddtdD \}}}}| }|||< |||< t|}| || | || | || | | || | | t|d ~~| t|d      }}	|	||< | || d S )Nc               @   s   e Zd ZdS )z(TestCopy._check_copy_weakdict.<locals>.CN)r   r   r   r   r   r   r   r   &  s   r   c                s   g | ]
}  qS r   r   ).0i)r   r   r   
<listcomp>(  s    z1TestCopy._check_copy_weakdict.<locals>.<listcomp>r   r@   r+   )r   rJ   r
   rP   r   r~   ZassertNotIn)
r   Z	_dicttypeabr/   r   uvr   r   r   )r   r   _check_copy_weakdict%  s     
zTestCopy._check_copy_weakdictc             C   s   |  tj d S )N)r   r   WeakKeyDictionary)r   r   r   r   test_copy_weakkeydict9  s    zTestCopy.test_copy_weakkeydictc             C   s   |  tj d S )N)r   r   WeakValueDictionary)r   r   r   r   test_copy_weakvaluedict<  s    z TestCopy.test_copy_weakvaluedictc                s   G dd dt   fddtdD \}}}}t }|||< |||< t|}| || | t|d | 	|| | | 	|| | | || j
|j
 | || j
|j
 ~| t|d d S )Nc               @   s   e Zd Zdd ZdS )z-TestCopy.test_deepcopy_weakkeydict.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r   A  s    z6TestCopy.test_deepcopy_weakkeydict.<locals>.C.__init__N)r   r   r   r   r   r   r   r   r   @  s   r   c                s   g | ]} |qS r   r   )r   r   )r   r   r   r   C  s    z6TestCopy.test_deepcopy_weakkeydict.<locals>.<listcomp>r   r@   r+   )r   rJ   r   r   r
   rm   r   r   r~   rP   r   )r   r   r   r/   r   r   r   r   )r   r   test_deepcopy_weakkeydict?  s    
z"TestCopy.test_deepcopy_weakkeydictc                s   G dd dt   fddtdD \}}}}t }|||< |||< t|}| || | t|d t	|
 dd d	\\}}\}	}
| || | |j|j | || | |	| | |	j|j | |
| ~~~	~
~| t|d
 d S )Nc               @   s   e Zd Zdd ZdS )z/TestCopy.test_deepcopy_weakvaluedict.<locals>.Cc             S   s
   || _ d S )N)r   )r   r   r   r   r   r   T  s    z8TestCopy.test_deepcopy_weakvaluedict.<locals>.C.__init__N)r   r   r   r   r   r   r   r   r   S  s   r   c                s   g | ]} |qS r   r   )r   r   )r   r   r   r   V  s    z8TestCopy.test_deepcopy_weakvaluedict.<locals>.<listcomp>r   r@   c             S   s
   | d j S )Nr   )r   )Zpairr   r   r   r   ^  r   z6TestCopy.test_deepcopy_weakvaluedict.<locals>.<lambda>)r   r+   )r   rJ   r   r   r
   rm   r   r   r~   sortedr   rP   r   r	   )r   r   r   r/   r   r   r   r   r   ztr   )r   r   test_deepcopy_weakvaluedictR  s$    
 z$TestCopy.test_deepcopy_weakvaluedictc             C   sT   G dd dt }| }|j|_t|}| |j|j | |jj| |  d S )Nc               @   s   e Zd Zdd ZdS )z0TestCopy.test_deepcopy_bound_method.<locals>.Fooc             S   s   d S )Nr   )r   r   r   r   mk  s    z2TestCopy.test_deepcopy_bound_method.<locals>.Foo.mN)r   r   r   r   r   r   r   r   Fooj  s   r   )r   r   r   r
   rm   r   r	   __self__)r   r   r=   gr   r   r   test_deepcopy_bound_methodi  s    
z#TestCopy.test_deepcopy_bound_methodN)Pr   r   r   r   r   r!   r*   r3   r4   r:   rN   rQ   rR   rT   rV   rX   rZ   r]   r^   r`   rd   rf   rh   rk   rl   rn   ro   rr   ru   rv   rw   rx   ry   rz   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      s   



	

	
	
r   c             C   s   | | S )Nr   )r   r   r   r   r   r   u  r   r   __main__)__doc__r
   r(   r   rE   operatorr   r   r   r   r   r   Zunittestr   r   r|   ZTestCaser   r   r   mainr   r   r   r   <module>   s&          l