B
    u9a	                 @   s   d dl Z d dlZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 G dd dejZG dd dejZd dl	mZ G dd	 d	ejZG d
d deZG dd dejZedkre  dS )    N)supportc               @   sj  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-e.j/dWdX Z0e.j/dYdZ Z1e.j/d[d\ Z2d]d^ Z3e.j/d_d` Z4e.j/dadb Z5e.j/dcdd Z6e.j/dedf Z7e.j/dgdh Z8e.j/didj Z9dkdl Z:dmdn Z;dodp Z<dqdr Z=dsdt Z>dudv Z?dwdx Z@dydz ZAd{d| ZBd}d~ ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdS )DictTestc          
   C   st   G dd dt }x^ddi|ddifD ]F}| t t f | W d Q R X | t i jf | W d Q R X q&W d S )Nc               @   s   e Zd ZdS )z7DictTest.test_invalid_keyword_arguments.<locals>.CustomN)__name__
__module____qualname__ r   r   /usr/lib/python3.7/test_dict.pyCustom   s   r	         )dictassertRaises	TypeErrorupdate)selfr	   Zinvalidr   r   r   test_invalid_keyword_arguments   s    z'DictTest.test_invalid_keyword_argumentsc             C   s    |  t i  | t i  d S )N)assertEqualr   assertIsNot)r   r   r   r   test_constructor   s    zDictTest.test_constructorc             C   sb   x\dD ]T}dd t |D }t| dd |D }dd| d }| t|t| qW d S )	N)r   r
         i  c             S   s$   g | ]}d  ttjd|fqS )    )joinrandomZsamplestringZascii_letters).0ir   r   r   
<listcomp>!   s   z5DictTest.test_literal_constructor.<locals>.<listcomp>c             s   s   | ]\}}d  ||V  qdS )z
{!r}: {:d}N)format)r   kvr   r   r   	<genexpr>$   s    z4DictTest.test_literal_constructor.<locals>.<genexpr>{z, })ranger   Zshuffler   r   evalr   )r   nitemsZformatted_itemsZdictliteralr   r   r   test_literal_constructor   s    

z!DictTest.test_literal_constructorc             C   sD   |  i  d | ddi |  ti d |  tddid d S )NTr
   r   F)assertIs
assertTruebool)r   r   r   r   	test_bool(   s    zDictTest.test_boolc             C   s   i }|  t| t  ddd}| }|  t|ddh | d| | d| | d| | d| | t|jd  |  ttdd d d S )Nr
   r   )abr.   r/   )r.   zdict_keys(['a']))r   setkeysassertInr   r   reprr   )r   dr    r   r   r   	test_keys.   s    
zDictTest.test_keysc             C   sf   i }|  t| t  ddi}|  t| dh | t|jd  |  ttdd d d S )Nr
   r   )r.   zdict_values([1]))r   r0   valuesr   r   r3   r   )r   r4   r   r   r   test_values;   s    zDictTest.test_valuesc             C   sf   i }|  t| t  ddi}|  t| dh | t|jd  |  ttdd d d S )Nr
   r   )r
   r   )r.   zdict_items([('a', 1)]))r   r0   r(   r   r   r3   r   )r   r4   r   r   r   
test_itemsC   s    zDictTest.test_itemsc             C   sl   i }|  d| | d|k | d|k ddd}| d| | d| |  d| | t|j d S )Nr.   r
   r   )r.   r/   r/   c)assertNotInassertFalser+   r2   r   r   __contains__)r   r4   r   r   r   test_containsL   s    
zDictTest.test_containsc             C   s2   i }|  t|d ddd}|  t|d d S )Nr   r
   r   )r.   r/   )r   len)r   r4   r   r   r   test_lenX   s    
zDictTest.test_lenc                s   ddd}|  |d d |  |d d d|d< d|d< |  |d d |  |d d |d= |  |ddd	 | t|j G  fd
ddt}i }d|| < | t|jd G dd dt G  fdddt}| }d||< d|_|  |j| d S )Nr
   r   )r.   r/   r.   r/      r9      )r.   r9   c                   s    e Zd Z fddZdd ZdS )z$DictTest.test_getitem.<locals>.BadEqc                s
     d S )Nr   )r   other)Excr   r   __eq__l   s    z+DictTest.test_getitem.<locals>.BadEq.__eq__c             S   s   dS )N   r   )r   r   r   r   __hash__n   s    z-DictTest.test_getitem.<locals>.BadEq.__hash__N)r   r   r   rD   rF   r   )rC   r   r   BadEqk   s   rG   *      c               @   s   e Zd ZdS )z"DictTest.test_getitem.<locals>.ExcN)r   r   r   r   r   r   r   rC   u   s    rC   c                   s   e Zd ZdZ fddZdS )z&DictTest.test_getitem.<locals>.BadHashFc                s   | j r  ndS d S )NrH   )fail)r   )rC   r   r   rF   y   s    z/DictTest.test_getitem.<locals>.BadHash.__hash__N)r   r   r   rJ   rF   r   )rC   r   r   BadHashw   s   rK   T)r   r   r   __getitem__objectKeyError	ExceptionrJ   )r   r4   rG   rK   xr   )rC   r   test_getitem^   s(    

zDictTest.test_getitemc             C   s4   dddd}|   | |i  | t|j d  d S )Nr
   r   r@   )r
   r   r@   )clearr   r   r   )r   r4   r   r   r   
test_clear   s    zDictTest.test_clearc                sl  i }| ddi | ddi | dddd | |dddd |   | |dddd | ttf|j d  G dd d}|  | |  | |dddd G d	d
 d
t |  G  fddd}|  |j |  G  fddd}|  |j |  G  fddd}|  |j |  G  fdddt}|  i j |  | ti j dg d S )Nr
   d   r      r@   )r
   r   r@   c               @   s$   e Zd Zdd Zdd Zdd ZdS )z,DictTest.test_update.<locals>.SimpleUserDictc             S   s   dddd| _ d S )Nr
   r   r@   )r
   r   r@   )r4   )r   r   r   r   __init__   s    z5DictTest.test_update.<locals>.SimpleUserDict.__init__c             S   s
   | j  S )N)r4   r1   )r   r   r   r   r1      s    z1DictTest.test_update.<locals>.SimpleUserDict.keysc             S   s
   | j | S )N)r4   )r   r   r   r   r   rL      s    z8DictTest.test_update.<locals>.SimpleUserDict.__getitem__N)r   r   r   rV   r1   rL   r   r   r   r   SimpleUserDict   s   rW   c               @   s   e Zd ZdS )z!DictTest.test_update.<locals>.ExcN)r   r   r   r   r   r   r   rC      s    rC   c                   s   e Zd Z fddZdS )z-DictTest.test_update.<locals>.FailingUserDictc                s    d S )Nr   )r   )rC   r   r   r1      s    z2DictTest.test_update.<locals>.FailingUserDict.keysN)r   r   r   r1   r   )rC   r   r   FailingUserDict   s   rX   c                   s    e Zd Z fddZdd ZdS )z-DictTest.test_update.<locals>.FailingUserDictc                s   G  fddd}| S )Nc                   s(   e Zd Zdd Zdd Z fddZdS )zEDictTest.test_update.<locals>.FailingUserDict.keys.<locals>.BogonIterc             S   s
   d| _ d S )Nr
   )r   )r   r   r   r   rV      s    zNDictTest.test_update.<locals>.FailingUserDict.keys.<locals>.BogonIter.__init__c             S   s   | S )Nr   )r   r   r   r   __iter__   s    zNDictTest.test_update.<locals>.FailingUserDict.keys.<locals>.BogonIter.__iter__c                s   | j rd| _ dS  d S )Nr   r.   )r   )r   )rC   r   r   __next__   s    zNDictTest.test_update.<locals>.FailingUserDict.keys.<locals>.BogonIter.__next__N)r   r   r   rV   rY   rZ   r   )rC   r   r   	BogonIter   s   r[   r   )r   r[   )rC   r   r   r1      s    
z2DictTest.test_update.<locals>.FailingUserDict.keysc             S   s   |S )Nr   )r   keyr   r   r   rL      s    z9DictTest.test_update.<locals>.FailingUserDict.__getitem__N)r   r   r   r1   rL   r   )rC   r   r   rX      s   c                   s    e Zd Zdd Z fddZdS )z-DictTest.test_update.<locals>.FailingUserDictc             S   s   G dd d}| S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )zEDictTest.test_update.<locals>.FailingUserDict.keys.<locals>.BogonIterc             S   s   t d| _d S )Nr.   )ordr   )r   r   r   r   rV      s    zNDictTest.test_update.<locals>.FailingUserDict.keys.<locals>.BogonIter.__init__c             S   s   | S )Nr   )r   r   r   r   rY      s    zNDictTest.test_update.<locals>.FailingUserDict.keys.<locals>.BogonIter.__iter__c             S   s2   | j tdkr*t| j }|  j d7  _ |S td S )Nzr
   )r   r]   chrStopIteration)r   Zrtnr   r   r   rZ      s
    
zNDictTest.test_update.<locals>.FailingUserDict.keys.<locals>.BogonIter.__next__N)r   r   r   rV   rY   rZ   r   r   r   r   r[      s   r[   r   )r   r[   r   r   r   r1      s    z2DictTest.test_update.<locals>.FailingUserDict.keysc                s    d S )Nr   )r   r\   )rC   r   r   rL      s    z9DictTest.test_update.<locals>.FailingUserDict.__getitem__N)r   r   r   r1   rL   r   )rC   r   r   rX      s   c                   s    e Zd Zdd Z fddZdS )z$DictTest.test_update.<locals>.badseqc             S   s   | S )Nr   )r   r   r   r   rY      s    z-DictTest.test_update.<locals>.badseq.__iter__c                s
     d S )Nr   )r   )rC   r   r   rZ      s    z-DictTest.test_update.<locals>.badseq.__next__N)r   r   r   rY   rZ   r   )rC   r   r   badseq   s   ra   )	r   r   r   r   AttributeErrorrR   rO   rM   
ValueError)r   r4   rW   rX   ra   r   )rC   r   test_update   s.    zDictTest.test_updatec       
         sl  |  tdd d d d i | d |  dd d d d |  ddddd |  g i  dd }|  | dd i | ti jd G d	d
 d
t}|  |ddd i |  | ddd i | |d| | | d| G dd dt}|d}|  |d d d | |tj | ttj G dd dt	 G  fdddt}|  |jdg G  fdddt
}|  tj|  G  fdddt}|  |jdg tttdtd|  tdtttddgd  G fdddt}dd tdD  }	|	jd d d d |  |dddh|	 d S ) Nabc)r.   r/   r9   )rA      r   c               s   s
   dV  d S )Nr
   r   r   r   r   r   g   s    z!DictTest.test_fromkeys.<locals>.gr
   r@   c               @   s   e Zd ZdS )z(DictTest.test_fromkeys.<locals>.dictlikeN)r   r   r   r   r   r   r   dictlike   s    rh   r.   c               @   s   e Zd Zdd ZdS )z&DictTest.test_fromkeys.<locals>.mydictc             S   s   t  S )N)collectionsUserDict)clsr   r   r   __new__   s    z.DictTest.test_fromkeys.<locals>.mydict.__new__N)r   r   r   rl   r   r   r   r   mydict   s   rm   Zab)r.   r/   c               @   s   e Zd ZdS )z#DictTest.test_fromkeys.<locals>.ExcN)r   r   r   r   r   r   r   rC      s    rC   c                   s   e Zd Z fddZdS )z(DictTest.test_fromkeys.<locals>.baddict1c                s
     d S )Nr   )r   )rC   r   r   rV      s    z1DictTest.test_fromkeys.<locals>.baddict1.__init__N)r   r   r   rV   r   )rC   r   r   baddict1   s   rn   c                   s    e Zd Zdd Z fddZdS )z&DictTest.test_fromkeys.<locals>.BadSeqc             S   s   | S )Nr   )r   r   r   r   rY      s    z/DictTest.test_fromkeys.<locals>.BadSeq.__iter__c                s
     d S )Nr   )r   )rC   r   r   rZ      s    z/DictTest.test_fromkeys.<locals>.BadSeq.__next__N)r   r   r   rY   rZ   r   )rC   r   r   BadSeq   s   ro   c                   s   e Zd Z fddZdS )z(DictTest.test_fromkeys.<locals>.baddict2c                s
     d S )Nr   )r   r\   value)rC   r   r   __setitem__   s    z4DictTest.test_fromkeys.<locals>.baddict2.__setitem__N)r   r   r   rq   r   )rC   r   r   baddict2   s   rr   r   c                   s   e Zd Z fddZdS )z(DictTest.test_fromkeys.<locals>.baddict3c                s    S )Nr   )rk   )r4   r   r   rl   
  s    z0DictTest.test_fromkeys.<locals>.baddict3.__new__N)r   r   r   rl   r   )r4   r   r   baddict3	  s   rs   c             S   s   i | ]
}||qS r   r   )r   r   r   r   r   
<dictcomp>  s    z*DictTest.test_fromkeys.<locals>.<dictcomp>
   r/   r9   )r   r   fromkeysr   r   r   assertIsInstanceri   rj   rO   rM   zipr%   copyr   )
r   rg   rh   rm   Zudrn   ro   rr   rs   Zresr   )rC   r4   r   test_fromkeys   sB    
(zDictTest.test_fromkeysc             C   s   dddd}|  | | | | | | | dddd | }d|d< | || | i  i  | t|jd  d S )Nr
   r   r@   )r
   r   r@   rA   )r   ry   r   assertNotEqualr   r   )r   r4   ry   r   r   r   	test_copy  s    zDictTest.test_copyc          
   C   s   xdD ]}t |d ||d  }| j|dp i }xt|D ]}|||< q>W | }| || | || d|d< | || | t|t|d  W d Q R X qW d S )N)ru   rT   i  i'  i r   )	dict_sizerp   r\   r
   )	r   Z	randrangeZsubTestr%   ry   r   r   r{   r>   )r   r}   r4   r   d2r   r   r   test_copy_fuzz  s    
zDictTest.test_copy_fuzzc             C   sT   G dd d}| }x:i ddi|difD ]$}|  }| t|t| q(W d S )Nc               @   s   e Zd ZdS )z0DictTest.test_copy_maintains_tracking.<locals>.AN)r   r   r   r   r   r   r   A/  s   r   r.   r
   val)ry   r   gc
is_tracked)r   r   r\   r4   r~   r   r   r   test_copy_maintains_tracking.  s
    z%DictTest.test_copy_maintains_trackingc             C   sB   dd t dD }xt dD ]
}||= qW | }| || d S )Nc             S   s   i | ]
}||qS r   r   )r   r    r   r   r   rt   ?  s    z1DictTest.test_copy_noncompact.<locals>.<dictcomp>i  i  )r%   ry   r   )r   r4   r    r~   r   r   r   test_copy_noncompact8  s
    
zDictTest.test_copy_noncompactc             C   s   i }|  |dd  | |ddd ddd}|  |dd  | |ddd | |dd | |ddd | t|j | t|jd d d  d S )Nr9   r@   r
   r   )r.   r/   r.   )r*   getr   r   r   )r   r4   r   r   r   test_getE  s    
zDictTest.test_getc                s   i }|  |dd  |dg  |  |dd  |dg d | |d d d |dg d | t|d d | t|j G dd dt G  fd	d
d
t}| }d||< d|_	|  |j|g  d S )NZkey0r\   r@   r   rA   r   c               @   s   e Zd ZdS )z%DictTest.test_setdefault.<locals>.ExcN)r   r   r   r   r   r   r   rC   ]  s    rC   c                   s   e Zd ZdZ fddZdS )z)DictTest.test_setdefault.<locals>.BadHashFc                s   | j r  ndS d S )NrH   )rJ   )r   )rC   r   r   rF   a  s    z2DictTest.test_setdefault.<locals>.BadHash.__hash__N)r   r   r   rJ   rF   r   )rC   r   r   rK   _  s   rK   rH   T)
r*   
setdefaultappendr   r>   r   r   rO   rM   rJ   )r   r4   rK   rP   r   )rC   r   test_setdefaultQ  s    zDictTest.test_setdefaultc             C   sd   G dd dt }| }|di}| }||g  | |jd | |jd | |j|j d d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z/DictTest.test_setdefault_atomic.<locals>.Hashedc             S   s   d| _ d| _d S )Nr   )
hash_counteq_count)r   r   r   r   rV   o  s    z8DictTest.test_setdefault_atomic.<locals>.Hashed.__init__c             S   s   |  j d7  _ dS )Nr
   rH   )r   )r   r   r   r   rF   r  s    z8DictTest.test_setdefault_atomic.<locals>.Hashed.__hash__c             S   s   |  j d7  _ t| t|kS )Nr
   )r   id)r   rB   r   r   r   rD   u  s    z6DictTest.test_setdefault_atomic.<locals>.Hashed.__eq__N)r   r   r   rV   rF   rD   r   r   r   r   Hashedn  s   r   rf   r
   )rM   r   r   r   r   )r   r   hashed1yhashed2r   r   r   test_setdefault_atomicl  s    
zDictTest.test_setdefault_atomicc          
   C   sp   G dd dt }| }|dddddddddi}| }g ||< | |jd | |jd | |j|j d d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z6DictTest.test_setitem_atomic_at_resize.<locals>.Hashedc             S   s   d| _ d| _d S )Nr   )r   r   )r   r   r   r   rV     s    z?DictTest.test_setitem_atomic_at_resize.<locals>.Hashed.__init__c             S   s   |  j d7  _ dS )Nr
   rH   )r   )r   r   r   r   rF     s    z?DictTest.test_setitem_atomic_at_resize.<locals>.Hashed.__hash__c             S   s   |  j d7  _ t| t|kS )Nr
   )r   r   )r   rB   r   r   r   rD     s    z=DictTest.test_setitem_atomic_at_resize.<locals>.Hashed.__eq__N)r   r   r   rV   rF   rD   r   r   r   r   r     s   r   rf   r   r
   r   r@   )rM   r   r   r   )r   r   r   r   r   r   r   r   test_setitem_atomic_at_resize  s    
z&DictTest.test_setitem_atomic_at_resizec             C   s  xdD ]}xt dD ]}d| }i }i }x0t |D ]$}||t|< |dk r2||t|< q2W |dkrj| }xft |D ]Z}|  \}}}	| |t| |  \}
}}| |t|
 | |dk o|	|k qtW | | | | qW qW i }| t|j d S )N)r
      r   r   )	r%   r3   ry   popitemr   intr;   r   rN   )r   ZcopymodeZlog2sizesizer.   r/   r   kaZvataZkbZvbtbr4   r   r   r   test_popitem  s*    

zDictTest.test_popitemc                s   i }d\}}|||< |  t|jd | ||| | t|d |  t|j| | |||| |||< | ||d| |  t|j G dd dt G  fdddt}| }d	||< d
|_|   |j| d S )N)re   defZghir   r
   c               @   s   e Zd ZdS )zDictTest.test_pop.<locals>.ExcN)r   r   r   r   r   r   r   rC     s    rC   c                   s   e Zd ZdZ fddZdS )z"DictTest.test_pop.<locals>.BadHashFc                s   | j r  ndS d S )NrH   )rJ   )r   )rC   r   r   rF     s    z+DictTest.test_pop.<locals>.BadHash.__hash__N)r   r   r   rJ   rF   r   )rC   r   r   rK     s   rK   rH   T)	r   rN   popr   r>   r   rO   rM   rJ   )r   r4   r    r!   rK   rP   r   )rC   r   test_pop  s"    zDictTest.test_popc          	   C   s@   i }d|d< |  t  x|D ]}d||d < qW W d Q R X d S )Nr
   )r   RuntimeError)r   r4   r   r   r   r   test_mutating_iteration  s
    
z DictTest.test_mutating_iterationc                sP   G  fddd  d} d}|di}||f _ d||< | ||di d S )Nc                   s,   e Zd ZdZdd Zdd Z fddZdS )z/DictTest.test_mutating_lookup.<locals>.NastyKeyNc             S   s
   || _ d S )N)rp   )r   rp   r   r   r   rV     s    z8DictTest.test_mutating_lookup.<locals>.NastyKey.__init__c             S   s   dS )Nr
   r   )r   r   r   r   rF     s    z8DictTest.test_mutating_lookup.<locals>.NastyKey.__hash__c                s(    j r j \}}d  _ ||= | j|jkS )N)mutate_dictrp   )r   rB   rm   r\   )NastyKeyr   r   rD     s
    
z6DictTest.test_mutating_lookup.<locals>.NastyKey.__eq__)r   r   r   r   rV   rF   rD   r   )r   r   r   r     s   r   r
   r   )r   r   )r   Zkey1Zkey2r4   r   )r   r   test_mutating_lookup  s    
zDictTest.test_mutating_lookupc                s   i }|  t|d d|d< |  t|d i }||d< |  t|d G dd dt G  fdd	d	t}d| i}|  t| d S )
Nz{}r   r
   z{1: 2}z
{1: {...}}c               @   s   e Zd ZdS )zDictTest.test_repr.<locals>.ExcN)r   r   r   r   r   r   r   rC     s    rC   c                   s   e Zd Z fddZdS )z#DictTest.test_repr.<locals>.BadReprc                s
     d S )Nr   )r   )rC   r   r   __repr__  s    z,DictTest.test_repr.<locals>.BadRepr.__repr__N)r   r   r   r   r   )rC   r   r   BadRepr  s   r   )r   r3   rO   rM   r   )r   r4   r   r   )rC   r   	test_repr  s    
zDictTest.test_reprc             C   s8   i }x t t d D ]}d|i}qW | tt| d S )NrT   r
   )r%   sysgetrecursionlimitr   RecursionErrorr3   )r   r4   r   r   r   r   test_repr_deep  s    zDictTest.test_repr_deepc          	      sx   |  i i  |  ddiddi G dd dt G  fdddt}| di}ddi}|   ||k W d Q R X d S )Nr
   r   c               @   s   e Zd ZdS )zDictTest.test_eq.<locals>.ExcN)r   r   r   r   r   r   r   rC     s    rC   c                   s    e Zd Z fddZdd ZdS )z DictTest.test_eq.<locals>.BadCmpc                s
     d S )Nr   )r   rB   )rC   r   r   rD     s    z'DictTest.test_eq.<locals>.BadCmp.__eq__c             S   s   dS )Nr
   r   )r   r   r   r   rF     s    z)DictTest.test_eq.<locals>.BadCmp.__hash__N)r   r   r   rD   rF   r   )rC   r   r   BadCmp  s   r   )r   rO   rM   r   )r   r   d1r~   r   )rC   r   test_eq  s    
zDictTest.test_eqc             C   s    |  dd  |  dd  d S )Nc             S   s   |   S )N)r1   )rP   r   r   r   <lambda>      z.DictTest.test_keys_contained.<locals>.<lambda>c             S   s   |   S )N)r(   )rP   r   r   r   r     r   )helper_keys_contained)r   r   r   r   test_keys_contained  s    zDictTest.test_keys_containedc             C   s  |t  }|t  }|ddd}|dddd}|dddd}|dddd}| ||k  | ||k | ||k | ||k | ||k | ||k | ||k | ||k  | ||k  | ||k | ||k | ||k | ||k | ||k | ||k | ||k  | ||k | ||k | ||k | ||k | ||k | ||k | ||k | ||k d S )Nr
   r   )r
   r   r@   )r
   r   r@   )rA   r   r@   )r   r+   r;   )r   fnemptyZempty2ZsmallerZlargerZlarger2Zlarger3r   r   r   r   !  s<    

zDictTest.helper_keys_containedc          	   C   s  G dd d}d| i}d| i}|  t | | k W d Q R X |  t | | k W d Q R X |  t | | k W d Q R X |  t | | k W d Q R X | | d}|  t | | k  W d Q R X |  t | | k W d Q R X d S )Nc               @   s   e Zd Zdd ZdS )z9DictTest.test_errors_in_view_containment_check.<locals>.Cc             S   s   t d S )N)r   )r   rB   r   r   r   rD   O  s    z@DictTest.test_errors_in_view_containment_check.<locals>.C.__eq__N)r   r   r   rD   r   r   r   r   CN  s   r   r
   )r
   r   )r   r   r(   )r   r   r   r~   Zd3r   r   r   %test_errors_in_view_containment_checkM  s     

z.DictTest.test_errors_in_view_containment_checkc             C   s   ddd  }dddd  }ddi  }| || t  | || ddh | || dh | || dh | ||@ ddh | ||@ t  | ||B dddh | ||A dh | ||A dddh d S )Nr
   r   )r
   r   r@   )r
   r   r@   rA   )r1   r   r0   )r   k1k2k3r   r   r   $test_dictview_set_operations_on_keysc  s    z-DictTest.test_dictview_set_operations_on_keysc             C   s   ddd  }dddd  }ddi  }| || t  | || ddh | || d	h | || d
h | ||@ ddh | ||@ t  | ||B ddd	h | ||A d	h | ||A ddd
h d S )Nr
   r   )r
   r   r@   )r
   r   r@   rA   )r
   r
   )r   r   )r@   r@   )rA   rA   )r(   r   r0   )r   r   r   r   r   r   r   %test_dictview_set_operations_on_itemsr  s    z.DictTest.test_dictview_set_operations_on_itemsc             C   s   |  ddi dhk |  dhddi k | ddi dhB ddh | dhddi B ddh |  ddi dhk |  dhddi k | ddi dhB ddh | dhddi B ddh d S )Nr
   r   )r
   r
   )r+   r1   r   r(   )r   r   r   r   "test_dictview_mixed_set_operations  s    z+DictTest.test_dictview_mixed_set_operationsc       
   	   C   sZ  |  ttd |  ti d G dd dt}|ddd}| |d d | |d d | d| | d|  | |d d	 G d
d dt}| }| t}|d	  W d Q R X | |jj	d G dd dt}| }| t
}|d	  W d Q R X | |jj	d G dd dt}| }	| t
}|	d	  W d Q R X | |jj	d d S )N__missing__c               @   s   e Zd Zdd ZdS )z DictTest.test_missing.<locals>.Dc             S   s   dS )NrH   r   )r   r\   r   r   r   r     s    z,DictTest.test_missing.<locals>.D.__missing__N)r   r   r   r   r   r   r   r   D  s   r   r   rA   )r
   r@   r
   r@   rH   c               @   s   e Zd Zdd ZdS )z DictTest.test_missing.<locals>.Ec             S   s   t |d S )N)r   )r   r\   r   r   r   r     s    z,DictTest.test_missing.<locals>.E.__missing__N)r   r   r   r   r   r   r   r   E  s   r   )rH   c               @   s   e Zd Zdd ZdS )z DictTest.test_missing.<locals>.Fc             S   s   dd | _ d S )Nc             S   s   d S )Nr   )r\   r   r   r   r     r   z;DictTest.test_missing.<locals>.F.__init__.<locals>.<lambda>)r   )r   r   r   r   rV     s    z)DictTest.test_missing.<locals>.F.__init__N)r   r   r   rV   r   r   r   r   F  s   r   c               @   s   e Zd ZdS )z DictTest.test_missing.<locals>.GN)r   r   r   r   r   r   r   G  s   r   )r;   hasattrr   r   r:   r1   r   r   	exceptionargsrN   )
r   r   r4   r   er9   r   fr   rg   r   r   r   test_missing  s0    zDictTest.test_missingc          	   C   s6   i }|  t}|d  W d Q R X | |jjd d S )N)r
   ))r
   )r   rN   r   r   r   )r   r4   r9   r   r   r   test_tuple_keyerror  s    zDictTest.test_tuple_keyerrorc          
      sn   G dd dt  G  fddd}i }| }| }d||< x.dD ]&}|   t|t  W d Q R X q@W d S )Nc               @   s   e Zd ZdS )z.DictTest.test_bad_key.<locals>.CustomExceptionN)r   r   r   r   r   r   r   CustomException  s   r   c                   s    e Zd Zdd Z fddZdS )z)DictTest.test_bad_key.<locals>.BadDictKeyc             S   s
   t | jS )N)hash	__class__)r   r   r   r   rF     s    z2DictTest.test_bad_key.<locals>.BadDictKey.__hash__c                s   t || jr |S )N)
isinstancer   )r   rB   )r   r   r   rD     s    z0DictTest.test_bad_key.<locals>.BadDictKey.__eq__N)r   r   r   rF   rD   r   )r   r   r   
BadDictKey  s   r   r
   )z	d[x2] = 2z	z = d[x2]zx2 in dz	d.get(x2)zd.setdefault(x2, 42)z	d.pop(x2)zd.update({x2: 2}))rO   r   execlocals)r   r   r4   Zx1Zx2Zstmtr   )r   r   test_bad_key  s    	
zDictTest.test_bad_keyc             C   sV   i }xt dD ]}|||< qW xt dD ]
}||= q(W xt ddD ]}|||< qBW d S )Nrf   	   )r%   )r   r4   r   r   r   r   test_resize1  s    
zDictTest.test_resize1c                s`   G  fdddt }i  dd | < d | < d | < d | < d | < d	d
 d< d S )Nc                   s"   e Zd Zdd Z fddZdS )z DictTest.test_resize2.<locals>.Xc             S   s   dS )Nrf   r   )r   r   r   r   rF     s    z)DictTest.test_resize2.<locals>.X.__hash__c                s   r    dS )NF)rR   )r   rB   )r4   resizingr   r   rD     s    z'DictTest.test_resize2.<locals>.X.__eq__N)r   r   r   rF   rD   r   )r4   r   r   r   X  s   r   Fr
   r   r@   rA   rf   Tr   r   )rM   )r   r   r   )r4   r   r   test_resize2  s    




