B
    u9a<                 @   sj   d dl Z d dlmZ d dlZd dlZG dd deZG dd deZG dd de jZ	e
d	krfe   dS )
    N)supportc               @   s   e Zd ZdS )NoAllN)__name__
__module____qualname__ r   r   "/usr/lib/python3.7/test___all__.pyr      s   r   c               @   s   e Zd ZdS )FailedImportN)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S )AllTestc             C   s6  i }t jdtfdtfdd. ytd| | W n   t|Y nX W d Q R X ttj| dsht	|i }| j
|d ytd| | W n: tk
r } z| d	||jj| W d d }~X Y nX d
|kr|d
= d|kr|d= t|}tj| j}t|}| ||d| | ||d| W d Q R X d S )Nz.* (module|package) T)quietz	import %s__all__)modulezfrom %s import *z__all__ failure in {}: {}: {}__builtins____annotations__zin module {})r   Zcheck_warningsDeprecationWarningResourceWarningexecr	   hasattrsysmodulesr   ZsubTest	ExceptionZfailformat	__class__r   setr   ZassertCountEqualZassertEqual)selfmodnamenamesekeysZall_listZall_setr   r   r   	check_all   s6    
"zAllTest.check_allc             c   s   xt t|D ]}tj||}tj|rtj|d}tj|r||| fV  x*| ||| d D ]\}}||fV  qlW q|dr|dkrq|||d d  fV  qW d S )Nz__init__.py.z.py)	sortedoslistdirpathjoinisdirexistswalk_modulesendswith)r   ZbasedirZmodpathfnr&   Zpkg_initpmr   r   r   r*   1   s    zAllTest.walk_modulesc          
   C   s,  t dg}tjdsdd l}g }g }tjtjt}x| 	|dD ]\}}|}d}	x$|r|||krld}	P |
dd }qZW |	rqHtjrt| y8t|d$}
d	|
 krt|| | W d Q R X W qH tk
r   || Y qH tk
r   || Y qHX qHW tjr(td
| td| d S )NZ
__future__javar   r   FTr!   rbs   __all__z8Following modules have no __all__ and have been ignored:z(Following modules failed to be imported:)r   r   platform
startswith_socketr$   r&   dirname__file__r*   
rpartitionr   verboseprintopenreadr   r    appendr	   )r   Z	blacklistr3   ZignoredZfailed_importsZlib_dirr&   r   r.   Zblacklistedfr   r   r   test_all?   s@    zAllTest.test_allN)r   r   r   r    r*   r=   r   r   r   r   r
      s   !r
   __main__)ZunittestZtestr   r$   r   RuntimeErrorr   r	   ZTestCaser
   r   mainr   r   r   r   <module>   s   ^