a
    zep                     @   s   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
mZmZmZmZ d dlmZ d dlmZ G dd deZG dd dejZG d	d
 d
ejZG dd dejZG dd dejZG dd dejZedkre  dS )    N)
call_Callcreate_autospec	MagicMockMockANY	_CallListpatchPropertyMock	_callable)datetimepartialc                   @   s&   e Zd Zdd Zdd ZdddZdS )		SomeClassc                 C   s   d S N selfabr   r   8/usr/lib/python3.9/unittest/test/testmock/testhelpers.pyone       zSomeClass.onec                 C   s   d S r   r   r   r   r   r   two   r   zSomeClass.twoNc                 C   s   d S r   r   r   r   r   r   r   three   r   zSomeClass.three)N)__name__
__module____qualname__r   r   r   r   r   r   r   r      s   r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )AnyTestc                 C   sF   |  tt  t }|t |t t }|td |jtd d S Nfoo)assertEqualr   objectr   assert_called_withr   mockr   r   r   test_any   s    

zAnyTest.test_anyc                 C   s$   |  ttd |  ttd d S )Nz<ANY>)r$   reprr   strr   r   r   r   	test_repr"   s    zAnyTest.test_reprc                 C   s,   t  }|t t d |jttd d S r!   )r   r   nowr&   r   r'   r   r   r   test_any_and_datetime'   s    zAnyTest.test_any_and_datetimec                 C   s   t  }G dd dt}t | fD ]}|  ||||d |j|||d | j||d ttttdtjtttdt t jttdg}| ||j	 | |j	| q$d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z9AnyTest.test_any_mock_calls_comparison_order.<locals>.Fooc                 S   s   d S r   r   r   otherr   r   r   __eq__1   r   z@AnyTest.test_any_mock_calls_comparison_order.<locals>.Foo.__eq__c                 S   s   d S r   r   r/   r   r   r   __ne__2   r   z@AnyTest.test_any_mock_calls_comparison_order.<locals>.Foo.__ne__N)r   r   r   r1   r2   r   r   r   r   Foo0   s   r3   r#   bar)Zzingaalpha)Za1Zz99)
r   r%   r   r-   
reset_mockmethodr   r   r$   
mock_calls)r   r(   r3   dexpectedr   r   r   $test_any_mock_calls_comparison_order.   s    z,AnyTest.test_any_mock_calls_comparison_orderc                 C   sN   G dd d}t  }|| d |ttdg |td |td d S )Nc                   @   s   e Zd Zdd ZdS )z%AnyTest.test_any_no_spec.<locals>.Fooc                 S   s   d S r   r   r/   r   r   r   r1   F   r   z,AnyTest.test_any_no_spec.<locals>.Foo.__eq__Nr   r   r   r1   r   r   r   r   r3   E   s   r3      r   assert_has_callsr   r   r&   assert_any_callr   r3   r(   r   r   r   test_any_no_specC   s    zAnyTest.test_any_no_specc                 C   sR   G dd d}t |d}|| d |ttdg |td |td d S )Nc                   @   s   e Zd Zdd ZdS )z*AnyTest.test_any_and_spec_set.<locals>.Fooc                 S   s   d S r   r   r/   r   r   r   r1   Q   r   z1AnyTest.test_any_and_spec_set.<locals>.Foo.__eq__Nr=   r   r   r   r   r3   P   s   r3   )specr>   r?   rB   r   r   r   test_any_and_spec_setN   s    
zAnyTest.test_any_and_spec_setN)	r   r   r   r)   r,   r.   r<   rC   rE   r   r   r   r   r       s   r    c                   @   s   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+S ),CallTestc                 C   s  t  }| |t   | |t d | |t d | |t i f | |t d | |t di f | |t ddi f | |t d | |t d | |t di f | |t d	di f t d
}| |t d
 | |t d | |t di f | |t ddi f t d}| |t d | |t ddi f t d}| |t d | |t ddi f | |t d | |t ddi f t ddif}| |t ddddif | |t dddif | |t dddif | |t ddif d S )N) r   )rG   r   rG   r   r"   r5   r   bazZspamr>         )rG   rL   rL   )r>   rM      )r#   rO   )rG   rO   rO   )r5   rO   r5   r   rN   r   r$   assertNotEqual)r   kallr   r   r   test_call_with_call\   s<    zCallTest.test_call_with_callc                 C   sj   t  }| |d | |d | |d | |d | |ddi f | |di f | |i f d S )Nr   r"   rH   r#   r   r#   )r   r$   r   argsr   r   r   test_empty__Call   s    zCallTest.test_empty__Callc                 C   s   t ddi f}| |d | |d | |ddi f | |di f | |d | |d | |i f | |d | |d | |di f d S )	Nr#   r   r"   rU   rH   )r5   rI   r5   rQ   rV   r   r   r   test_named_empty_call   s    zCallTest.test_named_empty_callc                 C   sf   t di f}| |d | |d | |ddi f | |di f | |jd | |ji  d S )NrL   rK   r#   rL   r#   )r   r$   rW   kwargsrV   r   r   r   test_call_with_args   s    zCallTest.test_call_with_argsc                 C   sh   t ddi f}| |d | |ddi f | |jd | |ji  | |d | |di f d S )Nr#   rL   rZ   rK   )r   r$   rW   r[   rR   rV   r   r   r   test_named_call_with_args   s    z"CallTest.test_named_call_with_argsc              	   C   s   t dtdddf}| |tdddf | |dtdddf | |ddtdddf | |dtdddf | |jd | |jtddd d S )Nr   rN   rP   r   r   r#   )r   dictr$   rW   r[   rV   r   r   r   test_call_with_kwargs   s    zCallTest.test_call_with_kwargsc              	   C   s   t ddtdddf}| |dtdddf | |ddtdddf | |jd | |jtddd | |tdddf | |dtdddf d S )Nr#   r   rN   rP   r^   )r   r_   r$   rW   r[   rR   rV   r   r   r   test_named_call_with_kwargs   s    z$CallTest.test_named_call_with_kwargsc                 C   sN   t di f}| |tddd | tddd| | tddd|g d S )NrL   r>   rM   rN   )r   r$   r   assertInrV   r   r   r   #test_call_with_args_call_empty_name   s    z,CallTest.test_call_with_args_call_empty_namec                 C   sR   |  tdtdd | tdtdddk | tdi ftdddk d S )NrK   r>   rM   rN   r>   rM   )rR   r   r   assertFalse