zDictTest.test_resize2c          
   C   s8   |  t  dd d d d d d d d d}W d Q R X i }d S )Nr
   r   )r.   r/   r9   r4   r   r   rg   h)r   ZeroDivisionError)r   r4   r   r   r   $test_empty_presized_dict_in_freelist  s    z-DictTest.test_empty_presized_dict_in_freelistc             C   s|   G dd dt }tjtjtjf}xV|D ]N}| }t|}|di}|||_t|j|_	~~t
  | | d d q&W d S )Nc               @   s   e Zd ZdS )z+DictTest.test_container_iterator.<locals>.CN)r   r   r   r   r   r   r   r     s   r   r
   zCycle was not collected)rM   r   r(   r6   r1   weakrefrefr!   iterrP   r   collectr*   )r   r   Zviewsr!   objr   	containerr   r   r   test_container_iterator	  s    


z DictTest.test_container_iteratorc             C   s&   t   t   | t || d S )N)r   r   r;   r   )r   tr   r   r   _not_tracked  s    zDictTest._not_trackedc             C   s8   |  t|| t  t  |  t|| d S )N)r+   r   r   r   )r   r   r   r   r   _tracked  s    zDictTest._trackedc             C   s   dddg f\}}}}|  i  |  |d|||di |  ddd |  dtd |  dt i | dg i | dg fi | di i | dt i d S )	Ng      ?r.   )r
   Nr   r
   r   )r
   r/   )r
   )NTFr   )r   r   rM   r   r0   )r   rP   r   r^   wr   r   r   test_track_literals%  s    
