ó
ŒwÛjc           @   sn  d  Z  d d l Z d d l m Z m Z m Z d d l m 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 Z d d l Z d d l Z d d l Z d d l m Z d e j k rÜ d d l Z n e j d ƒ ‚ e a d	 „  Z d
 „  Z d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d „  Z e d k rje ƒ  n  d S(   s   Tests for 'site'.

Tests assume the initial paths in sys.path once the interpreter has begun
executing have not been removed.

iÿÿÿÿN(   t   run_unittestt   TESTFNt   EnvironmentVarGuard(   t   captured_output(   t   support(   t   copyt   sites!   importation of site.py suppressedc          C   s§   t  j a t j r£ t j j t j ƒ r£ y$ t j t j ƒ t j	 t j ƒ Wq£ t
 k
 rŸ }  |  j t j t j f k r™ t j d t j |  f ƒ ‚ q  ‚  q£ Xn  d  S(   Ns-   unable to create user site directory (%r): %s(   t   syst   patht   OLD_SYS_PATHR   t   ENABLE_USER_SITEt   ost   isdirt	   USER_SITEt   makedirst
   addsitedirt   OSErrort   errnot   EACCESt   EPERMt   unittestt   SkipTest(   t   exc(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   setUpModule!   s    
	c           C   s   t  t j (d  S(   N(   R	   R   R   (    (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   tearDownModule3   s    t   HelperFunctionsTestsc           B   sÔ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d e	 d „ Z
 d	 „  Z d
 „  Z e j e j d k d ƒ d „  ƒ Z d „  Z e j e j d ƒ d „  ƒ Z d „  Z d „  Z d „  Z d „  Z RS(   s›   Tests for helper functions.

    The setting of the encoding (set using sys.setdefaultencoding) used by
    the Unicode implementation is not tested.

    c         C   sG   t  j |  _ t j |  _ t j |  _ t j |  _	 t
 t j ƒ |  _ d S(   s   Save a copy of sys.pathN(   R   R   t   sys_pathR   t	   USER_BASEt   old_baseR   t   old_sitet   PREFIXESt   old_prefixesR   t	   sysconfigt   _CONFIG_VARSt   old_vars(   t   self(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   setUp?   s
    c         C   sA   |  j  t j (|  j t _ |  j t _ |  j t _	 |  j
 t _ d S(   s   Restore sys.pathN(   R   R   R   R   R   R   R   R   R   R   R"   R    R!   (   R#   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   tearDownG   s
    c         C   s”   d } t  j j | Œ  } t j | Œ  \ } } |  j t  j j | ƒ | ƒ | t  j j | ƒ k rt |  j | | ƒ n |  j t  j j | ƒ | ƒ d  S(   Nt	   Beginningt   End(   R&   R'   (   R   R   t   joinR   t   makepatht   assertEqualt   abspatht   normcase(   R#   t
   path_partst   original_dirt   abs_dirt   norm_dir(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_makepathO   s    c         C   sy   t  j ƒ  } xf g  t j D]1 } | r t j j | ƒ r t  j | ƒ d ^ q D]# } |  j | | d | | f ƒ qN Wd  S(   Ni   sB   %s from sys.path not found in set returned by _init_pathinfo(): %s(   R   t   _init_pathinfoR   R   R   R   R)   t   assertIn(   R#   t   dir_setR   t   entry(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_init_pathinfo\   s    5c         C   sc   |  j  | j t j d | j ƒ |  j  t j | j ƒ d t j ƒ |  j t	 j j
 | j ƒ ƒ d S(   s>   Contain common code for testing results of reading a .pth files   %s not in sys.modulesi    N(   R3   t   importedR   t   modulesR   R)   t   good_dir_pathR   t   assertFalseR   t   existst   bad_dir_path(   R#   t   pth_file(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   pth_file_testsd   s    #c         C   sb   t  ƒ  } | j d t ƒ z7 | j ƒ  t j | j | j t ƒ  ƒ |  j	 | ƒ Wd  | j ƒ  Xd  S(   Nt   prep(
   t   PthFilet   cleanupt   Truet   createR   t
   addpackaget   base_dirt   filenamet   setR>   (   R#   R=   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_addpackagek   s    	
t   .c            sw   t  j j | ƒ } | d } t  j j | | ƒ ‰  t ˆ  d ƒ } |  j ‡  f d †  ƒ | j | ƒ | j ƒ  | | f S(   Ns   .ptht   wc              s   t  j ˆ  ƒ S(   N(   R   t   remove(    (   t   pth_fn(    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   <lambda>€   t    (   R   R   R+   R(   t   opent
   addCleanupt   writet   close(   R#   t   contentst   pth_dirt   pth_namet   pth_basenameR=   (    (   RL   s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   make_pthz   s    

c         C   sÊ   |  j  d ƒ \ } } t d ƒ � } t j | | t ƒ  ƒ Wd  QX|  j | j ƒ  d ƒ |  j | j ƒ  t j t	 j
 j | | ƒ ƒ ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ d  S(   Ns   import bad)syntax
t   stderrs   line 1t	   Tracebacks   import bad\)syntaxt   SyntaxError(   RW   R   R   RD   RG   t   assertRegexpMatchest   getvaluet   ret   escapeR   R   R(   (   R#   RT   RL   t   err_out(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt!   test_addpackage_import_bad_syntax…   s    c         C   s´   |  j  d ƒ \ } } t d ƒ � } t j | | t ƒ  ƒ Wd  QX|  j | j ƒ  d ƒ |  j | j ƒ  t j t	 j
 j | | ƒ ƒ ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ d  S(   Ns   randompath
import nosuchmodule
RX   s   line 2RY   t   ImportError(   RW   R   R   RD   RG   R[   R\   R]   R^   R   R   R(   (   R#   RT   RL   R_   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_addpackage_import_bad_exec”   s    t   win32sI   Windows does not raise an error for file paths containing null charactersc         C   s´   |  j  d ƒ \ } } t d ƒ � } t j | | t ƒ  ƒ Wd  QX|  j | j ƒ  d ƒ |  j | j ƒ  t j t	 j
 j | | ƒ ƒ ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ d  S(   Ns   abc def
RX   s   line 1RY   t	   TypeError(   RW   R   R   RD   RG   R[   R\   R]   R^   R   R   R(   (   R#   RT   RL   R_   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt#   test_addpackage_import_bad_pth_file    s    c         C   s\   t  ƒ  } | j d t ƒ z1 | j ƒ  t j | j t ƒ  ƒ |  j | ƒ Wd  | j ƒ  Xd  S(   NR?   (	   R@   RA   RB   RC   R   R   RE   RG   R>   (   R#   R=   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_addsitedir®   s    	
s<   requires access to PEP 370 user-site (site.ENABLE_USER_SITE)c         C   sP  t  j } |  j | t j ƒ t j j ƒ  } t j	 t j
 d d | g d | ƒ} |  j | d d | | f ƒ t j j ƒ  } t j	 t j
 d d d | g d | ƒ} |  j | d ƒ t j j ƒ  } d | d	 <t j	 t j
 d d | g d | ƒ} |  j | d ƒ t j j ƒ  } d
 | d <t j	 t j
 d d g d | ƒ} |  j | d ƒ d  S(   Ns   -cs$   import sys; sys.exit(%r in sys.path)t   envi   s,   %r is not in sys.path (sys.exit returned %r)s   -si    t   1t   PYTHONNOUSERSITEs   /tmpt   PYTHONUSERBASEs=   import sys, site; sys.exit(site.USER_BASE.startswith("/tmp"))(   R   R   R3   R   R   R   t   environR   t
   subprocesst   callt
   executableR*   (   R#   t   usersiteRg   t   rc(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_s_option»   s2    			
	
		c         C   s‹   d  t _ t j ƒ  } |  j t j | ƒ d  t _ d d  l } d  | _ t ƒ  �6 } d | d <|  j t j ƒ  j	 d ƒ t j ƒ  ƒ Wd  QXd  S(   Niÿÿÿÿt   xoxoRj   (
   t   NoneR   R   t   getuserbaseR*   R    R!   R   t
   assertTruet
   startswith(   R#   t	   user_baseR    Rk   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_getuserbaseÜ   s    			
c         C   sj   d  t _ d  t _ t j ƒ  } |  j t j | ƒ |  j | j t j ƒ | ƒ |  j t j t j ƒ  ƒ d  S(   N(	   Rs   R   R   R   t   getusersitepackagesR*   Ru   Rv   Rt   (   R#   t	   user_site(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_getusersitepackagesí   s    		c         C   sT  d g t  _ t  j ƒ  } t j d k rl |  j t | ƒ d ƒ t j j	 d d d ƒ } |  j | d | ƒ nä t j
 d k rú |  j t | ƒ d	 ƒ t j j	 d d
 d t j d  d ƒ } |  j | d | ƒ t j j	 d d
 d ƒ } |  j | d | ƒ nV |  j t | ƒ d	 ƒ |  j | d d ƒ t j j	 d d
 d ƒ } |  j | d | ƒ d  S(   NRr   t   os2emxt   riscosi   t   Libs   site-packagesi    t   /i   t   libt   pythoni   s   site-python(   R|   R}   (   R   R   t   getsitepackagesR   t   platformR*   t   lenR   R   R(   t   sept   version(   R#   t   dirst   wanted(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_getsitepackages÷   s"    	c            s`  d  t _ d  t _ d  t _ t ƒ  �ˆ } t j t	 j
 d d „  ƒ �d | d =| d =t j ƒ  } |  j | j d t	 j ƒ | ƒ t j ƒ  } |  j | j | ƒ | ƒ Wd  QXWd  QX‡  f d †  ‰  d  ˆ  _ d „  } t j t	 j
 d ˆ  ƒ �s t j t d	 | ƒ �W t j t d
 t ƒ �; t ƒ  } t j | ƒ |  j ˆ  j | ƒ |  j | ƒ Wd  QXWd  QXWd  QXd  S(   Nt
   expanduserc         S   s   |  S(   N(    (   R   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyRM     RN   Rj   t   APPDATAt   ~c            s   |  ˆ  _  t S(   N(   t   argt   False(   R   (   t
   fake_isdir(    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyR�   #  s    	c          W   s
   t  ‚ d  S(   N(   t   AssertionError(   t   args(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   must_not_be_called(  s    R   R   R
   (   Rs   R   R   R   R    R!   R   R   t	   swap_attrR   R   Rt   Ru   Rv   R…   Ry   R�   RB   RG   t   addusersitepackagesR*   R:   (   R#   Rk   Rw   Rz   R’   t   known_paths(    (   R�   s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_no_home_directory  s,    			%			(   t   __name__t
   __module__t   __doc__R$   R%   R1   R6   R>   RH   R   RW   R`   Rb   R   t   skipIfR   Rƒ   Re   Rf   t
   skipUnlessR   R
   Rq   Rx   R{   R‰   R–   (    (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyR   7   s"   								$	!		
	R@   c           B   s8   e  Z d  Z e d d d d „ Z d „  Z e d „ Z RS(   s/   Helper class for handling testing of .pth filest   timet   __testdir__t   __badc         C   s›   | d |  _  t j j d ƒ |  _ t j j |  j |  j  ƒ |  _ | |  _ | |  _ | |  _	 t j j |  j |  j ƒ |  _
 t j j |  j |  j	 ƒ |  _ d S(   s   Initialize instance variabless   .pthRN   N(   RF   R   R   R+   RE   R(   t	   file_pathR7   t   good_dirnamet   bad_dirnameR9   R<   (   R#   t   filename_baseR7   R    R¡   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   __init__;  s    			c         C   sw   t  |  j d ƒ } zC | d IJ| d IJ| d |  j IJ| |  j IJ| |  j IJWd | j ƒ  Xt j |  j ƒ d S(   so  Create a .pth file with a comment, blank lines, an ``import
        <self.imported>``, a line with self.good_dirname, and a line with
        self.bad_dirname.

        Creation of the directory for self.good_dir_path (based off of
        self.good_dirname) is also performed.

        Make sure to call self.cleanup() to undo anything done by this method.

        RJ   s   #import @bad module names   
s	   import %sN(	   RO   RŸ   R7   R    R¡   RR   R   t   mkdirR9   (   R#   t   FILE(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyRC   G  s    

c         C   sÕ   t  j j |  j ƒ r( t  j |  j ƒ n  | rb t j j |  j ƒ |  _	 |  j	 r� t j |  j =q� n |  j	 r� |  j	 t j |  j <n  t  j j |  j
 ƒ r© t  j |  j
 ƒ n  t  j j |  j ƒ rÑ t  j |  j ƒ n  d S(   s°   Make sure that the .pth file is deleted, self.imported is not in
        sys.modules, and that both self.good_dirname and self.bad_dirname are
        not existing directories.N(   R   R   R;   RŸ   RK   R   R8   t   getR7   t   imported_moduleR9   t   rmdirR<   (   R#   R?   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyRA   ]  s    		(   R—   R˜   R™   R   R£   RC   RŽ   RA   (    (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyR@   8  s
   	t   ImportSideEffectTestsc           B   s€   e  Z d  Z d „  Z d „  Z d „  Z d „  Z e j d ƒ d „  ƒ Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   s(   Test side-effects from importing 'site'.c         C   s   t  j |  _ d S(   s   Make a copy of sys.pathN(   R   R   R   (   R#   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyR$   r  s    c         C   s   |  j  t j (d S(   s   Restore sys.pathN(   R   R   R   (   R#   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyR%   v  s    c         C   sh   t  j ƒ  xW t t t f D]F } y) |  j t j j | j ƒ t	 | ƒ ƒ Wq t
 k
 r_ q q Xq Wd  S(   N(   R   t   abs__file__R   R   t   __builtin__Ru   R   t   isabst   __file__t   reprt   AttributeError(   R#   t   module(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_abs__file__z  s    
)c         C   sH   t  j ƒ  t ƒ  } x. t j D]# } |  j | | ƒ | j | ƒ q Wd  S(   N(   R   t   removeduppathsRG   R   R   t   assertNotInt   add(   R#   t
   seen_pathsR   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_no_duplicate_pathsˆ  s
    
	s   test not implementedc         C   s   d  S(   N(    (   R#   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_add_build_dir‘  s    c         C   s0   |  j  t t d ƒ ƒ |  j  t t d ƒ ƒ d  S(   Nt   quitt   exit(   Ru   t   hasattrR«   (   R#   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_setting_quit˜  s    c         C   s0   |  j  t t d ƒ ƒ |  j  t t d ƒ ƒ d  S(   Nt	   copyrightt   credits(   Ru   Rº   R«   (   R#   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_setting_copyright�  s    c         C   s   |  j  t t d ƒ ƒ d  S(   Nt   help(   Ru   Rº   R«   (   R#   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_setting_help¢  s    c         C   sx   t  j d k rt d d  l } | j ƒ  d j d ƒ rt x: t j j j ƒ  D] } | d k rG PqG qG W|  j d ƒ qt n  d  S(   NRc   iÿÿÿÿi   t   cpt   mbcss   did not alias mbcs(	   R   Rƒ   t   localet   getdefaultlocaleRv   t	   encodingst   aliasest
   itervaluest   fail(   R#   RÃ   t   value(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_aliasing_mbcs¦  s    c         C   s   |  j  t t d ƒ ƒ d  S(   Nt   setdefaultencoding(   Ru   Rº   R   (   R#   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_setdefaultencoding_removed°  s    c         C   sG   d t  j k rC y d d  l } Wn t k
 r2 qC X|  j d ƒ n  d  S(   Nt   sitecustomizeiÿÿÿÿs(   sitecustomize not imported automatically(   R   R8   RÍ   Ra   RÈ   (   R#   RÍ   (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   test_sitecustomize_executed´  s    (   R—   R˜   R™   R$   R%   R±   R¶   R   t   skipR·   R»   R¾   RÀ   RÊ   RÌ   RÎ   (    (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyR©   o  s   									
	c           C   s   t  t t ƒ d  S(   N(   R    R   R©   (    (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt	   test_main¾  s    t   __main__(    R™   R   t   test.test_supportR    R   R   R   t   testR   R«   R   R   R   R]   RÅ   Rl   R    R   R8   R   R   Rs   R	   R   R   t   TestCaseR   t   objectR@   R©   RÐ   R—   (    (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_site.pyt   <module>   s4   		ÿ 7O	