ó
Š]c           @   s/  d  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	 Z	 d d l
 m Z d d l m Z m Z m Z m Z m Z d d l m Z d „  Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d d d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d S(   s&   Support code for distutils test cases.iÿÿÿÿN(   t   deepcopy(   t   log(   t   DEBUGt   INFOt   WARNt   ERRORt   FATAL(   t   Distributionc            s   ‡  f d †  } | S(   Nc             s1   t  j ƒ   t  j d ƒ ˆ  |  | Ž  SWd  QXd  S(   Nt   ignore(   t   warningst   catch_warningst   simplefilter(   t   argst   kw(   t   func(    s(   lib/python2.7/distutils/tests/support.pyt   _capture_warnings   s    (    (   R   R   (    (   R   s(   lib/python2.7/distutils/tests/support.pyt   capture_warnings   s    t   LoggingSilencerc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sS   t  t |  ƒ j ƒ  t j t j ƒ |  _ t j j |  _	 |  j t j _ g  |  _
 d  S(   N(   t   superR   t   setUpR   t   set_thresholdR   t	   thresholdt   Logt   _logt   _old_logt   logs(   t   self(    (    s(   lib/python2.7/distutils/tests/support.pyR      s
    c         C   s6   t  j |  j ƒ |  j t  j _ t t |  ƒ j ƒ  d  S(   N(	   R   R   R   R   R   R   R   R   t   tearDown(   R   (    (    s(   lib/python2.7/distutils/tests/support.pyR   $   s    c         C   sQ   | t  t t t t f k r4 t d t | ƒ ƒ ‚ n  |  j j | | | f ƒ d  S(   Ns   %s wrong log level(	   R   R   R   R   R   t
   ValueErrort   strR   t   append(   R   t   levelt   msgR   (    (    s(   lib/python2.7/distutils/tests/support.pyR   )   s    c         G   sA   d „  } g  |  j  D]* \ } } } | | k r | | | ƒ ^ q S(   Nc         S   s   t  | ƒ d k r |  S|  | S(   Ni    (   t   len(   R    R   (    (    s(   lib/python2.7/distutils/tests/support.pyt   _format/   s    (   R   (   R   t   levelsR"   R   R    R   (    (    s(   lib/python2.7/distutils/tests/support.pyt   get_logs.   s    	c         C   s   g  |  _  d  S(   N(   R   (   R   (    (    s(   lib/python2.7/distutils/tests/support.pyt
   clear_logs6   s    (   t   __name__t
   __module__R   R   R   R$   R%   (    (    (    s(   lib/python2.7/distutils/tests/support.pyR      s
   	
			t   TempdirManagerc           B   sA   e  Z d  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z RS(   s}   Mix-in class that handles temporary directories for test cases.

    This is intended to be used with unittest.TestCase.
    c         C   s/   t  t |  ƒ j ƒ  t j ƒ  |  _ g  |  _ d  S(   N(   R   R(   R   t   ost   getcwdt   old_cwdt   tempdirs(   R   (    (    s(   lib/python2.7/distutils/tests/support.pyR   @   s    c         C   s_   t  j |  j ƒ t t |  ƒ j ƒ  x5 |  j rZ |  j j ƒ  } t j	 | t  j
 d k ƒ q& Wd  S(   Nt   ntt   cygwin(   R-   R.   (   R)   t   chdirR+   R   R(   R   R,   t   popt   shutilt   rmtreet   name(   R   t   d(    (    s(   lib/python2.7/distutils/tests/support.pyR   E   s
    c         C   s    t  j ƒ  } |  j j | ƒ | S(   sj   Create a temporary directory that will be cleaned up.

        Returns the path of the directory.
        (   t   tempfilet   mkdtempR,   R   (   R   R4   (    (    s(   lib/python2.7/distutils/tests/support.pyR6   N   s    t   xxxc         C   s\   t  | t t f ƒ r* t j j | Œ  } n  t | d ƒ } z | j | ƒ Wd | j ƒ  Xd S(   sW   Writes a file in the given path.


        path can be a string or a sequence.
        t   wN(	   t
   isinstancet   listt   tupleR)   t   patht   joint   opent   writet   close(   R   R<   t   contentt   f(    (    s(   lib/python2.7/distutils/tests/support.pyt
   write_fileW   s    t   fooc         K   sG   |  j  ƒ  } t j j | | ƒ } t j | ƒ t d | ƒ } | | f S(   s  Will generate a test environment.

        This function creates:
         - a Distribution instance using keywords
         - a temporary directory with a package structure

        It returns the package directory and the distribution
        instance.
        t   attrs(   R6   R)   R<   R=   t   mkdirR   (   R   t   pkg_nameR   t   tmp_dirt   pkg_dirt   dist(    (    s(   lib/python2.7/distutils/tests/support.pyt   create_diste   s
    
(   R&   R'   t   __doc__R   R   R6   RC   RK   (    (    (    s(   lib/python2.7/distutils/tests/support.pyR(   :   s   					t   DummyCommandc           B   s    e  Z d  Z d „  Z d „  Z RS(   sA   Class to store options for retrieval via set_undefined_options().c         K   s1   x* | j  ƒ  D] \ } } t |  | | ƒ q Wd  S(   N(   t   itemst   setattr(   R   t   kwargsR   t   val(    (    s(   lib/python2.7/distutils/tests/support.pyt   __init__z   s    c         C   s   d  S(   N(    (   R   (    (    s(   lib/python2.7/distutils/tests/support.pyt   ensure_finalized~   s    (   R&   R'   RL   RR   RS   (    (    (    s(   lib/python2.7/distutils/tests/support.pyRM   w   s   	t   EnvironGuardc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s)   t  t |  ƒ j ƒ  t t j ƒ |  _ d  S(   N(   R   RT   R   R    R)   t   environt   old_environ(   R   (    (    s(   lib/python2.7/distutils/tests/support.pyR   „   s    c         C   s•   xE |  j  j ƒ  D]4 \ } } t j j | ƒ | k r | t j | <q q Wx3 t j j ƒ  D]" } | |  j  k rX t j | =qX qX Wt t |  ƒ j ƒ  d  S(   N(	   RV   RN   R)   RU   t   gett   keysR   RT   R   (   R   t   keyt   value(    (    s(   lib/python2.7/distutils/tests/support.pyR   ˆ   s    (   R&   R'   R   R   (    (    (    s(   lib/python2.7/distutils/tests/support.pyRT   ‚   s   	c         C   s;   t  ƒ  } | d k r' t j d ƒ ‚ n  t j | |  ƒ d S(   sk  Helper for tests that need the xxmodule.c source file.

    Example use:

        def test_compile(self):
            copy_xxmodule_c(self.tmpdir)
            self.assertIn('xxmodule.c', os.listdir(self.tmpdir))

    If the source file can be found, it will be copied to *directory*.  If not,
    the test will be skipped.  Errors during copy are not caught.
    s>   cannot find xxmodule.c (test must run in the python build dir)N(   t   _get_xxmodule_patht   Nonet   unittestt   SkipTestR1   t   copy(   t	   directoryt   filename(    (    s(   lib/python2.7/distutils/tests/support.pyt   copy_xxmodule_c”   s    	c       	   C   s‘   t  j d ƒ }  t j j t j j t ƒ d ƒ t j j |  d d ƒ t j j |  d d d d d ƒ g } x$ | D] } t j j | ƒ rm | Sqm Wd  S(   Nt   srcdirs
   xxmodule.ct   Moduless   ..(   t	   sysconfigt   get_config_varR)   R<   R=   t   dirnamet   __file__t   exists(   Rc   t
   candidatesR<   (    (    s(   lib/python2.7/distutils/tests/support.pyR[   §   s    $c         C   sÈ   t  j d k r' t j j d ƒ |  _ n t j d ƒ rÄ t j d ƒ } | d k r` d g |  _	 qÄ t j
 d k r{ g  |  _	 qÄ | j d ƒ \ } } } g  | j t  j ƒ D] } | r¦ | ^ q¦ |  _	 n  d S(	   s4  Function needed to make build_ext tests pass.

    When Python was build with --enable-shared on Unix, -L. is not good
    enough to find the libpython<blah>.so.  This is because regrtest runs
    it under a tempdir, not in the top level where the .so lives.  By the
    time we've gotten here, Python's already been chdir'd to the tempdir.

    When Python was built with in debug mode on Windows, build_ext commands
    need their debug attribute set, and it is not done automatically for
    some reason.

    This function handles both of these things.  Example use:

        cmd = build_ext(dist)
        support.fixup_build_ext(cmd)
        cmd.ensure_finalized()

    Unlike most other Unix platforms, Mac OS X embeds absolute paths
    to shared libraries into executables, so the fixup is not needed there.
    R-   s   _d.exet   Py_ENABLE_SHAREDt	   RUNSHAREDt   .t   darwint   =N(   R)   R3   t   syst
   executablet   endswitht   debugRe   Rf   R\   t   library_dirst   platformt	   partitiont   splitt   pathsep(   t   cmdt	   runsharedR3   t   equalsRZ   R4   (    (    s(   lib/python2.7/distutils/tests/support.pyt   fixup_build_extº   s    (    (   RL   R)   Rp   R1   R5   R]   Re   R_   R    R	   t	   distutilsR   t   distutils.logR   R   R   R   R   t   distutils.coreR   R   t   objectR   R(   RM   RT   Rb   R[   R|   (    (    (    s(   lib/python2.7/distutils/tests/support.pyt   <module>   s&   (	"=		