o
    KXh                     @   sj   d dl Z d dlmZmZmZ d dlmZmZmZm	Z	m
Z
mZmZ G dd de jZedkr3e   dS dS )    N)is_instanceX	SomeClass)Mock	MagicMockNonCallableMagicMockNonCallableMockpatchcreate_autospecCallableMixinc                   @   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 )TestCallablec                 C   s$   |  t|t | t|t d S N)
assertTruer   r   assertFalser   selfmock r   M/opt/python-3.10.19/usr/lib/python3.10/unittest/test/testmock/testcallable.pyassertNotCallable      zTestCallable.assertNotCallablec                 C   sF   t  t fD ]}| t| | t|d | |jjt	| qd S )N__call__)
r   r   assertRaises	TypeErrorr   hasattrZassertIn	__class____name__reprr   r   r   r   test_non_callable   s
   zTestCallable.test_non_callablec                 C   s$   |  ttt |  ttt d S r   )r   
issubclassr   r   r   r   r   r   r   r   test_hierarchy   r   zTestCallable.test_hierarchyc                 C   s<   t  }| tt|jt t }| tt|jt d S r   )	r   r   r   typeoner   r   twor   )r   r#   r$   r   r   r   test_attributes#   s   zTestCallable.test_attributesc                 C   s\   G dd dt }| }| tt|j| G dd dt}| }| tt|j| d S )Nc                   @      e Zd ZdS )z-TestCallable.test_subclasses.<locals>.MockSubNr   
__module____qualname__r   r   r   r   MockSub,       r*   c                   @   r&   )z.TestCallable.test_subclasses.<locals>.MagicSubNr'   r   r   r   r   MagicSub2   r+   r,   )r   r   r   r"   r#   r   r$   )r   r*   r#   r,   r$   r   r   r   test_subclasses+   s   zTestCallable.test_subclassesc                 C   L   t dt dd}| }| |j | }|  | | | t| d S )N%s.XTspec	r	   r   start
addCleanupstopassert_called_once_withr   r   r   r   patcherr   instancer   r   r   test_patch_spec9      
zTestCallable.test_patch_specc                 C   r.   )Nr/   Tspec_setr2   r7   r   r   r   test_patch_spec_setE   r;   z TestCallable.test_patch_spec_setc                 C   @   t dt t d}| }| |j | | | t| d S )Nr/   r0   	r	   r   r   r3   r4   r5   r   r   r   r   r8   r   r   r   r   test_patch_spec_instanceQ   
   
z%TestCallable.test_patch_spec_instancec                 C   r?   )Nr/   r<   r@   rA   r   r   r   test_patch_spec_set_instanceZ   rC   z)TestCallable.test_patch_spec_set_instancec           	   
   C   s   G dd dt }G dd d|}G dd dt|}dD ]`}|||fD ]X}tdt fi ||iB}| }|  | t|t | t	t
|d	 | }|  |d
dd |d
dd |d
dd |jd
dd W d    n1 suw   Y  q"qd S )Nc                   @   s   e Zd Zdd ZdS )z>TestCallable.test_patch_spec_callable_class.<locals>.CallableXc                 S   s   d S r   r   r    r   r   r   r   e   s    zGTestCallable.test_patch_spec_callable_class.<locals>.CallableX.__call__N)r   r(   r)   r   r   r   r   r   	CallableXd   s    rE   c                   @   r&   )z8TestCallable.test_patch_spec_callable_class.<locals>.SubNr'   r   r   r   r   Subg   r+   rF   c                   @   r&   )z:TestCallable.test_patch_spec_callable_class.<locals>.MultiNr'   r   r   r   r   Multij   r+   rG   )r1   r=   r/   Z	foobarbaz         )r   r   r	   r   r6   r   r   r   r   AttributeErrorgetattrZfoo)	r   rE   rF   rG   argZKlassr   r9   resultr   r   r   test_patch_spec_callable_classc   s,   
z+TestCallable.test_patch_spec_callable_classc                 C   s4   t t}| }| t| t t }| t| d S r   )r
   r   r   r   )r   r   r9   r   r   r   test_create_autospec   s
   
z!TestCallable.test_create_autospecc                 C   s@   t tdd}| t| |  |j  | t|jdd d S )NT)r9   Zsomeargs)r
   r   r   r   Zwibbler6   r   r   r   r   test_create_autospec_instance   s
   
z*TestCallable.test_create_autospec_instanceN)r   r(   r)   r   r   r!   r%   r-   r:   r>   rB   rD   rO   rP   rR   r   r   r   r   r      s    			r   __main__)ZunittestZunittest.test.testmock.supportr   r   r   Zunittest.mockr   r   r   r   r	   r
   r   ZTestCaser   r   mainr   r   r   r   <module>   s   $ 