a
    ze(                     @   sz   d dl Z d dlZd dlmZ d dlmZ d dlZeeZG dd dZ	G dd dZ
G dd	 d	e jZed
krve   dS )    N)
gc_collect)assert_python_okc                   @   s   e Zd Zedd ZdS )
FullLoaderc                 C   s   d |jS )Nz<module '{}' (crafted)>)format__name__)clsm r	   &/usr/lib/python3.9/test/test_module.pymodule_repr   s    zFullLoader.module_reprN)r   
__module____qualname__classmethodr   r	   r	   r	   r
   r   
   s   r   c                   @   s   e Zd ZdS )
BareLoaderN)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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=S )>ModuleTestsc                 C   sl   t t }| |jd u  | tt| z|j}| dt	|  W n t
yV   Y n0 | |jt j d S )Nz__name__ = %s)
ModuleType__new__
assertTrue__dict__assertRaisesSystemErrordirr   ZfailreprAttributeErrorassertEqual__doc__)selffoosr	   r	   r
   test_uninitialized   s    
zModuleTests.test_uninitializedc                 C   s    t t }| tdt|d d S )Nz"module has no attribute 'not_here'not_here)r   r   assertRaisesRegexr   getattrr   r   r	   r	   r
   "test_uninitialized_missing_getattr!   s
    
z.ModuleTests.test_uninitialized_missing_getattrc                 C   s   t d}| tdt|d d S )Nr   z(module 'foo' has no attribute 'not_here'r    )r   r!   r   r"   r#   r	   r	   r
   test_missing_getattr)   s
    z ModuleTests.test_missing_getattrc              	   C   sl   t d}| |jd | |jd  | |jd  | |jd  | |jd  | |jdd d d d d d S )Nr   r   r   
__loader____package____spec__)	r   r   r   r   assertIsr'   r(   r)   r   r#   r	   r	   r
   test_no_docstring1   s    zModuleTests.test_no_docstringc              	   C   sD   t dd}| |jd | |jd | |jddd d d d d S )Nr   foodocr&   r   r   r   r   r   r#   r	   r	   r
   test_ascii_docstring=   s    
z ModuleTests.test_ascii_docstringc              	   C   sD   t dd}| |jd | |jd | |jddd d d d d S )Nr   	   foodocሴr&   r-   r#   r	   r	   r
   test_unicode_docstringG   s    
z"ModuleTests.test_unicode_docstringc              
   C   s|   t dd}d|_|j}|dd | |jd | |jd | |jd | |jdddd d d d | |j|u  d S )Nr   r/   *   r,   )r   r   barr'   r(   r)   )r   r2   r   __init__r   r   r   r   )r   r   dr	   r	   r
   test_reinitQ   s    
zModuleTests.test_reinitc                 C   s&   dd }t   | | jd d d S )Nc                  S   s   t d} d| _| S )Nr      )r   r2   )r   r	   r	   r
   fa   s    z+ModuleTests.test_dont_clear_dict.<locals>.fr2   r6   )r   r   r   )r   r7   r	   r	   r
   test_dont_clear_dict_   s    z ModuleTests.test_dont_clear_dictc                 C   s<   g }t d}||_d}t||j ~t  | |dg d S )Nr   zwclass A:
    def __init__(self, l):
        self.l = l
    def __del__(self):
        self.l.append(1)
a = A(destroyed)   )r   	destroyedexecr   r   r   )r   r:   r   r   r	   r	   r
   test_clear_dict_in_ref_cycleh   s    z(ModuleTests.test_clear_dict_in_ref_cyclec                 C   s:   t d}t|}| | | ~t  | | d  d S )Nr   )r   weakrefrefr*   r   )r   r   wrr	   r	   r
   test_weakrefw   s    
zModuleTests.test_weakrefc                 C   s   dd l m} ddl m} | |d | |jd | |jd | td |j W d    n1 sh0    Y  | |j	d t
jd= d S )	Nr   )testzThere is testr9      z Deprecated, use whatever insteadzThere is whatevertest.good_getattr)test.good_getattrgood_getattrrA   r   xyr!   r   ZyoloZwhateversysmodules)r   ggarA   r	   r	   r
   test_module_getattr   s    $zModuleTests.test_module_getattrc                 C   s   dd l m} ddlm} | |jd | |jd | t |j W d    n1 sZ0    Y  | t |j W d    n1 s0    Y  t	j
d= dt	j
v rt	j
d= d S )Nr   bad_getattr2r9   test.bad_getattrtest.bad_getattr2)test.bad_getattrbad_getattrrA   rM   r   rF   r   	TypeErrorZnoperH   rI   r   ZbgarM   r	   r	   r
   test_module_getattr_errors   s    $$
z&ModuleTests.test_module_getattr_errorsc                 C   s,   dd l m} | t|g d tjd= d S )Nr   )abcrC   )rD   rE   r   r   rH   rI   )r   rJ   r	   r	   r
   test_module_dir   s    zModuleTests.test_module_dirc                 C   s   dd l m} ddlm} | t t| W d    n1 s@0    Y  | t t| W d    n1 sr0    Y  tjd= dtjv rtjd= d S )Nr   rL   rN   rO   )	rP   rQ   rA   rM   r   rR   r   rH   rI   rS   r	   r	   r
   test_module_dir_errors   s    &&
