B
    '(b!=                 @   s@  d Z ddlmZmZmZmZmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZ ddlmZmZmZmZmZmZmZ ddlmZmZmZmZ dd	lm Z  G d
d de	Z!eeee"f  eee eee"  f dddZ#eeeeee"f f  eee eee"  f dddZ$G dd de	Z%G dd de	Z&dS )z/Test cases for type inference helper functions.    )ListOptionalTupleUnionDictSet)Suiteassert_equal)map_actuals_to_formals)group_comparison_operandsDisjointDict)Key)ArgKindARG_POSARG_OPTARG_STAR	ARG_STAR2	ARG_NAMEDNameExpr)AnyType	TupleTypeType	TypeOfAny)TypeFixturec               @   sT  e Zd ZdZddddZddddZdddd	Zddd
dZddddZddddZ	ddddZ
eedddZddddZddddZddddZddddZddddZdddd Zddd!d"Zddd#d$Zeeeef  eeeeeef f  eee  dd%d&d'Zee ee eee  edd(d)d*ZdS )+MapActualsToFormalsSuitez-Test cases for argmap.map_actuals_to_formals.N)returnc             C   s   |  g g g  d S )N)
assert_map)self r   B/home/dcms/DCMS/lib/python3.7/site-packages/mypy/test/testinfer.py
test_basic   s    z#MapActualsToFormalsSuite.test_basicc             C   s8   |  tgtgdgg |  ttgttgdgdgg d S )Nr      )r   r   )r   r   r   r   test_positional_only   s    

z-MapActualsToFormalsSuite.test_positional_onlyc             C   sF   |  g tgg g |  tgtgdgg |  tgttgdgg g d S )Nr   )r   r   r   )r   r   r   r   test_optional   s    
z&MapActualsToFormalsSuite.test_optionalc             C   sF   |  g tgg g |  tgtgdgg |  ttgtgddgg d S )Nr   r!   )r   r   r   )r   r   r   r   test_callee_star'   s    

z)MapActualsToFormalsSuite.test_callee_starc             C   sl   |  tgtgdgg |  ttgtgddgg |  tgttgdgdgg |  tgttgdgdgg d S )Nr   r!   )r   r   r   r   )r   r   r   r   test_caller_star2   s    

z)MapActualsToFormalsSuite.test_caller_starc             C   s:   |  tgg g  |  tgg g  |  tgtgdgg d S )Nr   )r   r   r   )r   r   r   r   test_too_many_caller_args@   s    z2MapActualsToFormalsSuite.test_too_many_caller_argsc          	   C   s|   t tj}| tgtgdgg| | | tgttgdgdgg| || | tgtttgdgdgg g| || d S )Nr   )r   r   special_formassert_vararg_mapr   r   tupler   )r   Zany_typer   r   r   test_tuple_starK   s     

