ó
‰wÛjc           @  sÞ   d  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 Z d „  Z d „  Z d „  Z d „  Z d d „ Z d	 „  Z d
 „  Z e d k rÚ e ƒ  n  d S(   sñ  
Command line tool to bisect failing CPython tests.

Find the test_os test method which alters the environment:

    ./python -m test.bisect_cmd --fail-env-changed test_os

Find a reference leak in "test_os", write the list of failing tests into the
"bisect" file:

    ./python -m test.bisect_cmd -o bisect -R 3:3 test_os

Load an existing list of tests from a file using -i option:

    ./python -m test --list-cases -m FileTests test_os > tests
    ./python -m test.bisect_cmd -i tests test_os
iÿÿÿÿ(   t   print_functionNc      	   C  sG   t  |  d ƒ �2 } x | D] } t | d | ƒq W| j ƒ  Wd  QXd  S(   Nt   wt   file(   t   opent   printt   flush(   t   filenamet   testst   fpt   name(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/bisect_cmd.pyt   write_tests    s    c         C  s5   |  s
 d  St  d t | ƒ |  f ƒ t |  | ƒ |  S(   Ns   Write %s tests into %s(   R   t   lenR
   (   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/bisect_cmd.pyt   write_output'   s
    c         C  s   d j  |  ƒ S(   Nt    (   t   join(   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/bisect_cmd.pyt   format_shell_args/   s    c         C  s×   t  j d d d g } | j |  j ƒ t j | d t j d t ƒ} y | j ƒ  d } Wn+ | j	 j
 ƒ  | j ƒ  | j ƒ  ‚  n X| j ƒ  } | rÇ t | ƒ } t d | | f ƒ t  j | ƒ n  | j ƒ  } | S(   Ns   -mt   tests   --list-casest   stdoutt   universal_newlinesi    s1   Failed to list tests: %s failed with exit code %s(   t   syst
   executablet   extendt	   test_argst
   subprocesst   Popent   PIPEt   Truet   communicateR   t   closet   killt   waitR   R   t   exitt
   splitlines(   R   t   cmdt   procR   t   exitcodeR   (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/bisect_cmd.pyt
   list_cases3   s(    		

c         C  sÇ   t  j ƒ  } z‘ t | | ƒ t j d d d | g } | j |  j ƒ t d t | ƒ ƒ t	 j
 | ƒ } y | j ƒ  } Wn | j ƒ  | j ƒ  ‚  n X| SWd  t j j | ƒ rÂ t j | ƒ n  Xd  S(   Ns   -mR   s   --matchfiles   + %s(   t   tempfilet   mktempR
   R   R   R   R   R   R   R   R   R   R   t   ost   patht   existst   unlink(   R   R   t
   huntrleakst   tmpR"   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/bisect_cmd.pyt	   run_testsJ   s     

c       	   C  s›   t  j ƒ  }  |  j d d d d ƒ|  j d d d d ƒ|  j d d	 d
 t d d d d ƒ|  j d d d
 t d d d d ƒ|  j ƒ  \ } } | | _ | S(   Ns   -is   --inputt   helpsU   Test names produced by --list-tests written into a file. If not set, run --list-testss   -os   --outputs   Result of the bisections   -ns   --max-testst   typet   defaulti   s:   Maximum number of tests to stop the bisection (default: 1)s   -Ns
   --max-iterid   s5   Maximum number of bisection iterations (default: 100)(   t   argparset   ArgumentParsert   add_argumentt   intt   parse_known_argsR   (   t   parserR   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/bisect_cmd.pyt
   parse_args_   s    	c          C  sÍ  t  ƒ  }  |  j rL t |  j ƒ �& } g  | D] } | j ƒ  ^ q+ } Wd  QXn t |  ƒ } t d t | ƒ ƒ t d t |  j ƒ ƒ t d |  j	 |  j
 f ƒ t |  j | ƒ } t ƒ  t j ƒ  } d } yxÿ t | ƒ |  j	 k rÌ| |  j
 k rÌt | ƒ } t | d d ƒ } t j | | ƒ } t d | t | ƒ t | ƒ f ƒ t ƒ  t |  | ƒ }	 t d | t | ƒ f ƒ t d |	 ƒ |	 r®t d	 ƒ | } t |  j | ƒ } n
 t d
 ƒ t ƒ  | d 7} qÎ WWn) t k
 rùt ƒ  t d ƒ t ƒ  n Xt d t | ƒ ƒ x | D] }
 t d |
 ƒ qWt ƒ  | rKt d | ƒ n  t j t j ƒ  | ƒ } t | ƒ |  j	 k r©t d | t j d | ƒ f ƒ t j d ƒ n  t d | t j d | ƒ f ƒ d  S(   Ns   Start bisection with %s testss   Test arguments: %ssx   Bisection will stop when getting %s or less tests (-n/--max-tests option), or after %s iterations (-N/--max-iter option)i   i   s!   [+] Iteration %s: run %s tests/%ss   ran %s tests/%sR    s"   Tests failed: use this new subtests5   Tests succeeded: skip this subtest, try a new subbsets   Bisection interrupted!s   Tests (%s):s   * %ss   Output written into %ss+   Bisection completed in %s iterations and %st   secondss+   Bisection failed after %s iterations and %s(   R8   t   inputR   t   stripR%   R   R   R   R   t	   max_testst   max_iterR   t   outputt   timet   maxt   randomt   sampleR.   t   KeyboardInterruptt   matht   ceilt   datetimet	   timedeltaR   R    (   R   R   t   lineR   R>   t
   start_timet	   iterationt   ntestt   subtestsR$   R   t   dt(    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/bisect_cmd.pyt   mains   s`    		('


t   __main__(   t   __doc__t
   __future__R    R2   RF   t   os.pathR(   RD   RA   R   R   R&   R?   R
   R   R   R%   t   NoneR.   R8   RN   t   __name__(    (    (    s…   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/bisect_cmd.pyt   <module>   s&   						A