
#8Zc        :   @   s  d  Z  e d j o e d   n d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 Z	 d d k
 Z
 d d k Z d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 g1 Z d e f d6     YZ d e f d7     YZ d e f d8     YZ d e f d9     YZ e d:  Z d; Z d Z d< a d< a d a d=   Z d>   Z d?   Z d@   Z dA   Z dB   Z dC   Z  d dD  Z! dE Z" e i# e i$ dF  Z% e" dG  Z& dH Z' dI   Z( y e) e* Z+ Wn e, j
 o e Z+ n Xe i- i. dJ  Z/ e i0 dJ j o
 dK Z1 n e i0 dL j o
 dM Z1 n dN Z1 e+ o e2 dO e)  o
 dP Z3 n e) dP dQ  Z3 e i4   Z5 e6 e dR  p e i7   dS dT j  o
 d Z8 qOe9 dU  Z8 y e8 i: dV  Wn e; j
 o qOXdW e8 GHn d Z< y e= e1 dX  Z< Wni e> j
 o] e i? i@ dY e1  ZA y e= eA dX  Z< eA Z1 [A Wqe> j
 o dZ e1 eA f GHqXn Xe< d j	 o e< iB   e e1  n [< eC d[  ZD d\ d]  ZE d^   ZF d_   ZG d`   ZH da   ZI db   ZJ dc eK f dd     YZL e de  ZM e iN df    ZO e iN dg    ZP d% eK f dh     YZQ d& eK f di     YZR d) eK f dj     YZS dk   ZT e iN dl    ZU dm   ZV dn   ZW d~ ZX do eX ZY dT eY ZZ dp eY Z[ e i\ Z] dq   Z^ dr eX ds  Z_ dr eX dt  Z` du   Za d/ d dv     YZb dw   Zc dx   Zd d dy  Ze dz   Zf d{   Zg d|   Zh d}   Zi d S(   s7   Supporting definitions for the Python regression tests.s   test.test_supports3   test_support must be imported from the test packageiNt   Errort
   TestFailedt   TestSkippedt   ResourceDeniedt   import_modulet   verboset   use_resourcest
   max_memuset   record_original_stdoutt   get_original_stdoutt   unloadt   unlinkt   rmtreet   forgett   is_resource_enabledt   requirest   find_unused_portt	   bind_portt   fcmpt   have_unicodet	   is_jythont   TESTFNt   HOSTt   FUZZt   findfilet   verifyt   vereqt   sortdictt   check_syntax_errort   open_urlresourcet   check_warningst   _check_py3k_warningst   CleanImportt   EnvironmentVarGuardt   captured_outputt   captured_stdoutt   TransientResourcet   transient_internett   run_with_localet   set_memlimitt
   bigmemtestt   bigaddrspacetestt   BasicTestRunnert   run_unittestt   run_doctestt   threading_setupt   threading_cleanupt   reap_childrent   strip_python_stderrc           B   s   e  Z d  Z RS(   s*   Base class for regression test exceptions.(   t   __name__t
   __module__t   __doc__(    (    (    s'   /usr/lib/python2.6/test/test_support.pyR       s   c           B   s   e  Z d  Z RS(   s   Test failed.(   R1   R2   R3   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR       s   c           B   s   e  Z d  Z RS(   s!  Test skipped.

    This can be raised to indicate that a test was deliberatly
    skipped, but not because a feature wasn't available.  For
    example, if some resource can't be used, such as the network
    appears to be unavailable, this should be raised instead of
    TestFailed.
    (   R1   R2   R3   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR   #   s   c           B   s   e  Z d  Z RS(   s   Test skipped because it requested a disallowed resource.

    This is raised when a test calls requires() for a resource that
    has not be enabled.  It is used to distinguish between expected
    and unexpected skips.
    (   R1   R2   R3   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR   -   s   c         C   s   t  i   i i   zb | o t  i d d t  n y t |  d d } Wn# t j
 o t d |    n X| SWd QXd S(   sO   Import the module to be tested, raising TestSkipped if it is not
    available.t   ignores   .+ (module|package)t   leveli    s   No module named N(	   t   warningst   catch_warningst   __exit__t	   __enter__t   filterwarningst   DeprecationWarningt
   __import__t   ImportErrorR   (   t   namet
   deprecatedt   module(    (    s'   /usr/lib/python2.6/test/test_support.pyR   5   s    i   i    c         C   s
   |  a  d  S(   N(   t   _original_stdout(   t   stdout(    (    s'   /usr/lib/python2.6/test/test_support.pyR   M   s    c           C   s   t  p t i S(   N(   RA   t   sysRB   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR	   Q   s    c         C   s(   y t  i |  =Wn t j
 o n Xd  S(   N(   RC   t   modulest   KeyError(   R>   (    (    s'   /usr/lib/python2.6/test/test_support.pyR
   T   s    c         C   s+   y t  i |   Wn t j
 o n Xd  S(   N(   t   osR   t   OSError(   t   filename(    (    s'   /usr/lib/python2.6/test/test_support.pyR   Z   s    c         C   sP   y t  i |   Wn8 t j
 o, } | i t i t i f j o   qL n Xd  S(   N(   t   shutilR   RG   t   errnot   ENOENTt   ESRCH(   t   patht   e(    (    s'   /usr/lib/python2.6/test/test_support.pyR   `   s
    c         C   sj   t  |   xY t i D]N } t t i i | |  t i d   t t i i | |  t i d   q Wd S(   sm   "Forget" a module was ever imported by removing it from sys.modules and
    deleting any .pyc and .pyo files.t   pyct   pyoN(   R
   RC   RM   R   RF   t   joint   extsep(   t   modnamet   dirname(    (    s'   /usr/lib/python2.6/test/test_support.pyR   h   s
    

 $c         C   s   t  d j	 o
 |  t  j S(   sP   Test whether a resource is enabled.  Known resources are set by
    regrtest.py.N(   R   t   None(   t   resource(    (    s'   /usr/lib/python2.6/test/test_support.pyR   s   s    c         C   sc   t  i   i i i d  d j o d St |   p+ | d j o d |  } n t |   n d S(   s   Raise ResourceDenied if the specified resource is not available.

    If the caller's module is __main__ then automatically return True.  The
    possibility of False being returned occurs when regrtest.py is executing.R1   t   __main__Ns$   Use of the `%s' resource not enabled(   RC   t	   _getframet   f_backt	   f_globalst   getR   RU   R   (   RV   t   msg(    (    s'   /usr/lib/python2.6/test/test_support.pyR   x   s    "t	   localhostc         C   s/   t  i  |  |  } t |  } | i   ~ | S(   s  Returns an unused port that should be suitable for binding.  This is
    achieved by creating a temporary socket with the same family and type as
    the 'sock' parameter (default is AF_INET, SOCK_STREAM), and binding it to
    the specified host address (defaults to 0.0.0.0) with the port set to 0,
    eliciting an unused ephemeral port from the OS.  The temporary socket is
    then closed and deleted, and the ephemeral port is returned.

    Either this method or bind_port() should be used for any tests where a
    server socket needs to be bound to a particular port for the duration of
    the test.  Which one to use depends on whether the calling code is creating
    a python socket, or if an unused port needs to be provided in a constructor
    or passed to an external program (i.e. the -accept argument to openssl's
    s_server mode).  Always prefer bind_port() over find_unused_port() where
    possible.  Hard coded ports should *NEVER* be used.  As soon as a server
    socket is bound to a hard coded port, the ability to run multiple instances
    of the test simultaneously on the same host is compromised, which makes the
    test a ticking time bomb in a buildbot environment. On Unix buildbots, this
    may simply manifest as a failed test, which can be recovered from without
    intervention in most cases, but on Windows, the entire python process can
    completely and utterly wedge, requiring someone to log in to the buildbot
    and manually kill the affected process.

    (This is easy to reproduce on Windows, unfortunately, and can be traced to
    the SO_REUSEADDR socket option having different semantics on Windows versus
    Unix/Linux.  On Unix, you can't have two AF_INET SOCK_STREAM sockets bind,
    listen and then accept connections on identical host/ports.  An EADDRINUSE
    socket.error will be raised at some point (depending on the platform and
    the order bind and listen were called on each socket).

    However, on Windows, if SO_REUSEADDR is set on the sockets, no EADDRINUSE
    will ever be raised when attempting to bind two identical host/ports. When
    accept() is called on each socket, the second caller's process will steal
    the port from the first caller, leaving them both in an awkwardly wedged
    state where they'll no longer respond to any signals or graceful kills, and
    must be forcibly killed via OpenProcess()/TerminateProcess().

    The solution on Windows is to use the SO_EXCLUSIVEADDRUSE socket option
    instead of SO_REUSEADDR, which effectively affords the same semantics as
    SO_REUSEADDR on Unix.  Given the propensity of Unix developers in the Open
    Source world compared to Windows ones, this is a common mistake.  A quick
    look over OpenSSL's 0.9.8g source shows that they use SO_REUSEADDR when
    openssl.exe is called with the 's_server' option, for example. See
    http://bugs.python.org/issue2550 for more info.  The following site also
    has a very thorough description about the implications of both REUSEADDR
    and EXCLUSIVEADDRUSE on Windows:
    http://msdn2.microsoft.com/en-us/library/ms740621(VS.85).aspx)

    XXX: although this approach is a vast improvement on previous attempts to
    elicit unused ports, it rests heavily on the assumption that the ephemeral
    port returned to us by the OS won't immediately be dished back out to some
    other process when we close and delete our temporary socket but before our
    calling code has a chance to bind the returned port.  We can deal with this
    issue if/when we come across it.(   t   socketR   t   close(   t   familyt   socktypet   tempsockt   port(    (    s'   /usr/lib/python2.6/test/test_support.pyR      s
    6
c         C   s  |  i  t i j o |  i t i j o t t d  o3 |  i t i t i  d j o t	 d   qi n t t d  o3 |  i t i t i
  d j o t	 d   q n t t d  o |  i t i t i d  q n |  i | d f  |  i   d } | S(   s%  Bind the socket to a free port and return the port number.  Relies on
    ephemeral ports in order to ensure we are using an unbound port.  This is
    important as many tests may be running simultaneously, especially in a
    buildbot environment.  This method raises an exception if the sock.family
    is AF_INET and sock.type is SOCK_STREAM, *and* the socket has SO_REUSEADDR
    or SO_REUSEPORT set on it.  Tests should *never* set these socket options
    for TCP/IP sockets.  The only case for setting these options is testing
    multicasting via multiple UDP sockets.

    Additionally, if the SO_EXCLUSIVEADDRUSE socket option is available (i.e.
    on Windows), it will be set on the socket.  This will prevent anyone else
    from bind()'ing to our host/port for the duration of the test.
    t   SO_REUSEADDRi   sH   tests should never set the SO_REUSEADDR socket option on TCP/IP sockets!t   SO_REUSEPORTsH   tests should never set the SO_REUSEPORT socket option on TCP/IP sockets!t   SO_EXCLUSIVEADDRUSEi    (   R`   R^   t   AF_INETt   typet   SOCK_STREAMt   hasattrt
   getsockoptt
   SOL_SOCKETRd   R   Re   t
   setsockoptRf   t   bindt   getsockname(   t   sockt   hostRc   (    (    s'   /usr/lib/python2.6/test/test_support.pyR      s    &!gư>c         C   s-  t  |  t  p t  | t  oH y: t |   t |  t } t |  |  | j o d SWqqXn t |   t |  j o t  |  t t f  o xR t t t	 |   t	 |    D]/ } t
 |  | | |  } | d j o | Sq Wt	 |   t	 |  j t	 |   t	 |  j  S|  | j |  | j  S(   Ni    (   t
   isinstancet   floatt   absR   Rh   t   tuplet   listt   ranget   mint   lenR   (   t   xt   yt   fuzzt   it   outcome(    (    s'   /usr/lib/python2.6/test/test_support.pyR      s     	/" 	-t   javas   $testt   riscost   testfiles   @testt    s   @test-s   latin-1t   getwindowsversioni   i   s'   u"@test-\u5171\u6709\u3055\u308c\u308b"t   Latin1sg   WARNING: The filename %r CAN be encoded by the filesystem.  Unicode filename tests may not be effectives   w+s   /tmps6   WARNING: tests will fail, unable to write to: %s or %sc         C   s|   t  i i |   o |  St i } t  i i |  g | } x; | D]3 } t  i i | |   } t  i i |  o | SqA W|  S(   s   Try to find a file on sys.path and the working directory.  If it is not
    found the argument passed to the function is returned (this does not
    necessarily signal failure; could still be the legitimate path).(   RF   RM   t   isabsRC   RT   RQ   t   exists(   t   filet   hereRM   t   dnt   fn(    (    s'   /usr/lib/python2.6/test/test_support.pyR   <  s    	  	s   test failedc         C   s   |  p t  |   n d S(   s   Verify that condition is true. If not, raise TestFailed.

       The optional argument reason can be given to provide
       a better error text.
    N(   R   (   t	   conditiont   reason(    (    s'   /usr/lib/python2.6/test/test_support.pyR   I  s    c         C   s+   |  | j p t  d |  | f   n d S(   s$  Raise TestFailed if a == b is false.

    This is better than verify(a == b) because, in case of failure, the
    error message incorporates repr(a) and repr(b) so you can see the
    inputs.

    Note that "not (a == b)" isn't necessarily the same as "a != b"; the
    former is tested.
    s   %r == %rN(   R   (   t   at   b(    (    s'   /usr/lib/python2.6/test/test_support.pyR   S  s    c         C   sR   |  i    } | i   g  } | D] } | d | q! ~ } d i |  } d | S(   s%   Like repr(dict), but in sorted order.s   %r: %rs   , s   {%s}(   t   itemst   sortRQ   (   t   dictR   t   _[1]t   pairt	   reprpairst
   withcommas(    (    s'   /usr/lib/python2.6/test/test_support.pyR   a  s
    
%c          C   s9   t  t d  }  z |  i   SWd |  i   t t  Xd S(   s`   
    Create an invalid file descriptor by opening and closing a file and return
    its fd.
    t   wbN(   t   openR   t   filenoR_   R   (   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyt   make_bad_fdi  s
    
c         C   s?   y t  | d d  Wn t j
 o n X|  i d |  d  S(   Ns   <test string>t   execs   Missing SyntaxError: "%s"(   t   compilet   SyntaxErrort   fail(   t   testcaset	   statement(    (    s'   /usr/lib/python2.6/test/test_support.pyR   u  s
    c   
      C   s:  d d  k  } d d  k } t d  | i  |   d i d  d } xS t i i t i i g D]9 } t i i | |  } t i i	 |  o t
 |  Sq[ Wt   d |  IJ| i |  d d } zd t
 | d  i i   } zA | ~ } | i   }	 x% |	 o | i |	  | i   }	 q WWd  QXWd  | i   Xt
 |  S(	   Nit   urlfetchi   t   /s   	fetching %s ...t   timeouti   R   (   t   urlparset   urllib2R   t   splitRF   RM   t   curdirt   pardirRQ   R   R   R	   t   urlopenR8   R9   t   readt   writeR_   (
   t   urlR   R   RH   RM   R   t   fR   t   outt   s(    (    s'   /usr/lib/python2.6/test/test_support.pyR   }  s&    
  & t   WarningsRecorderc           B   s8   e  Z d  Z d   Z d   Z e d    Z d   Z RS(   sy   Convenience wrapper for the warnings list returned on
       entry to the warnings.catch_warnings() context manager.
    c         C   s   | |  _  d |  _ d  S(   Ni    (   t	   _warningst   _last(   t   selft   warnings_list(    (    s'   /usr/lib/python2.6/test/test_support.pyt   __init__  s    	c         C   s`   t  |  i  |  i j o t |  i d |  S| t i i j o d  St d |  | f   d  S(   Nis   %r has no attribute %r(	   Ry   R   R   t   getattrR6   t   WarningMessaget   _WARNING_DETAILSRU   t   AttributeError(   R   t   attr(    (    s'   /usr/lib/python2.6/test/test_support.pyt   __getattr__  s
    c         C   s   |  i  |  i S(   N(   R   R   (   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyR6     s    c         C   s   t  |  i  |  _ d  S(   N(   Ry   R   R   (   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyt   reset  s    (   R1   R2   R3   R   R   t   propertyR6   R   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR     s
   		c         c   s  t  i d  } | i i d  } | o | i   n t i d t  i i	   } z, | ~ } t  i
 d i d  t |  VWd QXg  } | D] } | | i q ~ } g  }	 x |  D] \ }
 } t } x^ | D]U } t |  } t i |
 | t i  o* t | i |  o t } | i |  q q W| o" | o |	 i |
 | i f  q q W| o t d | d   n |	 o t d	 |	 d   n d S(
   s   Catch the warnings, then check if all the expected
    warnings have been raised and re-raise unexpected warnings.
    If 'quiet' is True, only re-raise the unexpected warnings.
    i   t   __warningregistry__t   recordR6   t   alwaysNs   unhandled warning %ri    s)   filter (%r, %s) did not catch any warning(   RC   RX   RZ   R[   t   clearR6   R7   t   TrueR8   R9   RD   t   simplefilterR   t   messaget   Falset   strt   ret   matcht   It
   issubclasst	   __class__t   removet   appendR1   t   AssertionError(   t   filterst   quiett   framet   registryR   t   wt   _[2]t   warningt   reraiset   missingR\   t   catt   seent   excR   (    (    s'   /usr/lib/python2.6/test/test_support.pyt   _filterwarnings  s4    )$  c          O   sM   | i  d  } |  p* d t f f }  | d j o
 t } q@ n t |  |  S(   s  Context manager to silence warnings.

    Accept 2-tuples as positional arguments:
        ("message regexp", WarningCategory)

    Optional argument:
     - if 'quiet' is True, it does not fail if a filter catches nothing
        (default True without argument,
         default False if some filters are defined)

    Without argument, it defaults to:
        check_warnings(("", Warning), quiet=True)
    R   R   N(   R[   t   WarningRU   R   R   (   R   t   kwargsR   (    (    s'   /usr/lib/python2.6/test/test_support.pyR     s    c          O   sD   t  i o |  p d t f f }  q. n d }  t |  | i d   S(   sk  Context manager to silence py3k warnings.

    Accept 2-tuples as positional arguments:
        ("message regexp", WarningCategory)

    Optional argument:
     - if 'quiet' is True, it does not fail if a filter catches nothing
        (default False)

    Without argument, it defaults to:
        _check_py3k_warnings(("", DeprecationWarning), quiet=False)
    R   R   (    (   RC   t   py3kwarningR;   R   R[   (   R   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyR     s
    
c           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s  Context manager to force import to return a new module reference.

    This is useful for testing module-level behaviours, such as
    the emission of a DeprecationWarning on import.

    Use like this:

        with CleanImport("foo"):
            __import__("foo") # new reference
    c         G   ss   t  i i   |  _ xZ | D]R } | t  i j o< t  i | } | i | j o t  i | i =n t  i | =q q Wd  S(   N(   RC   RD   t   copyt   original_modulesR1   (   R   t   module_namest   module_nameR@   (    (    s'   /usr/lib/python2.6/test/test_support.pyR     s     c         C   s   |  S(   N(    (   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyR9     s    c         G   s   t  i i |  i  d  S(   N(   RC   RD   t   updateR   (   R   t
   ignore_exc(    (    s'   /usr/lib/python2.6/test/test_support.pyR8     s    (   R1   R2   R3   R   R9   R8   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR      s   
		c           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s_   Class to help protect the environment variable properly.  Can be used as
    a context manager.c         C   s   h  |  _  d  S(   N(   t   _changed(   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyR   '  s    c         C   s>   | |  i  j o t i i |  |  i  | <n | t i | <d  S(   N(   R   RF   t   environR[   (   R   t   envvart   value(    (    s'   /usr/lib/python2.6/test/test_support.pyt   set*  s    c         C   sO   | |  i  j o t i i |  |  i  | <n | t i j o t i | =n d  S(   N(   R   RF   R   R[   (   R   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyt   unset0  s    c         C   s   |  S(   N(    (   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyR9   7  s    c         G   s`   xY |  i  i   D]H \ } } | d  j o" | t i j o t i | =qX q | t i | <q Wd  S(   N(   R   R   RU   RF   R   (   R   R   t   kt   v(    (    s'   /usr/lib/python2.6/test/test_support.pyR8   :  s     (   R1   R2   R3   R   R   R   R9   R8   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR!   "  s   				c           B   s2   e  Z d  Z d   Z d   Z d d d d  Z RS(   s   Raise ResourceDenied if an exception is raised while the context manager
    is in effect that matches the specified exception and attributes.c         K   s   | |  _  | |  _ d  S(   N(   R   t   attrs(   R   R   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyR   H  s    	c         C   s   |  S(   N(    (   R   (    (    s'   /usr/lib/python2.6/test/test_support.pyR9   L  s    c         C   s   | d j	 os t |  i |  o` x] |  i i   D]< \ } } t | |  p Pn t | |  | j o Pq0 q0 Wt d   n d S(   s   If type_ is a subclass of self.exc and value has attributes matching
        self.attrs, raise ResourceDenied.  Otherwise let the exception
        propagate (if any).s%   an optional resource is not availableN(   RU   R   R   R   t	   iteritemsRj   R   R   (   R   t   type_R   t	   tracebackR   t
   attr_value(    (    s'   /usr/lib/python2.6/test/test_support.pyR8   O  s      	N(   R1   R2   R3   R   R9   RU   R8   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR$   C  s   		c          C   sU   t  t d t i }  t  t i d t i } t  t d t i } t i |  | |  S(   s   Return a context manager that raises ResourceDenied when various issues
    with the Internet connection manifest themselves as exceptions.RJ   (	   R$   t   IOErrorRJ   t	   ETIMEDOUTR^   t   errort
   ECONNRESETt
   contextlibt   nested(   t   time_outt   socket_peer_resett   ioerror_peer_reset(    (    s'   /usr/lib/python2.6/test/test_support.pyR%   ]  s    c      	   c   s[   d d k  } t t |   } t t |  | i     z t t |   VWd t t |  |  Xd S(   s  Run the 'with' statement body using a StringIO object in place of a
    specific attribute on the sys module.
    Example use (with 'stream_name=stdout')::

       with captured_stdout() as s:
           print "hello"
       assert s.getvalue() == "hello"
    iN(   t   StringIOR   RC   t   setattr(   t   stream_nameR   t   orig_stdout(    (    s'   /usr/lib/python2.6/test/test_support.pyR"   f  s    
c           C   s
   t  d  S(   NRB   (   R"   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR#   x  s    c            s      f d   } | S(   Nc            s1       f d   }   i  | _    i | _ | S(   Nc             s   y. d d  k  } t |    } | i |  } Wn& t j
 o
   nB d  } } n1 Xx-  D]% } y | i | |  PWq^ q^ Xq^ Wz  |  |   SWd  | o | o | i | |  n Xd  S(   Ni(   t   localeR   t	   setlocaleR   RU   (   t   argst   kwdsR   t   categoryt   orig_localet   loc(   t   catstrt   funct   locales(    s'   /usr/lib/python2.6/test/test_support.pyt   inner  s&     (   t	   func_nameR3   (   R  R  (   R  R  (   R  s'   /usr/lib/python2.6/test/test_support.pyt	   decorator  s    (    (   R  R  R
  (    (   R  R  s'   /usr/lib/python2.6/test/test_support.pyR&     s    i   i   c         C   s   h d d 6t  d 6t d 6d t d 6} t i d |  t i t i B } | d  j o t d |  f   n t t	 | i
 d   | | i
 d	  i    } | a | t j o
 t } n | t d j  o t d
 |  f   n | a d  S(   Ni   R   t   mt   gt   ts   (\d+(\.\d+)?) (K|M|G|T)b?$s   Invalid memory limit %ri   i   s$   Memory limit %r too low to be useful(   t   _1Mt   _1GR   R   t
   IGNORECASEt   VERBOSERU   t
   ValueErrort   intRs   t   groupt   lowert   real_max_memuset   MAX_Py_ssize_tt   _2GR   (   t   limitt   sizesR  t   memlimit(    (    s'   /usr/lib/python2.6/test/test_support.pyR'     s     2
i   c            s       f d   } | S(   sQ  Decorator for bigmem tests.

    'minsize' is the minimum useful size for the test (in arbitrary,
    test-interpreted units.) 'memuse' is the number of 'bytes per size' for
    the test, or a good estimate of it. 'overhead' specifies fixed overhead,
    independent of the testsize, and defaults to 5Mb.

    The decorator tries to guess a good value for 'size' and passes it to
    the decorated test function. If minsize * memuse is more than the
    allowed memory use (as defined by max_memuse), the test is skipped.
    Otherwise, minsize is adjusted upward to use up to max_memuse.
    c            s7        f d   }  | _   | _  | _ | S(   Nc            s   t  p) d } |  i |   d t j  nc t t     } |  j  o* t o t i i d   i f  n d  St	 | d t   }   |  |  S(   Ni  i   s)   Skipping %s because of memory constraint
i2   (
   R   t   failIfR  R  R   RC   t   stderrR   R1   t   max(   R   t   maxsize(   R   t   memuset   minsizet   overhead(    s'   /usr/lib/python2.6/test/test_support.pyt   wrapper  s    #(   R!  R   R"  (   R   R#  (   R!  R"  R   (   R   s'   /usr/lib/python2.6/test/test_support.pyR
    s
    			(    (   R!  R   R"  R
  (    (   R!  R"  R   s'   /usr/lib/python2.6/test/test_support.pyR(     s    c            s       f d   } | S(   Nc            s4       f d   }  | _   | _  | _ | S(   Nc            sf   t  p
 d } nI  } t  o; t  |  j  o* t o t i i d   i f  n d  S  |  |  S(   Ni  s)   Skipping %s because of memory constraint
(   R  R   RC   R  R   R1   (   R   R  (   R   R   t   size(    s'   /usr/lib/python2.6/test/test_support.pyR#    s    
(   R$  R   R"  (   R   R#  (   R$  R"  R   (   R   s'   /usr/lib/python2.6/test/test_support.pyR
    s
    			(    (   R$  R   R"  R
  (    (   R"  R   R$  s'   /usr/lib/python2.6/test/test_support.pyt   precisionbigmemtest  s    c            s     f d   } | S(   s0   Decorator for tests that fill the address space.c            sD   t  t j  o) t o t i i d   i f  q@ n   |   Sd  S(   Ns)   Skipping %s because of memory constraint
(   R   R  R   RC   R  R   R1   (   R   (   R   (    s'   /usr/lib/python2.6/test/test_support.pyR#    s
    (    (   R   R#  (    (   R   s'   /usr/lib/python2.6/test/test_support.pyR)     s    c           B   s   e  Z d    Z RS(   c         C   s   t  i   } | |  | S(   N(   t   unittestt
   TestResult(   R   t   testt   result(    (    s'   /usr/lib/python2.6/test/test_support.pyt   run  s    
(   R1   R2   R*  (    (    (    s'   /usr/lib/python2.6/test/test_support.pyR*     s   c         C   s   t  o t i t i d d } n
 t   } | i |   } | i   p t | i	  d j o  | i
 o | i	 d d } nR t | i
  d j o  | i	 o | i
 d d } n d } t  p | d 7} n t |   n d S(   s2   Run tests from a unittest.TestSuite-derived class.t	   verbosityi   i   i    s   multiple errors occurreds!   ; run in verbose mode for detailsN(   R   R&  t   TextTestRunnerRC   RB   R*   R*  t   wasSuccessfulRy   t   errorst   failuresR   (   t   suitet   runnerR)  t   err(    (    s'   /usr/lib/python2.6/test/test_support.pyt
   _run_suite  s    	!!c          G   s   t  i t  i f } t  i   } x |  D] } t | t  oA | t i j o! | i t  i t i |   q t	 d   q% t | |  o | i |  q% | i t  i
 |   q% Wt |  d S(   s1   Run tests from unittest.TestCase-derived classes.s)   str arguments must be keys in sys.modulesN(   R&  t	   TestSuitet   TestCaseRr   R   RC   RD   t   addTestt   findTestCasesR  t	   makeSuiteR3  (   t   classest   valid_typesR0  t   cls(    (    s'   /usr/lib/python2.6/test/test_support.pyR+   &  s     !c         C   s   d d k  } | d j o
 t } n d } t i } t   t _ z@ | i |  d | \ } } | o t d | | f   n Wd | t _ Xt o d |  i | f GHn | | f S(   s  Run doctest on the given module.  Return (#failures, #tests).

    If optional argument verbosity is not specified (or is None), pass
    test_support's belief about verbosity on to doctest.  Else doctest's
    usual behavior is used (it searches sys.argv for -v).
    iNR   s   %d of %d doctests faileds,   doctest (%s) ... %d tests with zero failures(	   t   doctestRU   R   RC   RB   R	   t   testmodR   R1   (   R@   R+  R<  t   save_stdoutR   R  (    (    s'   /usr/lib/python2.6/test/test_support.pyR,   :  s    
	
c          C   s(   d d  k  }  t |  i  t |  i  f S(   Ni(   t	   threadingRy   t   _activet   _limbo(   R?  (    (    s'   /usr/lib/python2.6/test/test_support.pyR-   Z  s    c         C   s   d d  k  } d d  k } d } d } x? t | i  |  j o( | | j  o | d 7} | i d  q' Wd } x? t | i  | j o( | | j  o | d 7} | i d  qo Wd  S(   Nii
   i    i   g?(   R?  t   timeRy   R@  t   sleepRA  (   t
   num_activet	   num_limboR?  RB  t
   _MAX_COUNTt   count(    (    s'   /usr/lib/python2.6/test/test_support.pyR.   ^  s     #
 #
c          C   si   t  t d  oU d }  xL t o@ y1 t i |  t i  \ } } | d j o Pn Wq Pq Xq Wn d S(   s   Use this function at the end of test_main() whenever sub-processes
    are started.  This will help ensure that no extra children (zombies)
    stick around to hog resources and create problems when looking
    for refleaks.
    t   waitpidii    N(   Rj   RF   R   RH  t   WNOHANG(   t   any_processt   pidt   status(    (    s'   /usr/lib/python2.6/test/test_support.pyR/   m  s    	 	c         C   s   t  i d d |   i   }  |  S(   s   Strip the stderr of a Python process from potential debug output
    emitted by the interpreter.

    This will typically be run on the result of the communicate() method
    of a subprocess.Popen object.
    s   \[\d+ refs\]\r?\n?$R   (   R   t   subt   strip(   R  (    (    s'   /usr/lib/python2.6/test/test_support.pyR0     s    i   (    (j   R3   R1   R=   R   RJ   R^   RC   RF   RI   R6   R&  R   t   __all__t	   ExceptionR    R   R   R   R   R   R   RU   R   R   R  RA   R   R	   R
   R   R   R   R   R   R   Rg   Ri   R   R   R   R   t   unicodeR   R   t	   NameErrort   platformt
   startswithR   R>   R   Rr   t   TESTFN_UNICODEt   getfilesystemencodingt   TESTFN_ENCODINGRj   R   t   TESTFN_UNICODE_UNENCODEABLEt   evalt   encodet   UnicodeEncodeErrort   fpR   R   RM   RQ   t
   TMP_TESTFNR_   t   __file__R   R   R   R   R   R   R   t   objectR   R   t   contextmanagerR   R   R    R!   R$   R%   R"   R#   R&   R  R  R  t   _4GR  R  R'   R(   R%  R)   R*   R3  R+   R,   R-   R.   R/   R0   (    (    (    s'   /usr/lib/python2.6/test/test_support.pyt   <module>   s   			
							<	







					' !				%


		'			 			