o
    gf                     @   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rKe  dS dS )	zUnit tests for the copy module.    N)leltgegteqnec                   @   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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 ZNdS )TestCopyc                 C   s&   |  tjtj | ttjt d S N)assertIscopyErrorerrorZ
assertTrue
issubclass	Exceptionself r   D/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/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      
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   
   || _ d S r	   foor   r   r   r   r   __init__       
z+TestCopy.test_copy_copy.<locals>.C.__init__c                    
    | j S r	   r   r   Cr   r   __copy__"   r"   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   test_copy_copy   
   
zTestCopy.test_copy_copyc                    sP   G dd dt   fdd} d}| ttj| t |  t|}d S )Nc                   @      e Zd Zdd ZdS )z&TestCopy.test_copy_registry.<locals>.Cc                 S      t | }||_|S r	   r*   __new__r   clsr   objr   r   r   r1   +      
z.TestCopy.test_copy_registry.<locals>.C.__new__Nr'   r(   r)   r1   r   r   r   r   r%   *       r%   c                        | j ffS r	   r   r4   r$   r   r   pickle_C/      z-TestCopy.test_copy_registry.<locals>.pickle_Cr   )r*   assertRaises	TypeErrorr   copyregpickler   r:   r   r   r   r$   r   test_copy_registry)      zTestCopy.test_copy_registryc                    F   G  fdddt }g  | }t|}| || |  dg d S )Nc                           e Zd Z fddZdd ZdS )z'TestCopy.test_copy_reduce_ex.<locals>.Cc                         d dS N    appendr   protocr   r   __reduce_ex__8      
z5TestCopy.test_copy_reduce_ex.<locals>.C.__reduce_ex__c                 S      |  d d S Nzshouldn't call thisZfailr   r   r   r   
__reduce__;      z2TestCopy.test_copy_reduce_ex.<locals>.C.__reduce__Nr'   r(   r)   rO   rT   r   rM   r   r   r%   7       r%   rG   r*   r   r
   r   r   r%   r   r   r   rM   r   test_copy_reduce_ex6      
zTestCopy.test_copy_reduce_exc                    rC   )Nc                          e Zd Z fddZdS )z$TestCopy.test_copy_reduce.<locals>.Cc                    rE   rF   rI   r   rM   r   r   rT   E   rP   z/TestCopy.test_copy_reduce.<locals>.C.__reduce__Nr'   r(   r)   rT   r   rM   r   r   r%   D       r%   rG   rX   rY   r   rM   r   test_copy_reduceC      
zTestCopy.test_copy_reducec                 C   s,   G dd dt }| }| tjtj| d S )Nc                   @   r.   )z"TestCopy.test_copy_cant.<locals>.Cc                 S      | dr	t|t| |S NZ__reduce
startswithAttributeErrorr*   __getattribute__r   namer   r   r   rf   P      
z3TestCopy.test_copy_cant.<locals>.C.__getattribute__Nr'   r(   r)   rf   r   r   r   r   r%   O   r7   r%   )r*   r<   r   r   r   r%   r   r   r   r   test_copy_cantN      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|t	 g}|D ]}| 
t|| qDd S )Nc                   @      e Zd ZdS )z*TestCopy.test_copy_atomic.<locals>.ClassicNr'   r(   r)   r   r   r   r   ClassicZ       rp   c                   @   rn   )z+TestCopy.test_copy_atomic.<locals>.NewStyleNro   r   r   r   r   NewStyle\   rq   rr   c                   S      d S r	   r   r   r   r   r   f^      z$TestCopy.test_copy_atomic.<locals>.fc                   @   rn   )z0TestCopy.test_copy_atomic.<locals>.WithMetaclassNro   r   r   r   r   WithMetaclass`   rq   rv   	metaclass.r      d   Q	@TF              ?hello   helloሴs   world   
   rG   )r*   abcABCMetaNotImplemented__code__bytesrangeslicemaxpropertyr
   r   )r   rp   rr   rt   rv   testsr   r   r   r   test_copy_atomicY   s   zTestCopy.test_copy_atomicc                 C   sT   g d}t  |}| || | || g }t  |}| || | || d S )NrG   ry      r   r   assertIsNotr   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 )Nr   r   rG   ry   r   )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 )NrG   ry   r   barr   r   r   r   r   test_copy_dict|   s   