z(MapActualsToFormalsSuite.test_tuple_star)argsr   c             G   s   t t|t jS )N)r   listr   Z	std_tuple)r   r+   r   r   r   r)   ]   s    zMapActualsToFormalsSuite.tuplec             C   sD   |  dgtdfgdgg |  ddgtdftdfgdgdgg d S )Nxr   yr!   )r   r   )r   r   r   r   test_named_args`   s    
z(MapActualsToFormalsSuite.test_named_argsc             C   s.   |  dgtdftdftdfgg dgg g d S )Nr.   r-   zr   )r   r   )r   r   r   r   test_some_named_argsj   s    z-MapActualsToFormalsSuite.test_some_named_argsc             C   s   |  dgtdfgg g d S )Nr.   r-   )r   r   )r   r   r   r   test_missing_named_argp   s    z/MapActualsToFormalsSuite.test_missing_named_argc             C   s"   |  ddgtdfgddgg d S )Nr-   r   r!   )r   r   )r   r   r   r   test_duplicate_named_argv   s    z1MapActualsToFormalsSuite.test_duplicate_named_argc             C   sD   |  tgttdfgdgg g |  tdgttdfgdgdgg d S )Nr-   r   r!   )r   r   r   )r   r   r   r   test_varargs_and_bare_asterisk|   s    

z7MapActualsToFormalsSuite.test_varargs_and_bare_asteriskc             C   sx   |  dgtgdgg |  dtgtgddgg |  dtgtdftgdgdgg |  ttgtdftgdgdgg d S )Nr-   r   r!   )r   r   r   )r   r   r   r   test_keyword_varargs   s     


z-MapActualsToFormalsSuite.test_keyword_varargsc             C   s.   |  ttgtdftdfgddgddgg d S )Nr-   r.   r   r!   )r   r   r   r   )r   r   r   r   test_both_kinds_of_varargs   s    z3MapActualsToFormalsSuite.test_both_kinds_of_varargsc             C   sr   |  tgttgdgg g |  ttgttgdgdgg |  tgtdftgdgdgg |  tgtgdgg d S )Nr   r!   r-   )r   r   r   r   )r   r   r   r   test_special_cases   s    

z+MapActualsToFormalsSuite.test_special_cases)caller_kinds_callee_kinds_expectedr   c       	      C   s:   t |\}}t|\}}t||||dd }t|| d S )Nc             S   s
   t tjS )N)r   r   r'   )ir   r   r   <lambda>       z5MapActualsToFormalsSuite.assert_map.<locals>.<lambda>)expand_caller_kindsexpand_callee_kindsr
   r	   )	r   r8   r9   r:   caller_kindsZcaller_namescallee_kindsZcallee_namesresultr   r   r   r      s    
z#MapActualsToFormalsSuite.assert_map)r@   rA   r:   vararg_typer   c                s&   t |g |g  fdd}t|| d S )Nc                s    S )Nr   )r;   )rC   r   r   r<      r=   z<MapActualsToFormalsSuite.assert_vararg_map.<locals>.<lambda>)r
   r	   )r   r@   rA   r:   rC   rB   r   )rC   r   r(      s    z*MapActualsToFormalsSuite.assert_vararg_map)__name__
__module____qualname____doc__r    r"   r#   r$   r%   r&   r*   r   r   r)   r/   r1   r2   r3   r4   r5   r6   r7   r   r   r   strr   intr   r(   r   r   r   r   r      s4   



r   )kinds_or_namesr   c             C   sR   g }g }x@| D ]8}t |tr2|t || q|| |d  qW ||fS )N)
isinstancerH   appendr   )rJ   kindsnameskr   r   r   r>      s    



r>   )kinds_and_namesr   c             C   sZ   g }g }xH| D ]@}t |tr:||d  ||d  q|| |d  qW ||fS )Nr   r!   )rK   r)   rL   )rP   rM   rN   vr   r   r   r?      s    


r?   c               @   s^   e Zd ZdZeeef dddZddddZdddd	Z	ddd
dZ
ddddZdS )OperandDisjointDictSuitezTTest cases for checker.DisjointDict, which is used for type inference with operands.)r   c             C   s   t  S )N)r   )r   r   r   r   new   s    zOperandDisjointDictSuite.newNc             C   s~   |   }|ddhdh |dddhdh |dd	d
hdh | | ddhdhfdddhdhfdd	d
hdhfg d S )Nr   r!   group1         group2         group3)rS   add_mappingassertEqualitems)r   dr   r   r   test_independent_maps   s    
z.OperandDisjointDictSuite.test_independent_mapsc             C   s   |   }|ddhdh |ddhdh |ddhdh |d	dhd
h |d	dhdh |ddhdh | | dddd	dhddd
dhfdddhddhfg d S )Nr   r!   rT   rU   rX   rV   rW   r\   rY   Zgroup4rZ   Zgroup5r[   Zgroup6)rS   r]   r^   r_   )r   r`   r   r   r   test_partial_merging   s    
z-OperandDisjointDictSuite.test_partial_mergingc             C   s   |   }|dddhdh |dddhdh |dd	d
hdh |dddhdh |dddhdh |ddhdh | | ddddddd	d
ddddhddddddhfg d S )Nr   r!   rU   arV   rW   b
         c         r`      ef)rS   r]   r^   r_   )r   r`   r   r   r   test_full_merging  s    
z*OperandDisjointDictSuite.test_full_mergingc          
   C   s   |   }|dddhdh |dddhdh |ddddhd	h |d
ddddhdh |d
ddddhdh | | ddddddd
hddd	ddhfg d S )Nr   r!   rU   rc   rV   rW   rY   rd   rh   rZ   r`   rm   )rS   r]   r^   r_   )r   r`   r   r   r   !test_merge_with_multiple_overlaps  s    
z:OperandDisjointDictSuite.test_merge_with_multiple_overlaps)rD   rE   rF   rG   r   rI   rH   rS   ra   rb   ro   rp   r   r   r   r   rR      s   rR   c               @   s   e Zd ZdZeeef eeef dddZddddZ	ddd	d
Z
ddddZddddZddddZddddZdS )OperandComparisonGroupingSuitez1Test cases for checker.group_comparison_operands.)assignable_operandsr   c             C   s,   i }x"|  D ]\}}d|jf||< qW |S )NZFakeExpr)r_   name)r   rr   outputindexexprr   r   r   literal_keymap!  s    z-OperandComparisonGroupingSuite.literal_keymapN)r   c       
   
   C   sl  t d}t d}t d}t d}t d}d||fd||fd||fd||fg}| i }| |||||d}x||gD ]}	| t||	t dd	d
