ó
‹wÛjc           @   s  d  Z  d d l Z d d l m Z m Z m Z d d l m Z m Z d d l	 Z	 d d l
 Z
 d d l m Z d d l m Z m Z d d „ Z d	 „  Z d
 d d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d „  Z e d k re ƒ  n  d S(   s,   
Tests for fileinput module.
Nick Mathewson
iÿÿÿÿN(   t   verboset   TESTFNt   run_unittest(   t   unlinkt   check_warnings(   t   StringIO(   t	   FileInputt   hook_encodedt   wc         C   s:   t  t |  ƒ } t | | ƒ } | j | ƒ | j ƒ  | S(   N(   R   t   strt   opent
   writelinest   close(   t   it   linest   modet   namet   f(    (    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_fileinput.pyt   writeTmp   s
    
c          G   s   x |  D] } t  | ƒ q Wd  S(   N(   t   safe_unlink(   t   namesR   (    (    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_fileinput.pyt   remove_tempfiles   s    t
   LineReaderc           B   sJ   e  Z d  „  Z e d „  ƒ Z d „  Z d d „ Z d d „ Z d „  Z	 RS(   c         C   s   g  |  _  d  S(   N(   t
   _linesread(   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_fileinput.pyt   __init__!   s    c         C   s   z |  j  SWd  g  |  _  Xd  S(   N(   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_fileinput.pyt	   linesread$   s    c         C   s   t  | j t ƒ ƒ |  _ |  S(   N(   t   itert
   splitlinest   Truet   it(   R   t   filenameR   (    (    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_fileinput.pyt   openhook+   s    c         C   s&   t  |  j d ƒ } |  j j | ƒ | S(   Nt    (   t   nextR   R   t   append(   R   t   sizet   line(    (    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_fileinput.pyt   readline/   s    iÿÿÿÿc         C   s`   g  } d } xM t  r[ |  j ƒ  } | s+ | S| j | ƒ | t | ƒ 7} | | k r | Sq Wd  S(   Ni    (   R   R&   R#   t   len(   R   t   hintR   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_fileinput.pyt	   readlines4   s    	c         C   s   d  S(   N(    (   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_fileinput.pyR   @   s    N(
   t   __name__t
   __module__R   t   propertyR   R    t   NoneR&   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_fileinput.pyR      s   		t   BufferSizesTestsc           B   s    e  Z d  „  Z d d d „ Z RS(   c      	   C   s  xd d f D]\ } } zà t  d g  t d ƒ D] } d | d ^ q/ ƒ } t  d g  t d ƒ D] } d | d ^ q_ ƒ } t  d	 g  t d
 ƒ D] } d | d ^ q� ƒ } t  d g  t d ƒ D] } d | d ^ q¿ ƒ } |  j | | | | | | ƒ Wd  t | | | | ƒ Xq Wd  S(   Ni    i   i   i   s   Line %s of file 1
i   i
   s   Line %s of file 2
i   i   s   Line %s of file 3
i   s   Line %s of file 4
(   i    i    (   i   i   (   R   t   ranget   buffer_size_testR   (   R   t   roundt   bsR   t   t1t   t2t   t3t   t4(    (    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_fileinput.pyt   test_buffer_sizesD   s    0000 i    c         C   s�  t  j d ƒ } d | d } t r9 d | d | f GHn  t d | | | | f d | ƒ }	 t |	 ƒ }
 |	 j ƒ  |  j t |
 ƒ d ƒ |  j |
 d	 d
 ƒ |  j |
 d d ƒ |  j |	 j ƒ  d ƒ |  j |	 j	 ƒ  | ƒ t rö d | d | f GHn  t d | | | | f d | ƒ }	 d } x" | rA| d k rA|	 j
 ƒ  } q W|  j |	 j	 ƒ  | ƒ |  j |	 j ƒ  d ƒ |  j |	 j ƒ  d ƒ |  j |	 j ƒ  ƒ |  j |	 j ƒ  ƒ t rÆd | d | f GHn  |	 j ƒ  |  j |	 j
 ƒ  d ƒ |  j |	 j ƒ  d ƒ |	 j ƒ  t r"d | d | f GHn  t d | | | | d f d | ƒ }	 t j } zi t d ƒ t _ t |	 ƒ }
 |  j t |
 ƒ d ƒ |  j |
 d d ƒ |  j |	 j	 ƒ  d ƒ |	 j ƒ  Wd  | t _ Xt rád | d	 | f GHn  t d | | | | f d | ƒ }	 |  j |	 j ƒ  d ƒ |  j |	 j	 ƒ  d  ƒ |	 j ƒ  |  j |	 j ƒ  d ƒ |  j |	 j	 ƒ  d  ƒ t r€d | d | f GHn  t j } z[ t d | | | | f d  d d | ƒ }	 x# |	 D] } | d!  j ƒ  } | GHqºW|	 j ƒ  Wd  | t _ Xt d | | | | f d | ƒ }	 xj |	 D]b } |  j | d! d" ƒ | j | d!  ƒ } |  j | d  ƒ |  j t | j d ƒ ƒ |	 j ƒ  ƒ qW|	 j ƒ  d  S(#   Ns   LINE (\d+) OF FILE (\d+)i   i   s   %s. Simple iteration (bs=%s)i    t   filest   bufsizei   i   s   Line 5 of file 1
i   s   Line 1 of file 4
s   %s. Status variables (bs=%s)t   xs   Line 6 of file 2
i   s   %s. Nextfile (bs=%s)i   s   Line 1 of file 3
i   s   %s. Stdin (bs=%s)i   t   -s    Line 1 of stdin
Line 2 of stdin
i!   i    s   Line 2 of stdin
s   <stdin>s   %s. Boundary conditions (bs=%s)s   %s. Inplace (bs=%s)i   t   inplaceiÿÿÿÿs   
(   t   ret   compileR    R   t   listR   t   assertEqualR'   t   linenoR   R&   t
   filelinenot   assertFalset   isfirstlinet   isstdint   nextfilet   syst   stdinR   R-   t   stdoutt   uppert   matcht   assertNotEqualt   intt   group(   R   R3   R4   R5   R6   R2   R1   t   patt   startt   fiR   t   st	   savestdint
   savestdoutR%   t   m(    (    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_fileinput.pyR0   P   s„    !
!

$	
!
	'	
!)(   R*   R+   R7   R0   (    (    (    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_fileinput.pyR.   C   s   	t   FileInputTestsc           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   sE  z*t  d d g ƒ } t  d d g ƒ } t  d d g ƒ } t  d d g ƒ } t d | | | | f ƒ } | j ƒ  } |  j | d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  | ƒ | j ƒ  } |  j | ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  | ƒ | j ƒ  Wd  t	 | | | | ƒ Xd  S(	   Ni   R!   i   i   s   The only line there is.
i   R8   i    (
   R   R   R&   R@   RA   RB   R   RC   R   R   (   R   R3   R4   R5   R6   RQ   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_fileinput.pyt   test_zero_byte_filesž   s$    c         C   s¬   z— t  d d g ƒ } t  d d g ƒ } t d | | f ƒ } t | ƒ } |  j | d d d d	 d
 d g ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ Wd  t | | ƒ Xd  S(   Ni   s   A
B
Ci   s   D
E
FR8   s   A
s   B
t   Cs   D
s   E
t   Fi   i   (   R   R   R?   R@   RB   RA   R   (   R   R3   R4   RQ   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_fileinput.pyt%   test_files_that_dont_end_with_newlineµ   s    "c         C   sƒ   zq t  d d g ƒ } t j ƒ  } | d  k r6 d } n  t d t | | ƒ ƒ } t | ƒ } |  j | d d g ƒ Wd  t | ƒ Xd  S(   Ni   s   A
Bt   asciiR8   s   A
t   B(	   R   RG   t   getfilesystemencodingR-   R   t   unicodeR?   R@   R   (   R   R3   t   encodingRQ   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_fileinput.pyt   test_unicode_filenamesÁ   s    	c         C   sÌ   z· t  d d g ƒ } t  d d g ƒ } t d | | f ƒ } |  j | j ƒ  d ƒ | j ƒ  } |  j | j ƒ  d ƒ | j ƒ  |  j | j ƒ  d ƒ t | ƒ } |  j | j ƒ  d ƒ Wd  t | | ƒ Xd  S(   Ni   s   A
Bi   s   C
DR8   iÿÿÿÿ(	   R   R   R@   t   filenoR"   RL   RF   R?   R   (   R   R3   R4   RQ   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_fileinput.pyt   test_filenoÍ   s    
c         C   sŸ   y  t  d d ƒ } |  j d ƒ Wn t k
 r3 n XzY t d d g d d ƒ} t  d | d d ƒ } t | ƒ } |  j | d	 d
 d d g ƒ Wd  t | ƒ Xd  S(   NR   R   s-   FileInput should reject invalid mode argumenti   s   A
B
CDt   wbR8   t   Us   A
s   B
s   C
t   D(   R   t   failt
   ValueErrorR   R?   R@   R   (   R   RQ   R3   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_fileinput.pyt   test_opening_modeÜ   s     c         C   sÜ   y) t  d d d d „  ƒ } |  j d ƒ Wn t k
 r< n Xy  t  d d ƒ } |  j d ƒ Wn t k
 rp n XzY t d d g d d	 ƒ} t  d
 | d t d ƒ ƒ } t | ƒ } |  j | d d g ƒ Wd  t | ƒ Xd  S(   NR<   i   R    c         S   s   d  S(   N(   R-   (   R   RU   (    (    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_fileinput.pyt   <lambda>ï   R!   sG   FileInput should raise if both inplace and openhook arguments are givens2   FileInput should check openhook for being callables   +AEE-
+AEI-R   Rc   R8   s   utf-7u   A
u   B(   R   Rf   Rg   R   R   R?   R@   R   (   R   RQ   R3   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_fileinput.pyt   test_file_opening_hookì   s     c         C   sÞ   t  t d ƒ �2 } | j d ƒ | j d d ƒ | j d ƒ Wd  QX|  j t t ƒ t d t d t d ƒ ƒ } |  j | j ƒ  d	 ƒ |  j | j ƒ  d
 ƒ |  j | j ƒ  d ƒ |  j	 t
 ƒ � t | ƒ Wd  QX| j ƒ  d  S(   NRc   s   A
B
Cs
   123456789
iè  s   €R8   R    R[   u   A
u   B
u   C(   R
   R   t   writet
   addCleanupR   R   R   R@   R&   t   assertRaisest   UnicodeDecodeErrorR?   R   (   R   R   RQ   (    (    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_fileinput.pyt   test_readline  s    c         C   s$  t  ƒ  } t d d d g d | j ƒ } |  j | j g  ƒ |  j | j ƒ  d ƒ |  j | j d g ƒ |  j | j ƒ  d ƒ |  j | j d g ƒ |  j | j ƒ  d ƒ |  j | j d d g ƒ |  j | j ƒ  d ƒ |  j | j d g ƒ |  j | j ƒ  d ƒ |  j | j g  ƒ | j ƒ  d  S(   NR8   s   line1
line2s   line3
R    s   line1
t   line2R!   (   R   R   R    R@   R   R&   R   (   R   t   srcRQ   (    (    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_fileinput.pyt   test_readline_buffering  s    	c         C   s  t  ƒ  } t d d d g d | j ƒ } |  j | j g  ƒ |  j t | ƒ d ƒ |  j | j d g ƒ |  j t | ƒ d ƒ |  j | j d g ƒ |  j t | ƒ d ƒ |  j | j d d g ƒ |  j t t | ƒ |  j | j d g ƒ |  j t t | ƒ |  j | j g  ƒ | j ƒ  d  S(   NR8   s   line1
line2s   line3
R    s   line1
Rp   R!   (	   R   R   R    R@   R   R"   Rm   t   StopIterationR   (   R   Rq   RQ   (    (    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_fileinput.pyt   test_iteration_buffering&  s    	(   R*   R+   RW   RZ   R`   Rb   Rh   Rj   Ro   Rr   Rt   (    (    (    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_fileinput.pyRV   �   s   								t   Test_hook_encodedc           B   s   e  Z d  Z d „  Z RS(   s'   Unit tests for fileinput.hook_encoded()c            s¬   t  t d ƒ � } | j d ƒ Wd  QXˆ  j t t ƒ ‡  f d †  } | d d d d d g ƒ | d	 d d d d g ƒ | d
 d d d d g ƒ | d d d d d g ƒ d  S(   NRc   s   A
B
CD+IKw-c            sK   t  d t d |  d t d ƒ ƒ } t | ƒ } | j ƒ  ˆ  j | | ƒ d  S(   NR8   R   R    s   utf-7(   R   R   R   R?   R   R@   (   R   t   expected_linesRQ   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_fileinput.pyt   check?  s
    
t   ru   A
u   B
u   Cu   Dâ‚¬t   rURd   t   rb(   R
   R   Rk   Rl   R   (   R   R   Rw   (    (   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_fileinput.pyt
   test_modes9  s    (   R*   R+   t   __doc__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_fileinput.pyRu   6  s   c           C   s   t  t t t ƒ d  S(   N(   R   R.   RV   Ru   (    (    (    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_fileinput.pyt	   test_mainK  s    t   __main__(    (   R|   t   unittestt   test.test_supportR    R   R   R   R   R   RG   R=   R   t	   fileinputR   R   R   R   R   t   TestCaseR.   RV   Ru   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_fileinput.pyt   <module>   s   		$Z™	