zTestCopy.test_copy_dictc                 C   sV   h d}t  |}| || | || t }t  |}| || | || d S N>   rG   ry   r   )r   r   r   setr   r   r   r   test_copy_set      

zTestCopy.test_copy_setc                 C   s:   t h d}| t|| t  }| t|| d S r   )	frozensetr
   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   r   r   r   r   r   test_copy_bytearray   r   zTestCopy.test_copy_bytearrayc                 C   ,   G dd d}|d}|  t|| d S )Nc                   @      e Zd Zdd Zdd ZdS )z*TestCopy.test_copy_inst_vanilla.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!      r"   z3TestCopy.test_copy_inst_vanilla.<locals>.C.__init__c                 S      | j |j kS r	   r   r   otherr   r   r   __eq__   r;   z1TestCopy.test_copy_inst_vanilla.<locals>.C.__eq__Nr'   r(   r)   r!   r   r   r   r   r   r%          r%   r   r   r   rk   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                       (   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   r   r	   r   r    r   r   r   r!      r"   z0TestCopy.test_copy_inst_copy.<locals>.C.__init__c                    r#   r	   r   r   r$   r   r   r&      r"   z0TestCopy.test_copy_inst_copy.<locals>.C.__copy__c                 S   r   r	   r   r   r   r   r   r      r;   z.TestCopy.test_copy_inst_copy.<locals>.C.__eq__N)r'   r(   r)   r!   r&   r   r   r$   r   r   r%          r%   r   r   r   r   r$   r   test_copy_inst_copy   s   zTestCopy.test_copy_inst_copyc                 C   r   )Nc                   @   $   e Zd Zdd Zdd Zdd ZdS )z.TestCopy.test_copy_inst_getinitargs.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!      r"   z7TestCopy.test_copy_inst_getinitargs.<locals>.C.__init__c                 S      | j fS r	   r   r   r   r   r   __getinitargs__      z>TestCopy.test_copy_inst_getinitargs.<locals>.C.__getinitargs__c                 S   r   r	   r   r   r   r   r   r      r;   z5TestCopy.test_copy_inst_getinitargs.<locals>.C.__eq__Nr'   r(   r)   r!   r   r   r   r   r   r   r%          r%   r   r   rk   r   r   r   test_copy_inst_getinitargs      z#TestCopy.test_copy_inst_getinitargsc                 C   sZ   G dd dt }|d}t|}| || | || | || | |j|j d S )Nc                   @   r   )z-TestCopy.test_copy_inst_getnewargs.<locals>.Cc                 S   r/   r	   intr1   r   r3   r   r   r   r   r   r1      r5   z5TestCopy.test_copy_inst_getnewargs.<locals>.C.__new__c                 S   r   r	   r   r   r   r   r   __getnewargs__   r   z<TestCopy.test_copy_inst_getnewargs.<locals>.C.__getnewargs__c                 S   r   r	   r   r   r   r   r   r      r;   z4TestCopy.test_copy_inst_getnewargs.<locals>.C.__eq__Nr'   r(   r)   r1   r   r   r   r   r   r   r%          r%   r   r   r   assertIsInstancer   r   r   rY   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                   @   r   )z0TestCopy.test_copy_inst_getnewargs_ex.<locals>.Cc                S   r/   r	   r   r   r   r   r   r1      r5   z8TestCopy.test_copy_inst_getnewargs_ex.<locals>.C.__new__c                 S      dd| j ifS Nr   r   r   r   r   r   r   __getnewargs_ex__   rU   zBTestCopy.test_copy_inst_getnewargs_ex.<locals>.C.__getnewargs_ex__c                 S   r   r	   r   r   r   r   r   r      r;   z7TestCopy.test_copy_inst_getnewargs_ex.<locals>.C.__eq__Nr'   r(   r)   r1   r   r   r   r   r   r   r%      r   r%   r   r   r   rY   r   r   r   test_copy_inst_getnewargs_ex   s   
	
