o
    byG                     @   s   d Z ddlmZ ddlZddlZddlZddlZddlT ddlm	Z	 ddlm
Z
 ddlmZmZmZmZ G dd	 d	eZG d
d deZG dd deZdd ZdS )z%Check format checker helper functions    )unicode_literalsN)*)	reporters)lint)CheckerTestCaseMessage
set_config_tokenize_strc                   @   s0   e Zd ZeZdd Zdd Zdd Zdd Zd	S )
TestMultiStatementLinec                 C   s   t d}d| jj_| td|jd d | | W d    n1 s&w   Y  d| jj_| 	  | | W d    n1 sDw   Y  t d}| td|jd d | | W d    d S 1 skw   Y  d S )Nz#
        if True: pass  #@
        Fmultiple-statementsr   nodeTzB
        if True: pass  #@
        else:
            pass
        )
astroidextract_nodecheckerconfigZsingle_line_if_stmtassertAddsMessagesr   body
visitFirstassertNoMessagesselfstmt r   b/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/test/unittest_checker_format.pytestSingleLineIfStmts,   s"   


"z,TestMultiStatementLine.testSingleLineIfStmtsc                 C   s  t d}d| jj_| td|jd d | | W d    n1 s&w   Y  d| jj_| 	  | | W d    n1 sDw   Y  t d}d| jj_| td|jd d | | W d    n1 sow   Y  d| jj_| 	  | | W d    n1 sw   Y  t d}d| jj_| td|jd d | | W d    n1 sw   Y  d| jj_| td|jd d | | W d    d S 1 sw   Y  d S )	Nz4
        class MyError(Exception): pass  #@
        Fr   r   r   Tz5
        class MyError(Exception): a='a'  #@
        z<
        class MyError(Exception): a='a'; b='b'  #@
        )
r   r   r   r   Zsingle_line_class_stmtr   r   r   r   r   r   r   r   r   testSingleLineClassStmtsB   sB   







"z/TestMultiStatementLine.testSingleLineClassStmtsc                 C   sB   t d}|   | | W d    d S 1 sw   Y  d S )Nze
        try:  #@
            pass
        except:
            pass
        finally:
            pass)r   r   r   r   r   treer   r   r   'testTryExceptFinallyNoMultipleStatementg   s   
	"z>TestMultiStatementLine.testTryExceptFinallyNoMultipleStatementc                 C   s"   | j g  | j |jd  d S )Nr   )r   process_tokensZvisit_defaultr   r   r   r   r   r   t   s   z!TestMultiStatementLine.visitFirstN)	__name__
__module____qualname__FormatCheckerCHECKER_CLASSr   r   r   r   r   r   r   r   r
   )   s    %r
   c                   @   s8   e Zd ZeZdd Zdd Zdd Zdd Zd	d
 Z	dS )TestSuperfluousParenthesesc                 C   s\   t  | j_g d}|   |D ]}| jt|d qW d    d S 1 s'w   Y  d S )N)zif foo:z	if foo():zif (x and y) or z:zassert foo()z	assert ()zif (1, 2) in (3, 4):zif (a or b) in c:zreturn (x for x in x)zif (x for x in x):zfor x in (x for x in x):znot (foo or bar)znot (foo or bar) and bazr   setr   _keywords_with_parensr   _check_keyword_parenthesesr	   )r   casescoder   r   r   'testCheckKeywordParensHandlesValidCases|   s   

"zBTestSuperfluousParentheses.testCheckKeywordParensHandlesValidCasesc                 C   s  t  | j_tddddddftddddddftddddddftddd	dd
dftddddddftddddddftddddddftddddddftddddddftddddddfg
}|D ]#\}}}| | | jt|| W d    n1 sw   Y  qcd S )Nzsuperfluous-parens   iflineargs	if (foo):r   zif ((foo, bar)):zif (foo(bar)):returnzreturn ((x for x in x))notz	not (foo)zif not (foo):zif (not (foo)):   forzfor (x) in (1, 2, 3):zif (1) in (1, 2, 3):)r(   r   r)   r   r   r*   r	   )r   r+   msgr,   offsetr   r   r   .testCheckKeywordParensHandlesUnnecessaryParens   s6   
zITestSuperfluousParentheses.testCheckKeywordParensHandlesUnnecessaryParensc                 C   sT   t  | j_ddg}|D ]\}}| jt|| | j }t|d jt	s'J qd S )N)r3   r   )zassert (1 == 1)r   )
r(   r   r)   r*   r	   linterZrelease_messages
isinstancer2   str)r   r+   r,   r9   gotr   r   r   testCheckIfArgsAreNotUnicode   s   

