U
    9%e[                     @   s  d dl Z d dlm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	 d dl
Zd dlmZmZmZ d dlmZ d dlmZ d dl Z d dlmZmZmZmZmZ e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-d0d1 Z.d2d3 Z/d4d5 Z0d6d7 Z1d8d9 Z2d:d; Z3d<d= Z4d>d? Z5d@dA Z6dBdC Z7dDdE Z8dFdG Z9dHdI Z:dJdK Z;dLdM Z<dNdO Z=dPdQ Z>dRdS Z?dTdU Z@G dVdW dWeeZAG dXdY dYeAZBG dZd[ d[eAZCG d\d] d]eCZDG d^d_ d_eCZEG d`da daeCZFG dbdc dceCZGG ddde deeCZHG dfdg dgeAZIG dhdi dieAZJG djdk dkeAZKeLdlkre M  dS )m    N)
namedtuple)TypingError)compile_isolatedFlagserrorsjit)types)TestCaseenable_pyobj_flagsMemoryLeakMixintagcompile_functionPointabc                 C   s*   | dd dd |D i } td| t S )NZinitializerz, c                 s   s   | ]}t |V  qd S N)repr).0arg r   T/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/tests/test_sets.py	<genexpr>   s     z-_build_set_literal_usecase.<locals>.<genexpr>Z	build_set)joinr   globals)codeargsr   r   r   _build_set_literal_usecase   s    r   c                 C   s   d}t || S )Nz@if 1:
    def build_set():
        return {%(initializer)s}
    r   r   r   r   r   r   set_literal_return_usecase   s    r!   c                 C   s   d}t || S )Nz^if 1:
    def build_set():
        my_set = {%(initializer)s}
        return list(my_set)
    r   r    r   r   r   set_literal_convert_usecase#   s    r"   c                  C   s   t  } | d t| S N   )setaddlensr   r   r   empty_constructor_usecase,   s    
r*   c                 C   s   t | }t|S r   )r%   r'   r   r)   r   r   r   constructor_usecase1   s    r,   c                 C   s$   t | }g }|D ]}|| q|S r   r%   append)r   r)   lvr   r   r   iterator_usecase5   s
    r1   c                 C   s,   t  }||  || || t|S r   )r%   updatelist)r   r   cr)   r   r   r   update_usecase<   s
    


r5   c                 C   s   t | dd  }t|S r#   )r%   boolr+   r   r   r   bool_usecaseC   s    r7   c                 C   s$   t | }|D ]}|| qt|S r   )r%   remover3   r   r   r)   r0   r   r   r   remove_usecaseH   s    r:   c                 C   s$   t | }|D ]}|| qt|S r   )r%   discardr3   r9   r   r   r   discard_usecaseN   s    r<   c                 C   s2   t | }tdD ]}|| || qt|S )Ni  )r%   ranger&   r;   r3   )r   ur0   r)   ir   r   r   add_discard_usecaseT   s
    
r@   c                 C   s,   t | }g }t|dkr(||  q|S Nr   )r%   r'   r.   pop)r   r)   r/   r   r   r   pop_usecase[   s
    rC   c                 C   s(   t | }g }|D ]}|||k q|S r   r-   )r   r   r)   r/   r0   r   r   r   contains_usecaseb   s
    rD   c                 C   s   t | }|t | t|S r   )r%   difference_updater3   r   r   r)   r   r   r   difference_update_usecasei   s    rG   c                 C   s   t | }|t | t|S r   )r%   intersection_updater3   rF   r   r   r   intersection_update_usecasen   s    rI   c                 C   s   t | }|t | t|S r   )r%   symmetric_difference_updater3   rF   r   r   r   #symmetric_difference_update_usecases   s    rK   c                 C   s   t | t |S r   )r%   
isdisjointr   r   r   r   isdisjoint_usecasex   s    rM   c                 C   s   t | t |S r   )r%   issubsetr   r   r   r   issubset_usecase{   s    rO   c                 C   s   t | t |S r   )r%   
issupersetr   r   r   r   issuperset_usecase~   s    rQ   c                 C   s    t | }|  t|t|fS r   )r%   clearr'   r3   r   r)   r   r   r   clear_usecase   s    rT   c                 C   s(   t | }| }|  t|t|fS r   )r%   copyrB   r'   r3   r   r)   ssr   r   r   copy_usecase   s    rX   c                 C   s6   t | }|  | }|| d  t|t|fS rA   )r%   rR   rU   r&   r'   r3   rV   r   r   r   copy_usecase_empty   s
    rY   c                 C   s2   t | }|| | }|  t|t|fS r   )r%   r8   rU   rB   r'   r3   )r   r   r)   rW   r   r   r   copy_usecase_deleted   s
    
rZ   c                 C   s   t | }|t |}t|S r   )r%   
differencer3   r   r   sar)   r   r   r   difference_usecase   s    r^   c                 C   s   t | }|t |}t|S r   )r%   intersectionr3   r\   r   r   r   intersection_usecase   s    r`   c                 C   s   t | }|t |}t|S r   )r%   symmetric_differencer3   r\   r   r   r   symmetric_difference_usecase   s    rb   c                 C   s   t | }|t |}t|S r   )r%   unionr3   r\   r   r   r   union_usecase   s    rd   c                 C   s   t | }|S r   )r%   rS   r   r   r   set_return_usecase   s    re   c                 C   s   d S r   r   )xr   r   r   noop   s    rg   c                 C   s   d}| D ]}||7 }q|S )z!
    Expect a set of numbers
    r   r   rf   resr0   r   r   r   unbox_usecase   s    