zDictTest.test_track_literalsc       	      C   sV  G dd dt }dddt  fg | f\}}}}}t }| | d|d< | | d||< | | d||< | | | |  ||d< | | | |  d |d< | | | |  t }t }||d< | | | | ||d< | | t|||g}| | t }|| | | t||||g}| | t }|| | | t|||d	}| | t||||d
}| | t }|j|||d	 | | |j|d | | t||f|dfg}| | t||f||fg}| | t }|||f|dfg | | |||f||fg | | d S )Nc               @   s   e Zd ZdS )z-DictTest.test_track_dynamic.<locals>.MyObjectN)r   r   r   r   r   r   r   MyObject:  s   r   g      ?r.   r
   r   r@   rA   )rP   r   r^   )rP   r   r^   r   )r   )rM   r   r   ry   r   rv   r   )	r   r   rP   r   r^   r   or4   ddr   r   r   test_track_dynamic7  sh     





















zDictTest.test_track_dynamicc             C   s    G dd dt }| |  d S )Nc               @   s   e Zd ZdS )z,DictTest.test_track_subtypes.<locals>.MyDictN)r   r   r   r   r   r   r   MyDictz  s   r   )r   r   )r   r   r   r   r   test_track_subtypesw  s    zDictTest.test_track_subtypesc             C   sJ   G dd d}g }x2t |D ]&}| }d\|_|_|_||j qW |S )Nc               @   s   e Zd ZdS )z(DictTest.make_shared_key_dict.<locals>.CN)r   r   r   r   r   r   r   r     s   r   )r
   r   r@   )r%   rP   r   r^   r   __dict__)r   r'   r   Zdictsr   r.   r   r   r   make_shared_key_dict~  s    zDictTest.make_shared_key_dictc             C   s   |  d\}}d|d< t|}d|d< |dd t|}d|d< | || | t|dddddg | t|dddddg d S )Nr   r
   r.   r/   rP   r   r^   )r   r   	getsizeofr   assertGreaterr   list)r   r.   r/   Zsize_aZsize_br   r   r   test_splittable_setdefault  s    