assertTruer   r   r   r   test_call_ne   s    zCallTest.test_call_nec                 C   s8   t d}dd | tfD ]}| || | ||k qd S )NrK   r>   )r   intrR   re   )r   rS   valuer   r   r   test_call_non_tuples   s    zCallTest.test_call_non_tuplesc                 C   s^  |  tt d |  ttdd |  ttdddifd |  ttddddifd	 |  ttd
 |  ttd
 |  tt d |  ttdd |  ttddd |  tt jd |  ttdjjddjd |  tt jddddd |  tt  d |  ttddd |  tt   j	dd d S )Nzcall()r"   z
call.foo()rL   r   r   zcall(1, 2, 3, a='b')r5   zcall.bar(1, 2, 3, a='b')r   r>   zcall(1)thing)zzzcall(zz='thing')z
call().foorN   r   zcall().foo.bar().bingrM   zcall().foo(1, 2, a=3)zcall()()z	call()(2)zcall()().bar().baz.beep(1))
r$   r*   r   r   r+   r#   r5   bingrJ   beepr   r   r   r   r,      s6    zCallTest.test_reprc                 C   s|   |  t ddi f |  tddddddddddf t }|d	d
d |ddd |  |jtd	d
dtdddg d S )NrG   r   r#   r5   rN   rP   )r   r   r4   r>   rM      r^   )r$   r   r   call_args_listr'   r   r   r   	test_call   s    zCallTest.test_callc                 C   s   |  tdddi f |  tjjddddddif t }|dd	d
 |jjd
dd |  |jtdd	d
tjjd
ddg d S )Nr>   r#   )r>   Zeggs)fishzbar.bazr   rs   rM   rN   rp   r^   )r$   r   r#   r5   rJ   r   method_callsr'   r   r   r   test_attribute_call
  s    zCallTest.test_attribute_callc              	   C   s  t ddjddd}| |ddtddf t }|ddddd | |jt ddddd | |jt ddd | |jt dddddg | |j	t dddddg t }|d  j
jd	d t d  j
jd	d}| |j	d
 | | |j	|  d S )Nr>   rM   rN   rP   rm   z().foo().bar)rN   r^   rp   )r   r#   r5   r$   r_   r   Z	call_argsrR   rq   r9   rJ   ro   	call_list)r   resultr(   Z	last_callr   r   r   test_extended_call  s    zCallTest.test_extended_callc                 C   s@   t ddj}t ddj}| || | || | || d S Nr>   xrM   )r   r#   r$   rR   r   r   r   r   test_extended_not_equal*  s
    z CallTest.test_extended_not_equalc                 C   sH   t dd j}t dd j}| || | || | || d S rz   )r   r#   r5   r$   rR   r   r   r   r   test_nested_calls_not_equal2  s
    z$CallTest.test_nested_calls_not_equalc                 C   s   t  }|d | td |j t  }|dd | tdd |j t  }|ddd | tddd |j t  }t|dddjj	dd tdddjj	dd
 }| | |j d S )Nr>   rM   rN   rP      )r   r$   r   rw   r9   r8   rh   r#   r5   rJ   __int__)r   r(   rS   r   r   r   test_call_list:  s"    $$zCallTest.test_call_listc                 C   s>   |  tt t }t| |  |jtg |  tg|j d S r   )r$   r   r   r   rh   r9   r   mr   r   r   test_call_anyO  s
    zCallTest.test_call_anyc                 C   sh   t dddifdd}| t|d | |d d | |d ddi t dddif}| || d S )	Nrd   r   rN   T)r   rM   r   r>   )r   r$   len)r   rW   Z