rj   c                 C   s   d}| D ]}|t |7 }q|S )z 
    Expect a set of tuples
    r   r'   rh   r   r   r   unbox_usecase2   s    rl   c                 C   s"   | \}}|}|D ]}||7 }q|S )z2
    Expect a (number, set of numbers) tuple.
    r   rf   r   r   ri   r0   r   r   r   unbox_usecase3   s
    
rn   c                 C   s&   | \}}|}|D ]}|t |7 }q|S )z1
    Expect a (number, set of tuples) tuple.
    rk   rm   r   r   r   unbox_usecase4   s
    ro   c                 C   s&   |  d | | | t| t|fS N*   )r&   r2   r'   r]   sbr   r   r   reflect_simple   s    

rt   c                 C   sL   t |dkrtd} | d | | td}| | | t | t |fS )Nr$   )g      &@g      6@g     @@g      F@g      E@)g     K@g     P@)r'   r%   r&   r2   rJ   )r]   rs   scr   r   r   reflect_conditional   s    


rv   c                 C   s   |  d td S rp   )r&   ZeroDivisionErrorr(   r   r   r   reflect_exception   s    
rx   c                 C   s   |  |  | |kS r   )r&   rB   rr   r   r   r   reflect_dual   s    ry   c                 C   s4   t  }g }| D ] }||kr|| || q|S r   )r%   r&   r.   )srcseenri   r0   r   r   r   unique_usecase   s    
r|   c                       sL   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )BaseTestc                    s   t t|   td| _d S rp   )superr}   setUprandomRandomrndself	__class__r   r   r     s    zBaseTest.setUpc                 C   s   t t|S r   )nparangeintr   stopr   r   r   _range  s    zBaseTest._rangec                    s<    fddt |D }ttjr4tj|jdS |S dS )zD
        Choose *n* possibly duplicate items from sequence.
        c                    s   g | ]} j tqS r   )r   choicer3   r   r?   r   seqr   r   
<listcomp>  s     z+BaseTest._random_choice.<locals>.<listcomp>dtypeN)r=   
isinstancer   Zndarrayarrayr   )r   r   nr/   r   r   r   _random_choice	  s    zBaseTest._random_choicec                 C   s   |  t|}| ||S )z<
        Get a 1d array with many duplicate values.
        )r   r   sqrtr   r   r   r   r   r   r   duplicates_array  s    zBaseTest.duplicates_arrayc                 C   s   |  |d }| ||S )z;
        Get a 1d array with values spread around.
        g?)r   r   r   r   r   r   sparse_array  s    zBaseTest.sparse_arrayc                 C   st   t |tr8| |t t||D ]\}}| || q n8t |trd| |t | t|t| n| || d S r   )r   tupleZassertIsInstancezip_assert_equal_unorderedr3   assertPreciseEqualsorted)r   r   r   r>   r0   r   r   r   r   "  s    