z%TestCopy.test_copy_inst_getnewargs_exc                 C   r   )Nc                   @   r   )z+TestCopy.test_copy_inst_getstate.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!      r"   z4TestCopy.test_copy_inst_getstate.<locals>.C.__init__c                 S   
   d| j iS Nr   r   r   r   r   r   __getstate__   r"   z8TestCopy.test_copy_inst_getstate.<locals>.C.__getstate__c                 S   r   r	   r   r   r   r   r   r      r;   z2TestCopy.test_copy_inst_getstate.<locals>.C.__eq__Nr'   r(   r)   r!   r   r   r   r   r   r   r%      r   r%   r   r   rk   r   r   r   test_copy_inst_getstate   r   z TestCopy.test_copy_inst_getstatec                 C   r   )Nc                   @   r   )z+TestCopy.test_copy_inst_setstate.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!      r"   z4TestCopy.test_copy_inst_setstate.<locals>.C.__init__c                 S      |d | _ d S r   r   r   stater   r   r   __setstate__   rU   z8TestCopy.test_copy_inst_setstate.<locals>.C.__setstate__c                 S   r   r	   r   r   r   r   r   r      r;   z2TestCopy.test_copy_inst_setstate.<locals>.C.__eq__Nr'   r(   r)   r!   r   r   r   r   r   r   r%      r   r%   r   r   rk   r   r   r   test_copy_inst_setstate   r   z TestCopy.test_copy_inst_setstatec                 C   sF   G dd d}|d}|  t|| |d}|  t|| d S )Nc                   @   ,   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   r   r	   r   r    r   r   r   r!      r"   z=TestCopy.test_copy_inst_getstate_setstate.<locals>.C.__init__c                 S      | j S r	   r   r   r   r   r   r         zATestCopy.test_copy_inst_getstate_setstate.<locals>.C.__getstate__c                 S   r   r	   r   r   r   r   r   r      r"   zATestCopy.test_copy_inst_getstate_setstate.<locals>.C.__setstate__c                 S   r   r	   r   r   r   r   r   r      r;   z;TestCopy.test_copy_inst_getstate_setstate.<locals>.C.__eq__Nr'   r(   r)   r!   r   r   r   r   r   r   r   r%      
    r%   r   g        r   rk   r   r   r    test_copy_inst_getstate_setstate   s
   	z)TestCopy.test_copy_inst_getstate_setstatec                 C   s   d}t |}| || d S r   )r   deepcopyr   r   r   r   r   test_deepcopy_basic	  r   zTestCopy.test_deepcopy_basicc                 C   sZ   g }||g}t |}| || | || | |d |d  | |d |d  d S Nr   rG   )r   r   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                   @   rn   )z/TestCopy.test_deepcopy_issubclass.<locals>.MetaNro   r   r   r   r   Meta  rq   r   c                   @   rn   )z,TestCopy.test_deepcopy_issubclass.<locals>.CNro   r   r   r   r   r%      rq   r%   rw   )typer   r   r   )r   r   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   r   r	   r   r    r   r   r   r!   &  r"   z3TestCopy.test_deepcopy_deepcopy.<locals>.C.__init__Nc                    r#   r	   r   r   memor$   r   r   __deepcopy__(  r"   z7TestCopy.test_deepcopy_deepcopy.<locals>.C.__deepcopy__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_deepcopy_deepcopy$  r-   zTestCopy.test_deepcopy_deepcopyc                    sP   G dd dt   fdd} d}| ttj| t |  t|}d S )Nc                   @   r.   )z*TestCopy.test_deepcopy_registry.<locals>.Cc                 S   r/   r	   r0   r2   r   r   r   r1   1  r5   z2TestCopy.test_deepcopy_registry.<locals>.C.__new__Nr6   r   r   r   r   r%   0  r7   r%   c                    r8   r	   r   r9   r$   r   r   r:   5  r;   z1TestCopy.test_deepcopy_registry.<locals>.pickle_Cr   )r*   r<   r=   r   r   r>   r?   r@   r   r$   r   test_deepcopy_registry/  rB   zTestCopy.test_deepcopy_registryc                    F   G  fdddt }g  | }t|}| || |  dg d S )Nc                       rD   )z+TestCopy.test_deepcopy_reduce_ex.<locals>.Cc                    rE   rF   rI   rK   rM   r   r   rO   >  rP   z9TestCopy.test_deepcopy_reduce_ex.<locals>.C.__reduce_ex__c                 S   rQ   rR   rS   r   r   r   r   rT   A  rU   z6TestCopy.test_deepcopy_reduce_ex.<locals>.C.__reduce__NrV   r   rM   r   r   r%   =  rW   r%   rG   r*   r   r   r
   r   rY   r   rM   r   test_deepcopy_reduce_ex<  r[   z TestCopy.test_deepcopy_reduce_exc                    r   )Nc                       r\   )z(TestCopy.test_deepcopy_reduce.<locals>.Cc                    rE   rF   rI   r   rM   r   r   rT   K  rP   z3TestCopy.test_deepcopy_reduce.<locals>.C.__reduce__Nr]   r   rM   r   r   r%   J  r^   r%   rG   r   rY   r   rM   r   test_deepcopy_reduceI  r`   zTestCopy.test_deepcopy_reducec                 C   s,   G dd dt }| }| tjtj| d S )Nc                   @   r.   )z&TestCopy.test_deepcopy_cant.<locals>.Cc                 S   ra   rb   rc   rg   r   r   r   rf   V  ri   z7TestCopy.test_deepcopy_cant.<locals>.C.__getattribute__Nrj   r   r   r   r   r%   U  r7   r%   )r*   r<   r   r   r   rk   r   r   r   test_deepcopy_cantT  rm   zTestCopy.test_deepcopy_cantc                 C   st   G dd d}G dd dt }dd }d ddd	 d
ddddd|j|td|tt g}|D ]}| t|| q,d S )Nc                   @   rn   )z.TestCopy.test_deepcopy_atomic.<locals>.ClassicNro   r   r   r   r   rp   `  rq   rp   c                   @   rn   )z/TestCopy.test_deepcopy_atomic.<locals>.NewStyleNro   r   r   r   r   rr   b  rq   rr   c                   S   rs   r	   r   r   r   r   r   rt   d  ru   z(TestCopy.test_deepcopy_atomic.<locals>.fr   ry   rz   r{   TFr|   r}   r~   r   )r*   r   r   r   r   r
   r   r   )r   rp   rr   rt   r   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 NrG   ry   r   r   r   r   r   r   r   r   r   r   test_deepcopy_listl  
   