other_argsr   r   r   test_two_args_callX  s    zCallTest.test_two_args_callc                 C   sJ   |  tddd d |  tdd d |  tdddifd d d S )	Nr   r#   r   )r5   ZbarzrG   r   ZhelloZworld)r$   r   r   r   r   r   test_call_with_namea  s    zCallTest.test_call_with_namec              	   C   s   t  }|  d   | |jt t  t  dt    g t  }d|  d< | |jt t  t  ddg t  }t|   | |jt t  t   g d S )Nr5   r>   )	r   r#   r$   r9   r   __getitem____setitem__iter__iter__r   r   r   r   test_dunder_callf  s$    *zCallTest.test_dunder_callN)r   r   r   rT   rX   rY   r\   r]   r`   ra   rc   rg   rj   r,   rr   ru   ry   r}   r~   r   r   r   r   r   r   r   r   r   rF   Z   s*   %		rF   c                   @   s<  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(dMS )NSpecSignatureTestc                 C   s   |  tt|d |dd |jdd |  t|jjdd |  t|jd |  |j  |  t|jjd |  t|jd |  |j  |  t|jjd |  t|jdd |d |jd |jdd |jjdd d S )Nr#   r>   rM   rN   rP   rm   )	assertRaisesAttributeErrorgetattrr   r&   AssertionError	TypeErrorr   r   r'   r   r   r   _check_someclass_mock}  s.    



z'SpecSignatureTest._check_someclass_mockc                 C   s*   t t}| | t t }| | d S r   )r   r   r   r'   r   r   r   
test_basic  s    

zSpecSignatureTest.test_basicc                 C   sP   dd }t |dd}| | d G dd dt}t |dd}| | d d S )Nc                   S   s   d S r   r   r   r   r   r   f  r   z>SpecSignatureTest.test_create_autospec_return_value.<locals>.fr#   return_valuec                   @   s   e Zd ZdS )z@SpecSignatureTest.test_create_autospec_return_value.<locals>.FooNr   r   r   r   r   r   r   r3     s   r3   )r   r$   r%   )r   r   r(   r3   r   r   r   !test_create_autospec_return_value  s    z3SpecSignatureTest.test_create_autospec_return_valuec                 C   s,   t t}t| |  | |jjd d S )Nr   )r   rh   r7   r$   r   Z
call_countr   r   r   r   test_autospec_reset_mock  s    z*SpecSignatureTest.test_autospec_reset_mockc                 C   s>   G dd dt }t |d}| }| d |d d S )Nc                   @   s   e Zd Zdd ZdS )z;SpecSignatureTest.test_mocking_unbound_methods.<locals>.Fooc                 S   s   d S r   r   )r   r#   r   r   r   r#     r   z?SpecSignatureTest.test_mocking_unbound_methods.<locals>.Foo.fooNr   r   r   r#   r   r   r   r   r3     s   r3   r#   r>   )r%   r	   startr#   r&   )r   r3   pZmock_foor   r   r   test_mocking_unbound_methods  s
    z.SpecSignatureTest.test_mocking_unbound_methodsc                 C   s.   G dd dt }t|dd}| |jd d S )Nc                   @   s   e Zd ZdZdS )zESpecSignatureTest.test_create_autospec_keyword_arguments.<locals>.FoorN   Nr   r   r   r   r   r   r   r   r3     s   r3   3rm   )r%   r   r$   r   )r   r3   r   r   r   r   &test_create_autospec_keyword_arguments  s    z8SpecSignatureTest.test_create_autospec_keyword_argumentsc                 C   sV   d ddd}t |}|d |d | t|dd |ddd |jddd d S )Nr   c                S   s   d S r   r   r^   r   r   r   r#     r   zJSpecSignatureTest.test_create_autospec_keyword_only_arguments.<locals>.foor>   rM   rN   )r   r&   r   r   )r   r#   r   r   r   r   +test_create_autospec_keyword_only_arguments  s    
