ó
î%![c           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z	 d  d l
 m Z e j j j Z d „  Z d e j e j e j f d „  ƒ  YZ d e j f d	 „  ƒ  YZ e d
 k rÿ e j ƒ  n  d S(   iÿÿÿÿN(   t
   exceptions(   t   manager(   t	   resourcesc         C   sd   t  j ƒ  d k r* |  j j d ƒ d d St j d k r@ |  j S|  j j d ƒ s] |  j d  S|  j S(	   Nt   Jythons	   $py.classi    s   .pyi   i   iÿÿÿÿ(   i   i   (   t   platformt   python_implementationt   __file__t   splitt   syst   version_infot   endswith(   t   obj(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   _get_file_from_object   s    t   AstroidManagerTestc           B   s,  e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z e j e j d  d! k d ƒ d „  ƒ Z d „  Z d „  Z d „  Z d „  Z 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("   c         C   s9   t  t |  ƒ j ƒ  t j ƒ  |  _ |  j j |  j ƒ d  S(   N(   t   superR   t   setUpR   t   AstroidManagert   clear_cachet	   _builtins(   t   self(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyR   (   s    c         C   sH   t  j } |  j j | ƒ } |  j | j d ƒ |  j d |  j j ƒ d  S(   Nt   unittest(   R   R   R   t   ast_from_filet   assertEqualt   namet   assertInt   astroid_cache(   R   t   filepatht   ast(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_file-   s    	c         C   s[   t  j } |  j j | ƒ |  j j d d ƒ } |  j | j d ƒ |  j d |  j j ƒ d  S(   Nt   unhandledNameR   (   R   R   R   R   R   R   R   R   (   R   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_file_cache3   s
    	c         C   sQ   t  j } |  j j | d  t t ƒ } |  j | j d ƒ |  j d |  j j	 ƒ d  S(   NR   (
   R   R   R   R   t   Nonet   TrueR   R   R   R   (   R   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt    test_ast_from_file_astro_builder:   s    	c         C   s    |  j  t j |  j j d ƒ d  S(   NR   (   t   assertRaisesR    t   AstroidBuildingErrorR   R   (   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt/   test_ast_from_file_name_astro_builder_exception@   s    c         C   s?   |  j  j d ƒ } |  j | j d ƒ |  j | j ƒ  g  ƒ d  S(   Nt   __main__(   R   t   ast_from_module_nameR   R   t   items(   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_do_not_expose_mainD   s    c         C   s?   |  j  j d ƒ } |  j | j d ƒ |  j d |  j  j ƒ d  S(   NR   (   R   R&   R   R   R   R   (   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_module_nameI   s    c         C   sR   |  j  j d ƒ } |  j | j d ƒ |  j d |  j  j ƒ |  j | j t ƒ d  S(   Nt   time(   R   R&   R   R   R   R   t   pure_pythont   False(   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt+   test_ast_from_module_name_not_python_sourceN   s    c         C   s    |  j  t j |  j j d ƒ d  S(   Nt   unhandledModule(   R"   R    R#   R   R&   (   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt1   test_ast_from_module_name_astro_builder_exceptionT   s    	c         C   s    t  j } g  t d d ƒ D]! } t j d j | | ƒ ƒ ^ q } t  j j | ƒ z> x7 d D]/ } |  j j d | ƒ } |  j	 | t
 j ƒ q[ WWd  | t  _ Xd  S(	   Ni   i   s   data/path_{}_{}t   foot   bart   bazs   package.(   R0   R1   R2   (   R   t   patht   rangeR   t   findt   formatt   extendR   R&   t   assertIsInstancet   astroidt   Module(   R   t   roott   origpatht   indext   pathsR   t   module(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt-   _test_ast_from_old_namespace_package_protocolY   s    
4c         C   s   |  j  d ƒ d  S(   Nt   pkgutil(   R@   (   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_namespace_pkgutile   s    c         C   s   |  j  d ƒ d  S(   Nt   pkg_resources(   R@   (   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt%   test_ast_from_namespace_pkg_resourcesh   s    i   i   i   s    Needs PEP 420 namespace protocolc         C   s   t  j j t j d ƒ ƒ } t  j j | d ƒ } x' | | f D] } t j j d | ƒ q= Wzw |  j j	 d ƒ } |  j
 | t j ƒ |  j | j d ƒ t | j d ƒ ƒ } |  j
 | t j ƒ |  j | j d ƒ Wd  x$ t d ƒ D] } t j j d ƒ qá WXd  S(   Ns   data/namespace_pep_420t   contribute_to_namespacei    s   namespace_pep_420.modulet   vari*   i   (   t   osR3   t   dirnameR   R5   t   joinR   t   insertR   R&   R8   R9   R:   R   R   t   nextt   igetattrt   Constt   valueR4   t   pop(   R   t   data_dirt
   contributeRN   R?   RF   t   _(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_implicit_namespace_packagek   s    c         C   sÇ   d } t  j t j | g  ƒ g  t j d <z| |  j j d ƒ } t | j	 d ƒ ƒ } t | j	 d ƒ ƒ } |  j
 | t j ƒ |  j t j ƒ  |  j j d ƒ Wd  QXWd  t j d =t j j d ƒ Xd  S(   Ns!   foogle_fax-0.12.5-py2.7-nspkg.ptht   foogles
   foogle.faxt   at   xs   foogle.moogle(   t   sitet
   addpackageR   t   RESOURCE_PATHRC   t   _namespace_packagesR   R&   RK   RL   R8   R9   RM   R"   R    t   AstroidImportErrorR   t   modulesRO   (   R   t   pthR?   t	   submoduleRN   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt"   test_namespace_package_pth_support}   s    
c         C   so   d } t  j t j | g  ƒ d g t j d <g  t j d <z |  j j d ƒ Wd  t j d =t j	 j
 d ƒ Xd  S(   Ns!   foogle_fax-0.12.5-py2.7-nspkg.pths   foogle.crankRT   (   RW   RX   R   RY   RC   RZ   R   R&   R   R\   RO   (   R   R]   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_nested_namespace_import   s    
c         C   s¦   t  j } |  j j | ƒ } |  j | j d ƒ d } t j t j	 | g  ƒ g  t
 j d <z- |  j t j ƒ  |  j j d ƒ Wd  QXWd  t
 j d =t j j d ƒ Xd  S(   NR   s!   foogle_fax-0.12.5-py2.7-nspkg.pthRT   s   unittest.foogle.fax(   R   R   R   R   R   R   RW   RX   R   RY   RC   RZ   R"   R    R[   R&   R   R\   RO   (   R   R   R   R]   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt    test_namespace_and_file_mismatch˜   s    	
c         C   s  t  j } t  j j d d  ƒ t j | ƒ } t  j j d | ƒ zg |  j j	 d ƒ } |  j
 | j d ƒ t j j | d ƒ } |  j | j j | ƒ d | j | f ƒ Wd  d |  j j k rØ |  j j d =|  j j d =n  | t  j k rô t  j | =n  | t  _ Xd  S(   Nt   mypypai    s   %s doesn't endswith %s(   Rb   N(   R   R3   R\   RO   R   R   R5   RJ   R   R&   R   R   RG   RI   t
   assertTruet   fileR
   R   t   _mod_file_cachet   path_importer_cache(   R   t   archiveR<   t   archive_pathR?   t   end(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   _test_ast_from_zip¦   s     
c         C   s2   |  j  t j j j d t j j d ƒ g ƒ ƒ d  S(   Nt   datas   MyPyPa-0.1.0-py2.5.egg(   Rj   RG   R3   t   sepRI   t   normcase(   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_module_name_eggº   s    c         C   s2   |  j  t j j j d t j j d ƒ g ƒ ƒ d  S(   NRk   s   MyPyPa-0.1.0-py2.5.zip(   Rj   RG   R3   Rl   RI   Rm   (   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_module_name_zip¿   s    c         C   s8   t  j d ƒ } |  j j | ƒ } |  j | j d ƒ d S(   s   check if zip_import_data workss"   data/MyPyPa-0.1.0-py2.5.zip/mypypaRb   N(   R   R5   R   t   zip_import_dataR   R   (   R   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_zip_import_dataÄ   s    c         C   s    |  j  |  j j d ƒ d ƒ d S(   s6   check if zip_import_data return None without zipimportR3   N(   R   R   Rp   R   (   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt&   test_zip_import_data_without_zipimportÊ   s    c         C   s,   |  j  t t ƒ |  j j d d ƒ j ƒ d S(   sD   check if the unittest filepath is equals to the result of the methodR   N(   R   R   R   R   t   file_from_module_nameR   t   location(   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_file_from_moduleÎ   s    	c         C   s#   |  j  t j |  j j d d ƒ d S(   s?   check if the method launch a exception with a wrong module nameR.   N(   R"   R    R#   R   Rs   R   (   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt3   test_file_from_module_name_astro_building_exceptionÕ   s    c         C   sZ   |  j  j t ƒ } |  j | j t ƒ d d  l } |  j  j | ƒ } |  j | j t ƒ d  S(   Niÿÿÿÿ(   R   t   ast_from_moduleR   R   R+   R    R*   R,   (   R   R   R*   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_moduleÚ   s
    c         C   s?   |  j  j t ƒ } |  j | j d ƒ |  j d |  j  j ƒ d S(   s+   check if the module is in the cache managerR   N(   R   Rw   R   R   R   R   R   (   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_module_cacheá   s    c         C   s–   |  j  j t ƒ } |  j | j d ƒ |  j | j j ƒ  j t ƒ |  j  j t ƒ } |  j | j d ƒ |  j | j j ƒ  j t ƒ |  j	 d | ƒ d  S(   Nt   intt   objectt   __setattr__(
   R   t   ast_from_classRz   R   R   t   parentt   framet   BUILTINSR{   R   (   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_classç   s    c         C   s¢   |  j  j t t j ƒ } |  j | j d ƒ |  j | j j ƒ  j t ƒ |  j  j t	 t	 j ƒ } |  j | j d ƒ |  j | j j ƒ  j t ƒ |  j
 d | ƒ d S(   s.   check if the method works with the module nameRz   R{   R|   N(   R   R}   Rz   t
   __module__R   R   R~   R   R€   R{   R   (   R   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_class_with_moduleñ   s    c         C   s    |  j  t j |  j j d ƒ d S(   s/   give a wrong class at the ast_from_class methodN(   R"   R    R#   R   R}   R   (   R   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   test_ast_from_class_attr_errorü   s    c         C   s˜   d „  } |  j  t j ƒ  |  j j d ƒ Wd  QX|  j j | ƒ |  j t |  j j d ƒ ƒ |  j  t j ƒ  |  j j d ƒ Wd  QX|  j j d =d  S(   Nc         S   s    |  d k r t  St j ƒ  ‚ d  S(   Ns   foo.bar(   R   R    R#   (   t   modname(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   hook  s    s   foo.bars   foo.bar.bazi    (	   R"   R    R#   R   R&   t   register_failed_import_hookR   R   t   _failed_import_hooks(   R   R†   (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   testFailedImportHooks  s    	(   i   i   (#   t   __name__R‚   R   R   R   R!   R$   R(   R)   R-   R/   R@   RB   RD   R   t
   skipUnlessR   R	   RS   R_   R`   Ra   Rj   Rn   Ro   Rq   Rr   Ru   Rv   Rx   Ry   R   Rƒ   R„   R‰   (    (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyR   $   s:   												(													
		t   BorgAstroidManagerTCc           B   s   e  Z d  „  Z RS(   c         C   sJ   t  j ƒ  } | j t ƒ } t  j ƒ  } | j t ƒ } |  j | | ƒ d S(   sg   test that the AstroidManager is really a borg, i.e. that two different
        instances has same cacheN(   R   R   R&   R€   t   assertIs(   R   t   first_managert   builtt   second_managert   second_built(    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt	   test_borg  s
    (   RŠ   R‚   R’   (    (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyRŒ     s   R%   (   RG   R   RW   R   R   RC   t   sixR9   R    R   t   astroid.testsR   t   movest   builtinsRŠ   R€   R   t   SysPathSetupt   AstroidCacheSetupMixint   TestCaseR   RŒ   t   main(    (    (    s=   lib/python2.7/site-packages/astroid/tests/unittest_manager.pyt   <module>   s$   	
	ë