
'![c           @   sd   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 e f d     YZ	 d S(   s#   Unit tests for the imports checker.iN(   t   imports(   t   CheckerTestCaset   Messaget
   set_configt   TestImportsCheckerc           B   s;   e  Z e j Z e d  d  d    Z d   Z d   Z RS(	   t   ignored_modulest   external_modules   fake_module.submodulet   foot   barc         C   s}  t  j d  } |  j    |  j j |  Wd QXt  j d  } |  j    |  j j |  Wd QXt  j d  } |  j    |  j j |  Wd QXt  j d  } |  j    |  j j |  Wd QXt  j d  } |  j    |  j j |  Wd QXt  j d  } t d d	 | d
 d } |  j |   |  j j |  Wd QXt  j d  } |  j    |  j j |  Wd QXd S(   sh   Make sure that imports do not emit a 'import-error' when the
        module is configured to be ignored.s6   
        from external_module import anything
        NsE   
        from external_module.another_module import anything
        s(   
        import external_module
        s<   
        from fake_module.submodule import anything
        sC   
        from fake_module.submodule.deeper import anything
        s!   
        import foo, bar
        s   multiple-importst   nodet   argss   foo, bars/   
        import foo
        import bar
        (   t   astroidt   extract_nodet   assertNoMessagest   checkert   visit_importfromt   visit_importR   t   assertAddsMessages(   t   selfR	   t   msg(    (    sC   lib/python2.7/site-packages/pylint/test/unittest_checker_imports.pyt   test_import_error_skipped   s:    							c         C   sT   t  j d  } t d d d | d d	  } |  j |   |  j j |  Wd QXd S(
   sP   
        Test that duplicate imports on single line raise 'reimported'.
        s#   from time import sleep, sleep, timet   msg_idt
   reimportedR	   R
   t   sleepi   N(   R   i   (   R   R   R   R   R   R   (   R   R	   R   (    (    sC   lib/python2.7/site-packages/pylint/test/unittest_checker_imports.pyt   test_reimported_same_lineJ   s    c      
   C   s  t  j j t  j j t   } t  j j | d d d  } t |   } | j   } Wd  QXt j	 | d d d | } | j
 d } t d d d	 |  } |  j |   |  j j |  Wd  QX|  j    |  j j | j
 d
  Wd  QX|  j   # |  j j | j
 d j
 d  Wd  QXd  S(   Nt   regrtest_datat
   beyond_tops   __init__.pyt   module_namet   pathi    R   s   relative-beyond-top-levelR	   i   i   (   t   osR   t   abspatht   dirnamet   __file__t   joint   opent   readR   t   parset   bodyR   R   R   R   R   (   R   t   hereR   t   streamt   datat   modulet   import_fromR   (    (    sC   lib/python2.7/site-packages/pylint/test/unittest_checker_imports.pyt   test_relative_beyond_top_levelS   s    	(   R   s   fake_module.submoduleR   R   (	   t   __name__t
   __module__R    t   ImportsCheckert   CHECKER_CLASSR   R   R   R+   (    (    (    sC   lib/python2.7/site-packages/pylint/test/unittest_checker_imports.pyR      s   	  1		(
   t   __doc__R   R   t   pylint.checkersR    t   pylint.testutilsR   R   R   R   (    (    (    sC   lib/python2.7/site-packages/pylint/test/unittest_checker_imports.pyt   <module>
   s
   