z7TestSuperfluousParentheses.testCheckIfArgsAreNotUnicodec                 C   sX   d}t |}|   | j| | jt| W d    d S 1 s%w   Y  d S )Nz<from __future__ import print_function
print('Hello world!')
)r   parser   r   Zprocess_moduler    r	   )r   r,   r   r   r   r   ,testFuturePrintStatementWithoutParensWarning   s   

"zGTestSuperfluousParentheses.testFuturePrintStatementWithoutParensWarningc                 C   sP   t  | j_d}|   | jjt|dd W d    d S 1 s!w   Y  d S )Nzif 'bar' in (DICT or {}):r6   )startr'   )r   r,   r   r   r   testKeywordParensFalsePositive   s
   

"z9TestSuperfluousParentheses.testKeywordParensFalsePositiveN)
r!   r"   r#   r$   r%   r-   r:   r@   rB   rD   r   r   r   r   r&   y   s    		r&   c                   @   s   e Zd ZeZdd Zdd Zdd Zeg d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S )TestCheckSpacec                 C   P   g d}|    |D ]
}| jt| qW d    d S 1 s!w   Y  d S )N)z(a)
z(a * (b + c))
z
(#
    a)
r   r   r    r	   r   Z
good_casesr,   r   r   r   testParenthesesGood      
"z"TestCheckSpace.testParenthesesGoodc                 C     |  tdddd | jtd W d    n1 sw   Y  |  tdddd | jtd W d    n1 s?w   Y  |  tdddd | jtd	 W d    n1 saw   Y  |  tddd
d | jtd W d    d S 1 sw   Y  d S )Nbad-whitespacer.   )Noallowedafterbracketz( a)
^r0   z( a)
)rM   rN   beforerP   z	(a )
   ^z(a )
)rM   rN   rQ   rP   zfoo (a)
    ^zfoo (a)
)rM   rN   rQ   rP   z{1: 2} [1]
       ^z{1: 2} [1]
r   r   r   r    r	   r   r   r   r   testParenthesesBad   H   			"z!TestCheckSpace.testParenthesesBadc                 C   s   |    | jtd | jtd W d    n1 sw   Y  g | jj_|    | jtd W d    d S 1 sAw   Y  d S )N(a, )
z(a,)
)r   r   r    r	   r   no_space_checkrS   r   r   r   testTrailingCommaGood   s   


"z$TestCheckSpace.testTrailingCommaGood)rW   c                 C   J   |  tdddd | jtd W d    d S 1 sw   Y  d S )NrL   r.   )rM   rN   rQ   rP   z(a, )
    ^r0   rV   rR   rS   r   r   r   testTrailingCommaBad   s   "z#TestCheckSpace.testTrailingCommaBadc                 C   rY   )NrL   r.   )rM   rN   rQ   commaz(a , b)
   ^r0   z(a , b)
rR   rS   r   r   r   	testComma	  s   "zTestCheckSpace.testCommac                 C   rF   )N)z[a:b]
z[a : b]
z[a : ]
z[:a]
z[:]
z[::]
rG   rH   r   r   r   testSpacesAllowedInsideSlices  rJ   z,TestCheckSpace.testSpacesAllowedInsideSlicesc                 C   s   |   A | jtd | jtd | jtd | jtd | jtd | jtd | jtd W d    d S 1 sHw   Y  d S )Nzfoo(foo=bar)
zfoo(foo: int = bar)
z!foo(foo: module.classname = bar)
zfoo(foo: Dict[int, str] = bar)
zfoo(foo: 'int' = bar)
z!foo(foo: Dict[int, 'str'] = bar)
zlambda x=1: x
rG   rS   r   r   r   testKeywordSpacingGood  s   
"z%TestCheckSpace.testKeywordSpacingGoodc                 C   s  |  tdddd | jtd W d    n1 sw   Y  |  tdddd | jtd W d    n1 s?w   Y  |  tdddd | jtd	 W d    n1 saw   Y  |  tddd
d | jtd W d    n1 sw   Y  |  tdddd | jtd W d    n1 sw   Y  |  tdddd | jtd W d    n1 sw   Y  |  tdddd | jtd W d    n1 sw   Y  |   | jtd W d    d S 1 sw   Y  d S )NrL   r.   )rM   rN   rQ   keyword argument assignmentz(foo =bar)
     ^r0   z(foo =bar)
)rM   rN   rO   r_   z(foo= bar)
    ^z(foo= bar)
)rM   rN   aroundr_   z(foo = bar)
     ^z(foo = bar)
)Exactly onerequiredrQ   r_   z(foo: int= bar)
         ^z(foo: int= bar)
)ra   rb   rO   r_   z(foo: int =bar)
          ^z(foo: int =bar)
)ra   rb   r`   r_   z(foo: int=bar)
         ^z(foo: int=bar)
)ra   rb   r`   r_   z%(foo: List[int]=bar)
               ^z(foo: List[int]=bar)
