o
    żŃŠbķ  ć                   @   sl   d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
 ej ej e”dd”ZG dd	 d	eZdS )
z#Unit tests for the imports checker.é    N)Śimports)ŚCheckerTestCaseŚMessageŚ
set_config)Ś	UNDEFINEDZregrtest_dataŚ c                   @   sD   e Zd ZejZedddd Zdd Zdd Z	d	d
 Z
dd ZdS )ŚTestImportsChecker)Zexternal_modulezfake_module.submoduleZfooŚbar)Zignored_modulesc                 C   sČ  t  d”}|  ”  | j |” W d   n1 sw   Y  t  d”}|  ”  | j |” W d   n1 s9w   Y  t  d”}|  ”  | j |” W d   n1 sXw   Y  t  d”}|  ”  | j |” W d   n1 sww   Y  t  d”}|  ”  | j |” W d   n1 sw   Y  t  d”}td|d	d
}|  |” | j |” W d   n1 s½w   Y  t  d”}|  ”  | j |” W d   dS 1 sŻw   Y  dS )ziMake sure that imports do not emit an 'import-error' when the
        module is configured to be ignored.z6
        from external_module import anything
        NzE
        from external_module.another_module import anything
        z(
        import external_module
        z<
        from fake_module.submodule import anything
        zC
        from fake_module.submodule.deeper import anything
        z!
        import foo, bar
        zmultiple-importszfoo, bar)ŚnodeŚargsz/
        import foo
        import bar
        )ŚastroidŚextract_nodeŚassertNoMessagesŚcheckerŚvisit_importfromZvisit_importr   ŚassertAddsMessages©Śselfr
   Śmsg© r   śc/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/test/unittest_checker_imports.pyŚtest_import_error_skipped   sV   ’
’’
’’
’’
’’
’’’’
"’z,TestImportsChecker.test_import_error_skippedc                 C   sT   t  d”}td|dd}|  |” | j |” W d   dS 1 s#w   Y  dS )zP
        Test that duplicate imports on single line raise 'reimported'.
        z#from time import sleep, sleep, timeZ
reimported)Śsleepé   )Śmsg_idr
   r   N)r   r   r   r   r   r   r   r   r   r   Śtest_reimported_same_line]   s
   
"’z,TestImportsChecker.test_reimported_same_linec                 C   sŚ   t j dt”}|jd }td|d}|  |” | j |” W d    n1 s(w   Y  |  	”  | j |jd ” W d    n1 sEw   Y  |  	”  | j |jd jd ” W d    d S 1 sfw   Y  d S )NZ
beyond_topr   zrelative-beyond-top-level)r   r
   r   é   )
r   ŚMANAGERŚast_from_module_nameŚ	REGR_DATAŚbodyr   r   r   r   r   ©r   ŚmoduleŚimport_fromr   r   r   r   Śtest_relative_beyond_top_levelf   s   
’
’
"’z1TestImportsChecker.test_relative_beyond_top_levelc                 C   sR   t j dt”}|jd }|  ”  | j |” W d    d S 1 s"w   Y  d S )NZinit_wildcardr   )r   r   r   r   r    r   r   r   )r   r"   r#   r   r   r   Śtest_wildcard_import_initr   s
   

"’z,TestImportsChecker.test_wildcard_import_initc                 C   sd   t j dt”}|jd }td|dtd}|  |” | j 	|” W d    d S 1 s+w   Y  d S )NZwildcardr   zwildcard-importŚempty)r   r
   r   Ś
confidence)
r   r   r   r   r    r   r   r   r   r   r!   r   r   r   Śtest_wildcard_import_non_inity   s   
ü"’z0TestImportsChecker.test_wildcard_import_non_initN)Ś__name__Ś
__module__Ś__qualname__r   ZImportsCheckerZCHECKER_CLASSr   r   r   r$   r%   r(   r   r   r   r   r      s    ’
>	r   )Ś__doc__Śosr   Zpylint.checkersr   Zpylint.testutilsr   r   r   Zpylint.interfacesr   ŚpathŚjoinŚdirnameŚ__file__r   r   r   r   r   r   Ś<module>   s   