zTestCopy.test_deepcopy_listc                 C   sb   g }| | t|}tD ]
}| t||| q| || | |d | | t	|d d S r   )
rJ   r   r   comparisonsr<   RecursionErrorr   r
   r   lenr   r   r   opr   r   r   test_deepcopy_reflexive_lists  s   

z%TestCopy.test_deepcopy_reflexive_listc                 C      d}t |}| || d S Nr   r   r   r
   r   r   r   r   test_deepcopy_empty_tuple}  r   z"TestCopy.test_deepcopy_empty_tuplec                 C   sF   ddgdf}t |}| || | || | |d |d  d S r   r   r   r   r   r   test_deepcopy_tuple  r   zTestCopy.test_deepcopy_tuplec                 C   r   )N)rG   ry   r   r   r   r   r   r   !test_deepcopy_tuple_of_immutables  r   z*TestCopy.test_deepcopy_tuple_of_immutablesc                 C   sp   g f}|d  | t|}tD ]
}| t||| q| || | |d |d  | |d d | d S Nr   )rJ   r   r   r   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 )NrG   ry   r   r   r   r   r   r   r   r   test_deepcopy_dict  s
   
zTestCopy.test_deepcopy_dictc                 C   sz   i }||d< t |}tD ]
}| t||| qtD ]
}| t||| q| || | |d | | 	t
|d d S )Nr   rG   )r   r   order_comparisonsr<   r=   equality_comparisonsr   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 r   )r   r   r
   idr   r   r   r   r   r   r   test_deepcopy_keepalive  s   z TestCopy.test_deepcopy_keepalivec                 C   sj   i }g d}t ||}| || | t|d i }dg}t ||}| || | t|d d S )N)rG   ry   r      ry   r   )r   r   r   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                   @   r   )z.TestCopy.test_deepcopy_inst_vanilla.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!     r"   z7TestCopy.test_deepcopy_inst_vanilla.<locals>.C.__init__c                 S   r   r	   r   r   r   r   r   r     r;   z5TestCopy.test_deepcopy_inst_vanilla.<locals>.C.__eq__Nr   r   r   r   r   r%     r   r%   r   r   r   r   r   r   rY   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                       r   )z/TestCopy.test_deepcopy_inst_deepcopy.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!     r"   z8TestCopy.test_deepcopy_inst_deepcopy.<locals>.C.__init__c                    s    t | j|S r	   )r   r   r   r   r$   r   r   r        z<TestCopy.test_deepcopy_inst_deepcopy.<locals>.C.__deepcopy__c                 S   r   r	   r   r   r   r   r   r     r;   z6TestCopy.test_deepcopy_inst_deepcopy.<locals>.C.__eq__N)r'   r(   r)   r!   r   r   r   r$   r   r   r%     r   r%   r   r   r   r   r$   r   test_deepcopy_inst_deepcopy  s   