z BaseTest._assert_equal_unorderedc                    s"   t dd  fdd}|S )NTZnopythonc                     s    |  } |  } || d S r   )r   )r   expectedgotcfuncpyfuncr   r   r   check/  s    z)BaseTest.unordered_checker.<locals>.checkr   r   r   r   r   r   r   unordered_checker-  s    zBaseTest.unordered_checker)__name__
__module____qualname__r   r   r   r   r   r   r   __classcell__r   r   r   r   r}      s   
r}   c                   @   s,   e Zd ZefddZefddZdd ZdS )TestSetLiteralsc                 C   s   t d}| j||d d S )N)r$         r   flags)r!   run_nullary_func)r   r   r   r   r   r   test_build_set8  s    zTestSetLiterals.test_build_setc                 C   sP   t d}| j||d t d}| j||d\}}| t| t|  d S )N)r$          @y              @r   r   )r   r   )r!   r   ZassertIstyperB   )r   r   r   r   r   r   r   r   test_build_heterogeneous_set<  s
    z,TestSetLiterals.test_build_heterogeneous_setc                 C   sH   t | d}t|}tdd|}| }| }| t|t| d S )N2   Tr   )r3   r   r"   r   r   r   )r   r   r   r   r   r   r   r   r   test_build_set_nopythonD  s    z'TestSetLiterals.test_build_set_nopythonN)r   r   r   r   r   r   r   r   r   r   r   r   6  s   r   c                   @   sd  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-dWS )XTestSetsc                    sd   t tdd     ttdd  fdd}|d |d d S )NTr   c                    s    |  |  d S r   r   )r   r   r   r   r   W  s    z(TestSets.test_constructor.<locals>.check   )r*   r   r   r,   r   r   r   r   r   r   r   test_constructorP  s    zTestSets.test_constructorc                 C   s4   t }tdd|}| d}| ||t| d S )NTr   r   )re   r   r   assertEqualr%   )r   r   r   r   r   r   r   test_set_return]  s    
zTestSets.test_set_returnc                 C   s.   t }| |}|| d || d d S Nr   )r1   r   r   r   r   r   r   r   test_iteratord  s    
zTestSets.test_iteratorc                 C   s<   t }| |}| d}| d}| d}|||| d S Nr   )r5   r   r   r   )r   r   r   r   r   r4   r   r   r   test_updatek  s    



zTestSets.test_updatec                 C   s4   t }| |}| d}|d d d }||| d S )Nr   
   )r:   r   r   r   r   r   r   r   r   r   r   test_removet  s
    

zTestSets.test_removec              	   C   sf   |    t}tdd|}tt| d}|dd  }|d f}| t ||| W 5 Q R X d S )NTr   r   r$   r   )Zdisable_leak_checkr:   r   r   r%   r   assertRaisesKeyError)r   r   r   itemsr   r   r   r   r   test_remove_error|  s    
zTestSets.test_remove_errorc                 C   s0   t }| |}| d}| d}||| d S r   )r<   r   r   r   r   r   r   test_discard  s
    


zTestSets.test_discardc                 C   s@   t }| |}d }}||kr.| d\}}q||f|| dS )z
        Check that the insertion logic does not create an infinite lookup
        chain with deleted entries (insertion should happen at the first
        deleted entry, not at the free entry at the end of the chain).
        See issue #1913.
        Nr   )r@   r   r   r   r   r   r   test_add_discard  s    
