a
    zeg                     @   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ddlm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ne)supportc                   @   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.9/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   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 r
   foor   r   r   r   r   __init__!   s    z+TestCopy.test_copy_copy.<locals>.C.__init__c                    s
    | j S r
   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   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 r
   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 r
   r   r.   r!   r   r   pickle_C0   s    z-TestCopy.test_copy_registry.<locals>.pickle_Cr   )r'   assertRaises	TypeErrorr   copyregpickler   r1   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__9   s    
z5TestCopy.test_copy_reduce_ex.<locals>.C.__reduce_ex__c                 S   s   |  d d S Nzshouldn't call thisZfailr   r   r   r   
__reduce__<   s    z2TestCopy.test_copy_reduce_ex.<locals>.C.__reduce__Nr$   r%   r&   rA   rD   r   r?   r   r   r"   8   s   r"   r9   r'   r   r   r   r   r"   r   r   r   r?   r   test_copy_reduce_ex7   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 r8   r;   r   r?   r   r   rD   F   s    
z/TestCopy.test_copy_reduce.<locals>.C.__reduce__Nr$   r%   r&   rD   r   r?   r   r   r"   E   s   r"   r9   rF   rG   r   r?   r   test_copy_reduceD   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 NZ__reduce
startswithAttributeErrorr'   __getattribute__r   namer   r   r   rO   Q   s    
z3TestCopy.test_copy_cant.<locals>.C.__getattribute__Nr$   r%   r&   rO   r   r   r   r   r"   P   s   r"   )r'   r2   r   r   r   r"   r   r   r   r   test_copy_cantO   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|t	 g}|D ]}| 
t|| qd S )Nc                   @   s   e Zd ZdS )z*TestCopy.test_copy_atomic.<locals>.ClassicNr$   r%   r&   r   r   r   r   Classic[   s   rV   c                   @   s   e Zd ZdS )z+TestCopy.test_copy_atomic.<locals>.NewStyleNrU   r   r   r   r   NewStyle]   s   rW   c                   S   s   d S r
   r   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>.WithMetaclassNrU   r   r   r   r   WithMetaclassa   s   rY   	metaclass.r      d   Q	@TF              ?hello   helloሴs   world   
   r9   )r'   abcABCMetaNotImplemented__code__bytesrangeslicemaxpropertyr   r   )r   rV   rW   rX   rY   testsr   r   r   r   test_copy_atomicZ   s    zTestCopy.test_copy_atomicc                 C   sT   g d}t  |}| || | || g }t  |}| || | || d S )Nr9   r\      r   r   assertIsNotr   r   r   r   test_copy_listk   s    

zTestCopy.test_copy_listc                 C   sN   d}|  t|| d}|  t|| dddg f}|  t|| d S )Nro   r   r9   r\   rp   )r   r   r   r   r   r   r   test_copy_tupleu   s    zTestCopy.test_copy_tuplec                 C   sV   ddd}t  |}| || | || i }t  |}| || | || d S )Nr9   r\   r   barrq   r   r   r   r   test_copy_dict}   s    


zTestCopy.test_copy_dictc                 C   sV   h d}t  |}| || | || t }t  |}| || | || d S N>   r9   r\   rp   )r   r   rr   setr   r   r   r   test_copy_set   s    

zTestCopy.test_copy_setc                 C   s:   t h d}| t|| t  }| t|| d S ry   )	frozensetr   r   rt   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   rr   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 r
   r   r   r   r   r   r       s    z3TestCopy.test_copy_inst_vanilla.<locals>.C.__init__c                 S   s   | j |j kS r
   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   rS   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 r
   r   r   r   r   r   r       s    z0TestCopy.test_copy_inst_copy.<locals>.C.__init__c                    s
    | j S r
   r   r   r!   r   r   r#      s    z0TestCopy.test_copy_inst_copy.<locals>.C.__copy__c                 S   s   | j |j kS 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   rt   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 r
   r   r   r   r   r   r       s    z7TestCopy.test_copy_inst_getinitargs.<locals>.C.__init__c                 S   s   | j fS r
   r   r   r   r   r   __getinitargs__   s    z>TestCopy.test_copy_inst_getinitargs.<locals>.C.__getinitargs__c                 S   s   | j |j kS 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   rS   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 r
   intr+   r   r-   r   r   r   r   r   r+      s    