z#DictTest.test_splittable_setdefaultc          	   C   s   |  d\}}t|}|d= | t |d= W d Q R X | t|| | t|ddg | t|dddg d|d< | t|dddg | t|dddg d S )Nr   r   rP   r^   rH   )r   r   r   r   rN   r   r   r   )r   r.   r/   	orig_sizer   r   r   test_splittable_del  s    
zDictTest.test_splittable_delc          	   C   s   |  d\}}t|}|d | t |d W d Q R X | t|| | t|ddg | t|dddg d|d< | t|dddg | t|dddg d S )Nr   r   rP   r^   rH   )	r   r   r   r   r   rN   r   r   r   )r   r.   r/   r   r   r   r   test_splittable_pop  s    

zDictTest.test_splittable_popc          	   C   s:   |  d\}}d|d< | t |d W d Q R X d S )Nr   rA   r.   )r   r   rN   r   )r   r.   r/   r   r   r   test_splittable_pop_pending  s    z$DictTest.test_splittable_pop_pendingc          	   C   s   |  d\}}t|}| }| |d | t |d= W d Q R X | t|| | t|ddg | t|dddg d S )Nr   )r^   r@   r^   rP   r   )	r   r   r   r   r   r   rN   r   r   )r   r.   r/   r   itemr   r   r   test_splittable_popitem  s    
z DictTest.test_splittable_popitemc             C   s   dd l }G dd d}| }d|_| ||j |jd | ||j d|_| ||j | }d|_| ||j |j  | ||j d|_| ||j d S )Nr   c               @   s   e Zd ZdS )z5DictTest.test_splittable_setattr_after_pop.<locals>.CN)r   r   r   r   r   r   r   r     s   r   r
   r.   r   r@   )	_testcapir.   r+   Zdict_hassplittabler   r   r;   r   )r   r   r   r.   r   r   r   !test_splittable_setattr_after_pop  s     