z=SpecSignatureTest.test_create_autospec_keyword_only_argumentsc                 C   s6   t  }dd }||_t|}|d |jd d S )Nc                 S   s   d S r   r   rm   r   r   r   r     r   z@SpecSignatureTest.test_function_as_instance_attribute.<locals>.frn   )r   r   r   r&   )r   objr   r(   r   r   r   #test_function_as_instance_attribute  s    
z5SpecSignatureTest.test_function_as_instance_attributec                 C   sv   t g }|d |jd | tt|d G dd dt}t |}|jd |jjd | tt|jd d S )Nr#   c                   @   s   e Zd Zg ZdS )z0SpecSignatureTest.test_spec_as_list.<locals>.FooNr   r   r   r   r   r3     s   r3   rN   )r   appendr&   r   r   r   r%   r#   )r   r(   r3   r   r   r   test_spec_as_list  s    
z#SpecSignatureTest.test_spec_as_listc                 C   s6   G dd dt }t|}||jfD ]}| | q"d S )Nc                   @   s   e Zd Ze ZdS )z.SpecSignatureTest.test_attributes.<locals>.SubNr   r   r   r   attrr   r   r   r   Sub  s   r   )r   r   r   r   )r   r   Zsub_mockr(   r   r   r   test_attributes  s    z!SpecSignatureTest.test_attributesc                    s   G dd dt  G  fdddt }t|}|d | t |  W d    n1 s^0    Y  | t |dd W d    n1 s0    Y  d S )Nc                   @   s   e Zd Zdd ZdS )zVSpecSignatureTest.test_spec_has_descriptor_returning_function.<locals>.CrazyDescriptorc                 S   s   |d u rdd S d S )Nc                 S   s   d S r   r   r{   r   r   r   <lambda>  r   zpSpecSignatureTest.test_spec_has_descriptor_returning_function.<locals>.CrazyDescriptor.__get__.<locals>.<lambda>r   )r   r   type_r   r   r   __get__  s    z^SpecSignatureTest.test_spec_has_descriptor_returning_function.<locals>.CrazyDescriptor.__get__Nr   r   r   r   r   r   r   r   CrazyDescriptor  s   r   c                       s   e Zd Z  ZdS )zNSpecSignatureTest.test_spec_has_descriptor_returning_function.<locals>.MyClassN)r   r   r   	some_attrr   r   r   r   MyClass  s   r   r>   rM   )r%   r   r   r   r   )r   r   r(   r   r   r   +test_spec_has_descriptor_returning_function  s    
&z=SpecSignatureTest.test_spec_has_descriptor_returning_functionc                    s   G  fdddt    }| t |j W d    n1 s@0    Y  | |dd t|}|d | t |  W d    n1 s0    Y  | t |dd W d    n1 s0    Y  d S )Nc                       s&   e Zd Z fddZdd Z  ZS )zISpecSignatureTest.test_spec_has_function_not_in_bases.<locals>.CrazyClassc                    s   t  |  dg S )Ncrazy)super__dir__r   )
CrazyClass	__class__r   r   r     s    zQSpecSignatureTest.test_spec_has_function_not_in_bases.<locals>.CrazyClass.__dir__c                 S   s   |dkrdd S t |d S )Nr   c                 S   s   | S r   r   r{   r   r   r   r     r   zgSpecSignatureTest.test_spec_has_function_not_in_bases.<locals>.CrazyClass.__getattr__.<locals>.<lambda>r   )r   itemr   r   r   __getattr__  s    zUSpecSignatureTest.test_spec_has_function_not_in_bases.<locals>.CrazyClass.__getattr__)r   r   r   r   r   __classcell__r   r   )r   r   r     s   r   *   r>   rM   )r%   r   r   r0   r$   r   r   r   )r   instr(   r   r   r   #test_spec_has_function_not_in_bases	  s    
$
&z5SpecSignatureTest.test_spec_has_function_not_in_basesc                 C   s   G dd dt }t|}|d |jd | tt|jd |d |jd | t|jdd | tt|jd |	ddg |j	ddg | tt|j	d |j
d |j
jd | tt|j
d d S )Nc                   @   s   e Zd Zdd ZeZi ZdS )zGSpecSignatureTest.test_builtin_functions_types.<locals>.BuiltinSubclassc                 S   s   d S r   r   )r   argr   r   r   r5   '  r   zKSpecSignatureTest.test_builtin_functions_types.<locals>.BuiltinSubclass.barN)r   r   r   r5   sortedr   r   r   r   r   BuiltinSubclass&  s   r   rN   r#   r5   r>   rM   )listr   r   r&   r   r   r   r5   r   r   r   popr   r   r(   r   r   r   test_builtin_functions_types"  s    

z.SpecSignatureTest.test_builtin_functions_typesc                 C   s   G dd dt }t|}|dd |  |d tddt tdg}| |j| |jdd |j  |jd |	tjddtj tjdg | |j| d S )Nc                   @   s   e Zd Ze ZdS )z0SpecSignatureTest.test_method_calls.<locals>.SubNr   r   r   r   r   r   ?  s   r   r>   rM   rN   )
r   r   r   r   r   r   r$   rt   r   extend)r   r   r(   r;   r   r   r   test_method_calls>  s    

 z#SpecSignatureTest.test_method_callsc                 C   s|   G dd dt }t|}| t |g  | tt| | tt|j | t |g  | |d t | |jd t d S )Nc                   @   s   e Zd Zi ZdS )z=SpecSignatureTest.test_magic_methods.<locals>.BuiltinSubclassN)r   r   r   r   r   r   r   r   r   U  s   r   r#   )	r   r   r$   r   r   rh   r   assertIsInstancer   r   r   r   r   test_magic_methodsT  s    z$SpecSignatureTest.test_magic_methodsc                 C   s`   G dd dt }|| fD ]@}t|dd}| | | tt|dd | tt|jdd qd S )Nc                   @   s   e Zd Ze ZdS )z,SpecSignatureTest.test_spec_set.<locals>.SubNr   r   r   r   r   r   c  s   r   T)Zspec_setr#   r5   )r   r   r   r   r   setattrr   )r   r   rD   r(   r   r   r   test_spec_setb  s    
zSpecSignatureTest.test_spec_setc                 C   s   G dd dt }G dd d|}G dd dt|}|| || || fD ]@}t|}|dd |jdd |d	d
 |jd	d
 qHd S )Nc                   @   s$   e Zd Zedd Zedd ZdS )z/SpecSignatureTest.test_descriptors.<locals>.Fooc                 S   s   d S r   r   )clsr   r   r   r   r   r   p  s    z1SpecSignatureTest.test_descriptors.<locals>.Foo.fc                 S   s   d S r   r   r^   r   r   r   gr  s    z1SpecSignatureTest.test_descriptors.<locals>.Foo.gN)r   r   r   classmethodr   staticmethodr   r   r   r   r   r3   o  s   