z"ModuleTests.test_module_dir_errorsc                 C   s   ddl m} | t |j W d    n1 s20    Y  | t |j W d    n1 sb0    Y  dtjv r~tjd= d S )Nr   )bad_getattr3ztest.bad_getattr3)rA   rZ   r   r   ZoneZ
delgetattrrH   rI   )r   rZ   r	   r	   r
   test_module_getattr_tricky   s    $$
z&ModuleTests.test_module_getattr_trickyc                 C   s    t d}|`| t|d d S )Nr   z<module '?'>)r   r   r   r   r   r   r	   r	   r
   test_module_repr_minimal   s    z$ModuleTests.test_module_repr_minimalc                 C   s   t d}| t|d d S Nr   z<module 'foo'>r   r   r   r\   r	   r	   r
   test_module_repr_with_name   s    z&ModuleTests.test_module_repr_with_namec                 C   s"   t d}d|_| t|d d S Nr   /tmp/foo.pyz!<module 'foo' from '/tmp/foo.py'>)r   __file__r   r   r\   r	   r	   r
   'test_module_repr_with_name_and_filename   s    z3ModuleTests.test_module_repr_with_name_and_filenamec                 C   s&   t d}|`d|_| t|d d S )Nr   rb   z<module '?' from '/tmp/foo.py'>)r   r   rc   r   r   r\   r	   r	   r
   #test_module_repr_with_filename_only   s    z/ModuleTests.test_module_repr_with_filename_onlyc                 C   s   t d}| t|d d S r^   r_   r\   r	   r	   r
   $test_module_repr_with_loader_as_None   s    z0ModuleTests.test_module_repr_with_loader_as_Nonec                 C   s4   t d}|`t|_tt}| t|d| d S Nr   z<module '?' ({})>)r   r   r   r'   r   r   r   r   r   Zloader_reprr	   r	   r
   -test_module_repr_with_bare_loader_but_no_name   s    z9ModuleTests.test_module_repr_with_bare_loader_but_no_namec                 C   s4   t d}|`t|_tt}| t|d| d S rg   )r   r   r   r'   r   r   r   rh   r	   r	   r
   -test_module_repr_with_full_loader_but_no_name   s    z9ModuleTests.test_module_repr_with_full_loader_but_no_namec                 C   s0   t d}t|_tt}| t|d| d S )Nr   z<module 'foo' ({})>)r   r   r'   r   r   r   )r   r   r   r	   r	   r
   !test_module_repr_with_bare_loader   s    z-ModuleTests.test_module_repr_with_bare_loaderc                 C   s"   t d}t|_| t|d d S )Nr   <module 'foo' (crafted)>)r   r   r'   r   r   r\   r	   r	   r
   !test_module_repr_with_full_loader   s
    z-ModuleTests.test_module_repr_with_full_loaderc                 C   s(   t d}t|_d|_| t|d d S ra   )r   r   r'   rc   r   r   r\   r	   r	   r
   .test_module_repr_with_bare_loader_and_filename   s    z:ModuleTests.test_module_repr_with_bare_loader_and_filenamec                 C   s(   t d}t|_d|_| t|d d S )Nr   rb   rl   )r   r   r'   rc   r   r   r\   r	   r	   r
   .test_module_repr_with_full_loader_and_filename   s    z:ModuleTests.test_module_repr_with_full_loader_and_filenamec                 C   s   |  ttd d S )Nz<module 'sys' (built-in)>)r   r   rH   )r   r	   r	   r
   test_module_repr_builtin   s    z$ModuleTests.test_module_repr_builtinc                 C   sZ   t t}d}d}| |d t| |d|| | |t| d  |d|| d S )Nz<module 'unittest' from 'z__init__.py'>z{!r} does not start with {!r}z{!r} does not end with {!r})r   unittestr   lenr   )r   rZstarts_withZ	ends_withr	   r	   r
   test_module_repr_source  s    

z#ModuleTests.test_module_repr_sourcec                 C   s:   t dd\}}}| | | }| t|h d d S )Nz-czfrom test import final_a>   s	   len = lens   shutil.rmtree = rmtrees   final_b.x = bs   x = as   final_a.x = as   x = b)r   ZassertFalse
splitlinesr   set)r   rcouterrlinesr	   r	   r
   $test_module_finalization_at_shutdown  s    
z0ModuleTests.test_module_finalization_at_shutdownc                    s:   G dd d G  fdddt }| tt|dd d S )Nc                   @   s   e Zd Zdd ZdS )z;ModuleTests.test_descriptor_errors_propagate.<locals>.Descrc                 S   s   t d S )N)RuntimeError)r   otr	   r	   r
   __get__  s    zCModuleTests.test_descriptor_errors_propagate.<locals>.Descr.__get__N)r   r   r   r   r	   r	   r	   r
   Descr  s   r   c                       s   e Zd Z  ZdS )z7ModuleTests.test_descriptor_errors_propagate.<locals>.MN)r   r   r   melonr	   r   r	   r
   M  s   r   Zmymodr   )r   r   r|   r"   )r   r   r	   r   r
    test_descriptor_errors_propagate  s    z,ModuleTests.test_descriptor_errors_propagateN)!r   r   r   r   r$   r%   r+   r.   r0   r5   r8   r<   r@   rK   rT   rX   rY   r[   r]   r`   rd   re   rf   ri   rj   rk   rm   rn   ro   rp   rt   r{   r   r	   r	   r	   r
   r      s<   

	
		r   __main__)rq   r=   Ztest.supportr   Ztest.support.script_helperr   rH   typer   r   r   ZTestCaser   r   mainr	   r	   r	   r
   <module>   s     