a
    zeu                     @   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rXe 
  dS )    N)systemc                   @   sL   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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   -/usr/lib/python3.9/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   sz  t  }tj D ]2}zt|tr,||j W q ty@   Y q0 qt	t
jt
jtd d}z|  }ztt|}W n  ty   | d|  Y n0 | ||d|  || g }d}|D ]|}| }|d}	||	d d  }
d|
v r>|
d}|
|d d	 }|
d |d  }
t |kr>||
 qd
|
v rb|
d
}|
d |d  }
ztt|
}W n" ty   | d|
  Y n0 ||	k r|||f n(||	kr|d	 d |	kr|  q| t||d	 d d|j|d	 d jf  z| |  W n ty(   Y n0 | |
| ||
 |}|	}qW |  n
|  0 | t|dd|  d S )Nr   zexception_hierarchy.txtz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   sx    











z$ExceptionClassTests.test_inheritance)lengthr   strreprc              	   C   s6   t | j|D ]$\}\}}| ||d|||f  qd S )Nz%s: %s != %s)zipinterface_testsr5   )r
   resultsZ	test_nameZgivenZexpectedr   r   r   interface_test_driverT   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   r6   r   r=   r>   r   r   rB   )r
   argr:   rA   r   r   r   test_interface_single_argY   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   r6   r   r=   r>   r   r   rB   )r
   	arg_countr   r:   rA   r   r   r   test_interface_multi_argb   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   r6   r   rG   r=   r>   r   r   rB   )r
   r:   rA   r   r   r   test_interface_no_argl   s    
z)ExceptionClassTests.test_interface_no_argN)r   
__module____qualname____doc__r   r   r;   r@   rB   rE   rJ   rL   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   s4   z|W n t y   Y dS 0 | dt|  dS )z6Make sure that raising 'object_' triggers a TypeError.Nz!TypeError expected for raising %s)r"   r-   typer
   r7   r   r   r   raise_failsx   s
    zUsageTests.raise_failsc                 C   s   z zt W n |y   Y n0 W n4 ty2   Y n$ t yT   | dt|  Y n0 z"zt W n |fyt   Y n0 W n6 ty   Y dS  t y   | dt|  Y n0 dS )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-   rQ   rR   r   r   r   catch_fails   s(    

zUsageTests.catch_failsc                 C   s*   G dd dt }| | | |  d S )Nc                   @   s   e Zd ZdS )zDUsageTests.test_raise_new_style_non_exception.<locals>.NewStyleClassNr   rM   rN   r   r   r   r   NewStyleClass   s   rV   )r   rS   )r
   rV   r   r   r   "test_raise_new_style_non_exception   s    
z-UsageTests.test_raise_new_style_non_exceptionc                 C   s   |  d d S NrC   )rS   r	   r   r   r   test_raise_string   s    zUsageTests.test_raise_stringc                 C   s*   G dd dt }| | | |  d S )Nc                   @   s   e Zd ZdS )zAUsageTests.test_catch_non_BaseException.<locals>.NonBaseExceptionNrU   r   r   r   r   NonBaseException   s   rZ   )r   rT   )r
   rZ   r   r   r   test_catch_non_BaseException   s    
z'UsageTests.test_catch_non_BaseExceptionc                 C   s   |  t  d S r   )rT   r    r	   r   r   r   !test_catch_BaseException_instance   s    z,UsageTests.test_catch_BaseException_instancec                 C   s   |  d d S rX   )rT   r	   r   r   r   test_catch_string   s    zUsageTests.test_catch_stringN)r   rM   rN   rO   rS   rT   rW   rY   r[   r\   r]   r   r   r   r   rP   t   s   
rP   __main__)Zunittestr   r$   platformr   r1   ZTestCaser   rP   r   mainr   r   r   r   <module>   s   mB