o
    bq                     @   s@   d Z ddlZddlmZ ddlmZmZmZ G dd deZdS )z!Unittest for the logging checker.    N)logging)CheckerTestCaseMessage
set_configc                   @   s   e Zd ZejZdd Zdd Zdd Ze	ddgd	d
d Z
dd Zdd Zdd Zdd Ze	dddd Ze	dddd Ze	dddd ZdS )TestLoggingModuleDetectionc                 C   r   t d}| jd  | j|d  | td|d d | j|d  W d    d S 1 s2w   Y  d S )NzI
        import logging #@
        logging.warn('%s' % '%s')  #@
        r   logging-not-lazy   nodeastroidextract_nodecheckervisit_modulevisit_importassertAddsMessagesr   
visit_callselfstmts r   c/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/test/unittest_checker_logging.py$test_detects_standard_logging_module      "z?TestLoggingModuleDetection.test_detects_standard_logging_modulec                 C   s   t d}| | d S )NzO
        import logging
        logging.error('0} - {1}'.format(1, 2))
        )r   parsewalk)r   r   r   r   r   (test_dont_crash_on_invalid_format_string    s   zCTestLoggingModuleDetection.test_dont_crash_on_invalid_format_stringc                 C   r   )NzV
        import logging as blogging #@
        blogging.warn('%s' % '%s')  #@
        r   r   r	   r
   r   r   r   r   r   ,test_detects_renamed_standard_logging_module)   r   zGTestLoggingModuleDetection.test_detects_renamed_standard_logging_moduler   z
my.logging)Zlogging_modulesc                 C   r   )Nz^
        from my import logging as blogging #@
        blogging.warn('%s' % '%s')  #@
        r   r   r	   r
   r   r   r   r   r   test_nonstandard_logging_module5   s   "z:TestLoggingModuleDetection.test_nonstandard_logging_modulec                 C   sl   t dd|}| jd  | j|d  |   | j|d  W d    d S 1 s/w   Y  d S )NI
        import logging #@
        logging.error<placeholder> #@
        <placeholder>r   r	   )r   r   replacer   r   r   ZassertNoMessagesr   )r   stmtr   r   r   r    _assert_brace_format_no_messagesB   s   
"z;TestLoggingModuleDetection._assert_brace_format_no_messagesc                 C   sz   t dd|}| jd  | j|d  | t||d d | j|d  W d    d S 1 s6w   Y  d S )Nr    r!   r   r	   r
   )	r   r   r"   r   r   r   r   r   r   )r   msgr#   r   r   r   r   _assert_brace_format_messageP   s   "z7TestLoggingModuleDetection._assert_brace_format_messagec                 C      |  d| d S )Nzlogging-too-few-argsr&   r   r#   r   r   r   !_assert_brace_format_too_few_args^      z<TestLoggingModuleDetection._assert_brace_format_too_few_argsc                 C   r'   )Nzlogging-too-many-argsr(   r)   r   r   r   "_assert_brace_format_too_many_argsa   r+   z=TestLoggingModuleDetection._assert_brace_format_too_many_argsnew)Zlogging_format_stylec                 C   sJ   |  d |  d |  d |  d |  d |  d |  d d S )Nz('constant string')z('{}')z	('{}', 1)z
('{0}', 1)z('{named}', {'named': 1})z('{} {named}', 1, {'named': 1})z ('{0} {named}', 1, {'named': 1}))r$   r   r   r   r   *test_brace_format_style_matching_argumentsd   s   





zETestLoggingModuleDetection.test_brace_format_style_matching_argumentsc                 C   s@   |  d |  d |  d |  d |  d |  d d S )Nz('{}, {}', 1)z('{0}, {1}', 1)z%('{named1}, {named2}', {'named1': 1})z('{0}, {named}', 1)z('{}, {named}', {'named': 1})z('{0}, {named}', {'named': 1}))r*   r.   r   r   r   $test_brace_format_style_too_few_argsn   s   




z?TestLoggingModuleDetection.test_brace_format_style_too_few_argsc                 C   s6   |  d |  d |  d |  d |  d d S )Nz('constant string', 1, 2)z('{}', 1, 2)z('{0}', 1, 2)z#('{}, {named}', 1, 2, {'named': 1})z$('{0}, {named}', 1, 2, {'named': 1}))r,   r.   r   r   r   ,test_brace_format_style_not_enough_argumentsw   s
   



zGTestLoggingModuleDetection.test_brace_format_style_not_enough_argumentsN)__name__
__module____qualname__r   ZLoggingCheckerZCHECKER_CLASSr   r   r   r   r   r$   r&   r*   r,   r/   r0   r1   r   r   r   r   r      s"    	

	
r   )	__doc__r   Zpylint.checkersr   Zpylint.testutilsr   r   r   r   r   r   r   r   <module>   s
   	