o
    GXh                     @   s`   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e	dkr.e 
  dS dS )    N)systemc                   @   sT   e Zd ZdZdd Zdd Zdd ZdZd	d
 Zdd Z	dd Z
dd Zdd ZdS )ExceptionClassTestsz]Tests for anything relating to exception objects themselves (e.g.,
    inheritance hierarchy)c                 C   s   |  ttt d S N)
assertTrue
issubclass	Exceptionobjectself r   A/opt/python-3.10.19/usr/lib/python3.10/test/test_baseexception.pytest_builtins_new_style   s   z+ExceptionClassTests.test_builtins_new_stylec                 C   s,   dD ]}|  t||d|jj|f  qd S )N)args__str____repr__z%s missing %s attribute)r   hasattr	__class____name__)r
   Zinsattrr   r   r   verify_instance_interface   s   
z-ExceptionClassTests.verify_instance_interfacec              	   C   sv  t  }tj D ]}zt|tr||j W q ty    Y qw t	t
jt
jtd ddd}z|  }ztt|}W n tyP   | d|  Y nw | ||d|  || g }d}|D ]}| }|d}	||	d d  }
d	|
v r|
d	}|
|d
 d }|
d |d
  }
t |kr||
 qed|
v r|
d}|
d |d
  }
ztt|
}W n ty   | d|
  Y nw ||	k r|||f n||	kr|d d |	kr|  |d d |	ks| t||d d
 d|j|d d
 jf  z| |  W n
 ty   Y nw | |
| ||
 |}|	}qeW |  n|  w | t|dd|  d S )Nr   zexception_hierarchy.txtzutf-8)encodingzbase class %s not a built-inz%s not found-   (   [z%s not a built-in exceptionz%s is not a subclass of %sz%s not accounted for) setbuiltins__dict__valuesr   BaseExceptionaddr   	TypeErroropenospathjoinsplit__file__readlinerstripgetattrAttributeErrorfailZassertIndiscardrindexindexplatform_systemappendpopr   r   closeassertEquallen)r
   Zexc_setobject_Zinheritance_treeZsuperclass_namelast_excZsuperclassesZ
last_depthZexc_linedepthZexc_nameZparen_indexZplatform_nameZleft_bracketexcr   r   r   test_inheritance   s   







#z$ExceptionClassTests.test_inheritance)lengthr   strreprc              	   C   s6   t | j|D ]\}\}}| ||d|||f  qd S )Nz%s: %s != %s)zipinterface_testsr6   )r
   resultsZ	test_nameZgivenZexpectedr   r   r   interface_test_driverU   s
   
z)ExceptionClassTests.interface_test_driverc                 C   sZ   d}t |}t|jdg|jd |gt|t|gt|d|jj|f gf}| | d S )Nspamr   r   z%s(%r))r   r7   r   r>   r?   r   r   rC   )r
   argr;   rB   r   r   r   test_interface_single_argZ   s   z-ExceptionClassTests.test_interface_single_argc                 C   sd   d}t t|}t| }t|j|g|j|gt|t|gt||jjt|j gf}| 	| d S )N   )
tupleranger   r7   r   r>   r?   r   r   rC   )r
   	arg_countr   r;   rB   r   r   r   test_interface_multi_argc   s   z,ExceptionClassTests.test_interface_multi_argc                 C   sJ   t  }t|jdg|jt gt|dgt||jjd gf}| | d S )Nr    z())	r   r7   r   rH   r>   r?   r   r   rC   )r
   r;   rB   r   r   r   test_interface_no_argm   s   
z)ExceptionClassTests.test_interface_no_argc                    sX   dd l }i  G  fdddt}G dd dt}t }|  | < |  |  d S )Nr   c                       s$   e Zd Zdef fddZ  ZS )zXExceptionClassTests.test_setstate_refcount_no_crash.<locals>.HashThisKeyWillClearTheDictreturnc                    s      t  S r   )clearsuper__hash__r	   )r   dr   r   rQ   {   s   
zaExceptionClassTests.test_setstate_refcount_no_crash.<locals>.HashThisKeyWillClearTheDict.__hash__)r   
__module____qualname__intrQ   __classcell__r   rR   )r   r   HashThisKeyWillClearTheDictz   s    rX   c                   @      e Zd ZdS )zBExceptionClassTests.test_setstate_refcount_no_crash.<locals>.ValueNr   rS   rT   r   r   r   r   Value~       r[   )gcr>   r   __setstate__Zcollect)r
   r]   rX   r[   r;   r   rW   r   test_setstate_refcount_no_crashu   s   
z3ExceptionClassTests.test_setstate_refcount_no_crashN)r   rS   rT   __doc__r   r   r<   rA   rC   rF   rK   rM   r_   r   r   r   r   r      s    >	
r   c                   @   sH   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d Z
dS )
UsageTestszTest usage of exceptionsc                 C   s   z| t y   Y dS w )z6Make sure that raising 'object_' triggers a TypeError.N)r#   r.   typer
   r8   r   r   r   raise_fails   s
   zUsageTests.raise_failsc                 C   s   zzt  |y   Y nw W n ty   Y n t y(   | dt|  Y nw zzt  |fy8   Y W dS w  tyB   Y dS  t yT   | dt|  Y dS w )z,Catching 'object_' should raise a TypeError.z#TypeError expected when catching %sNz;TypeError expected when catching %s as specified in a tuple)r   r#   r.   rb   rc   r   r   r   catch_fails   s2   zUsageTests.catch_failsc                 C   *   G dd dt }| | | |  d S )Nc                   @   rY   )zDUsageTests.test_raise_new_style_non_exception.<locals>.NewStyleClassNrZ   r   r   r   r   NewStyleClass   r\   rg   )r   rd   )r
   rg   r   r   r   "test_raise_new_style_non_exception   s   
z-UsageTests.test_raise_new_style_non_exceptionc                 C      |  d d S NrD   )rd   r	   r   r   r   test_raise_string      zUsageTests.test_raise_stringc                 C   rf   )Nc                   @   rY   )zAUsageTests.test_catch_non_BaseException.<locals>.NonBaseExceptionNrZ   r   r   r   r   NonBaseException   r\   rm   )r   re   )r
   rm   r   r   r   test_catch_non_BaseException   s   
z'UsageTests.test_catch_non_BaseExceptionc                 C   s   |  t  d S r   )re   r!   r	   r   r   r   !test_catch_BaseException_instance   s   z,UsageTests.test_catch_BaseException_instancec                 C   ri   rj   )re   r	   r   r   r   test_catch_string   rl   zUsageTests.test_catch_stringN)r   rS   rT   r`   rd   re   rh   rk   rn   ro   rp   r   r   r   r   ra      s    
ra   __main__)Zunittestr   r%   platformr   r2   ZTestCaser   ra   r   mainr   r   r   r   <module>   s     B