ó
‹wÛjc           @   s‡  d  Z  d d l Z d d l m Z m Z m Z d d l Z d d l Z d d l Z e d d e	 ƒZ
 e j j d ƒ s— e j d k s— e j j d ƒ r´ e j d	 e j d
 ƒ ‚ n  e d Z e j j e d ƒ Z e j j e 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 e j f d „  ƒ  YZ d „  Z  e! d k rƒe  ƒ  n  d S(   s1   
   Tests for the mhlib module
   Nick Mathewson
iÿÿÿÿN(   t   run_unittestt   TESTFNt   import_modulet   mhlibt
   deprecatedt   wint   riscost   atheoss   skipped on %s -- s   too many Unix assumptionst   _MHt   MHs   .mh_profilec         C   s   t  j j |  j d ƒ Œ  S(   Nt   /(   t   ost   patht   joint   split(   t   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_mhlib.pyt   normF   s    c         C   sf   t  j j |  ƒ d } | r< t  j j | ƒ r< t | ƒ n  t |  d ƒ } | j | ƒ | j ƒ  d  S(   Ni    t   w(   R   R   R   t   existst   mkdirst   opent   writet   close(   t   fnamet   contentst   dirR   (    (    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_mhlib.pyt	   writeFile"   s    c         C   s&   t  |  ƒ } | j ƒ  } | j ƒ  | S(   N(   R   t   readR   (   R   R   t   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_mhlib.pyt   readFile*   s    
c         C   sI   g  |  j  ƒ  D] \ } } d | | f ^ q } t t d j | ƒ ƒ d  S(   Ns   %s: %s
t    (   t	   iteritemsR   t
   _mhprofileR   (   t   dictt   kt   vR   (    (    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_mhlib.pyt   writeProfile0   s    /c         C   s0   t  |  ƒ }  t t j j t d ƒ d |  ƒ d  S(   Nt   contexts   Current-Folder: %s
(   R   R   R   R   R   t   _mhpath(   t   folder(    (    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_mhlib.pyt   writeContext4   s    c         C   s3   t  |  ƒ }  t t j j t |  d ƒ d | ƒ d  S(   Ns   .mh_sequencess   cur: %s
(   R   R   R   R   R   R&   (   R'   t   cur(    (    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_mhlib.pyt   writeCurMessage9   s    c         C   s–   t  |  ƒ }  d j g  | j ƒ  D] \ } } d | | f ^ q ƒ } d | | f } t t j j t |  ƒ ƒ t t j j t |  t | ƒ ƒ | ƒ d  S(   NR   s   %s: %s
s   %s
%s
(	   R   R   R   R   R   R   R&   R   t   str(   R'   t   nt   headerst   bodyR"   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_mhlib.pyt   writeMessage>   s
    8c           C   s   t  j t j j t ƒ t ƒ S(   N(   R   R	   R   R   t   abspathR&   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_mhlib.pyt   getMHE   s    c         C   sN   |  j  d ƒ } g  | D]$ } t | ƒ d k r | j ƒ  ^ q } | j ƒ  | S(   Ns   
i   (   R   t   lent   stript   sort(   t   st   linest   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_mhlib.pyt	   sortLinesH   s    1
c         C   sU   t  j j |  ƒ s |  d k r" d  St  j j |  ƒ \ } } t | ƒ t  j |  ƒ d  S(   NR   (   R   R   R   R   R   t   mkdir(   R   t   baset   file(    (    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_mhlib.pyR   O   s
    
c         C   sž   t  j j |  ƒ s d  Sxf t  j |  ƒ D]U } t  j j |  | ƒ } t  j j | ƒ r` t | ƒ q& y t  j | ƒ Wq& q& Xq& Wy t  j |  ƒ Wn n Xd  S(   N(	   R   R   R   t   listdirR   t   isdirt   deltreet   unlinkt   rmdir(   R   R   t   fullname(    (    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_mhlib.pyR>   V   s    t
   MhlibTestsc           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sW  t  t ƒ t t ƒ t i t j j t ƒ d 6d d 6d d 6ƒ t d d i d d	 6d
 d 6d d 6d ƒ t d d i d
 d	 6d d 6d d 6d ƒ xP t	 d d ƒ t	 d d d ƒ D]/ } t d | i d d	 6d | d 6d | ƒ q¯ Wd „  } | d d ƒ | d d ƒ | d d ƒ | d d ƒ | d d ƒ | d  d ƒ | d! d ƒ | d! d ƒ d  S("   Nt   Patht   emacst   Editors   camping holidays   ignored-attributet   inboxi   s   Mrs. Premiset   Froms   Mrs. Conclusiont   Tos   18 July 2001t   Dates   Hullo, Mrs. Conclusion!
i   s   29 July 2001s   Hullo, Mrs. Premise!
i   ie   iÉ   t   widet   nowheres   message #%st   Subjects   This is message number %s
c         S   s2   t  |  | i d |  | f d 6d | |  f ƒ d  S(   Ns   Message %s/%sRL   s    This is message number %s in %s
(   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_mhlib.pyt   deep‚   s    	s   deep/f1i   s   deep/f2i   i   RM   s
   deep/f2/f3(
   R>   t   _mhrootR   R&   R$   R   R   R0   R/   t   range(   t   selft   iRM   (    (    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_mhlib.pyt   setUph   s4    

	
	
&		c         C   s   t  t ƒ d  S(   N(   R>   RN   (   RP   (    (    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_mhlib.pyt   tearDown�   s    c         C   s|  t  d ƒ t d d ƒ t ƒ  } |  j } | | j d ƒ d ƒ | | j d ƒ d  ƒ | | j ƒ  t j j	 t
 ƒ ƒ | | j ƒ  d ƒ | j d ƒ | | j ƒ  d ƒ | t t j j t
 d ƒ ƒ d ƒ | j d ƒ | j d ƒ } | | j ƒ  t j j t j j	 t
 ƒ d ƒ ƒ | | j ƒ  t j j t j j	 t
 ƒ d d	 ƒ ƒ | | j d
 ƒ t j j t j j	 t
 ƒ d d ƒ ƒ d  S(   NRF   i   RE   RD   s   not-setRJ   R%   s   Current-Folder: wide
s   .mh_sequencesi   t   1(   R(   R*   R1   t   assertEqualt
   getprofilet   Nonet   getpathR   R   R0   R&   t
   getcontextt
   setcontextR   R   t
   openfoldert   getfullnamet   getsequencesfilenamet   getmessagefilename(   RP   t   mht   eqRF   (    (    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_mhlib.pyt
   test_basic’   s(    
		"%c         C   sN  t  ƒ  } |  j } | j ƒ  } | j ƒ  | | d d d g ƒ | j ƒ  } | j ƒ  t t d d d d d d g ƒ } | j ƒ  | | | ƒ | j d ƒ } | j ƒ  | | t t d d g ƒ ƒ | j d ƒ } | j ƒ  | | t t d d d g ƒ ƒ | | j t d ƒ ƒ t d ƒ g ƒ | | j d ƒ g  ƒ | | j d ƒ g  ƒ d  S(   NRM   RF   RJ   s   deep/f1s   deep/f2s
   deep/f2/f3(	   R1   RU   t   listfoldersR4   t   listallfolderst   mapR   t   listsubfolderst   listallsubfolders(   RP   R_   R`   t   folderst   tfolders(    (    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_mhlib.pyt   test_listfolders¬   s(    		




%c            sñ  t  ƒ  } |  j ‰  t d d ƒ | j d ƒ ‰ ˆ j ƒ  } ˆ  | t d d ƒ t d d d ƒ ƒ ˆ  ˆ j ƒ  d ƒ ˆ j d ƒ ˆ  t t	 j
 j t d d ƒ ƒ d	 ƒ ‡  ‡ f d
 †  } | d t d d ƒ ƒ | d t d d ƒ t d d d ƒ ƒ | d t d d ƒ t d d d ƒ ƒ | d t d d ƒ ƒ | d t d d ƒ ƒ | d t d d d ƒ ƒ | d d g ƒ | d d g ƒ | d d g ƒ | d d g ƒ | d d d d g ƒ | d t d d ƒ ƒ | d t d  d d ƒ ƒ | d! d d d g ƒ d d" d# d$ d% d& d' d( g } g  t d d) ƒ D] } | | k r'| ^ q'} ˆ j i d g d 6| d* 6| d+ 6ƒ t t	 j
 j t d d ƒ ƒ } t | ƒ } ˆ  | d, d- d. g ƒ | d* | ƒ | d/ d g ƒ | d0 d d" g ƒ | d1 d' d( g ƒ d  S(2   NRJ   i7   i   ie   iÉ   i   ic   s   .mh_sequencess   cur: 99
c            s   ˆ  ˆ j  |  ƒ | ƒ d  S(   N(   t   parsesequence(   t   seqt   val(   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_mhlib.pyt   seqeqÔ   s    s   5-55i8   s   90-108iZ   im   s   10:10i
   i   s   10:+10s   101:10iy   R)   t   .t   previb   t   nextid   s   cur:-3ia   s	   first-curs   150-lasti—   s	   prev-nexti   i   i   i   i   i   i   i   t   lowprimet	   lowcomposs   cur: 5s,   lowcompos: 6 8-10 12 14-16 18 20-22 24-28 30s   lowprime: 5 7 11 13 17 19 23 29s
   lowprime:1s
   lowprime:2s   lowprime:-2(   R1   RU   R*   R[   t   listmessagesRO   t
   getcurrentt
   setcurrentR   R   R   R   R&   t   putsequencesR8   (   RP   R_   t   allRm   t	   lowprimest   xRr   t   seqs(    (   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_mhlib.pyt   test_sequenceÇ   sN    		&&&.	
c            s  t  ƒ  } |  j } | j d ƒ |  j d | j ƒ  ƒ t j j t d ƒ } |  j	 t j j
 | ƒ ƒ | j d ƒ ‰  ‡  f d †  } | d ƒ | d ƒ | d ƒ | t ˆ  j d ƒ ƒ d ƒ | ˆ  j ƒ  d d d g ƒ t j | ƒ } | j ƒ  | | d d d	 g ƒ ˆ  j d d g ƒ t j | ƒ } | j ƒ  | | d
 d d	 g ƒ | ˆ  j ƒ  d g ƒ | d ƒ | d ƒ | d ƒ | j d ƒ | j d ƒ } | | j ƒ  g  ƒ ˆ  j d | d ƒ ˆ  j d | d ƒ | ˆ  j ƒ  d d g ƒ | | j ƒ  d d g ƒ | t | j d ƒ ƒ d ƒ ˆ  j d | d ƒ | ˆ  j ƒ  d d g ƒ | t | j d ƒ ƒ d ƒ ˆ  j d d g | ƒ | ˆ  j ƒ  g  ƒ | | j ƒ  d d d d d g ƒ | t | j d ƒ ƒ d ƒ | j d ƒ | j d ƒ |  j d | j ƒ  ƒ |  j	 t j j
 | ƒ ƒ d  S(   Nt   dummy1c            s-   d |  |  f } ˆ  j  |  t j | ƒ ƒ d  S(   Ns(   From: foo
Subject: %s

Dummy Message %s
(   t   createmessaget   StringIO(   R,   t   msg(   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_mhlib.pyt   create  s    i   i   i	   s&   From: foo
Subject: 9

Dummy Message 9
t   7t   8t   9s   ,7s   ,8i
   i   i   t   dummy2i   i   s(   From: foo
Subject: 10

Dummy Message 10
i   i   s(   From: foo
Subject: 12

Dummy Message 12
(   R1   RU   t
   makefoldert   assertInRb   R   R   R   R&   t
   assertTrueR   R[   R   R^   Rs   R<   R4   t   removemessagest   movemessaget   copymessaget   refilemessagest   deletefoldert   assertNotIn(   RP   R_   R`   R   R€   t   filest   f2(    (   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_mhlib.pyt   test_modifyþ   s^    		







"c         C   sì   t  ƒ  } |  j } | j d ƒ } | j d ƒ } | | j d ƒ d ƒ | | j d ƒ d ƒ t | j ƒ  ƒ } | | d d d	 g ƒ t | j d
 „  ƒ ƒ } | | d d g ƒ | | j ƒ  d ƒ | | j d ƒ d ƒ | j j	 ƒ  ~ d  S(   NRF   i   RG   s   Mrs. PremiseRH   s   Mrs. Conclusions   Date: 18 July 2001s   From: Mrs. Premises   To: Mrs. Conclusionc         S   s   t  |  ƒ d k S(   Ni   (   R2   (   t   h(    (    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_mhlib.pyt   <lambda>L  R   s   Hullo, Mrs. Conclusion!

i    (
   R1   RU   R[   t   openmessaget	   getheaderR8   t   getheadertextt   getbodytextt   fpR   (   RP   R_   R`   R   R   R6   (    (    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_mhlib.pyt	   test_read<  s"    			
	
(	   t   __name__t
   __module__RR   RS   Ra   Ri   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_mhlib.pyRB   g   s   	'				7	>c           C   s   t  t ƒ d  S(   N(   R    RB   (    (    (    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_mhlib.pyt	   test_mainW  s    t   __main__("   t   __doc__t   unittestt   test.test_supportR    R   R   R   R~   t   syst   TrueR   t   platformt
   startswitht   SkipTestRN   R   R   R&   R    R   R   R   R$   R(   R*   R/   R1   R8   R   R>   t   TestCaseRB   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_mhlib.pyt   <module>   s6   !
											ð	