z$TestCopy.test_deepcopy_inst_deepcopyc                 C   N   G dd d}|dg}t |}| || | || | |j|j d S )Nc                   @   r   )z2TestCopy.test_deepcopy_inst_getinitargs.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!     r"   z;TestCopy.test_deepcopy_inst_getinitargs.<locals>.C.__init__c                 S   r   r	   r   r   r   r   r   r     r   zBTestCopy.test_deepcopy_inst_getinitargs.<locals>.C.__getinitargs__c                 S   r   r	   r   r   r   r   r   r     r;   z9TestCopy.test_deepcopy_inst_getinitargs.<locals>.C.__eq__Nr   r   r   r   r   r%     r   r%   r   r   rY   r   r   r   test_deepcopy_inst_getinitargs     

z'TestCopy.test_deepcopy_inst_getinitargsc                 C   sl   G dd dt }|dg}t|}| || | || | || | |j|j | |j|j d S )Nc                   @   r   )z1TestCopy.test_deepcopy_inst_getnewargs.<locals>.Cc                 S   r/   r	   r   r   r   r   r   r1     r5   z9TestCopy.test_deepcopy_inst_getnewargs.<locals>.C.__new__c                 S   r   r	   r   r   r   r   r   r     r   z@TestCopy.test_deepcopy_inst_getnewargs.<locals>.C.__getnewargs__c                 S   r   r	   r   r   r   r   r   r     r;   z8TestCopy.test_deepcopy_inst_getnewargs.<locals>.C.__eq__Nr   r   r   r   r   r%     r   r%   r   r   r   r   r   r   r   r   rY   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                   @   r   )z4TestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.Cc                S   r/   r	   r   r   r   r   r   r1     r5   z<TestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.C.__new__c                 S   r   r   r   r   r   r   r   r     rU   zFTestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.C.__getnewargs_ex__c                 S   r   r	   r   r   r   r   r   r     r;   z;TestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.C.__eq__Nr   r   r   r   r   r%     r   r%   r   r   r  rY   r   r   r    test_deepcopy_inst_getnewargs_ex  s   	
z)TestCopy.test_deepcopy_inst_getnewargs_exc                 C   r  )Nc                   @   r   )z/TestCopy.test_deepcopy_inst_getstate.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!     r"   z8TestCopy.test_deepcopy_inst_getstate.<locals>.C.__init__c                 S   r   r   r   r   r   r   r   r     r"   z<TestCopy.test_deepcopy_inst_getstate.<locals>.C.__getstate__c                 S   r   r	   r   r   r   r   r   r     r;   z6TestCopy.test_deepcopy_inst_getstate.<locals>.C.__eq__Nr   r   r   r   r   r%     r   r%   r   r   rY   r   r   r   test_deepcopy_inst_getstate  r  z$TestCopy.test_deepcopy_inst_getstatec                 C   r  )Nc                   @   r   )z/TestCopy.test_deepcopy_inst_setstate.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!     r"   z8TestCopy.test_deepcopy_inst_setstate.<locals>.C.__init__c                 S   r   r   r   r   r   r   r   r     rU   z<TestCopy.test_deepcopy_inst_setstate.<locals>.C.__setstate__c                 S   r   r	   r   r   r   r   r   r     r;   z6TestCopy.test_deepcopy_inst_setstate.<locals>.C.__eq__Nr   r   r   r   r   r%     r   r%   r   r   rY   r   r   r   test_deepcopy_inst_setstate  r  z$TestCopy.test_deepcopy_inst_setstatec                 C   s   G dd d}|dg}t |}| || | || | |j|j |g }t |}| || | || | |j|j d S )Nc                   @   r   )
z8TestCopy.test_deepcopy_inst_getstate_setstate.<locals>.Cc                 S   r   r	   r   r    r   r   r   r!   )  r"   zATestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__init__c                 S   r   r	   r   r   r   r   r   r   +  r   zETestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__getstate__c                 S   r   r	   r   r   r   r   r   r   -  r"   zETestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__setstate__c                 S   r   r	   r   r   r   r   r   r   /  r;   z?TestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__eq__Nr   r   r   r   r   r%   (  r   r%   r   r   rY   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                   @   rn   )z0TestCopy.test_deepcopy_reflexive_inst.<locals>.CNro   r   r   r   r   r%   >  rq   r%   )r   r   r   r   r
   rY   r   r   r   test_deepcopy_reflexive_inst=  s   