z*DictTest.test_splittable_setattr_after_popc          	   C   s   xt tjd D ]}dddd}t|}t||}t|}| t|t| t|}yt|}W n t	k
r~   wY nX t||}t|}||= | t|t| qW d S )Nr
   r.   r/   r9   )r
   r   r@   )
r%   pickleHIGHEST_PROTOCOLr   dumpsloadsr   sortednextr`   )r   protodataitr4   dropr   r   r   test_iterator_pickling  s    


zDictTest.test_iterator_picklingc             C   s   xt tjd D ]}dddd}t| }t||}t|}| |tj	j
 | t|| t|}t|}t||}t|}||d = | t|| qW d S )Nr
   r.   r/   r9   )r
   r   r@   r   )r%   r   r   r   r(   r   r   rw   ri   re   Iteratorr   r   r   )r   r   r   Zitorgr4   r  r  r   r   r   test_itemiterator_pickling  s    



z#DictTest.test_itemiterator_picklingc             C   s   xt tjd D ]}dddd}t| }t||}t|}| tt	|tt	|  t|}t
|}t||}t|}t	||g }| t|tt	|  qW d S )Nr
   r.   r/   r9   )r
   r   r@   )r%   r   r   r   r6   r   r   r   r   r   r   )r   r   r   r  r4   r  r6   r   r   r   test_valuesiterator_pickling"  s    
 

z%DictTest.test_valuesiterator_picklingc             C   sZ   G dd d}|d}G dd dt }| |jt||d | |j|j|d  d S )Nc               @   s   e Zd Zdd ZdS )z=DictTest.test_instance_dict_getattr_str_subclass.<locals>.Fooc             S   s
   || _ d S )N)msg)r   r  r   r   r   rV   4  s    zFDictTest.test_instance_dict_getattr_str_subclass.<locals>.Foo.__init__N)r   r   r   rV   r   r   r   r   Foo3  s   r  Z123c               @   s   e Zd ZdS )z>DictTest.test_instance_dict_getattr_str_subclass.<locals>._strN)r   r   r   r   r   r   r   _str7  s   r	  r  )strr   r  getattrr   )r   r  r   r	  r   r   r   'test_instance_dict_getattr_str_subclass2  s
    z0DictTest.test_instance_dict_getattr_str_subclassc             C   s<   G dd d}| }d|j d< d|_| |j ddd d S )Nc               @   s   e Zd ZdS )zFDictTest.test_object_set_item_single_instance_non_str_key.<locals>.FooN)r   r   r   r   r   r   r   r  =  s    r  r
   r.   )r
   r.   )r   r.   r   )r   r  r   r   r   r   0test_object_set_item_single_instance_non_str_key<  s
    
z9DictTest.test_object_set_item_single_instance_non_str_keyc                sD   G fddd  fdddD xt D ]}||< q0W d S )Nc                   s   e Zd Z fddZdS )z4DictTest.check_reentrant_insertion.<locals>.Mutatingc                s     d S )Nr   )r   )r4   mutater   r   __del__H  s    z<DictTest.check_reentrant_insertion.<locals>.Mutating.__del__N)r   r   r   r  r   )r4   r  r   r   MutatingG  s   r  c                s   i | ]}  |qS r   r   )r   r    )r  r   r   rt   K  s    z6DictTest.check_reentrant_insertion.<locals>.<dictcomp>Zabcdefghijklmnopqr)r   )r   r  r    r   )r  r4   r  r   check_reentrant_insertionC  s    z"DictTest.check_reentrant_insertionc                s>   dd }  |  fdd}  | dd }  | d S )Nc             S   s   d| d< d S )Nrf   r/   r   )r4   r   r   r   r  Q  s    z1DictTest.test_reentrant_insertion.<locals>.mutatec                s   |   j |   d S )N)r   r   rR   )r4   )r   r   r   r  U  s    c             S   s   x| r|    qW d S )N)r   )r4   r   r   r   r  Z  s    )r  )r   r  r   )r   r   test_reentrant_insertionO  s    

z!DictTest.test_reentrant_insertionc                sZ   G  fddd}dd t ddD }t| d | < | dddi}| t|j  d S )Nc                   s    e Zd Zdd Z fddZdS )z)DictTest.test_merge_and_mutate.<locals>.Xc             S   s   dS )Nr   r   )r   r   r   r   rF   a  s    z2DictTest.test_merge_and_mutate.<locals>.X.__hash__c                s       dS )NF)rR   )r   r   )rB   r   r   rD   d  s    z0DictTest.test_merge_and_mutate.<locals>.X.__eq__N)r   r   r   rF   rD   r   )rB   r   r   r   `  s   r   c             S   s   g | ]}|d fqS )r   r   )r   r   r   r   r   r   h  s    z2DictTest.test_merge_and_mutate.<locals>.<listcomp>r
   i9  r   )r%   r   r   r   r   )r   r   lr4   r   )rB   r   test_merge_and_mutate_  s    
