ó
4¶†\c           @   sn   d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   checker(   t   TestCaset   skipIft   TypeableVisitorTestsc           B   sY   e  Z d  Z e d „  ƒ Z d „  Z d „  Z e e j	 d	 k  d ƒ d „  ƒ Z
 d „  Z RS(
   s&   
    Tests of L{_TypeableVisitor}
    c         C   s,   t  j |  ƒ } t j ƒ  } | j | ƒ | S(   sV   
        Run L{_TypeableVisitor} on the parsed source and return the visitor.
        (   t   astt   parseR    t   _TypeableVisitort   visit(   t   st   treet   visitor(    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt   _run_visitor   s    c         C   sš   |  j  d ƒ } |  j | j d d d d g ƒ |  j | j d t j ƒ |  j | j d t j ƒ |  j | j d t j ƒ |  j | j d t j	 ƒ d S(   sA   
        Test that the typeable node types are collected
        s   x = 1  # assignment
for x in range(1): pass  # for loop
def f(): pass  # function definition
with a as b: pass  # with statement
i   i   i   i   N(
   R   t   assertEqualt   typeable_linest   assertIsInstancet   typeable_nodesR   t   Assignt   Fort   FunctionDeft   With(   t   selfR
   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt   test_node_types   s    	c         C   s`   |  j  d ƒ } |  j | j d d g ƒ |  j | j d t j ƒ |  j | j d t j ƒ d S(   sƒ   
        Test the common pitfall of missing `generic_visit` in visitors by
        ensuring that nested nodes are reported
        s   def f():
    x = 1
i   i   N(   R   R   R   R   R   R   R   R   (   R   R
   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt   test_visitor_recurses)   s
    	i   i   s   async syntax introduced in py35c         C   s}   |  j  d ƒ } |  j | j d d d g ƒ |  j | j d t j ƒ |  j | j d t j ƒ |  j | j d t j ƒ d S(   s@   
        Test that the PEP 492 node types are collected
        so   async def f():  # async def
    async for x in y:  pass  # async for
    async with a as b: pass  # async with
i   i   i   N(	   R   R   R   R   R   R   t   AsyncFunctionDeft   AsyncFort	   AsyncWith(   R   R
   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt   test_py35_node_types8   s    	c         C   sM   |  j  d ƒ } |  j | j d d g ƒ |  j | j d j d j d ƒ d S(   sn   
        Test that when two typeable nodes are present on a line, the last
        typeable one wins.
        s   x = 1; y = 1i   i    t   yN(   R   R   R   R   t   targetst   id(   R   R
   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt   test_last_node_winsI   s    (   i   i   (   t   __name__t
   __module__t   __doc__t   staticmethodR   R   R   R   t   syst   version_infoR   R   (    (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyR      s   
		!t   CollectTypeCommentsTestsc           B   s€   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   s,   
    Tests of L{_collect_type_comments}
    c         C   sD   t  j |  ƒ } t j |  ƒ } t j | | ƒ } d „  | j ƒ  Dƒ S(   sÒ   
        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   s8   h  |  ]. \ } } t  | ƒ t d  „  | Dƒ ƒ f ’ q S(   c         s   s   |  ] \ } } | Vq d  S(   N(    (   t   .0t   _R   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pys	   <genexpr>d   s    (   t   typet   tuple(   R&   t   kt   v(    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pys	   <setcomp>d   s   	 (   R   R   R    t   make_tokenst   _collect_type_commentst   items(   R   R	   t   tokenst   ret(    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt   _collectZ   s    c         C   s/   |  j  d ƒ } |  j | t j d f h ƒ d S(   s@   
        Test that the function works for binary source
        s   x = 1  # type: ints   # type: intN(   s   # type: int(   R1   t   assertSetEqualR   R   (   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt
   test_bytesf   s    c         C   s/   |  j  d ƒ } |  j | t j d f h ƒ d S(   s>   
        Test that the function works for text source
        u   x = 1  # type: ints   # type: intN(   s   # type: int(   R1   R   R   R   (   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt	   test_textm   s    c         C   s&   |  j  d ƒ } |  j | t ƒ  ƒ d S(   s9   
        Test that a non-type comment is ignored
        s   x = 1  # noqaN(   R1   R2   t   set(   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt   test_non_type_comment_ignoredt   s    c         C   s&   |  j  d ƒ } |  j | t ƒ  ƒ d S(   sP   
        Test that a type comment before something typeable is ignored.
        s   # type: int
x = 1N(   R1   R2   R5   (   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt!   test_type_comment_before_typeable{   s    c         C   s&   |  j  d ƒ } |  j | t ƒ  ƒ d S(   sH   
        Test that `# type: ignore` comments are not collected.
        s   x = 1  # type: ignoreN(   R1   R2   R5   (   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt    test_type_ignore_comment_ignored‚   s    c         C   sH   |  j  d ƒ } |  j | t ƒ  ƒ |  j  d ƒ } |  j | t ƒ  ƒ d S(   sg   
        Test that `# type: ignore` comments with more content are also not
        collected.
        s   x = 1  # type: ignore # noqas   x = 1  #type:ignore#noqaN(   R1   R2   R5   (   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt*   test_type_ignore_with_other_things_ignored‰   s    c         C   s/   |  j  d ƒ } |  j | t j d f h ƒ d  S(   Ns   x = 1  # type: int  # noqas   # type: int  # noqa(   s   # type: int  # noqa(   R1   R2   R   R   (   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt,   test_type_comment_with_extra_still_collected“   s    c         C   s/   |  j  d ƒ } |  j | t j d f h ƒ d  S(   Ns   x = 1 #type:ints	   #type:int(   s	   #type:int(   R1   R2   R   R   (   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt$   test_type_comment_without_whitespace—   s    c         C   s/   |  j  d ƒ } |  j | t j d f h ƒ d  S(   Ns   x = 1 # type: ignore[T]s   # type: ignore[T](   s   # type: ignore[T](   R1   R2   R   R   (   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt)   test_type_comment_starts_with_word_ignore›   s    c         C   s/   |  j  d ƒ } |  j | t j d f h ƒ d S(   sn   
        Test that when two typeable nodes are present on a line, the last
        typeable one wins.
        s   def f(): x = 1  # type: ints   # type: intN(   s   # type: int(   R1   R2   R   R   (   R   R0   (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyR   Ÿ   s    c         C   s5   |  j  d ƒ } t j d f h } |  j | | ƒ d S(   sw   
        Test that type comments for function arguments are all attributed to
        the function definition.
        s]   def f(
        a,  # type: int
        b,  # type: str
):
    # type: (...) -> None
    pass
s   # type: ints   # type: strs   # type: (...) -> NoneN(   s   # type: ints   # type: strs   # type: (...) -> None(   R1   R   R   R2   (   R   R0   t   expected(    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt#   test_function_def_assigned_comments§   s
    	(   R   R    R!   R"   R1   R3   R4   R6   R7   R8   R9   R:   R;   R<   R   R>   (    (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyR%   U   s   						
				(	   R   R#   t   pyflakesR    t   pyflakes.test.harnessR   R   R   R%   (    (    (    s9   lib/python2.7/site-packages/pyflakes/test/test_checker.pyt   <module>   s
   M