gfdd
dgfdddgfdddgfg | t||	dhdd	d
dgfdddgfdddgfg | t||	dhdd	d
gfdd
dgfdddgfdddgfg | t||	ddhdd	d
dgfdddgfdddgfg qvW d S )Nx0x1x2x3x4z==<)r   r!   rU   rV   rW   r   r!   rU   rV   rW   )r   rw   r^   r   set)
r   rx   ry   rz   r{   r|   Zbasic_inputZnone_assignableZall_assignableZ
assignabler   r   r   test_basic_cases'  s*    $
.&.z/OperandComparisonGroupingSuite.test_basic_casesc          
   C   s  t d}t d}t d}t d}t d}t d}| td||fd||fd||fd||fg| i ddhdd	d
dgfddddgfg | td||fd||fd||fd||fg| i ddhdd	d
dddgfg | td||fd||fd||fd||fg| i ddhdd	d
gfdd
dddgfg | td||fd||fd||fd||fd||fg| i ddhdd	d
dgfdddgfddddgfg d S )Nrx   ry   rz   r{   r|   x5z==isr   r!   rU   rV   rW   r}   rY   )r   r^   r   rw   )r   rx   ry   rz   r{   r|   r   r   r   r   test_multiple_groupsG  s<    """*z3OperandComparisonGroupingSuite.test_multiple_groupsc       	      C   s>  t d}t d}t d}t d}t d}dddd	gfd
d	dgfddddgfg}dddd	dddgfd
d	dgfg}d||fd||fd
||fd||fd||fg}| t|| ||||||ddh|d | t|| ||||ddh|d | t|| ||||ddh|d | t|| ||ddh|d d S )Nrx   ry   rz   r{   r|   z==r   r!   rU   r}   rV   rW   rY   )r   r!   rU   rV   rW   rY   z/All vars are assignable, everything is combined)r!   rU   rV   rW   z#x0 is unassignable, so no combining)r   r!   rV   rY   z3Some vars are unassignable but x0 is, so we combine)r   rY   z2All vars are unassignable but x0 is, so we combine)r   r^   r   rw   )	r   rx   ry   rz   r{   r|   Znothing_combinedZeverything_combinedZ
two_groupsr   r   r   test_multiple_groups_coalescingp  sH    & ,z>OperandComparisonGroupingSuite.test_multiple_groups_coalescingc             C   s   t d}t d}t d}t d}d||fd||fd||fd||fg}| |||||d}| t||ddhddd	d
gfdd
ddgfgd d S )Nrx   ry   rz   r{   z==r   )r   r!   rU   rV   rW   r   r!   rU   rV   rW   z)Different operators can never be combined)r   rw   r^   r   )r   rx   ry   rz   r{   groupskeymapr   r   r   (test_multiple_groups_different_operators  s    $zGOperandComparisonGroupingSuite.test_multiple_groups_different_operatorsc       
      C   s   t d}t d}d||fg}dddgfg}i d|id|i||dg}t dhdhg}x8|D ]0}x*|D ]"}| |}	| t||	|| qdW qZW d S )Nrx   ry   z==r   r!   )r   r!   r   )r   r~   rw   r^   r   )
r   rx   ry   Zsingle_comparisonZexpected_outputZassignable_combinationsZto_group_byZcombo	operatorsr   r   r   r   test_single_pair  s    



z/OperandComparisonGroupingSuite.test_single_pairc             C   s0   |  tg i t g  |  tg i dhg  d S )Nz==)r^   r   r~   )r   r   r   r   test_empty_pair_list  s    z3OperandComparisonGroupingSuite.test_empty_pair_list)rD   rE   rF   rG   r   rI   r   r   rw   r   r   r   r   r   r   r   r   r   r   rq     s     )3rq   N)'rG   typingr   r   r   r   r   r   Zmypy.test.helpersr   r	   Zmypy.argmapr
   Zmypy.checkerr   r   Zmypy.literalsr   Z
mypy.nodesr   r   r   r   r   r   r   Z
mypy.typesr   r   r   r   Zmypy.test.typefixturer   r   rH   r>   r?   rR   rq   r   r   r   r   <module>   s     $ =""9