r3   c                   @   s   e Zd ZdS )z/SpecSignatureTest.test_descriptors.<locals>.BarNr   r   r   r   r   Baru  r   r   c                   @   s   e Zd ZdS )z/SpecSignatureTest.test_descriptors.<locals>.BazNr   r   r   r   r   Bazw  r   r   r>   rM   rN   rP   )r%   r   r   r   assert_called_once_withr   )r   r3   r   r   rD   r(   r   r   r   test_descriptorsn  s    z"SpecSignatureTest.test_descriptorsc                 C   s   G dd dt }||_t|}|  | |jj |  |j  | |jt tj g | 	|j
|j | |j
|j |j
  | t|jjj d S )Nc                   @   s   e Zd Zdd ZdZeZdS )z+SpecSignatureTest.test_recursive.<locals>.Ac                 S   s   d S r   r   r   r   r   r   r     r   z-SpecSignatureTest.test_recursive.<locals>.A.azfoo bar bazN)r   r   r   r   r#   r5   r   r   r   r   A  s   r   )r%   Br   re   Zcalledr   r$   rt   r   ZassertIsr#   r5   assertIsNotlowerr   r   r&   )r   r   r(   r   r   r   test_recursive  s    

z SpecSignatureTest.test_recursivec                 C   s^  G dd dt }t|}| ||  || fD ]L}|jdd |jjdd |jd | t|jdd | tt|d q0t| }|d |jd |jjdd | t|jdd | tt|d | t| |j	
d |j	j
d |j	j
jdd	 | tt|j	d
 |	 
d |	 j
d |	 j
jdd	 | tt|	 d
 d S )Nc                   @   s$   e Zd Zdd ZG dd deZdS )z@SpecSignatureTest.test_spec_inheritance_for_classes.<locals>.Fooc                 S   s   d S r   r   )r   r|   r   r   r   r     r   zBSpecSignatureTest.test_spec_inheritance_for_classes.<locals>.Foo.ac                   @   s   e Zd Zdd ZdS )zDSpecSignatureTest.test_spec_inheritance_for_classes.<locals>.Foo.Barc                 S   s   d S r   r   )r   yr   r   r   r     r   zFSpecSignatureTest.test_spec_inheritance_for_classes.<locals>.Foo.Bar.fNr   r   r   r   r   r   r   r   r     s   r   N)r   r   r   r   r%   r   r   r   r   r   r3     s   r3   r   r{   r#   r5   r   rp   )r   r   )r%   r   r   r   r&   r   r   r   r   r   r   )r   r3   Z
class_mockZ	this_mockZinstance_mockr   r   r   !test_spec_inheritance_for_classes  s0    

z3SpecSignatureTest.test_spec_inheritance_for_classesc                 C   s   G dd dt }||_t|}| }| tt|d | }| tt|d t| }| tt|d | t| | }| tt|d d S )Nc                   @   s   e Zd ZdZdS )z+SpecSignatureTest.test_inherit.<locals>.FoorN   Nr   r   r   r   r   r3     s   r3   r   )r%   r3   r   r   r   r   r   )r   r3   r(   instanceZattr_instanceZcall_resultr   r   r   test_inherit  s    
zSpecSignatureTest.test_inheritc                 C   s   t d t t t d t t t i  t t t g  t t t t  t t t d t t t d t t t d t d d S )Nr>   r#   g      ?y              ?FT)r   rh   r+   r_   r   setfloatcomplexr   r   r   r   test_builtins  s     
zSpecSignatureTest.test_builtinsc                 C   s   dd }t |}| t| |dd |dd |jddd |jddd ||_t |}| t|j |dd |jdd |jjddd d S )	Nc                 S   s   d S r   r   r^   r   r   r   r     r   z*SpecSignatureTest.test_function.<locals>.fr>   rM   r   r^   rN   rP   )r   r   r   r&   r   r   r   r(   r   r   r   test_function  s    
zSpecSignatureTest.test_functionc                    s   G dd dt  G  fdddt }| |ddd t|| tfdd	 | ddjj | tfd
d	 j}|j	|j
f d S )Nc                   @   s   e Zd ZdddZdS )z;SpecSignatureTest.test_skip_attributeerrors.<locals>.RaiserNc                 S   s   |d u rt dd S )Nz$Can only be accessed via an instancer   )r   r   typer   r   r   r     s    zCSpecSignatureTest.test_skip_attributeerrors.<locals>.Raiser.__get__)Nr   r   r   r   r   Raiser  s   r   c                       s   e Zd Z  Zedd ZdS )z@SpecSignatureTest.test_skip_attributeerrors.<locals>.RaiserClassc                 S   s   | | S r   r   r^   r   r   r   existing  s    zISpecSignatureTest.test_skip_attributeerrors.<locals>.RaiserClass.existingN)r   r   r   raiserr   r   r   )r   r   r   RaiserClass  s   r   r>   rM   rN   c                    s     dddS )Nr>   rM   rN   )r   r{   sr   r   r     r   z=SpecSignatureTest.test_skip_attributeerrors.<locals>.<lambda>c                      s    j S r   )Znonexistingr   r   r   r   r     r   )r%   r$   r   r   r   r   r   r   r   r#   r5   )r   r   r   r   )r   r   r   test_skip_attributeerrors  s    z+SpecSignatureTest.test_skip_attributeerrorsc                 C   s   G dd dt }t|}| t| |d |d |jdd | t|jd |dd |dd |jddd | jt|jddd d S )	Nc                   @   s   e Zd ZdddZdS )z3SpecSignatureTest.test_signature_class.<locals>.FoorN   c                 S   s   d S r   r   r   r   r   r   __init__  r   z<SpecSignatureTest.test_signature_class.<locals>.Foo.__init__N)rN   r   r   r   r   r   r   r   r   r3     s   r3   r>   rm   rM   rP   r   r^   )r%   r   r   r   r   r   r&   rB   r   r   r   test_signature_class  s    

