B
    18™\5)  ã               @   s~   d dl Z d dlZd dlmZ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rze  ¡  dS )é    N)Ú
gc_collectÚrequires_type_collecting)Ú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
   úT/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/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
e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ed9d:„ ƒZ d;d<„ Z!d=S )>ÚModuleTestsc             C   sn   t  t ¡}|  |jd k¡ |  tt|¡ y|j}|  dt	|ƒ ¡ W n t
k
rX   Y nX |  |jt j¡ d S )Nz__name__ = %s)Ú
ModuleTypeÚ__new__Ú
assertTrueÚ__dict__ÚassertRaisesÚSystemErrorÚdirr   Ú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
   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
   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   Úfoodoc)r   r   r'   r(   r)   )r   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   u	   foodocáˆ´)r   r   r'   r(   r)   )r   r   r   r   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|k¡ d S )Nr   u	   foodocáˆ´é*   r,   )r   r   Úbarr'   r(   r)   )r   r0   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   r0   )r   r
   r
   r   Úfa   s    z+ModuleTests.test_dont_clear_dict.<locals>.fr0   r4   )r   r   r   )r   r5   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   r8   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_weakrefx   s    
zModuleTests.test_weakrefc          	   C   sx   dd l m} ddl m} |  |d¡ |  |jd¡ |  |jd¡ |  td¡ |j W d Q R X |  |j	d¡ t
jd= d S )	Nr   )ÚtestzThere is testr7   é   z Deprecated, use whatever insteadzThere is whateverztest.good_getattr)Útest.good_getattrÚgood_getattrr?   r   ÚxÚyr#   r   ZyoloZwhateverÚsysÚmodules)r   Úggar?   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 Q R X |  t¡ |j W d Q R X t	j
d= dt	j
kr†t	j
d= d S )Nr   )Úbad_getattr2r7   ztest.bad_getattrztest.bad_getattr2)Útest.bad_getattrÚbad_getattrr?   rI   r   rC   r   Ú	TypeErrorZnoperE   rF   )r   ÚbgarI   r
   r
   r   Útest_module_getattr_errorsŒ   s    
z&ModuleTests.test_module_getattr_errorsc             C   s.   dd l m} |  t|ƒdddg¡ tjd= d S )Nr   ÚaÚbÚcztest.good_getattr)rA   rB   r   r   rE   rF   )r   rG   r
   r
   r   Útest_module_dir™   s    zModuleTests.test_module_dirc          	   C   sr   dd l m} ddlm} |  t¡ t|ƒ W d Q R X |  t¡ t|ƒ W d Q R X tjd= dtjkrntjd= d S )Nr   )rI   ztest.bad_getattrztest.bad_getattr2)	rJ   rK   r?   rI   r   rL   r   rE   rF   )r   rM   rI   r
   r
   r   Útest_module_dir_errorsž   s    
z"ModuleTests.test_module_dir_errorsc          	   C   sZ   ddl m} |  t¡ |j W d Q R X |  t¡ |j W d Q R X dtjkrVtjd= d S )Nr   )Úbad_getattr3ztest.bad_getattr3)r?   rT   r   r   ZoneZ
delgetattrrE   rF   )r   rT   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
   r   Útest_module_repr_with_name¹   s    z&ModuleTests.test_module_repr_with_namec             C   s"   t dƒ}d|_|  t|ƒd¡ d S )Nr   z/tmp/foo.pyz!<module 'foo' from '/tmp/foo.py'>)r   Ú__file__r   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   z/tmp/foo.pyz<module '?' from '/tmp/foo.py'>)r   r   rX   r   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ƒ}|jd kst‚|  t|ƒd¡ d S )Nr   z<module 'foo'>)r   r'   ÚAssertionErrorr   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	   Ú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 )Nr   z<module '?' ({})>)r   r   r   r'   r   r   r   )r   r	   r]   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   z<module 'foo' (crafted)>)r   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 )Nr   z/tmp/foo.pyz!<module 'foo' from '/tmp/foo.py'>)r   r   r'   rX   r   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   z/tmp/foo.pyz<module 'foo' (crafted)>)r   r   r'   rX   r   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   rE   )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   sB   t ddƒ\}}}|  |¡ | ¡ }|  t|ƒddddddh¡ d S )	Nz-czfrom test import final_as   x = as   x = bs   final_a.x = as   final_b.x = bs	   len = lens   shutil.rmtree = rmtree)r   Ú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   rt   r
   r
   r
   r   ÚDescr  s   ru   c                   s   e Zd Z” ƒ ZdS )z7ModuleTests.test_descriptor_errors_propagate.<locals>.MN)r   r   r   Úmelonr
   )ru   r
   r   ÚM  s   rw   Zmymodrv   )r   r   rq   r$   )r   rw   r
   )ru   r   Ú test_descriptor_errors_propagate  s    z,ModuleTests.test_descriptor_errors_propagateN)"r   r   r   r!   r%   r&   r+   r-   r.   r3   r6   r   r:   r>   rH   rN   rR   rS   rU   rV   rW   rY   rZ   r\   r^   r_   r`   ra   rb   rc   rd   rh   rp   rx   r
   r
   r
   r   r      s<   

	
		r   Ú__main__)re   r;   Ztest.supportr   r   Ztest.support.script_helperr   rE   Útyper   r   r   ÚTestCaser   r   Úmainr
   r
   r
   r   Ú<module>   s     