z%TestCopy.test_deepcopy_reflexive_instc                 C   sF   G dd dt }| }t|}| || t|}| || d S )Nc                   @   r.   )z+TestCopy.test_reconstruct_string.<locals>.Cc                 S   s   dS )NrH   r   r   r   r   r   rT   J  ru   z6TestCopy.test_reconstruct_string.<locals>.C.__reduce__Nr]   r   r   r   r   r%   I  r7   r%   )r*   r   r
   r   rY   r   r   r   test_reconstruct_stringH  s   

z TestCopy.test_reconstruct_stringc                    sX   G  fdddt    }d|_t|}| |j|j t|}| |j|j d S )Nc                       r\   )z,TestCopy.test_reconstruct_nostate.<locals>.Cc                    s    dfS r   r   r   r$   r   r   rT   T  r   z7TestCopy.test_reconstruct_nostate.<locals>.C.__reduce__Nr]   r   r$   r   r   r%   S  r^   r%   r   )r*   r   r   r
   r+   r   r   r   r$   r   test_reconstruct_nostateR  s   

z!TestCopy.test_reconstruct_nostatec                    b   G  fdddt    }dg|_t|}| || t|}| || | |j|j d S )Nc                       rD   )z*TestCopy.test_reconstruct_state.<locals>.Cc                        d| j fS r   __dict__r   r$   r   r   rT   _  r;   z5TestCopy.test_reconstruct_state.<locals>.C.__reduce__c                 S   r   r	   r  r   r   r   r   r   a  r;   z1TestCopy.test_reconstruct_state.<locals>.C.__eq__Nr'   r(   r)   rT   r   r   r$   r   r   r%   ^      r%   r   r*   r   r   r   r   r   r   r   r$   r   test_reconstruct_state]  s   

zTestCopy.test_reconstruct_statec                    r  )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                    r  r   r  r   r$   r   r   rT   m  r;   z>TestCopy.test_reconstruct_state_setstate.<locals>.C.__reduce__c                 S   s   | j | d S r	   )r  updater   r   r   r   r   o     z@TestCopy.test_reconstruct_state_setstate.<locals>.C.__setstate__c                 S   r   r	   r  r   r   r   r   r   q  r;   z:TestCopy.test_reconstruct_state_setstate.<locals>.C.__eq__N)r'   r(   r)   rT   r   r   r   r$   r   r   r%   l  s    r%   r   r  r   r   r$   r   test_reconstruct_state_setstatek  s   

z(TestCopy.test_reconstruct_state_setstatec                 C   sD   G dd dt }| }||_t|}| || | |j| d S )Nc                   @   rn   )z.TestCopy.test_reconstruct_reflexive.<locals>.CNro   r   r   r   r   r%   |  rq   r%   )r*   r   r   r   r   r
   rY   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                       rD   )z&TestCopy.test_reduce_4tuple.<locals>.Cc                    s    d| j t| fS r   )r  iterr   r$   r   r   rT     r  z1TestCopy.test_reduce_4tuple.<locals>.C.__reduce__c                 S      t | t |ko| j|jkS r	   )listr  r   r   r   r   r        