zDictTest.test_merge_and_mutatec             C   sH   t | tt t | dd t t | dd t t | dd t d S )Nc             S   s   t |  S )N)r   r1   )r4   r   r   r   r   p  r   z4DictTest.test_free_after_iterating.<locals>.<lambda>c             S   s   t |  S )N)r   r6   )r4   r   r   r   r   q  r   c             S   s   t |  S )N)r   r(   )r4   r   r   r   r   r  r   )r   Zcheck_free_after_iteratingr   r   )r   r   r   r   test_free_after_iteratingn  s    z"DictTest.test_free_after_iteratingc                s<   G  fddd}| di | | i|   k d S )Nc                   s,   e Zd ZfddZ fddZdd ZdS )z9DictTest.test_equal_operator_modifying_operand.<locals>.Xc                s       d S )N)rR   )r   )dict_br   r   r  w  s    zADictTest.test_equal_operator_modifying_operand.<locals>.X.__del__c                s       dS )NT)rR   )r   rB   )dict_ar   r   rD   z  s    z@DictTest.test_equal_operator_modifying_operand.<locals>.X.__eq__c             S   s   dS )N   r   )r   r   r   r   rF   ~  s    zBDictTest.test_equal_operator_modifying_operand.<locals>.X.__hash__N)r   r   r   r  rD   rF   r   )r  r  r   r   r   v  s   r   r   )r+   )r   r   r   )r  r  r   %test_equal_operator_modifying_operandt  s    
z.DictTest.test_equal_operator_modifying_operandc                sT   G  fdddt }i  |dd|ddi yt  W n tk
rN   Y nX d S )Nc                   s    e Zd Zdd Z fddZdS )zADictTest.test_fromkeys_operator_modifying_dict_operand.<locals>.Xc             S   s   dS )Nr  r   )r   r   r   r   rF     s    zJDictTest.test_fromkeys_operator_modifying_dict_operand.<locals>.X.__hash__c                s   t  dkr   dS )Nr
   F)r>   rR   )r   rB   )r4   r   r   rD     s    zHDictTest.test_fromkeys_operator_modifying_dict_operand.<locals>.X.__eq__N)r   r   r   rF   rD   r   )r4   r   r   r     s   r   r
   r   )r   r   rv   r   )r   r   r   )r4   r   -test_fromkeys_operator_modifying_dict_operand  s    	z6DictTest.test_fromkeys_operator_modifying_dict_operandc                sP   G  fdddt }i  |d|dh yt  W n tk