zTestSets.test_add_discardc                 C   s    t }| |}|| d d S r   )rC   r   r   r   r   r   r   test_pop  s    
zTestSets.test_popc                    sD   t tdd  fdd}d}d}||| d S )NTr   c                    s    | | | | d S r   r   r   r   r   r   r     s    z%TestSets.test_contains.<locals>.checkr   )rD   r   r   )r   r   r   r   r   r   r   test_contains  s    

zTestSets.test_containsc                 C   sF   |  |}d}t||D ]&\}}| |}| |}||| qd S )Nr$   r   i  r   	itertoolsproductr   )r   r   r   sizesnanbr   r   r   r   r   _test_xxx_update  s    


zTestSets._test_xxx_updatec                 C   s   |  t d S r   )r   rG   r   r   r   r   test_difference_update  s    zTestSets.test_difference_updatec                 C   s   |  t d S r   )r   rI   r   r   r   r   test_intersection_update  s    z!TestSets.test_intersection_updatec                 C   s   |  t d S r   )r   rK   r   r   r   r    test_symmetric_difference_update  s    z)TestSets.test_symmetric_difference_updatec                    s   t dd  fdd}ttddg\}}||@ || ||B ||A g}dd |D }t||D ]\}}||| qrd S )	NTr   c                    s    | | | | d S r   r   r   r   r   r   r     s    z(TestSets._test_comparator.<locals>.checkr      c                 S   s   g | ]}t |qS r   )r   r   rf   r   r   r   r     s     z-TestSets._test_comparator.<locals>.<listcomp>)r   mapr%   r   r   r   )r   r   r   r   r   r   r   r   r   _test_comparator  s    zTestSets._test_comparatorc                 C   s   |  t d S r   )r   rM   r   r   r   r   test_isdisjoint  s    zTestSets.test_isdisjointc                 C   s   |  t d S r   )r   rO   r   r   r   r   test_issubset  s    zTestSets.test_issubsetc                 C   s   |  t d S r   )r   rQ   r   r   r   r   test_issuperset  s    zTestSets.test_issupersetc                 C   s    t }| |}|| d d S r   )rT   r   r   r   r   r   r   
test_clear  s    
zTestSets.test_clearc                 C   sx   t }| |}|| d t}| |}| d}|| t}| |}|dd | d}|||t|d   d S )Nr   r$   r$   r         r   )rX   r   r   rY   rZ   r'   )r   r   r   r   r   r   r   	test_copy  s    





zTestSets.test_copyc                 C   s.   t }| |}|| d || d d S )Nr$   r   )r7   r   r   r   r   r   r   	test_bool  s    
zTestSets.test_boolc                 C   sX   |  |}d\}}||| d}t||D ]&\}}| |}| |}||| q,d S )N)r   )r   r      r   rq   r   r   )r   r   r   r   r   r   r   r   r   r   r   _test_set_operator  s    