z-TestCopy.test_reduce_4tuple.<locals>.C.__eq__Nr  r   r$   r   r   r%     r  r%   rG   ry   r   r   )r  r   r   r   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                       rD   )z&TestCopy.test_reduce_5tuple.<locals>.Cc                    s    d| j d |  fS r   )r  itemsr   r$   r   r   rT     s   z1TestCopy.test_reduce_5tuple.<locals>.C.__reduce__c                 S   r  r	   )dictr  r   r   r   r   r     r  z-TestCopy.test_reduce_5tuple.<locals>.C.__eq__Nr  r   r$   r   r   r%     r  r%   r   rG   ry   )r   r   )r"  r   r   r   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                   @      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%         
r%   r   )r*   r   r   r
   rY   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                   @   r$  )z'TestCopy.test_deepcopy_slots.<locals>.Cr   Nr%  r   r   r   r   r%     r'  r%   r   )r*   r   r   r   r   r   rY   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 r	   )r  keys_keyssuperr!   )r   dr+   r   r   r!     s   z8TestCopy.test_deepcopy_dict_subclass.<locals>.C.__init__c                    s,   t  || || jvr| j| d S d S r	   )r,  __setitem__r+  rJ   )r   keyitemr.  r   r   r/    s   
z;TestCopy.test_deepcopy_dict_subclass.<locals>.C.__setitem__r	   )r'   r(   r)   r!   r/  __classcell__r   r   r.  r   r%     s    r%   r   r   )r-  rG   r   )r"  r   r   r   r+  r   assertNotEqualrY   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                   @   rn   )z+TestCopy.test_copy_list_subclass.<locals>.CNro   r   r   r   r   r%     rq   r%   rG   ry   r   r      r   )r  r   r   r   r
   rY   r   r   r   test_copy_list_subclass     

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                   @   rn   )z/TestCopy.test_deepcopy_list_subclass.<locals>.CNro   r   r   r   r   r%     rq   r%   rG   ry   r   r   r5  r   )r  r   r   r   r   r   rY   r   r   r   test_deepcopy_list_subclass  r7  z$TestCopy.test_deepcopy_list_subclassc                 C   sJ   G dd dt }|g d}| t |d t|}| t |d d S )Nc                   @   rn   )z,TestCopy.test_copy_tuple_subclass.<locals>.CNro   r   r   r   r   r%     rq   r%   r   )tupler   r   rY   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                   @   rn   )z0TestCopy.test_deepcopy_tuple_subclass.<locals>.CNro   r   r   r   r   r%     rq   r%   rG   ry   r   r   )r9  r   r   r   r   rY   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                   @   r.   )z-TestCopy.test_getstate_exc.<locals>.EvilStatec                 S   s   t d)Nzain't got no stickin' state)
ValueErrorr   r   r   r   r     r   z:TestCopy.test_getstate_exc.<locals>.EvilState.__getstate__N)r'   r(   r)   r   r   r   r   r   	EvilState  r7   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 r	   r   r   r   r   r   r   r         z(TestCopy.test_copy_function.<locals>.fooc                   S   rs   r	   r   r   r   r   r   <lambda>      z-TestCopy.test_copy_function.<locals>.<lambda>)r   r   
global_foor   r   r   r   r   r   test_copy_function  
   zTestCopy.test_copy_functionc                 C   sJ   |  ttt dd }|  t|| dd }|  t|| d S )Nc                 S   r?  r	   r   r@  r   r   r   r     rA  z,TestCopy.test_deepcopy_function.<locals>.fooc                   S   rs   r	   r   r   r   r   r   rB    rC  z1TestCopy.test_deepcopy_function.<locals>.<lambda>)r   r   r   rD  rE  r   r   r   test_deepcopy_function  rG  zTestCopy.test_deepcopy_functionc                 C   sN   G dd dt }| }t|}||}| || ~||}| || d S )Nc                   @   rn   )z"TestCopy._check_weakref.<locals>.CNro   r   r   r   r   r%   
  rq   r%   )r*   weakrefrefr
   )r   Z_copyr%   r4   r   r   r   r   r   _check_weakref	  s   
