
\Kc           @   s  d  Z  e d j o e d  n d d k Z d e f d     YZ d e f d     YZ d	 e f d
     YZ d e f d     YZ d Z	 d Z d a d a d a d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d d d  Z d Z d   Z y e d Z Wn e j
 o d Z n Xe i i d  Z d d k Z e i  d j o
 d Z! n e i  d j o
 d Z! n d Z! e o e" d e  o
 d  Z# n e d  d!  Z# e i$   Z% e& e d"  p e i'   d# d$ j  o
 d Z( q2e) d%  Z( y e( i* d&  Wn e+ j
 o q2Xd' e( GHn d Z, y e- e! d(  Z, Wni e. j
 o] e i/ i0 d) e!  Z1 y e- e1 d(  Z, e1 Z! [1 Wqe. j
 o d* e! e1 f GHqXn Xe, d j	 o e, i2   e e!  n [ [, e3 d+  Z4 d, d-  Z5 d.   Z6 d/   Z7 d0   Z8 d1   Z9 d2   Z: dD Z; d3 e; Z< d$ e< Z= d4 e< Z> d5 dE d6     YZ? e?   Z@ d7   ZA d8 e; d9  ZB d8 e; d:  ZC d;   ZD d d kE ZE d< dF d=     YZF d d>  ZG d?   ZH d d@  ZI dA   ZJ dB   ZK dC   ZL d S(G   s7   Supporting definitions for the Python regression tests.s   test.test_supports3   test_support must be imported from the test packageiNt   Errorc           B   s   e  Z d  Z RS(   s*   Base class for regression test exceptions.(   t   __name__t
   __module__t   __doc__(    (    (    s'   /usr/lib/python2.5/test/test_support.pyR       s   t
   TestFailedc           B   s   e  Z d  Z RS(   s   Test failed.(   R   R   R   (    (    (    s'   /usr/lib/python2.5/test/test_support.pyR      s   t   TestSkippedc           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.
    (   R   R   R   (    (    (    s'   /usr/lib/python2.5/test/test_support.pyR      s   t   ResourceDeniedc           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.
    (   R   R   R   (    (    (    s'   /usr/lib/python2.5/test/test_support.pyR      s   i   i    c         C   s
   |  a  d  S(   N(   t   _original_stdout(   t   stdout(    (    s'   /usr/lib/python2.5/test/test_support.pyt   record_original_stdout*   s    c           C   s   t  p t i S(   N(   R   t   sysR   (    (    (    s'   /usr/lib/python2.5/test/test_support.pyt   get_original_stdout.   s    c         C   s(   y t  i |  =Wn t j
 o n Xd  S(   N(   R
   t   modulest   KeyError(   t   name(    (    s'   /usr/lib/python2.5/test/test_support.pyt   unload1   s    c         C   s7   d d  k  } y | i |   Wn t j
 o n Xd  S(   Ni(   t   ost   unlinkt   OSError(   t   filenameR   (    (    s'   /usr/lib/python2.5/test/test_support.pyR   7   s
    c         C   sv   t  |   d d k } xY t i D]N } t | i i | |  | i d   t | i i | |  | 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.iNt   pyct   pyo(   R   R   R
   t   pathR   t   joint   extsep(   t   modnameR   t   dirname(    (    s'   /usr/lib/python2.5/test/test_support.pyt   forget>   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(   t   use_resourcest   None(   t   resource(    (    s'   /usr/lib/python2.5/test/test_support.pyt   is_resource_enabledJ   s    c         C   sf   t  i   i i i d  d j o d Sn 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.R   t   __main__Ns$   Use of the `%s' resource not enabled(   R
   t	   _getframet   f_backt	   f_globalst   getR   R   R   (   R   t   msg(    (    s'   /usr/lib/python2.5/test/test_support.pyt   requiresO   s    "t    i1  c      	   C   s   d d k  } d d k } x | d d d d g D] } y< |  i | | f  | d j o |  i   d } n | SWq. | i j
 o7 \ } } | | i j o   n t i d | IJq. Xq. Wt d	  d S(
   s   Try to bind the sock to a port.  If we are running multiple
    tests and we don't try multiple ports, the test can fails.  This
    makes the test more robust.iNi&  i(  i  i    i   s6     WARNING: failed to listen on port %d, trying anothers    unable to find port to listen on(	   t   sockett   errnot   bindt   getsocknamet   errort
   EADDRINUSER
   t
   __stderr__R   (   t   sockt   hostt   preferred_portR(   R)   t   portt   errR%   (    (    s'   /usr/lib/python2.5/test/test_support.pyt	   bind_port]   s    
 gư>c         C   sR  t  |   t  d  j p t  |  t  d  j o` yR t |  |  \ }  } t |   t |  t } t |  |  | j o d Sn WqEqEXn t  |   t  |  j o t  |   t  d  t  g   f j ou xU t t t |   t |    D]2 } t |  | | |  } | d j o | Sq q Wt t |   t |   Sn t |  |  S(   Ng        i    (    (	   t   typet   coercet   abst   FUZZt   ranget   mint   lent   fcmpt   cmp(   t   xt   yt   fuzzt   it   outcome(    (    s'   /usr/lib/python2.5/test/test_support.pyR<   {   s     2>" t   javas   $testt   riscost   testfiles   @tests   @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   d d k  } | i i |   o |  Sn t i } | i i |  g | } x> | D]6 } | i i | |   } | i i |  o | SqP qP 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).iN(   R   R   t   isabsR
   R   R   t   exists(   t   filet   hereR   R   t   dnt   fn(    (    s'   /usr/lib/python2.5/test/test_support.pyt   findfile   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.5/test/test_support.pyt   verify   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.5/test/test_support.pyt   vereq   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   sortR   (   t   dictRU   t   _[1]t   pairt	   reprpairst
   withcommas(    (    s'   /usr/lib/python2.5/test/test_support.pyt   sortdict   s
    
%c         C   s7   y t  |  d d  Wn t j
 o n Xd |  GHd  S(   Ns   <string>t   execs   Missing SyntaxError: "%s"(   t   compilet   SyntaxError(   t	   statement(    (    s'   /usr/lib/python2.5/test/test_support.pyt   check_syntax  s
    c      	   C   s   d d  k  } d d  k } d d  k } | i |   d i d  d } xV | i i | i i g D]< } | i i | |  } | i i |  o t	 |  Sq] q] Wt
 d  t   d |  IJ| i |  |  \ } } t	 |  S(   Nii   t   /t   urlfetchs   	fetching %s ...(   t   urllibt   urlparset   os.patht   splitR   t   curdirt   pardirR   RI   t   openR&   R   t   urlretrieve(   t   urlRd   Re   R   R   R   RM   t   _(    (    s'   /usr/lib/python2.5/test/test_support.pyt   open_urlresource  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   localet   getattrt	   setlocalet   AttributeErrorR   (   t   argst   kwdsRo   t   categoryt   orig_localet   loc(   t   catstrt   funct   locales(    s'   /usr/lib/python2.5/test/test_support.pyt   inner!  s&     (   t	   func_nameR   (   Ry   R{   (   Rz   Rx   (   Ry   s'   /usr/lib/python2.5/test/test_support.pyt	   decorator   s    (    (   Rx   Rz   R}   (    (   Rz   Rx   s'   /usr/lib/python2.5/test/test_support.pyt   run_with_locale  s    i   i   t   _Dummyc           B   s   e  Z d    Z RS(   c         C   s   | S(   N(    (   t   selfRA   t   j(    (    s'   /usr/lib/python2.5/test/test_support.pyt   __getslice__K  s    (   R   R   R   (    (    (    s'   /usr/lib/python2.5/test/test_support.pyR   J  s   c         C   s   d d  k  } h  d d <t d <t d <d t d <} | i d |  | i | 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(   Nii   t   kt   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   ret   _1Mt   _1Gt   matcht
   IGNORECASEt   VERBOSER   t
   ValueErrort   intt   floatt   groupt   lowert   real_max_memuset   MAX_Py_ssize_tt   _2Gt
   max_memuse(   t   limitR   t   sizesR   t   memlimit(    (    s'   /usr/lib/python2.5/test/test_support.pyt   set_memlimitO  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,
    independant 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  nf t t     } |  j  o- t o t i i d   i f  n d  Sn t	 | d t   }   |  |  S(   Ni  i   s)   Skipping %s because of memory constraint
i2   (
   R   t   failIfR   R   t   verboseR
   t   stderrt   writeR   t   max(   R   t   maxsize(   t   ft   memuset   minsizet   overhead(    s'   /usr/lib/python2.5/test/test_support.pyt   wrappers  s    #(   R   R   R   (   R   R   (   R   R   R   (   R   s'   /usr/lib/python2.5/test/test_support.pyR}   r  s
    			(    (   R   R   R   R}   (    (   R   R   R   s'   /usr/lib/python2.5/test/test_support.pyt
   bigmemteste  s    c            s       f d   } | S(   Nc            s4       f d   }  | _   | _  | _ | S(   Nc            si   t  p
 d } nL  } t  o> t  |  j  o- t o t i i d   i f  n d  Sn   |  |  S(   Ni  s)   Skipping %s because of memory constraint
(   R   R   R
   R   R   R   (   R   R   (   R   R   t   size(    s'   /usr/lib/python2.5/test/test_support.pyR     s    
(   R   R   R   (   R   R   (   R   R   R   (   R   s'   /usr/lib/python2.5/test/test_support.pyR}     s
    			(    (   R   R   R   R}   (    (   R   R   R   s'   /usr/lib/python2.5/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   R
   R   R   R   (   R   (   R   (    s'   /usr/lib/python2.5/test/test_support.pyR     s
    (    (   R   R   (    (   R   s'   /usr/lib/python2.5/test/test_support.pyt   bigaddrspacetest  s    t   BasicTestRunnerc           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.5/test/test_support.pyt   run  s    
(   R   R   R   (    (    (    s'   /usr/lib/python2.5/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 } np t | i
  d j o  | i	 o | i
 d d } n: | d j o
 d } n d | i | i f } t |   t |   n d S(   s2   Run tests from a unittest.TestSuite-derived class.t	   verbosityi   i   i    s0   errors occurred; run in verbose mode for detailss   errors occurred in %s.%sN(   R   R   t   TextTestRunnerR
   R   R   R   t   wasSuccessfulR;   t   errorst   failuresR   R   R   R   (   t   suitet	   testclasst   runnerR   R3   R%   (    (    s'   /usr/lib/python2.5/test/test_support.pyt	   run_suite  s    	!!
c          G   s   t  i   } xQ |  D]I } t | t  i t  i f  o | i |  q | i t  i |   q Wt |   d j o |  d } n d } t | |  d S(   s1   Run tests from unittest.TestCase-derived classes.i   i    N(	   R   t	   TestSuitet
   isinstancet   TestCaset   addTestt	   makeSuiteR;   R   R   (   t   classesR   t   clsR   (    (    s'   /usr/lib/python2.5/test/test_support.pyt   run_unittest  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   doctestR   R   R
   R   R   t   testmodR   R   (   t   moduleR   R   t   save_stdoutR   R   (    (    s'   /usr/lib/python2.5/test/test_support.pyt   run_doctest  s    
	
c          C   s(   d d  k  }  t |  i  t |  i  f S(   Ni(   t	   threadingR;   t   _activet   _limbo(   R   (    (    s'   /usr/lib/python2.5/test/test_support.pyt   threading_setup  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   timeR;   R   t   sleepR   (   t
   num_activet	   num_limboR   R   t
   _MAX_COUNTt   count(    (    s'   /usr/lib/python2.5/test/test_support.pyt   threading_cleanup  s     #
 #
c          C   su   d d k  }  t |  d  oU d } xL t o@ y1 |  i | |  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.
    iNt   waitpidi    (   R   t   hasattrt   TrueR   t   WNOHANG(   R   t   any_processt   pidt   status(    (    s'   /usr/lib/python2.5/test/test_support.pyt   reap_children  s    	 	i   (    (    (M   R   R   t   ImportErrorR
   t	   ExceptionR    R   R   R   R   R   R   R   R   R   R	   R   R   R   R   R   R&   R4   R8   R<   t   unicodet   have_unicodet	   NameErrort   platformt
   startswitht	   is_jythonR   R   t   TESTFNR   t   TESTFN_UNICODEt   getfilesystemencodingt   TESTFN_ENCODINGR   RF   t   TESTFN_UNICODE_UNENCODEABLEt   evalt   encodet   UnicodeEncodeErrort   fpRj   t   IOErrorR   R   t
   TMP_TESTFNt   closet   __file__RN   RQ   RT   R\   Ra   Rn   R~   R   R   R   t   _4GR   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s'   /usr/lib/python2.5/test/test_support.pys   <module>   s   
							







					%



	'		 		