o
    Zœc~  ã                   @   sP   d dl Z d dlZd dlmZ d dlmZmZ G dd„ deƒZG dd„ deƒZdS )é    N)Úchecker)ÚTestCaseÚskipIfc                   @   sL   e Zd ZdZedd„ ƒZdd„ Zdd„ Zee	j
dk d	ƒd
d„ ƒZdd„ ZdS )ÚTypeableVisitorTestsz&
    Tests of L{_TypeableVisitor}
    c                 C   s    t  | ¡}t ¡ }| |¡ |S )zV
        Run L{_TypeableVisitor} on the parsed source and return the visitor.
        )ÚastÚparser   Ú_TypeableVisitorÚvisit)ÚsÚtreeÚvisitor© r   úP/var/www/chikooza/env/lib/python3.10/site-packages/pyflakes/test/test_checker.pyÚ_run_visitor   s   

z!TypeableVisitorTests._run_visitorc                 C   sp   |   d¡}|  |jg d¢¡ |  |jd tj¡ |  |jd tj¡ |  |jd tj¡ |  |jd tj	¡ dS )zA
        Test that the typeable node types are collected
        zx = 1  # assignment
for x in range(1): pass  # for loop
def f(): pass  # function definition
with a as b: pass  # with statement
)é   é   é   é   r   r   r   r   N)
r   ÚassertEqualÚtypeable_linesÚassertIsInstanceÚtypeable_nodesr   ÚAssignÚForÚFunctionDefÚWith©Úselfr   r   r   r   Útest_node_types   s   ÿz$TypeableVisitorTests.test_node_typesc                 C   sH   |   d¡}|  |jddg¡ |  |jd tj¡ |  |jd tj¡ dS )zƒ
        Test the common pitfall of missing `generic_visit` in visitors by
        ensuring that nested nodes are reported
        zdef f():
    x = 1
r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   Útest_visitor_recurses)   s   ÿz*TypeableVisitorTests.test_visitor_recurses)r   é   zasync syntax introduced in py35c                 C   s\   |   d¡}|  |jg d¢¡ |  |jd tj¡ |  |jd tj¡ |  |jd tj¡ dS )z@
        Test that the PEP 492 node types are collected
        zoasync def f():  # async def
    async for x in y:  pass  # async for
    async with a as b: pass  # async with
)r   r   r   r   r   r   N)	r   r   r   r   r   r   ÚAsyncFunctionDefÚAsyncForÚ	AsyncWithr   r   r   r   Útest_py35_node_types8   s   ÿz)TypeableVisitorTests.test_py35_node_typesc                 C   s:   |   d¡}|  |jddg¡ |  |jd jd jd¡ dS )ún
        Test that when two typeable nodes are present on a line, the last
        typeable one wins.
        zx = 1; y = 1r   r   ÚyN)r   r   r   r   ÚtargetsÚidr   r   r   r   Útest_last_node_winsI   s   
z(TypeableVisitorTests.test_last_node_winsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r   r   ÚsysÚversion_infor$   r)   r   r   r   r   r      s    
	
r   c                   @   st   e Zd Z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S )ÚCollectTypeCommentsTestsz,
    Tests of L{_collect_type_comments}
    c                 C   s2   t  | ¡}t | ¡}t ||¡}dd„ | ¡ D ƒS )zÒ
        Run L{_collect_type_comments} on the parsed source and return the
        mapping from nodes to comments.  The return value is converted to
        a set: {(node_type, tuple of comments), ...}
        c                 S   s*   h | ]\}}t |ƒtd d„ |D ƒƒf’qS )c                 s   s    | ]\}}|V  qd S )Nr   )Ú.0Ú_r
   r   r   r   Ú	<genexpr>d   s   € z>CollectTypeCommentsTests._collect.<locals>.<setcomp>.<genexpr>)ÚtypeÚtuple)r2   ÚkÚvr   r   r   Ú	<setcomp>d   s   * z4CollectTypeCommentsTests._collect.<locals>.<setcomp>)r   r   r   Úmake_tokensÚ_collect_type_commentsÚitems)r
   r   ÚtokensÚretr   r   r   Ú_collectZ   s   