zTestSets._test_set_operatorc                 C   s   dt |d }td|t S )Nzrif 1:
        def operator_usecase(a, b):
            s = set(a) %(op)s set(b)
            return list(s)
        opoperator_usecasedictr   r   r   r   r   r   r   r   make_operator_usecase  s    zTestSets.make_operator_usecasec                 C   s   dt |d }td|t S )Nzif 1:
        def inplace_operator_usecase(a, b):
            sa = set(a)
            sb = set(b)
            sc = sa
            sc %(op)s sb
            return list(sc), list(sa)
        r   inplace_operator_usecaser   r   r   r   r   make_inplace_operator_usecase  s    z&TestSets.make_inplace_operator_usecasec                 C   s   dt |d }td|t S )Nz\if 1:
        def comparison_usecase(a, b):
            return set(a) %(op)s set(b)
        r   comparison_usecaser   r   r   r   r   make_comparison_usecase  s    z TestSets.make_comparison_usecasec                 C   s   |  t d S r   )r   r^   r   r   r   r   test_difference  s    zTestSets.test_differencec                 C   s   |  t d S r   )r   r`   r   r   r   r   test_intersection   s    zTestSets.test_intersectionc                 C   s   |  t d S r   )r   rb   r   r   r   r   test_symmetric_difference#  s    z"TestSets.test_symmetric_differencec                 C   s   |  t d S r   )r   rd   r   r   r   r   
test_union&  s    zTestSets.test_unionc                 C   s   |  | d d S )N&r   r   r   r   r   r   test_and)  s    zTestSets.test_andc                 C   s   |  | d d S )N|r   r   r   r   r   test_or,  s    zTestSets.test_orc                 C   s   |  | d d S )N-r   r   r   r   r   test_sub/  s    zTestSets.test_subc                 C   s   |  | d d S )N^r   r   r   r   r   test_xor2  s    zTestSets.test_xorc                 C   s   |  | d d S )Nz==r   r   r   r   r   r   test_eq5  s    zTestSets.test_eqc                 C   s   |  | d d S )Nz!=r  r   r   r   r   test_ne8  s    zTestSets.test_nec                 C   s   |  | d d S )Nz<=r  r   r   r   r   test_le;  s    zTestSets.test_lec                 C   s   |  | d d S )N<r  r   r   r   r   test_lt>  s    zTestSets.test_ltc                 C   s   |  | d d S )Nz>=r  r   r   r   r   test_geA  s    zTestSets.test_gec                 C   s   |  | d d S )N>r  r   r   r   r   test_gtD  s    zTestSets.test_gtc                 C   s   |  | d d S )Nz&=r   r   r   r   r   r   	test_iandG  s    zTestSets.test_iandc                 C   s   |  | d d S )Nz|=r  r   r   r   r   test_iorJ  s    zTestSets.test_iorc                 C   s   |  | d d S )Nz-=r  r   r   r   r   	test_isubM  s    zTestSets.test_isubc                 C   s   |  | d d S )Nz^=r  r   r   r   r   	test_ixorP  s    zTestSets.test_ixorN).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   N  sV   	
	r   c                   @   s   e Zd ZdZdd ZdS )TestFloatSetsz-
    Test sets with floating-point keys.
    c                 C   s   t j|t jdt d S )Nr   g?)r   r   Zfloat32r   r   r   r   r   [  s    zTestFloatSets._rangeNr   r   r   __doc__r   r   r   r   r   r  T  s   r  c                   @   s   e Zd ZdZdd ZdS )TestTupleSetsz$
    Test sets with tuple keys.
    c                 C   sL   t j|t jd}|d@ }|d@ t j}|d? d@ t j}tt|||S )Nr   l   UU*UU* l   *UU     r$   )r   r   Zint64ZastypeZint32Zbool_r3   r   )r   r   r   r   r4   dr   r   r   r   c  s
    zTestTupleSets._rangeNr  r   r   r   r   r  _  s   r  c                   @   s   e Zd ZdZdd ZdS )TestUnicodeSetszR
    Test sets with unicode keys. For the purpose of testing refcounted sets.
    c                 C   s   dd t t|D S )Nc                 S   s   g | ]}d  |qS )zA{})formatr   r   r   r   r   p  s     z*TestUnicodeSets._range.<locals>.<listcomp>)r=   r   r   r   r   r   r   o  s    zTestUnicodeSets._rangeNr  r   r   r   r   r  k  s   r  c                   @   s   e Zd Zdd ZdS )TestSetsInvalidDtypec              	   C   sV   t dd|}tddddg}tddd	g}d
}| t| ||| W 5 Q R X d S )NTr   r$   r   r   r   r   r   r4   z!All Sets must be of the same typer   r%   assertRaisesRegexr   r   r   r   r   r   msgr   r   r   r   u  s    z'TestSetsInvalidDtype._test_set_operatorN)r   r   r   r   r   r   r   r   r  s  s   r  c                   @   sl   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )TestSetsInvalidc                 C   s   |  |}t|S r   )ra   r3   rF   r   r   r   rb     s    
z,TestSetsInvalid.symmetric_difference_usecasec                 C   s   |  |}t|S r   )r[   r3   rF   r   r   r   r^     s    
z"TestSetsInvalid.difference_usecasec                 C   s   |  |}t|S r   )r_   r3   rF   r   r   r   r`     s    
z$TestSetsInvalid.intersection_usecasec                 C   s   |  |}t|S r   )rc   r3   rF   r   r   r   rd     s    
zTestSetsInvalid.union_usecasec              	   C   sL   t dd|}tddddg}d}d}| t| ||| W 5 Q R X d S )	NTr   r$   r   r   r   )r$   r   r   zAll arguments must be Setsr  r  r   r   r   r     s    z"TestSetsInvalid._test_set_operatorc                 C   s   |  tj d S r   )r   r  r^   r   r   r   r   r     s    zTestSetsInvalid.test_differencec                 C   s   |  tj d S r   )r   r  r`   r   r   r   r   r     s    z!TestSetsInvalid.test_intersectionc                 C   s   |  tj d S r   )r   r  rb   r   r   r   r   r     s    z)TestSetsInvalid.test_symmetric_differencec                 C   s   |  tj d S r   )r   r  rd   r   r   r   r   r     s    zTestSetsInvalid.test_unionc                 C   s   dt |d }td|t S )Nzhif 1:
        def operator_usecase(a, b):
            s = a %(op)s b
            return list(s)
        r   r   r   r   r   r   r   r     s    z%TestSetsInvalid.make_operator_usecasec                 C   s   dt |d }td|t S )Nzif 1:
        def inplace_operator_usecase(a, b):
            sa = a
            sb = b
            sc = sa
            sc %(op)s sb
            return list(sc), list(sa)
        r   r   r   r   r   r   r   r     s    z-TestSetsInvalid.make_inplace_operator_usecasec                 C   s   dt |d }td|t S )NzWif 1:
        def comparison_usecase(a, b):
            return set(a) %(op)s b
        r   r   r   r   r   r   r   r     s    z'TestSetsInvalid.make_comparison_usecaseN)r   r   r   rb   r^   r`   rd   r   r   r   r   r   r   r   r   r   r   r   r   r    s   r  c                   @   sN   e Zd ZdZejdd Zdd Zdd Zdd	 Z	d