z&SpecSignatureTest.test_signature_classc                 C   s   G dd dt }t| d S )Nc                   @   s   e Zd ZdS )z6SpecSignatureTest.test_class_with_no_init.<locals>.FooNr   r   r   r   r   r3   *  s   r3   )r%   r   )r   r3   r   r   r   test_class_with_no_init'  s    z)SpecSignatureTest.test_class_with_no_initc                 C   s   G dd dt }t|}|dd |dd |jddd | t|d |dd}| t| |dd |d |jdd |d |d |jdd t|dd}|dd |jdd | t| |d |d d S )Nc                   @   s   e Zd Zdd Zdd ZdS )z;SpecSignatureTest.test_signature_callable.<locals>.Callablec                 S   s   d S r   r   )r   r|   r   r   r   r   r   1  r   zDSpecSignatureTest.test_signature_callable.<locals>.Callable.__init__c                 S   s   d S r   r   r   r   r   r   __call__2  r   zDSpecSignatureTest.test_signature_callable.<locals>.Callable.__call__N)r   r   r   r   r   r   r   r   r   Callable0  s   r   r>   rM   r|   r   r   rm   )r%   r   r   r   r   r&   )r   r   r(   r   r   r   r   test_signature_callable/  s(    





z)SpecSignatureTest.test_signature_callablec                 C   sv   G dd dt }t|}| }|  | t|d | t| | t|d t| }| t| | t|d d S )Nc                   @   s   e Zd Zdd ZdS )zASpecSignatureTest.test_signature_noncallable.<locals>.NonCallablec                 S   s   d S r   r   r   r   r   r   r   M  s    zJSpecSignatureTest.test_signature_noncallable.<locals>.NonCallable.__init__Nr   r   r   r   r   NonCallableL  s   r   r   )r%   r   r   r   r   )r   r   r(   r   r   r   r   test_signature_noncallableK  s    
z,SpecSignatureTest.test_signature_noncallablec                 C   sD   G dd dt }t|}|j}| |td  |  |j  d S )Nc                   @   s   e Zd ZdZdS )z8SpecSignatureTest.test_create_autospec_none.<locals>.FooN)r   r   r   r5   r   r   r   r   r3   ]  s   r3   )r%   r   r5   assertNotIsInstancer   r#   r   )r   r3   r(   Znoner   r   r   test_create_autospec_none\  s    z+SpecSignatureTest.test_create_autospec_nonec                 C   sf   G dd dt }t|}|d |jd |jjdd |jdd |jd |jjdd d S )Nc                   @   s   e Zd Zdd ZdS )zMSpecSignatureTest.test_autospec_functions_with_self_in_odd_place.<locals>.Fooc                 S   s   d S r   r   )r   r   r   r   r   r   j  r   zOSpecSignatureTest.test_autospec_functions_with_self_in_odd_place.<locals>.Foo.fNr   r   r   r   r   r3   i  s   r3   
   r   )r%   r   r   r&   )r   r3   r   r   r   r   .test_autospec_functions_with_self_in_odd_placeh  s    
z@SpecSignatureTest.test_autospec_functions_with_self_in_odd_placec                    sv   G dd dt  G dd dtG  fdddt }t|}fdd}||j ||j ||j ||j d S )	Nc                   @   s&   e Zd Zdd ZdddZdd ZdS )	zCSpecSignatureTest.test_autospec_data_descriptor.<locals>.Descriptorc                 S   s
   || _ d S r   )ri   )r   ri   r   r   r   r   w  s    zLSpecSignatureTest.test_autospec_data_descriptor.<locals>.Descriptor.__init__Nc                 S   s   | S r   r   )r   r   r   r   r   r   r   z  s    zKSpecSignatureTest.test_autospec_data_descriptor.<locals>.Descriptor.__get__c                 S   s   d S r   r   )r   r   ri   r   r   r   __set__}  r   zKSpecSignatureTest.test_autospec_data_descriptor.<locals>.Descriptor.__set__)N)r   r   r   r   r   r   r   r   r   r   