z!CollectTypeCommentsTests._collectc                 C   ó"   |   d¡}|  |tjdfh¡ dS )z@
        Test that the function works for binary source
        s   x = 1  # type: int©ú# type: intN©r?   ÚassertSetEqualr   r   ©r   r>   r   r   r   Ú
test_bytesf   ó   
z#CollectTypeCommentsTests.test_bytesc                 C   r@   )z>
        Test that the function works for text source
        zx = 1  # type: intrA   N)r?   r   r   r   rE   r   r   r   Ú	test_textm   rG   z"CollectTypeCommentsTests.test_textc                 C   ó   |   d¡}|  |tƒ ¡ dS )z9
        Test that a non-type comment is ignored
        zx = 1  # noqaN©r?   rD   ÚsetrE   r   r   r   Útest_non_type_comment_ignoredt   ó   
z6CollectTypeCommentsTests.test_non_type_comment_ignoredc                 C   rI   )zP
        Test that a type comment before something typeable is ignored.
        z# type: int
x = 1NrJ   rE   r   r   r   Ú!test_type_comment_before_typeable{   rM   z:CollectTypeCommentsTests.test_type_comment_before_typeablec                 C   rI   )zH
        Test that `# type: ignore` comments are not collected.
        zx = 1  # type: ignoreNrJ   rE   r   r   r   Ú test_type_ignore_comment_ignored‚   rM   z9CollectTypeCommentsTests.test_type_ignore_comment_ignoredc                 C   s4   |   d¡}|  |tƒ ¡ |   d¡}|  |tƒ ¡ dS )zg
        Test that `# type: ignore` comments with more content are also not
        collected.
        zx = 1  # type: ignore # noqazx = 1  #type:ignore#noqaNrJ   rE   r   r   r   Ú*test_type_ignore_with_other_things_ignored‰   s   

zCCollectTypeCommentsTests.test_type_ignore_with_other_things_ignoredc                 C   ó"   |   d¡}|  |tjdfh¡ d S )Nzx = 1  # type: int  # noqa)z# type: int  # noqarC   rE   r   r   r   Ú,test_type_comment_with_extra_still_collected“   ó   
zECollectTypeCommentsTests.test_type_comment_with_extra_still_collectedc                 C   rQ   )Nzx = 1 #type:int)z	#type:intrC   rE   r   r   r   Ú$test_type_comment_without_whitespace—   rS   z=CollectTypeCommentsTests.test_type_comment_without_whitespacec                 C   s   |   d¡}|  |tƒ ¡ d S )Nzx = 1 # type: ignore[T]rJ   rE   r   r   r   Ú)test_type_comment_starts_with_word_ignore›   s   
zBCollectTypeCommentsTests.test_type_comment_starts_with_word_ignorec                 C   r@   )r%   zdef f(): x = 1  # type: intrA   NrC   rE   r   r   r   r)   Ÿ   s   
z,CollectTypeCommentsTests.test_last_node_winsc                 C   s&   |   d¡}tjdfh}|  ||¡ dS )zw
        Test that type comments for function arguments are all attributed to
        the function definition.
        z]def f(
        a,  # type: int
        b,  # type: str
):
    # type: (...) -> None
    pass
)rB   z# type: strz# type: (...) -> NoneN)r?   r   r   rD   )r   r>   Úexpectedr   r   r   Ú#test_function_def_assigned_comments§   s   ÿþz<CollectTypeCommentsTests.test_function_def_assigned_commentsN)r*   r+   r,   r-   r.   r?   rF   rH   rL   rN   rO   rP   rR   rT   rU   r)   rW   r   r   r   r   r1   U   s    

r1   )	r   r/   Úpyflakesr   Úpyflakes.test.harnessr   r   r   r1   r   r   r   r   Ú<module>   s    M