rJ   Y nX d S )Nc                   s    e Zd Zdd Z fddZdS )z@DictTest.test_fromkeys_operator_modifying_set_operand.<locals>.Xc             S   s   dS )Nr  r   )r   r   r   r   rF     s    zIDictTest.test_fromkeys_operator_modifying_set_operand.<locals>.X.__hash__c                s   t  dkr   dS )Nr
   F)r>   rR   )r   rB   )r4   r   r   rD     s    zGDictTest.test_fromkeys_operator_modifying_set_operand.<locals>.X.__eq__N)r   r   r   rF   rD   r   )r4   r   r   r     s   r   r
   r   )r   r   rv   r   )r   r   r   )r4   r   ,test_fromkeys_operator_modifying_set_operand  s    	z5DictTest.test_fromkeys_operator_modifying_set_operandc                s2   G  fddd}dt  i d| f  k d S )Nc                   s   e Zd Z fddZdS )z:DictTest.test_dictitems_contains_use_after_free.<locals>.Xc                s       tS )N)rR   NotImplemented)r   rB   )r4   r   r   rD     s    zADictTest.test_dictitems_contains_use_after_free.<locals>.X.__eq__N)r   r   r   rD   r   )r4   r   r   r     s   r   r   )r0   r(   )r   r   r   )r4   r   &test_dictitems_contains_use_after_free  s    
