m๒
ญfIc           @   s๑   d  Z  d k Z d k l Z l Z l Z l Z d k Z d k Z d k	 Z	 d k
 Z
 d k Z d e	 i j o d k Z n e d   d e i f d     YZ d e f d     YZ d	 e i f d
     YZ d   Z e d j o 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.

N(   s   TestSkippeds
   TestFaileds   run_unittests   TESTFNt   sites!   importation of site.py suppressedt   HelperFunctionsTestsc           B   sM   t  Z d  Z d   Z d   Z 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   s   t  i |  _ d S(   s   Save a copy of sys.pathN(   t   syst   patht   selft   sys_path(   R   (    (    t+   /mit/python/lib/python2.4/test/test_site.pyt   setUp   s     c         C   s   |  i t _ d S(   s   Restore sys.pathN(   R   R   R   R   (   R   (    (    R   t   tearDown"   s     c         C   s   d } t i i |   } t i |   \ } } |  i
 t i i |  |  | t i i |  j o |  i
 | |  n |  i
 t i i |  |  d  S(   Nt	   Beginningt   End(   R	   R
   (   t
   path_partst   osR   t   joint   original_dirR    t   makepatht   abs_dirt   norm_dirR   t   failUnlessEqualt   abspatht   normcase(   R   R   R   R   R   (    (    R   t   test_makepath&   s    c         C   s   t  i   } xw g  } t i D]8 } | o+ t i i |  o | t  i |  d q q ~ D]& } |  i | | j d | | f  q\ Wd  S(   Ni   sB   %s from sys.path not found in set returned by _init_pathinfo(): %s(   R    t   _init_pathinfot   dir_sett   _[1]R   R   R   t   isdirR   t   entryR   t
   failUnless(   R   R   R   R   R   (    (    R   t   test_init_pathinfo3   s
    P c         C   sj   |  i | i t i j d | i  |  i t i | i  d t i	 j  |  i t
 i	 i | i   d S(   s>   Contain common code for testing results of reading a .pth files   %s not in sys.pathi    N(   R   R   t   pth_filet   importedR   t   modulesR    R   t   good_dir_pathR   R   t   existst   bad_dir_path(   R   R   (    (    R   t   pth_file_tests;   s
     &c         C   sb   t    } | i d t  z7 | i   t i | i | i t	    |  i |  Wd  | i   Xd  S(   Nt   prep(   t   PthFileR   t   cleanupt   Truet   createR    t
   addpackaget   base_dirt   filenamet   setR   R#   (   R   R   (    (    R   t   test_addpackageB   s    	
 c         C   s\   t    } | i d t  z1 | i   t i | i t    |  i
 |  Wd  | i   Xd  S(   NR$   (   R%   R   R&   R'   R(   R    t
   addsitedirR*   R,   R   R#   (   R   R   (    (    R   t   test_addsitedirQ   s    	
 (
   t   __name__t
   __module__t   __doc__R   R   R   R   R#   R-   R/   (    (    (    R   R      s    						R%   c           B   s8   t  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 i i d  |  _ t i i |  i |  i  |  _ | |  _	 | |  _
 | |  _ t i i |  i |  i
  |  _ t i i |  i |  i  |  _ d S(   s   Initialize instance variabless   .ptht    N(   t   filename_baseR   R+   R   R   R   R*   R   t	   file_pathR   t   good_dirnamet   bad_dirnameR    R"   (   R   R7   R   R9   R:   (    (    R   t   __init__a   s     			c      	   C   sw   t  |  i d  } zC | d IJ| d IJ| d |  i IJ| |  i IJ| |  i IJWd | i   Xt i	 |  i
  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.

        t   wUs   #import @bad module names   
s	   import %sN(   t   openR   R8   t   FILER   R9   R:   t   closeR   t   mkdirR    (   R   R>   (    (    R   R(   m   s    
 

 c         C   sแ   t  i i |  i  o t  i |  i  n | o7 t i i	 |  i
  |  _ |  i o t i |  i
 =q n" |  i o |  i t i |  i
 <n t  i i |  i  o t  i |  i  n t  i i |  i  o t  i |  i  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   R8   t   removeR$   R   R   t   getR   t   imported_moduleR    t   rmdirR"   (   R   R$   (    (    R   R&      s     

(   R0   R1   R2   t   TESTFNR;   R(   t   FalseR&   (    (    (    R   R%   ^   s    	t   ImportSideEffectTestsc           B   sq   t  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(   s(   Test side-effects from importing 'site'.c         C   s   t  i |  _ d S(   s   Make a copy of sys.pathN(   R   R   R   R   (   R   (    (    R   R      s     c         C   s   |  i t _ d S(   s   Restore sys.pathN(   R   R   R   R   (   R   (    (    R   R      s     c         C   se   t  i   xT t t t f D]C } y$ |  i t i i	 | i
  |  Wq t j
 o
 q q Xq Wd  S(   N(   R    t   abs__file__R   R   t   __builtin__t   moduleR   R   R   t   isabst   __file__t   AttributeError(   R   RJ   (    (    R   t   test_abs__file__    s    
 $c         C   sK   t  i   t   } x1 t i D]& } |  i | | j  | i |  q Wd  S(   N(	   R    t   removeduppathsR,   t
   seen_pathsR   R   R   R   t   add(   R   RP   R   (    (    R   t   test_no_duplicate_pathsฎ   s    
	
 c         C   s   d  S(   N(    (   R   (    (    R   t   test_add_build_dirท   s    c         C   s0   |  i t t d   |  i t t d   d  S(   Nt   quitt   exit(   R   R   t   hasattrRI   (   R   (    (    R   t   test_setting_quitฝ   s    c         C   s0   |  i t t d   |  i t t d   d  S(   Nt	   copyrightt   credits(   R   R   RV   RI   (   R   (    (    R   t   test_setting_copyrightย   s    c         C   s   |  i t t d   d  S(   Nt   help(   R   R   RV   RI   (   R   (    (    R   t   test_setting_helpว   s    c         C   s{   t  i d j og d  k } | i   d i d  o@ x= t i i i   D] } | d j o PqF qF W|  i
 d  qw n d  S(   Nt   win32i   t   cpt   mbcss   did not alias mbcs(   R   t   platformt   localet   getdefaultlocalet
   startswitht	   encodingst   aliasest
   itervaluest   valueR   t   fail(   R   Ra   Rg   (    (    R   t   test_aliasing_mbcsห   s    	 	c         C   s   |  i t t d   d  S(   Nt   setdefaultencoding(   R   R   RV   R   (   R   (    (    R   t   test_setdefaultencoding_removedี   s    c         C   sK   t  i i d  p4 y d  k } Wn t j
 o qG X|  i d  n d  S(   Nt   sitecustomizes(   sitecustomize not imported automatically(   R   R   t   has_keyRl   t   ImportErrorR   Rh   (   R   Rl   (    (    R   t   test_sitecustomize_executedู   s    (   R0   R1   R2   R   R   RN   RR   RS   RW   RZ   R\   Ri   Rk   Ro   (    (    (    R   RG      s    										
	c           C   s   t  t t  d  S(   N(   t   run_unittestR   RG   (    (    (    R   t	   test_mainๆ   s    t   __main__(   R2   t   unittestt   test.test_supportt   TestSkippedt
   TestFailedRp   RE   RI   R   R   Rd   t   tempfileR   R    t   TestCaseR   t   objectR%   RG   Rq   R0   (   Ru   R%   Rw   RG   Rs   R    RI   R   R   Rd   Rp   Rv   R   RE   Rq   (    (    R   t   ?   s    						H7Q	