z5TestCopy.test_copy_inst_getnewargs.<locals>.C.__new__c                 S   s   | j fS r
   r   r   r   r   r   __getnewargs__   s    z<TestCopy.test_copy_inst_getnewargs.<locals>.C.__getnewargs__c                 S   s   | j |j kS r
   r   r   r   r   r   r      s    z4TestCopy.test_copy_inst_getnewargs.<locals>.C.__eq__Nr$   r%   r&   r+   r   r   r   r   r   r   r"      s   r"   r   r   r   assertIsInstancer   rr   r   rG   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 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 r
   r   r   r   r   r   r      s    z7TestCopy.test_copy_inst_getnewargs_ex.<locals>.C.__eq__Nr$   r%   r&   r+   r   r   r   r   r   r   r"      s   r"   r   r   r   rG   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 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 r
   r   r   r   r   r   r      s    z2TestCopy.test_copy_inst_getstate.<locals>.C.__eq__Nr$   r%   r&   r    r   r   r   r   r   r   r"      s   r"   r   r   rS   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 r
   r   r   r   r   r   r       s    z4TestCopy.test_copy_inst_setstate.<locals>.C.__init__c                 S   s   |d | _ d S r   r   r   stater   r   r   __setstate__   s    z8TestCopy.test_copy_inst_setstate.<locals>.C.__setstate__c                 S   s   | j |j kS r
   r   r   r   r   r   r      s    z2TestCopy.test_copy_inst_setstate.<locals>.C.__eq__Nr$   r%   r&   r    r   r   r   r   r   r   r"      s   r"   r   r   rS   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 r
   r   r   r   r   r   r       s    z=TestCopy.test_copy_inst_getstate_setstate.<locals>.C.__init__c                 S   s   | j S r
   r   r   r   r   r   r      s    zATestCopy.test_copy_inst_getstate_setstate.<locals>.C.__getstate__c                 S   s
   || _ d S r
   r   r   r   r   r   r      s    zATestCopy.test_copy_inst_getstate_setstate.<locals>.C.__setstate__c                 S   s   | j |j kS r
   r   r   r   r   r   r      s    z;TestCopy.test_copy_inst_getstate_setstate.<locals>.C.__eq__Nr$   r%   r&   r    r   r   r   r   r   r   r   r"      s   r"   r   g        r   rS   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
  s    
zTestCopy.test_deepcopy_basicc                 C   sZ   g }||g}t |}| || | || | |d |d  | |d |d  d S Nr   r9   )r   r   r   rr   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>.MetaNrU   r   r   r   r   Meta  s   r   c                   @   s   e Zd ZdS )z,TestCopy.test_deepcopy_issubclass.<locals>.CNrU   r   r   r   r   r"   !  s   r"   rZ   )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   s
   || _ d S r
   r   r   r   r   r   r    '  s    z3TestCopy.test_deepcopy_deepcopy.<locals>.C.__init__Nc                    s
    | j S r
   r   r   memor!   r   r   __deepcopy__)  s    z7TestCopy.test_deepcopy_deepcopy.<locals>.C.__deepcopy__)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_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 r
   r*   r,   r   r   r   r+   2  s    
z2TestCopy.test_deepcopy_registry.<locals>.C.__new__Nr/   r   r   r   r   r"   1  s   r"   c                    s    | j ffS r
   r   r0   r!   r   r   r1   6  s    z1TestCopy.test_deepcopy_registry.<locals>.pickle_Cr   )r'   r2   r3   r   r   r4   r5   r6   r   r!   r   test_deepcopy_registry0  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 r8   r;   r=   r?   r   r   rA   ?  s    