d Z
dd Zdd ZdS )TestUnboxingz>
    Test unboxing of Python sets into native Numba sets.
    c              	   c   s:   |  t}d V  W 5 Q R X |d k	r6| t|j| d S r   )r   	TypeErrorZassertRegexpMatchesstr	exception)r   r  raisesr   r   r   assert_type_error  s    zTestUnboxing.assert_type_errorc                    s"   t dd  fdd}|S )NTr   c                    s    | } | } || d S r   r   )r   r   r   r   r   r   r     s    z'TestUnboxing.check_unary.<locals>.checkr   r   r   r   r   check_unary  s    zTestUnboxing.check_unaryc                 C   s>   |  t}|tddg |tddg |ttd d S )Nr$   r   y              ?y              @d   )r$  rj   r%   r=   r   r   r   r   test_numbers  s    
zTestUnboxing.test_numbersc                 C   s.   |  t}|tddg |tddg d S )N)r$   r   )r   r   )r$                  @)r   y              @)r$  rl   r%   r   r   r   r   test_tuples  s    
zTestUnboxing.test_tuplesc                 C   s$   |  t}|dtdddgf d S )Nr$   r   r   r   )r$  rn   r%   r   r   r   r   test_set_inside_tuple  s    
z"TestUnboxing.test_set_inside_tuplec                 C   s"   |  t}|dtddgf d S )Nr$   )r   )r   )r$  ro   r%   r   r   r   r   test_set_of_tuples_inside_tuple  s    
z,TestUnboxing.test_set_of_tuples_inside_tuplec              	   C   s  d}t }tdd|}tddg}| | || W 5 Q R X | |tddg | | |tddg W 5 Q R X | | |dtddgf W 5 Q R X | | |tdtddg W 5 Q R X tddg}| ttf}|| W 5 Q R X d S )	Nzcan't unbox heterogeneous setTr   r$   g      @r'  )r$   )r   r   )	rg   r   r%   r#  r   r   r   
IndexError
ValueError)r   r  r   r   vallstr"  r   r   r   test_errors  s      zTestUnboxing.test_errorsN)r   r   r   r  
contextlibcontextmanagerr#  r$  r&  r(  r)  r*  r/  r   r   r   r   r    s   
r  c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )TestSetReflectionzE
    Test reflection of native Numba sets on Python set objects.
    c           
   
   C   s   t dd|}tddddgtdgftddddgtdd	d