Descriptorv  s   
r   c                   @   s   e Zd ZdS )zCSpecSignatureTest.test_autospec_data_descriptor.<locals>.MyPropertyNr   r   r   r   r   
MyProperty  s   r   c                       s2   e Zd ZdgZedd Zdd Z dZdS )z<SpecSignatureTest.test_autospec_data_descriptor.<locals>.Fooslotc                 S   s   d S r   r   r   r   r   r   prop  s    zASpecSignatureTest.test_autospec_data_descriptor.<locals>.Foo.propc                 S   s   d S r   r   r   r   r   r   subprop  s    zDSpecSignatureTest.test_autospec_data_descriptor.<locals>.Foo.subpropr   N)r   r   r   	__slots__propertyr  r  descr   )r   r   r   r   r3     s   

r3   c                    sH     | t | ddd | ddd | ddd | jddd d S )Nr>   rM   rN   rP   r   rp   )r   r   abcr   )Z	mock_attrr   r   r   check_data_descriptor  s
    zNSpecSignatureTest.test_autospec_data_descriptor.<locals>.check_data_descriptor)r%   r  r   r  r  r  r  )r   r3   r#   r  r   )r   r   r   r   test_autospec_data_descriptoru  s    		


z/SpecSignatureTest.test_autospec_data_descriptorc                 C   s\   t tjt }| | t t|}|  |  |  |ddd |ddd d S )NrP   r   rp   )	types
MethodTypetimectimer   r+   r   r   r7   )r   methZmockedr   r   r   'test_autospec_on_bound_builtin_function  s    z9SpecSignatureTest.test_autospec_on_bound_builtin_functionc                 C   s0   G dd d}| }t |}| t|d d S )Nc                   @   s   e Zd Zdd ZdS )zESpecSignatureTest.test_autospec_getattr_partial_function.<locals>.Fooc                 S   s   t dd |S )Nc                 S   s   | S r   r   )namer   r   r   r     r   zcSpecSignatureTest.test_autospec_getattr_partial_function.<locals>.Foo.__getattr__.<locals>.<lambda>r   )r   Z	attributer   r   r   r     s    zQSpecSignatureTest.test_autospec_getattr_partial_function.<locals>.Foo.__getattr__N)r   r   r   r   r   r   r   r   r3     s   r3   r   )r   re   hasattr)r   r3   proxyZautospecr   r   r   &test_autospec_getattr_partial_function  s    z8SpecSignatureTest.test_autospec_getattr_partial_functionc                 C   sp   dd }t |}|dd |ddd | t|t| | |jtddtdddg | t|d d S )Nc                 S   s   d S r   r   r   r   r   r   myfunc  r   z=SpecSignatureTest.test_spec_inspect_signature.<locals>.myfuncr>   rM   r   )r   r$   inspect	signaturer9   r   r   r   )r   r  r(   r   r   r   test_spec_inspect_signature  s    
 z-SpecSignatureTest.test_spec_inspect_signaturec                 C   s   dt t t t ddd}| |ddddd	 t|}|dddd |ddd | t|t| | |jtddddtdddg | t|d | jt|dddd