z9TestCopy.test_deepcopy_reduce_ex.<locals>.C.__reduce_ex__c                 S   s   |  d d S rB   rC   r   r   r   r   rD   B  s    z6TestCopy.test_deepcopy_reduce_ex.<locals>.C.__reduce__NrE   r   r?   r   r   r"   >  s   r"   r9   r'   r   r   r   r   rG   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 r8   r;   r   r?   r   r   rD   L  s    
z3TestCopy.test_deepcopy_reduce.<locals>.C.__reduce__NrI   r   r?   r   r   r"   K  s   r"   r9   r   rG   r   r?   r   test_deepcopy_reduceJ  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 rK   rL   rP   r   r   r   rO   W  s    
z7TestCopy.test_deepcopy_cant.<locals>.C.__getattribute__NrR   r   r   r   r   r"   V  s   r"   )r'   r2   r   r   r   rS   r   r   r   test_deepcopy_cantU  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t g}|D ]}| t|| qRd S )Nc                   @   s   e Zd ZdS )z.TestCopy.test_deepcopy_atomic.<locals>.ClassicNrU   r   r   r   r   rV   a  s   rV   c                   @   s   e Zd ZdS )z/TestCopy.test_deepcopy_atomic.<locals>.NewStyleNrU   r   r   r   r   rW   c  s   rW   c                   S   s   d S r
   r   r   r   r   r   rX   e  s    z(TestCopy.test_deepcopy_atomic.<locals>.fr   r\   r]   r^   TFr_   r`   ra   )r'   rg   rk   rl   r   r   r   )r   rV   rW   rX   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 Nr9   r\   rp   r   r   r   r   rr   r   r   r   r   test_deepcopy_listm  s
    
zTestCopy.test_deepcopy_listc                 C   sb   g }| | t|}tD ]}| t||| q| || | |d | | t	|d d S r   )
r<   r   r   comparisonsr2   RecursionErrorrr   r   r   lenr   r   r   opr   r   r   test_deepcopy_reflexive_listt  s    

z%TestCopy.test_deepcopy_reflexive_listc                 C   s   d}t |}| || d S Nr   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 r   r   r   r   r   r   test_deepcopy_tuple  s
    
zTestCopy.test_deepcopy_tuplec                 C   s   d}t |}| || d S )N)r9   r\   rp   r   r   r   r   r   !test_deepcopy_tuple_of_immutables  s    
z*TestCopy.test_deepcopy_tuple_of_immutablesc                 C   sp   g f}|d  | t|}tD ]}| t||| q"| || | |d |d  | |d d | d S Nr   )r<   r   r   r   r2   r   rr   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 )Nr9   r\   rp   rv   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||| q4| || | |d | | 	t
|d d S )Nr   r9   )r   r   order_comparisonsr2   r3   equality_comparisonsr   rr   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)r9   r\   rp      r\   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                   @   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 r
   r   r   r   r   r   r      s    z7TestCopy.test_deepcopy_inst_vanilla.<locals>.C.__init__c                 S   s   | j |j kS r
   r   r   r   r   r   r     s    z5TestCopy.test_deepcopy_inst_vanilla.<locals>.C.__eq__Nr   r   r   r   r   r"     s   r"   r   r   r   r   rr   r   rG   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 r
   r   r   r   r   r   r      s    z8TestCopy.test_deepcopy_inst_deepcopy.<locals>.C.__init__c                    s    t | j|S r
   )r   r   r   r   r!   r   r   r     s    z<TestCopy.test_deepcopy_inst_deepcopy.<locals>.C.__deepcopy__c                 S   s   | j |j kS r
   r   r   r   r   r   r     s    z6TestCopy.test_deepcopy_inst_deepcopy.<locals>.C.__eq__N)r$   r%   r&   r    r   r   r   r!   r   r   r"     s   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 r
   r   r   r   r   r   r      s    z;TestCopy.test_deepcopy_inst_getinitargs.<locals>.C.__init__c                 S   s   | j fS r
   r   r   r   r   r   r     s    zBTestCopy.test_deepcopy_inst_getinitargs.<locals>.C.__getinitargs__c                 S   s   | j |j kS r
   r   r   r   r   r   r     s    z9TestCopy.test_deepcopy_inst_getinitargs.<locals>.C.__eq__Nr   r   r   r   r   r"     s   r"   r   r   rG   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 r
   r   r   r   r   r   r+     s    
z9TestCopy.test_deepcopy_inst_getnewargs.<locals>.C.__new__c                 S   s   | j fS r
   r   r   r   r   r   r     s    z@TestCopy.test_deepcopy_inst_getnewargs.<locals>.C.__getnewargs__c                 S   s   | j |j kS r
   r   r   r   r   r   r     s    z8TestCopy.test_deepcopy_inst_getnewargs.<locals>.C.__eq__Nr   r   r   r   r   r"     s   r"   r   r   r   r   r   r   rr   r   rG   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 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 r   r   r   r   r   r   r      s    zFTestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.C.__getnewargs_ex__c                 S   s   | j |j kS r
   r   r   r   r   r   r     s    z;TestCopy.test_deepcopy_inst_getnewargs_ex.<locals>.C.__eq__Nr   r   r   r   r   r"     s   r"   r   r   r   rG   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 r
   r   r   r   r   r   r      s    z8TestCopy.test_deepcopy_inst_getstate.<locals>.C.__init__c                 S   s
   d| j iS r   r   r   r   r   r   r     s    z<TestCopy.test_deepcopy_inst_getstate.<locals>.C.__getstate__c                 S   s   | j |j kS r
   r   r   r   r   r   r     s    z6TestCopy.test_deepcopy_inst_getstate.<locals>.C.__eq__Nr   r   r   r   r   r"     s   r"   r   r   rG   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 r
   r   r   r   r   r   r      s    z8TestCopy.test_deepcopy_inst_setstate.<locals>.C.__init__c                 S   s   |d | _ d S r   r   r   r   r   r   r     s    z<TestCopy.test_deepcopy_inst_setstate.<locals>.C.__setstate__c                 S   s   | j |j kS r
   r   r   r   r   r   r      s    z6TestCopy.test_deepcopy_inst_setstate.<locals>.C.__eq__Nr   r   r   r   r   r"     s   r"   r   r   rG   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 r
   r   r   r   r   r   r    *  s    zATestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__init__c                 S   s   | j S r
   r   r   r   r   r   r   ,  s    zETestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__getstate__c                 S   s
   || _ d S r
   r   r   r   r   r   r   .  s    zETestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__setstate__c                 S   s   | j |j kS r
   r   r   r   r   r   r   0  s    z?TestCopy.test_deepcopy_inst_getstate_setstate.<locals>.C.__eq__Nr   r   r   r   r   r"   )  s   r"   r   r   rG   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>.CNrU   r   r   r   r   r"   ?  s   r"   )r   r   r   rr   r   rG   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>.INrU   r   r   r   r   IH  s   r   rc   )r   ri   r   r   rr   r   stopr   )r   r   r   r   r   r   r   test_deepcopy_rangeG  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   rD   V  s    z6TestCopy.test_reconstruct_string.<locals>.C.__reduce__NrI   r   r   r   r   r"   U  s   r"   )r'   r   r   r   rG   r   r   r   test_reconstruct_stringT  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 r   r   r   r!   r   r   rD   `  s    z7TestCopy.test_reconstruct_nostate.<locals>.C.__reduce__NrI   r   r!   r   r   r"   _  s   r"   r   )r'   r   r   r   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 r   __dict__r   r!   r   r   rD   k  s    z5TestCopy.test_reconstruct_state.<locals>.C.__reduce__c                 S   s   | j |j kS r
   r   r   r   r   r   r   m  s    z1TestCopy.test_reconstruct_state.<locals>.C.__eq__Nr$   r%   r&   rD   r   r   r!   r   r   r"   j  s   r"   r   r'   r   r   r   r   rr   r   r   r!   r   test_reconstruct_statei  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 r   r   r   r!   r   r   rD   y  s    z>TestCopy.test_reconstruct_state_setstate.<locals>.C.__reduce__c                 S   s   | j | d S r
   )r   updater   r   r   r   r   {  s    z@TestCopy.test_reconstruct_state_setstate.<locals>.C.__setstate__c                 S   s   | j |j kS r
   r   r   r   r   r   r   }  s    z:TestCopy.test_reconstruct_state_setstate.<locals>.C.__eq__N)r$   r%   r&   rD   r   r   r   r!   r   r   r"   x  s   r"   r   r   r   r   r!   r   test_reconstruct_state_setstatew  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>.CNrU   r   r   r   r   r"     s   r"   )r'   r   r   r   rr   r   rG   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 r   )r   iterr   r!   r   r   rD     s    z1TestCopy.test_reduce_4tuple.<locals>.C.__reduce__c                 S   s   t | t |ko| j|jkS r
   )listr   r   r   r   r   r     s    
