ó
[³XMc           @   s‰   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d e j f d „  ƒ  YZ	 d e	 f d „  ƒ  YZ
 e	 e
 g Z d S(	   s   
Test cases for dirdbm module.
iÿÿÿÿN(   t   unittest(   t   dirdbmt   DirDbmTestCasec           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s:   |  j  ƒ  |  _ t j |  j ƒ |  _ d d d	 f |  _ d  S(
   Nt   abct   foos   /lalalt    t    
t   baz(   s   abcR   (   s   /lalalR   (   R   R   (   t   mktempt   pathR   t   opent   dbmt   items(   t   self(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyt   setUp   s    c         C   sD   d j  d ƒ } d |  j | <d |  j | <|  j |  j | d ƒ d  S(   Ns   //==t   base64t   a(   t   decodeR   t   assertEquals(   R   t   k(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyt   testAll   s    c         C   sJ   d d l  m } d d l m } | j d ƒ } d | d <| j | ƒ d  S(   Niÿÿÿÿ(   R   (   t   rebuilds   dirdbm.rebuild.testt   valuet   key(   t   twisted.persistedR   t   twisted.pythonR   t   Shelf(   R   R   R   t   s(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyt   testRebuildInteraction   s
    
c         C   sË  |  j  } g  } g  } x; |  j D]0 \ } } | | | <| j | ƒ | j | ƒ q W| j ƒ  | j ƒ  xH |  j D]= \ } } | j | ƒ s• t d ‚ | | | k sq t d ‚ qq Wy | d Wn t k
 rÑ n Xd sá t d ‚ t | j ƒ  ƒ } t | j	 ƒ  ƒ } t | j ƒ  ƒ } | j ƒ  | j ƒ  | j ƒ  t |  j ƒ }	 |	 j ƒ  | | k syt d t
 | ƒ t
 | ƒ f ‚ | | k s¤t d t
 | ƒ t
 | ƒ f ‚ |	 | k sÏt d t
 |	 ƒ t
 | ƒ f ‚ |  j ƒ  }
 | j |
 ƒ } t | j ƒ  ƒ } t | j	 ƒ  ƒ } t | j ƒ  ƒ } | j ƒ  | j ƒ  | j ƒ  | | k sit d	 t
 | ƒ t
 | ƒ f ‚ | | k s”t d
 t
 | ƒ t
 | ƒ f ‚ | | k s¿t d t
 | ƒ t
 | ƒ f ‚ | j ƒ  t | j ƒ  ƒ t | j	 ƒ  ƒ k ot | j ƒ  ƒ k od k n st d ‚ t j |
 ƒ x7 |  j D], \ } } | | =| j | ƒ s4t d ‚ q4Wt | j ƒ  ƒ d k s…t d ‚ t | j	 ƒ  ƒ d k s¦t d ‚ t | j ƒ  ƒ d k sÇt d ‚ d  S(   Ns   has_key() faileds   database has wrong valuet   XXXi    s)   didn't raise KeyError on non-existent keys%   .keys() output didn't match: %s != %ss'   .values() output didn't match: %s != %ss   items() didn't match: %s != %ss'   .copyTo().keys() didn't match: %s != %ss)   .copyTo().values() didn't match: %s != %ss(   .copyTo().items() didn't match: %s != %ss   .clear() faileds#   has_key() even though we deleted its   database has keyss   database has valuess   database has items(   R   R   t   appendt   sortt   has_keyt   AssertionErrort   KeyErrort   listt   keyst   valuest   reprR   t   copyTot   cleart   lent   shutilt   rmtree(   R   t   dR$   R%   R   t   vt   dbkeyst   dbvaluest   dbitemsR   t   copyPatht   d2t   copykeyst
   copyvaluest	   copyitems(    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyt   testDbm(   s`    	






+++


+++
T!!c         C   sL   d d  l  } d |  j d <|  j t | j  ƒ  |  j j d ƒ ƒ d k ƒ d  S(   NiÿÿÿÿR-   R   i   (   t   timeR   t   assert_t   abst   getModificationTime(   R   R7   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyt   testModificationTimej   s    
c         C   sž  |  j  j d ƒ } t t j j |  j | d ƒ d ƒ } | j d ƒ | j ƒ  |  j  j d ƒ } t t j j |  j | ƒ d ƒ } | j d ƒ | j ƒ  t t j j |  j | d ƒ d ƒ } | j d ƒ | j ƒ  t t j j |  j d ƒ d ƒ } | j d	 ƒ | j ƒ  t j	 |  j ƒ } | d d k s4t
 ‚ | d d k sJt
 ‚ t j t j j |  j d
 ƒ ƒ srt
 ‚ t j t j j |  j d ƒ ƒ sšt
 ‚ d S(   s8   DirDBM: test recovery from directory after a faked crasht   key1s   .rplt   wbR   t   key2t   correctt   wrongs   aa.newt   deleteds   *.news   *.rplN(   R   t   _encodeR
   t   osR	   t   joint   writet   closeR   t   DirDBMR!   t   glob(   R   R   t   ft   k2R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyt   testRecoveryy   s&    %
!
%
!
(c         C   sê   |  j  t |  j j d d ƒ y  |  j  t |  j j d d ƒ Wn* t j k
 rh |  j |  j t j ƒ n X|  j  t |  j j	 d ƒ |  j  t |  j j
 d ƒ |  j  t |  j j d ƒ |  j  t |  j j d ƒ |  j  t |  j j d ƒ d S(   sâ   
        L{dirdbm.DirDBM} operations only support string keys: other types
        should raise a C{AssertionError}. This really ought to be a
        C{TypeError}, but it'll stay like this for backward compatibility.
        i   t   3t   2i   N(   t   assertRaisesR!   R   t   __setitem__R    t   FailTestt   assertIsInstanceR   R   t   __getitem__t   __delitem__R    t   __contains__R:   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyt   test_nonStringKeys“   s     (	   t   __name__t
   __module__R   R   R   R6   R;   RK   RU   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyR      s   			
	B		t   ShelfTestCasec           B   s   e  Z d  „  Z RS(   c         C   sI   |  j  ƒ  |  _ t j |  j ƒ |  _ d d d d d d d f f |  _ d  S(   NR   R   s   /lalalR   R   R   t   inti   t   floatg      (@t   tuple(   s   abcs   foo(   s   /lalals    (   s    
s   baz(   s   inti   (   s   floatg      (@(   Ni   (   R   R	   R   R   R   t   NoneR   (   R   (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyR   ©   s    	(   RV   RW   R   (    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyRX   §   s   (   t   __doc__RC   R*   RH   t   twisted.trialR    R   R   t   TestCaseR   RX   t	   testCases(    (    (    s<   /usr/lib/python2.7/dist-packages/twisted/test/test_dirdbm.pyt   <module>   s   $˜	