ó
[³XMc           @   s¥   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z m Z d e j	 f d „  ƒ  YZ
 d e j f d „  ƒ  YZ d e j	 f d	 „  ƒ  YZ d S(
   iÿÿÿÿN(   t   unittest(   t   logfilet   runtimet   LogFileTestCasec           B   s§   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z e j j ƒ  rœ d e _ n  d „  Z RS(   s%   
    Test the rotating log file.
    c         C   sJ   |  j  ƒ  |  _ t j |  j ƒ d |  _ t j j |  j |  j ƒ |  _ d  S(   Ns   test.log(   t   mktempt   dirt   ost   makedirst   namet   patht   join(   t   self(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   setUp   s    	c         C   sB   t  j |  j d ƒ t  j j |  j ƒ r> t  j |  j d ƒ n  d S(   sž   
        Restore back write rights on created paths: if tests modified the
        rights, that will allow the paths to be removed easily afterwards.
        iÿ  N(   R   t   chmodR   R	   t   exists(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   tearDown   s    c         C   s‰   t  j |  j |  j ƒ } | j d ƒ | j d ƒ | j ƒ  | j d ƒ | j ƒ  t |  j d ƒ } |  j	 | j
 ƒ  d ƒ | j ƒ  d  S(   Nt   123t   456t   7890t   rt
   1234567890(   R   t   LogFileR   R   t   writet   flusht   closet   openR	   t   assertEqualst   read(   R   t   logt   f(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   testWriting    s    

c         C   sš  t  j |  j |  j d d ƒ} | j d ƒ | j d ƒ | j d ƒ |  j t j j d |  j ƒ ƒ |  j t j j d |  j ƒ ƒ | j d	 ƒ |  j t j j d |  j ƒ ƒ |  j t j j d |  j ƒ ƒ |  j t j j d
 |  j ƒ ƒ | j d ƒ |  j t j j d
 |  j ƒ ƒ | j	 ƒ  |  j t j j d
 |  j ƒ ƒ |  j t j j d |  j ƒ ƒ | j
 ƒ  |  j | j ƒ  d d d g ƒ d  S(   Nt   rotateLengthi
   R   t   4567890t   1i   s   %s.1s   %s.2t    s   %s.3t   3s   %s.4i   i   i   t   11111111111(   R   R   R   R   R   t   assert_R   R	   R   t   rotateR   R   t   listLogs(   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   testRotation,   s"     !  !!
 !
c         C   sï   t  j |  j |  j ƒ } | j d ƒ | j ƒ  t  j |  j |  j ƒ } |  j | j d ƒ |  j | j j	 ƒ  | j ƒ | j d ƒ |  j | j d ƒ |  j | j j	 ƒ  | j ƒ | j } | j
 d d ƒ |  j | j ƒ  d ƒ | j ƒ  d  S(   Nt
   0123456789i
   t   abci   i    t   0123456789abc(   R   R   R   R   R   R   R   t   sizet   _filet   tellt   seekR   (   R   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt
   testAppendE   s    
	c         C   s  t  j |  j |  j ƒ } | j d ƒ | j d ƒ | j ƒ  | j d ƒ | j ƒ  |  j | j ƒ  d g ƒ | j	 ƒ  } | j
 j d ƒ |  j | j ƒ  d g ƒ |  j | j ƒ  g  ƒ | j ƒ  | j d ƒ } |  j | j ƒ  d d g ƒ |  j | j ƒ  g  ƒ | j ƒ  |  j t | j d ƒ |  j t | j d ƒ | j ƒ  |  j | j ƒ  d d g ƒ | j d ƒ } | j
 j d ƒ |  j | j ƒ  d g ƒ |  j | j ƒ  g  ƒ | j ƒ  | j d ƒ } |  j | j ƒ  d d g ƒ |  j | j ƒ  g  ƒ | j ƒ  d  S(   Ns   abc
s   def
s   ghi
i   i    i   R!   (   R   R   R   R   R   R&   R   R   R'   t   getCurrentLogR-   R/   t	   readLinesR   t   getLogt   assertRaisest
   ValueErrort	   TypeError(   R   R   t   reader(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   testLogReaderU   s:    





c         C   sš   t  |  j d ƒ j ƒ  } t j |  j d ƒ t j |  j ƒ t j } t j |  j	 |  j
 ƒ } | j d ƒ | j ƒ  |  j | t j |  j ƒ t j ƒ d S(   sH   
        Check rotated files have same permissions as original.
        t   wiÇ  R*   N(   R   R	   R   R   R   t   statt   ST_MODER   R   R   R   R   R&   R   (   R   R   t   modeR   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   testModePreservationz   s    
c         C   sù   t  j |  j |  j ƒ } | j d ƒ t j |  j d ƒ y% t t j j	 |  j d ƒ d ƒ } Wn t
 t f k
 rv n X| j ƒ  d S| j ƒ  | j d ƒ | j ƒ  | j } |  j | j ƒ  d ƒ | j d d ƒ |  j | j ƒ  d	 ƒ | j ƒ  d S(
   sH   
        Check it keeps working when permission on dir changes.
        R*   im  t   xxxR9   Nt   defi   i    t   abcdef(   R   R   R   R   R   R   R   R   R	   R
   t   OSErrort   IOErrorR   R&   R   R-   R   R.   R/   R   (   R   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   test_noPermission‡   s"    %


	c         C   s0  t  j |  j |  j d d d d ƒ} | j d ƒ | j d ƒ |  j t j j d |  j ƒ ƒ | j d ƒ |  j t j j d
 |  j ƒ ƒ | j d ƒ |  j t j j d |  j ƒ ƒ |  j	 t
 d |  j ƒ j ƒ  d ƒ | j d ƒ |  j	 t
 d |  j ƒ j ƒ  d ƒ |  j t j j d |  j ƒ ƒ d S(   sl   
        Test it respect the limit on the number of files when maxRotatedFiles
        is not None.
        R   i
   t   maxRotatedFilesi   R!   i   t   2s   %s.1R#   s   %s.2t   4s   %s.3t   5s   %s.4NR$   t   22222222222t   33333333333t   44444444444R$   t   55555555555RH   (   R   R   R   R   R   t
   failUnlessR   R	   R   R   t   fileR   (   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   test_maxNumberOfLog§   s    	   ##c         C   s§   t  j |  j |  j d d d ƒ} t  j j |  j d d d ƒ} |  j | j | j ƒ |  j t j j | j ƒ | j ƒ |  j | j	 | j	 ƒ |  j | j
 | j
 ƒ d S(   s/   
        Test the fromFullPath method.
        i
   t   defaultModeiÿ  N(   R   R   R   R   t   fromFullPathR	   R   R   t   abspathR   RO   (   R   t   log1t   log2(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   test_fromFullPath½   s    !"c         C   s™   t  |  j d ƒ } t j |  j d ƒ t j t j |  j ƒ t j ƒ } | j ƒ  t j	 |  j
 |  j ƒ } |  j t j t j |  j ƒ t j ƒ | ƒ d S(   sx   
        Test the default permission of the log file: if the file exist, it
        should keep the permission.
        R9   iÇ  N(   RM   R	   R   R   R:   t   S_IMODER;   R   R   R   R   R   R   (   R   R   t   currentModeRR   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   test_defaultPermissionsÈ   s    "
%c         C   sv   t  j |  j |  j d d ƒ} t j t j |  j ƒ t j ƒ } t	 j
 j ƒ  rb |  j | d ƒ n |  j | d ƒ d S(   sG   
        Test specifying the permissions used on the log file.
        RO   i6   i$  N(   R   R   R   R   R:   RU   R   R	   R;   R   t   platformt	   isWindowsR   (   R   RR   R<   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   test_specifiedPermissionsÖ   s
    "c         C   sÖ   t  j |  j |  j ƒ } | j d ƒ t j j |  j d ƒ } t j |  j | ƒ | j	 ƒ  | j d ƒ | j
 ƒ  t |  j d ƒ } |  j | j ƒ  d ƒ | j
 ƒ  t | d ƒ } |  j | j ƒ  d ƒ | j
 ƒ  d S(   s‹   
        L{logfile.LogFile.reopen} allows to rename the currently used file and
        make L{logfile.LogFile} create a new file.
        t   hello1s   save.logt   hello2R   N(   R   R   R   R   R   R   R	   R
   t   renamet   reopenR   R   R   R   (   R   RR   t   savePathR   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   test_reopenã   s    


s   Can't test reopen on Windowsc         C   s8   |  j  t t j |  j d ƒ } |  j | j t j ƒ d S(   sR   
        Specifying an invalid directory to L{LogFile} raises C{IOError}.
        t   this_dir_does_not_existN(   R4   RB   R   R   R   R   t   errnot   ENOENT(   R   t   e(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   test_nonExistentDirû   s    (   t   __name__t
   __module__t   __doc__R   R   R   R(   R0   R8   R=   RC   RN   RT   RW   RZ   R`   R   RX   RY   t   skipRe   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyR   
   s"   		
				%		 					t   RiggedDailyLogFilec           B   s    e  Z d  Z d „  Z d „  Z RS(   g        c         C   s#   t  j j |  ƒ |  j ƒ  |  _ d  S(   N(   R   t   DailyLogFilet	   _openFilet   toDatet   lastDate(   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyRl     s    c         G   s+   | r t  j | Œ  d  St  j |  j ƒ d  S(   Ni   (   t   timet   gmtimet   _clock(   R   t   args(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyRm     s    (   Rf   Rg   Rq   Rl   Rm   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyRj     s   	t   DailyLogFileTestCasec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s!   
    Test rotating log file.
    c         C   sJ   |  j  ƒ  |  _ t j |  j ƒ d |  _ t j j |  j |  j ƒ |  _ d  S(   Ns   testdaily.log(   R   R   R   R   R   R	   R
   (   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyR     s    	c         C   s†   t  |  j |  j ƒ } | j d ƒ | j d ƒ | j ƒ  | j d ƒ | j ƒ  t |  j d ƒ } |  j | j	 ƒ  d ƒ | j ƒ  d  S(   NR   R   R   R   R   (
   Rj   R   R   R   R   R   R   R	   R   R   (   R   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyR     s    

c         C   so  t  |  j |  j ƒ } g  t d ƒ D]$ } |  j d | j | d ƒ ^ q" } d | _ | j d ƒ d | _ | j d ƒ d | _ | j d ƒ |  j t	 j j
 | d
 ƒ ƒ |  j t	 j j
 | d ƒ ƒ d | _ | j d ƒ |  j t	 j j
 | d
 ƒ ƒ |  j t	 j j
 | d ƒ ƒ |  j t	 j j
 | d ƒ ƒ d | _ | j d ƒ |  j t	 j j
 | d ƒ ƒ d  S(   Ni   t   .i€Q g        R   iÀ¨  R    R!   i   i    i   i £ R"   i   iô R#   R$   (   Rj   R   R   t   rangeR	   t   suffixRq   R   R%   R   R   (   R   R   t   dayt   days(    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyR(   *  s$    7					(   Rf   Rg   Rh   R   R   R(   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyRs     s   		(   R   Ro   R:   Rb   t   twisted.trialR    t   twisted.pythonR   R   t   TestCaseR   Rk   Rj   Rs   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/test/test_logfile.pyt   <module>   s
   0û