z-TestCopy.test_reduce_4tuple.<locals>.C.__eq__Nr   r   r!   r   r   r"     s   r"   r9   r\   rp   r   )r   r   r   rr   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 r   )r   itemsr   r!   r   r   rD     s    z1TestCopy.test_reduce_5tuple.<locals>.C.__reduce__c                 S   s   t | t |ko| j|jkS r
   )dictr   r   r   r   r   r     s    
z-TestCopy.test_reduce_5tuple.<locals>.C.__eq__Nr   r   r!   r   r   r"     s   r"   r   r9   r\   )rw   rp   )r   r   r   rr   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   rG   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   Nr   r   r   r   r   r"     s   r"   r   )r'   r   r   r   r   rr   rG   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 r
   )r   __setitem__r   r<   )r   keyitemr   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   r9   rw   )r   r   r   r   r   rr   assertNotEqualrG   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>.CNrU   r   r   r   r   r"     s   r"   r9   r\   rp   r      r   )r   r   r   r   r   rG   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>.CNrU   r   r   r   r   r"     s   r"   r9   r\   rp   r   r   r   )r   r   r   r   r   rr   rG   r   r   r   test_deepcopy_list_subclass  s    

z$TestCopy.test_deepcopy_list_subclassc                 C   sJ   G dd dt }|g d}| t |d t|}| t |d d S )Nc                   @   s   e Zd ZdS )z,TestCopy.test_copy_tuple_subclass.<locals>.CNrU   r   r   r   r   r"     s   r"   ro   )tupler   r   rG   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>.CNrU   r   r   r   r   r"     s   r"   r9   r\   rp   r   )r   r   r   r   rr   rG   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)
ValueErrorr   r   r   r   r     s    z:TestCopy.test_getstate_exc.<locals>.EvilState.__getstate__N)r$   r%   r&   r   r   r   r   r   	EvilState  s   r   )r'   r2   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 r
   r   r   r   r   r   r   r   	      z(TestCopy.test_copy_function.<locals>.fooc                   S   s   d S r
   r   r   r   r   r   <lambda>  r  z-TestCopy.test_copy_function.<locals>.<lambda>)r   r   