z$(arg: Tuple[
    int, str] = None):
)r   r   r   r    r	   r   rS   r   r   r   testKeywordSpacingBad)  s   
$z$TestCheckSpace.testKeywordSpacingBadc                 C   sN   dg}|    |D ]
}| jt| q
W d    d S 1 s w   Y  d S )Nza = b
a < b
a
< b
rG   rH   r   r   r   testOperatorSpacingGood  s   
"z&TestCheckSpace.testOperatorSpacingGoodc                 C   rK   )NrL   r.   )ra   rb   rQ   
comparisonza< b
 ^r0   za< b
)ra   rb   rO   re   za <b
  ^za <b
)ra   rb   r`   re   za<b
 ^za<b
)ra   rb   r`   re   za<  b
 ^za<  b
rR   rS   r   r   r   testOperatorSpacingBad  rU   z%TestCheckSpace.testOperatorSpacingBadc                 C   s>   |    | jtd W d   dS 1 sw   Y  dS )znMake sure ellipses in function typing annotation
        doesn't cause a false positive bad-whitespace messagez$def foo(t: Tuple[str, ...] = None):
NrG   rS   r   r   r   !testValidTypingAnnotationEllipses  s
   
"z0TestCheckSpace.testValidTypingAnnotationEllipsesc                 C   s  g | j j_| tddd | j td W d    n1 s!w   Y  | tddd | j td W d    n1 sBw   Y  | tddd | j td W d    n1 scw   Y  |   | j td W d    n1 sw   Y  dg| j j_|   | j td W d    n1 sw   Y  |   | j td W d    n1 sw   Y  |   | j td W d    d S 1 sw   Y  d S )	Nztrailing-whitespacer6   )r1   za = 1
 
b = 2
za = 1
	
b = 2
za = 1

b = 2
za = 1

b = 2
z
empty-line)r   r   rW   r   r   r    r	   r   rS   r   r   r   testEmptyLines  s.   




"zTestCheckSpace.testEmptyLinesc                 C   s\   |     ttjdddd}|gtd }| j| W d   dS 1 s'w   Y  dS )zMake sure the encoding token doesn't change the checker's behavior

        _tokenize_str doesn't produce an encoding token, but
        reading a file does
        zutf-8)r   r    zif (
        None):
    pass
N)r   tokenize	TokenInfoENCODINGr	   r   r    )r   Zencoding_tokentokensr   r   r   test_encoding_token  s   
"z"TestCheckSpace.test_encoding_tokenN)r!   r"   r#   r$   r%   rI   rT   rX   r   rZ   r\   r]   r^   rc   rd   rf   rg   rh   rn   r   r   r   r   rE      s     %	


o%rE   c               	   C   s   t jddd} |  | d W d   n1 sw   Y  z2t }t|}|| || jddg}t	
 }|| || |jrHJ W t| j dS t| j w )zm
    Test for issue with disabling tokenizer messages
    that extend beyond the scope of the ast tokens
    wF)deletez#
mylist = [
    None
        ]
    Nz-dzbad-continuation)tempfileNamedTemporaryFilewriter   ZPyLinterr$   Zregister_checkerZload_command_line_configurationnamer   ZCollectingReporterZset_reportercheckmessagesosremove)file_r<   r   r2   Z
myreporterr   r   r   &test_disable_global_option_end_of_line  s$   



rz   )__doc__
__future__r   rj   rw   rq   r   Zpylint.checkers.formatZpylintr   r   Zpylint.testutilsr   r   r   r	   r
   r&   rE   rz   r   r   r   r   <module>   s    PN  .