zTestCopy._check_weakrefc                 C   s   |  tj d S r	   )rK  r   r   r   r   r   test_copy_weakref  r  zTestCopy.test_copy_weakrefc                 C      |  tj d S r	   )rK  r   r   r   r   r   r   test_deepcopy_weakref  r  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                   @   rn   )z(TestCopy._check_copy_weakdict.<locals>.CNro   r   r   r   r   r%     rq   r%   c                    s   g | ]}  qS r   r   .0ir$   r   r   
<listcomp>  s    z1TestCopy._check_copy_weakdict.<locals>.<listcomp>r   ry   rG   )r*   r   r   r   r   r   ZassertNotIn)
r   Z	_dicttypeabrN   r-  uvr   r   r   r$   r   _check_copy_weakdict  s    
zTestCopy._check_copy_weakdictc                 C   rM  r	   )rW  rI  WeakKeyDictionaryr   r   r   r   test_copy_weakkeydict.  r  zTestCopy.test_copy_weakkeydictc                 C   rM  r	   )rW  rI  WeakValueDictionaryr   r   r   r   test_copy_weakvaluedict1  r  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                   @   r.   )z-TestCopy.test_deepcopy_weakkeydict.<locals>.Cc                 S   r   r	   rQ  r   rQ  r   r   r   r!   6  r"   z6TestCopy.test_deepcopy_weakkeydict.<locals>.C.__init__Nr'   r(   r)   r!   r   r   r   r   r%   5  r7   r%   c                       g | ]} |qS r   r   rO  r$   r   r   rR  8      z6TestCopy.test_deepcopy_weakkeydict.<locals>.<listcomp>r   ry   rG   )r*   r   rI  rX  r   r   r3  r   r   r   rQ  )r   rS  rT  rN   r-  rU  rV  r   r$   r   test_deepcopy_weakkeydict4  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                   @   r.   )z/TestCopy.test_deepcopy_weakvaluedict.<locals>.Cc                 S   r   r	   r\  r]  r   r   r   r!   I  r"   z8TestCopy.test_deepcopy_weakvaluedict.<locals>.C.__init__Nr^  r   r   r   r   r%   H  r7   r%   c                    r_  r   r   rO  r$   r   r   rR  K  r`  z8TestCopy.test_deepcopy_weakvaluedict.<locals>.<listcomp>r   ry   c                 S   s
   | d j S r   r\  )Zpairr   r   r   rB  S  s   
 z6TestCopy.test_deepcopy_weakvaluedict.<locals>.<lambda>)r0  rG   )r*   r   rI  rZ  r   r   r3  r   r   sortedr!  r   rQ  r
   )r   rS  rT  rN   r-  rU  rV  r   r   ztr   r$   r   test_deepcopy_weakvaluedictG  s$   
 z$TestCopy.test_deepcopy_weakvaluedictc                 C   sT   G dd dt }| }|j|_t|}| |j|j | |jj| |  d S )Nc                   @   r.   )z0TestCopy.test_deepcopy_bound_method.<locals>.Fooc                 S   rs   r	   r   r   r   r   r   m`  ru   z2TestCopy.test_deepcopy_bound_method.<locals>.Foo.mN)r'   r(   r)   rf  r   r   r   r   Foo_  r7   rg  )r*   rf  rT  r   r   r   r
   __self__)r   rg  rt   gr   r   r   test_deepcopy_bound_method^  s   
z#TestCopy.test_deepcopy_bound_methodN)Or'   r(   r)   r   r   r,   rA   rZ   r_   rl   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)  r4  r6  r8  r:  r;  r>  rF  rH  rK  rL  rN  rW  rY  r[  ra  re  rj  r   r   r   r   r      s    



	


	
r   c                 C   r?  r	   r   r@  r   r   r   rD  j  rA  rD  __main__)__doc__r   r>   rI  r   operatorr   r   r   r   r   r   Zunittestr   r   r   ZTestCaser   rD  r'   mainr   r   r   r   <module>   s*           a