d d S )Nr   )r   r   creturnc                S   s   | | | S r   r   )r   r   r  r   r   r   r#     s    zFSpecSignatureTest.test_spec_inspect_signature_annotations.<locals>.foor>   rM   rN   )r  rp   rP   )r   )	rh   r$   r   r  r  r9   r   r   r   )r   r#   r(   r   r   r   'test_spec_inspect_signature_annotations  s    $z9SpecSignatureTest.test_spec_inspect_signature_annotationsc                 C   s"   dd }t |}| |jd d S )Nc                   S   s   dS )NZnoper   r   r   r   r   r     r   z>SpecSignatureTest.test_spec_function_no_name.<locals>.<lambda>Zfuncopy)r   r$   r   )r   funcr(   r   r   r   test_spec_function_no_name  s    z,SpecSignatureTest.test_spec_function_no_namec                 C   sf   dd }t |}|d |tdg | t  |tdg W d    n1 sX0    Y  d S )Nc                 S   s   d S r   r   rm   r   r   r   r     r   z@SpecSignatureTest.test_spec_function_assert_has_calls.<locals>.fr>   rM   )r   r@   r   r   r   r   r   r   r   #test_spec_function_assert_has_calls  s    z5SpecSignatureTest.test_spec_function_assert_has_callsc                 C   sZ   dd }t |}|d |d | t |d W d    n1 sL0    Y  d S )Nc                 S   s   d S r   r   rm   r   r   r   r     r   z?SpecSignatureTest.test_spec_function_assert_any_call.<locals>.fr>   rM   )r   rA   r   r   r   r   r   r   "test_spec_function_assert_any_call  s    
z4SpecSignatureTest.test_spec_function_assert_any_callc                 C   sv   dd }t  }t||d}|dd | |jtdg | |jtdg |  | |jg  | |jg  d S )Nc                 S   s   d S r   r   rm   r   r   r   r     r   z:SpecSignatureTest.test_spec_function_reset_mock.<locals>.fr   r>   rM   )r   r   r$   r9   r   r7   )r   r   rvr(   r   r   r   test_spec_function_reset_mock  s    z/SpecSignatureTest.test_spec_function_reset_mockN))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   {  sL   


&,		r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestCallListc                 C   s  t  }| |jt |dd |dd |dd |dd tddtddtddtddfD ]}| ||j q`tddtddg}| ||j tddtddg}| ||j tddtddg}| ||j tddg}| ||j | td|j | tdg|j d S )	Nr>   rM   rN   rm   rP   rp   r   rs   )r   r   rq   r   r   rb   ZassertNotIn)r   r(   rS   Zcallsr   r   r   !test_args_list_contains_call_list  s$    



(z.TestCallList.test_args_list_contains_call_listc                 C   sJ   t  }|dd |jdd |j jddd d}| t|j| d S )	Nr>   rM   rN   rm   rs   Zdog)catzU[call(1, 2),
 call.foo(a=3),
 call.foo.bar(),
 call.foo.bar().baz('fish', cat='dog')])r   r#   r5   rJ   r$   r+   r9   )r   r(   r;   r   r   r   test_call_list_str  s    
zTestCallList.test_call_list_strc                 C   s   t dt td}| }zftj |  t }|j |  | |j	t
 t
 g d|_| |j	t
 t
 t
dg W |  n
|  0 d S )Nz%s.SomeClass.one)Znew_callablerN   )r	   r   r
   r   r   r   r   r&   r$   r9   r   stop)r   r   r(   r   r   r   r   test_propertymock&  s    zTestCallList.test_propertymockc                 C   s@   t  }t }|t|_|j}|  | |t  | |t d S r   )r   r
   r   r#   r   r   r   )r   r   r   Zreturnedr   r   r   test_propertymock_returnvalue8  s    
z*TestCallList.test_propertymock_returnvalueN)r   r   r   r"  r$  r&  r'  r   r   r   r   r!    s   r!  c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestCallablePredicatec                 C   s(   t tttttfD ]}| t| qd S r   )r+   bytesrh   r   tupler   rf   r   )r   r   r   r   r   	test_typeE  s    zTestCallablePredicate.test_typec                 C   s&   G dd d}| }|  t| d S )Nc                   @   s   e Zd Zdd ZdS )z>TestCallablePredicate.test_call_magic_method.<locals>.Callablec                 S   s   d S r   r   r   r   r   r   r   K  r   zGTestCallablePredicate.test_call_magic_method.<locals>.Callable.__call__N)r   r   r   r   r   r   r   r   r   J  s   r   )rf   r   )r   r   r   r   r   r   test_call_magic_methodI  s    z,TestCallablePredicate.test_call_magic_methodc                 C   s"   G dd d}|  t|j d S )Nc                   @   s   e Zd Zedd ZdS )zATestCallablePredicate.test_staticmethod.<locals>.WithStaticMethodc                   S   s   d S r   r   r   r   r   r   
staticfuncQ  s    zLTestCallablePredicate.test_staticmethod.<locals>.WithStaticMethod.staticfuncN)r   r   r   r   r-  r   r   r   r   WithStaticMethodP  s   r.  )rf   r   r-  )r   r.  r   r   r   test_staticmethodO  s    z'TestCallablePredicate.test_staticmethodc                 C   s"   G dd d}|  t|j d S )Nc                   @   s   e Zd ZedZdS )zMTestCallablePredicate.test_non_callable_staticmethod.<locals>.BadStaticMethodN)r   r   r   r   not_callabler   r   r   r   BadStaticMethodV  s   r1  re   r   r0  )r   r1  r   r   r   test_non_callable_staticmethodU  s    z4TestCallablePredicate.test_non_callable_staticmethodc                 C   s"   G dd d}|  t|j d S )Nc                   @   s   e Zd Zedd ZdS )z?TestCallablePredicate.test_classmethod.<locals>.WithClassMethodc                 S   s   d S r   r   )r   r   r   r   	classfunc\  s    zITestCallablePredicate.test_classmethod.<locals>.WithClassMethod.classfuncN)r   r   r   r   r4  r   r   r   r   WithClassMethod[  s   r5  )rf   r   r4  )r   r5  r   r   r   test_classmethodZ  s    z&TestCallablePredicate.test_classmethodc                 C   s"   G dd d}|  t|j d S )Nc                   @   s   e Zd ZedZdS )zKTestCallablePredicate.test_non_callable_classmethod.<locals>.BadClassMethodN)r   r   r   r   r0  r   r   r   r   BadClassMethoda  s   r7  r2  )r   r7  r   r   r   test_non_callable_classmethod`  s    z3TestCallablePredicate.test_non_callable_classmethodN)	r   r   r   r+  r,  r/  r3  r6  r8  r   r   r   r   r(  C  s   r(  __main__)r  r  r
  ZunittestZunittest.mockr   r   r   r   r   r   r   r	   r
   r   r   	functoolsr   r%   r   ZTestCaser    rF   r   r!  r(  r   mainr   r   r   r   <module>   s*   0E  #     G#