ó
‹wÛjc           @   s÷   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 Z d  d l	 m
 Z
 e j e  j d k d ƒ d e j f d „  ƒ  Yƒ Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d „  Z e d k ró e ƒ  n  d S(   iÿÿÿÿN(   t   run_unittest(   t   FileIOt   posixs   tests requires a posix system.t   TestFileIOSignalInterruptc           B   s_   e  Z d  „  Z d „  Z d „  Z d d e d „ Z d „  Z d Z d „  Z	 d „  Z
 d	 „  Z RS(
   c         C   s   d  |  _ d  S(   N(   t   Nonet   _process(   t   self(    (    sŠ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_file_eintr.pyt   setUp   s    c         C   sJ   |  j  rF |  j  j ƒ  d  k rF y |  j  j ƒ  WqF t k
 rB qF Xn  d  S(   N(   R   t   pollR   t   killt   OSError(   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/test_file_eintr.pyt   tearDown    s
    c         C   s   d S(   s�   Returns the infile = ... line of code for the reader process.

        subclasseses should override this to test different IO objects.
        s9   import _io ;infile = _io.FileIO(sys.stdin.fileno(), "rb")(    (   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/test_file_eintr.pyt   _generate_infile_setup_code'   s    t    c         C   s¦   |  j  j ƒ  d k rJ t j d ƒ y |  j  j ƒ  WqJ t k
 rF qJ Xn  | r| |  j  j ƒ  \ } } | | 7} | | 7} n  |  j d | | j	 ƒ  | j	 ƒ  f ƒ d S(   s;  A common way to cleanup and fail with useful debug output.

        Kills the process if it is still running, collects remaining output
        and fails the test with an error message including the output.

        Args:
            why: Text to go after "Error from IO process" in the message.
            stdout, stderr: standard output and error from the process so
                far to include in the error message.
            communicate: bool, when True we call communicate() on the process
                after killing it to gather additional output.
        gš™™™™™¹?s/   Error from IO process %s:
STDOUT:
%sSTDERR:
%s
N(
   R   R   R   t   timet   sleept	   terminateR
   t   communicatet   failt   decode(   R   t   whyt   stdoutt   stderrR   t
   stdout_endt
   stderr_end(    (    sŠ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_file_eintr.pyt   fail_with_process_info/   s    
	c         C   s¾  |  j  ƒ  } t j t j d d d | d d | d d g d t j d t j d	 t j ƒ|  _ |  j j j t	 d
 ƒ ƒ } | d
 k r� |  j
 d d	 | ƒn  |  j j j | ƒ d } g  } xz | s8t j |  j j g d d d ƒ \ } } } |  j j t j ƒ | d 7} | d k r¿ |  j j ƒ  |  j d ƒ q¿ q¿ W|  j j j ƒ  } | d k rm|  j
 d d	 | ƒn  |  j j d d ƒ \ }	 }
 |  j j rº|  j
 d |  j j |	 |
 d t ƒn  d S(   sn  Generic buffered read method test harness to validate EINTR behavior.

        Also validates that Python signal handlers are run during the read.

        Args:
            data_to_write: String to write to the child process for reading
                before sending it a signal, confirming the signal was handled,
                writing a final newline and closing the infile pipe.
            read_and_verify_code: Single "line" of code to read from a file
                object named 'infile' and validate the result.  This will be
                executed as part of a python subprocess fed data_to_write.
        s   -us   -cs\   import io, signal, sys ;signal.signal(signal.SIGINT, lambda s, f: sys.stderr.write("$\n")) ;s    ;s"   sys.stderr.write("Worm Sign!\n") ;s   infile.close()t   stdinR   R   s   Worm Sign!
s   while awaiting a signi    gš™™™™™©?i   iÈ   s,   reader process failed to handle our signals.s   $
s   while awaiting signalt   inputs   
s   exited rc=%dR   N(    (    (   R   t
   subprocesst   Popent   syst
   executablet   PIPER   R   t   readt   lenR   R   t   writet   selectt   send_signalt   signalt   SIGINTR	   R   t   readlineR   t
   returncodet   False(   R   t   data_to_writet   read_and_verify_codet   infile_setup_codet	   worm_signt   signals_sentt   rlistt   _t   signal_lineR   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/test_file_eintr.pyt   _test_readingJ   s<    

	*

s­   got = infile.{read_method_name}() ;expected = {expected!r} ;assert got == expected, ("{read_method_name} returned wrong data.\n""got data %r\nexpected %r" % (got, expected))c      	   C   s/   |  j  d d d |  j j d d d d ƒ ƒ d S(	   s1   readline() must handle signals and not lose data.R+   s   hello, world!R,   t   read_method_nameR(   t   expecteds   hello, world!
N(   R3   t   _READING_CODE_TEMPLATEt   format(   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/test_file_eintr.pyt   test_readlineš   s
    	c      
   C   s5   |  j  d d d |  j j d d d d d g ƒ ƒ d	 S(
   s2   readlines() must handle signals and not lose data.R+   s   hello
world!R,   R4   t	   readlinesR5   s   hello
s   world!
N(   R3   R6   R7   (   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/test_file_eintr.pyt   test_readlines¢   s
    	c      	   C   sZ   |  j  d d d |  j j d d d d ƒ ƒ |  j  d d d |  j j d d d d ƒ ƒ d	 S(
   s0   readall() must handle signals and not lose data.R+   s   hello
world!R,   R4   t   readallR5   s   hello
world!
R!   N(   R3   R6   R7   (   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/test_file_eintr.pyt   test_readallª   s    	
	(   t   __name__t
   __module__R   R   R   t   TrueR   R3   R6   R8   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/test_file_eintr.pyR      s   				I		t   TestBufferedIOSignalInterruptc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   d S(   s?   Returns the infile = ... line of code to make a BufferedReader.se   infile = io.open(sys.stdin.fileno(), "rb") ;import _io ;assert isinstance(infile, _io.BufferedReader)(    (   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/test_file_eintr.pyR   º   s    c      	   C   s/   |  j  d d d |  j j d d d d ƒ ƒ d S(	   s<   BufferedReader.read() must handle signals and not lose data.R+   s   hello
world!R,   R4   R!   R5   s   hello
world!
N(   R3   R6   R7   (   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/test_file_eintr.pyR<   ¿   s
    	(   R=   R>   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/test_file_eintr.pyR@   ¹   s   	t   TestTextIOSignalInterruptc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   d S(   s>   Returns the infile = ... line of code to make a TextIOWrapper.sr   infile = io.open(sys.stdin.fileno(), "rt", newline=None) ;import _io ;assert isinstance(infile, _io.TextIOWrapper)(    (   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/test_file_eintr.pyR   É   s    c      	   C   s/   |  j  d d d |  j j d d d d ƒ ƒ d S(	   s1   readline() must handle signals and not lose data.R+   s   hello, world!R,   R4   R(   R5   s   hello, world!
N(   R3   R6   R7   (   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/test_file_eintr.pyR8   Î   s
    	c      
   C   s5   |  j  d d d |  j j d d d d d g ƒ ƒ d	 S(
   s2   readlines() must handle signals and not lose data.R+   s   hello
world!R,   R4   R9   R5   s   hello
s   world!
N(   R3   R6   R7   (   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/test_file_eintr.pyR:   Ö   s
    	c      	   C   s/   |  j  d d d |  j j d d d d ƒ ƒ d S(	   s-   read() must handle signals and not lose data.R+   s   hello
world!R,   R4   R!   R5   s   hello
world!
N(   R3   R6   R7   (   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/test_file_eintr.pyR<   Þ   s
    	(   R=   R>   R   R8   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/test_file_eintr.pyRA   È   s   			c          C   sQ   g  t  ƒ  j ƒ  D]- }  t |  t ƒ r t |  t j ƒ r |  ^ q } t | Œ  d  S(   N(   t   globalst   valuest
   isinstancet   typet
   issubclasst   unittestt   TestCaseR    (   t   tct
   test_cases(    (    sŠ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_file_eintr.pyt	   test_mainç   s    -t   __main__(   t   osR$   R&   R   R   t   test.test_supportR    R   RG   t   _ioR   t
   skipUnlesst   nameRH   R   R@   RA   RK   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/test_file_eintr.pyt   <module>   s   �	