ddgfg}|D ]|\}}t|}t|}|||}| ||H |||}	| |	| | || | |d |k|	d |k ~~	W 5 Q R X qNd S )NTr   g      ?r   g      @g      @g        g      @g      @g      @g       @g      "@r   )r   r%   assertRefCountr   r   )
r   r   r   Zsamplesdestrz   r   r   ZpyresZcresr   r   r   check_reflection  s     

z"TestSetReflection.check_reflectionc                 C   s   |  t d S r   )r5  rt   r   r   r   r   test_reflect_simple  s    z%TestSetReflection.test_reflect_simplec                 C   s   |  t d S r   )r5  rv   r   r   r   r   test_reflect_conditional  s    z*TestSetReflection.test_reflect_conditionalc              
   C   sp   t }tdd|}tdddg}| |< | t || W 5 Q R X | |tddddg W 5 Q R X dS )zd
        When the function exits with an exception, sets should still be
        reflected.
        Tr   r$   r   r   rq   N)rx   r   r%   r3  r   rw   r   )r   r   r   r)   r   r   r   test_reflect_exception"  s    z(TestSetReflection.test_reflect_exceptionc                 C   sd   t }tdd|}tdddg}| }|||}|||}| || | || | || dS )zf
        When the same set object is reflected twice, behaviour should
        be consistent.
        Tr   r$   r   r   N)ry   r   r%   rU   r   ZassertRefCountEqual)r   r   r   ZpysetZcsetr   r   r   r   r   test_reflect_same_set/  s    

z'TestSetReflection.test_reflect_same_setc                 C   sH   t ddt}tdg}dd |D }|| | dd |D | dS )zO
        When the set wasn't mutated, no reflection should take place.
        Tr   y              )@c                 S   s   g | ]}t |qS r   idr   r   r   r   r   E  s     z8TestSetReflection.test_reflect_clean.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   r:  r   r   r   r   r   G  s     N)r   rg   r%   r   )r   r   r)   Zidsr   r   r   test_reflect_clean>  s
    
z$TestSetReflection.test_reflect_cleanN)
r   r   r   r  r5  r6  r7  r8  r9  r<  r   r   r   r   r2    s   r2  c                   @   s    e Zd ZdZdd Zdd ZdS )TestExamplesz!
    Examples of using sets.
    c                 C   s.   t }| |}|| d || d d S r   )r|   r   r   r   r   r   r   r   test_uniqueO  s    
zTestExamples.test_uniquec                 C   s   dd }|  |}|  d S )Nc                  S   s.   t d} t }|dddh ||  |S )Nr$   r   r   )r   Zuint64r%   r2   r&   )r?   Rr   r   r   implX  s
    

z9TestExamples.test_type_coercion_from_update.<locals>.impl)r   )r   r@  r   r   r   r   test_type_coercion_from_updateV  s    
z+TestExamples.test_type_coercion_from_updateN)r   r   r   r  r>  rA  r   r   r   r   r=  J  s   r=  __main__)NZunittestcollectionsr   r0  r   mathr   sysZnumba.core.errorsr   numpyr   Znumba.core.compilerr   r   r   Znumbar   Z
numba.corer	   Znumba.tests.supportr
   r   r   r   r   r   r   r!   r"   r*   r,   r1   r5   r7   r:   r<   r@   rC   rD   rG   rI   rK   rM   rO   rQ   rT   rX   rY   rZ   r^   r`   rb   rd   re   rg   rj   rl   rn   ro   rt   rv   rx   ry   r|   r}   r   r   r  r  r  r  r  r  r2  r=  r   mainr   r   r   r   <module>   s   
			

6  DBC