global_foor   r   rw   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 r
   r   r  r   r   r   r     r  z,TestCopy.test_deepcopy_function.<locals>.fooc                   S   s   d S r
   r   r   r   r   r   r    r  z1TestCopy.test_deepcopy_function.<locals>.<lambda>)r   r   r   r  r  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>.CNrU   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 r
   )r  r   r   r   r   r   test_copy_weakref   s    zTestCopy.test_copy_weakrefc                 C   s   |  tj d S r
   )r  r   r   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  | t|d      }}	|	||< | || d S )Nc                   @   s   e Zd ZdS )z(TestCopy._check_copy_weakdict.<locals>.CNrU   r   r   r   r   r"   '  s   r"   c                    s   g | ]
}  qS r   r   .0ir!   r   r   
<listcomp>)  r  z1TestCopy._check_copy_weakdict.<locals>.<listcomp>r   r\   r9   )	r'   ri   r   rr   r   r   r   
gc_collectZ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 r
   )r  r	  WeakKeyDictionaryr   r   r   r   test_copy_weakkeydict;  s    zTestCopy.test_copy_weakkeydictc                 C   s   |  tj d S r
   )r  r	  WeakValueDictionaryr   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  | 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 r
   r  r   r  r   r   r   r    C  s    z6TestCopy.test_deepcopy_weakkeydict.<locals>.C.__init__Nr$   r%   r&   r    r   r   r   r   r"   B  s   r"   c                    s   g | ]} |qS r   r   r  r!   r   r   r  E  r  z6TestCopy.test_deepcopy_weakkeydict.<locals>.<listcomp>r   r\   r9   )r'   ri   r	  r  r   r   r   r   r   rr   r  r   r  )r   r  r  r@   r   r  r  r   r!   r   test_deepcopy_weakkeydictA  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  | 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 r
   r  r  r   r   r   r    W  s    z8TestCopy.test_deepcopy_weakvaluedict.<locals>.C.__init__Nr  r   r   r   r   r"   V  s   r"   c                    s   g | ]} |qS r   r   r  r!   r   r   r  Y  r  z8TestCopy.test_deepcopy_weakvaluedict.<locals>.<listcomp>r   r\   c                 S   s
   | d j S r   r  )Zpairr   r   r   r  a  r  z6TestCopy.test_deepcopy_weakvaluedict.<locals>.<lambda>)r   r9   )r'   ri   r	  r  r   r   r   r   r   sortedr   rr   r  r   r   r  )r   r  r  r@   r   r  r  r   r   ztr   r!   r   test_deepcopy_weakvaluedictU  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 r
   r   r   r   r   r   mo  s    z2TestCopy.test_deepcopy_bound_method.<locals>.Foo.mN)r$   r%   r&   r$  r   r   r   r   Foon  s   r%  )r'   r$  r  r   r   r   r   __self__)r   r%  rX   gr   r   r   test_deepcopy_bound_methodm  s    
z#TestCopy.test_deepcopy_bound_methodN)Pr$   r%   r&   r   r   r)   r7   rH   rJ   rT   rn   rs   ru   rx   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   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 r
   r   r  r   r   r   r  y  r  r  __main__)__doc__r   r4   r	  rd   operatorr   r   r   r   r   r   Zunittesttestr   r   r   r   ZTestCaser	   r  r$   mainr   r   r   r   <module>   s(          o