z/DictTest.test_dictitems_contains_use_after_freec                s*   G  fddd}| dg t  g d S )Nc                   s   e Zd Z fddZdS )z,DictTest.test_init_use_after_free.<locals>.Xc                s   g  d d < dS )Nr  r   )r   )pairr   r   rF     s    z5DictTest.test_init_use_after_free.<locals>.X.__hash__N)r   r   r   rF   r   )r  r   r   r     s   r   {   )r   )r   r   r   )r  r   test_init_use_after_free  s    
z!DictTest.test_init_use_after_freec                sF   G fdddt   fddtdD fdd}| t| d S )Nc                   s   e Zd Z fddZdS )z;DictTest.test_oob_indexing_dictiter_iternextitem.<locals>.Xc                s       d S )N)rR   )r   )r4   r   r   r    s    zCDictTest.test_oob_indexing_dictiter_iternextitem.<locals>.X.__del__N)r   r   r   r  r   )r4   r   r   r     s   r   c                s   i | ]} ||qS r   r   )r   r   )r   r   r   rt     s    zDDictTest.test_oob_indexing_dictiter_iternextitem.<locals>.<dictcomp>r   c                 s*   x$   D ]} | d dkr
d  d< q
W d S )Nr   r   )r(   )result)r4   r   r   iter_and_mutate  s    zIDictTest.test_oob_indexing_dictiter_iternextitem.<locals>.iter_and_mutate)r   r%   r   r   )r   r"  r   )r   r4   r   'test_oob_indexing_dictiter_iternextitem  s    z0DictTest.test_oob_indexing_dictiter_iternextitemc             C   s   t ddg}|d t| }t|}| t| | G dd dt}dddg}||}| |tt|  G dd dt}||}| |d d d	 tt|  d S )
N)r.   r
   )r/   r   r.   c               @   s   e Zd ZdS )z1DictTest.test_dict_copy_order.<locals>.CustomDictN)r   r   r   r   r   r   r   
CustomDict  s   r$  )r9   r@   c               @   s    e Zd Zdd ZeZdd ZdS )z9DictTest.test_dict_copy_order.<locals>.CustomReversedDictc             S   s   t tt| S )N)reversedr   r   r1   )r   r   r   r   r1     s    z>DictTest.test_dict_copy_order.<locals>.CustomReversedDict.keysc             S   s   t t| S )N)r%  r   r(   )r   r   r   r   r(     s    z?DictTest.test_dict_copy_order.<locals>.CustomReversedDict.itemsN)r   r   r   r1   rY   r(   r   r   r   r   CustomReversedDict  s   r&  r   )ri   OrderedDictmove_to_endr   r(   r   r   )r   ZodZexpectedry   r$  Zpairsr4   r&  r   r   r   test_dict_copy_order  s    

	zDictTest.test_dict_copy_orderN)Jr   r   r   r   r   r)   r-   r5   r7   r8   r=   r?   rQ   rS   rd   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   cpython_onlyr   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   		&L:
!,+@	
		r   c               @   s   e Zd Zejdd ZdS )CAPITestc                s   ddl m} dddd}| ||dtdd | ||dtdd | ||d	td	d | t|g dtd | t|i dtd G d
d dt G  fddd}| |  }}|di}| |||t|d |  |||t| d S )Nr   )dict_getitem_knownhashr
   r   r@   )rP   r   r^   rP   r   r^   c               @   s   e Zd ZdS )z,CAPITest.test_getitem_knownhash.<locals>.ExcN)r   r   r   r   r   r   r   rC     s    rC   c                   s    e Zd Z fddZdd ZdS )z.CAPITest.test_getitem_knownhash.<locals>.BadEqc                s    d S )Nr   )r   rB   )rC   r   r   rD     s    z5CAPITest.test_getitem_knownhash.<locals>.BadEq.__eq__c             S   s   dS )N   r   )r   r   r   r   rF     s    z7CAPITest.test_getitem_knownhash.<locals>.BadEq.__hash__N)r   r   r   rD   rF   r   )rC   r   r   rG     s   rG   )r   r,  r   r   r   SystemErrorrN   rO   )r   r,  r4   rG   r   r   r   )rC   r   test_getitem_knownhash  s    zCAPITest.test_getitem_knownhashN)r   r   r   r   r*  r/  r   r   r   r   r+    s   r+  )mapping_testsc               @   s   e Zd ZeZdS )GeneralMappingTestsN)r   r   r   r   	type2testr   r   r   r   r1    s   r1  c               @   s   e Zd ZdS )DictN)r   r   r   r   r   r   r   r3    s   r3  c               @   s   e Zd ZeZdS )SubclassMappingTestsN)r   r   r   r3  r2  r   r   r   r   r4    s   r4  __main__)ri   Zcollections.abcr   r   r   r   r   Zunittestr   Ztestr   ZTestCaser   r+  r0  ZBasicTestMappingProtocolr1  r   r3  r4  r   mainr   r   r   r   <module>   s4            d