ó
ŚxxTc           @   s   d  d l  Z  d  d l Z d  d l Z d e j f d     YZ d e j f d     YZ d   Z d   Z e	 d k r~ e   n  d S(	   i˙˙˙˙Nt   CollationTestsc           B   sP   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C   s   d  S(   N(    (   t   self(    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   setUp   s    c         C   s   d  S(   N(    (   R   (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   tearDown   s    c         C   sa   t  j d  } y! | j d d  |  j d  Wn* t k
 r\ } |  j | j d d  n Xd  S(   Ns   :memory:t   Xi*   s   should have raised a TypeErrori    s   parameter must be callable(   t   sqlitet   connectt   create_collationt   failt	   TypeErrort   assertEqualt   args(   R   t   cont   e(    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   CheckCreateCollationNotCallable"   s    c         C   sM   t  j d  } y! | j d t  |  j d  Wn t  j k
 rH } n Xd  S(   Ns   :memory:s   colläs%   should have raised a ProgrammingError(   R   R   R   t   cmpR   t   ProgrammingError(   R   R   R   (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   CheckCreateCollationNotAscii*   s    c         C   s  t  j d k  r d  Sd   } t  j d  } | j d |  d } | j |  j   } | d d d	 k s | d d d
 k s | d d d k r˘ |  j d  n  | j d d   y& | j |  j   } |  j d  Wn3 t  j k
 r} |  j	 | j
 d j   d  n Xd  S(   Ni   i   i   c         S   s   t  |  |  S(   N(   R   (   t   xt   y(    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   mycoll5   s    s   :memory:R   sÉ   
            select x from (
            select 'a' as x
            union
            select 'b' as x
            union
            select 'c' as x
            ) order by x collate mycoll
            i    t   ct   bt   as#   the expected order was not returneds&   should have raised an OperationalErrors"   no such collation sequence: mycoll(   i   i   i   (   R   t   version_infoR   R   t   executet   fetchallR   t   Nonet   OperationalErrorR
   R   t   lower(   R   R   R   t   sqlt   resultR   (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   CheckCollationIsUsed2   s    		<c         C   sf   d   } t  j d  } | j d |  d } | j |  j   } |  j | d
 d d g d d	 d  S(   Nc         S   s   |  | k |  | k  d S(   Ni   i    l        (    (   R   R   (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyR   P   s    s   :memory:R   sÉ   
            select x from (
            select 'a' as x
            union
            select 'b' as x
            union
            select 'c' as x
            ) order by x collate mycoll
            R   R   R   t   msgs#   the expected order was not returned(   R   (   R   (   R   (   R   R   R   R   R   R
   (   R   R   R   R   R   (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt!   CheckCollationReturnsLargeIntegerO   s    		c         C   s   t  j d  } | j d t  | j d d    | j d  j   } | d d d k so | d d d k r |  j d	  n  d
 S(   s   
        Register two different collation functions under the same name.
        Verify that the last one is actually used.
        s   :memory:R   c         S   s   t  |  |  S(   N(   R   (   R   R   (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   <lambda>i   s    si   
            select x from (select 'a' as x union select 'b' as x) order by x collate mycoll
            i    R   i   R   s    wrong collation function is usedN(   R   R   R   R   R   R   R   (   R   R   R   (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   CheckCollationRegisterTwiceb   s    (c         C   s   t  j d  } | j d t  | j d d  y | j d  |  j d  Wn< t  j k
 r } | j d j	 d  s |  j d  q n Xd S(	   su   
        Register a collation, then deregister it. Make sure an error is raised if we try
        to use it.
        s   :memory:R   s?   select 'a' as x union select 'b' as x order by x collate mycolls&   should have raised an OperationalErrori    s   no such collation sequences   wrong OperationalError raisedN(
   R   R   R   R   R   R   R   R   R   t
   startswith(   R   R   R   (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   CheckDeregisterCollationp   s    (
   t   __name__t
   __module__R   R   R   R   R    R"   R$   R&   (    (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyR       s   							t   ProgressTestsc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c            sR   t  j d  } g      f d   } | j | d  | j d  |  j    d S(   sK   
        Test that the progress handler is invoked once it is set.
        s   :memory:c              s     j  d   d S(   Ni    (   t   appendR   (    (   t   progress_calls(    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   progress   s    i   s0   
            create table foo(a, b)
            N(   R   R   t   set_progress_handlerR   t
   assertTrue(   R   R   R,   (    (   R+   s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   CheckProgressHandlerUsed   s    c            s   t  j d  } g      f d   } | j | d  | j   } | j d  t    } g    | j | d  | j d  t    } |  j | |  d S(   s=   
        Test that the opcode argument is respected.
        s   :memory:c              s     j  d   d S(   Ni    (   R*   R   (    (   R+   (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyR,      s    i   s1   
            create table foo (a, b)
            i   s1   
            create table bar (a, b)
            N(   R   R   R-   t   cursorR   t   lent   assertGreaterEqual(   R   R   R,   t   curst   first_countt   second_count(    (   R+   s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   CheckOpcodeCount   s    c            s]   t  j d  } g      f d   } | j | d  | j   } |  j t  j | j d  d S(   sW   
        Test that returning a non-zero value stops the operation in progress.
        s   :memory:c              s     j  d   d S(   Ni   (   R*   R   (    (   R+   (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyR,   ­   s    i   s   create table bar (a, b)N(   R   R   R-   R0   t   assertRaisesR   R   (   R   R   R,   R3   (    (   R+   s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   CheckCancelOperation§   s    c            st   t  j d  } g      f d   } | j | d  | j d d  | j d  j   |  j t    d d  d S(   sc   
        Test that setting the progress handler to None clears the previously set handler.
        s   :memory:c              s     j  d  d S(   Ni   i    (   R*   (    (   t   action(    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyR,   ˝   s    i   s&   select 1 union select 2 union select 3i    s    progress handler was not clearedN(   R   R   R-   R   R   R   R
   R1   (   R   R   R,   (    (   R9   s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   CheckClearHandlerˇ   s    (   R'   R(   R/   R6   R8   R:   (    (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyR)      s   			c          C   s7   t  j t d  }  t  j t d  } t  j |  | f  S(   Nt   Check(   t   unittestt	   makeSuiteR    R)   t	   TestSuite(   t   collation_suitet   progress_suite(    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   suiteĹ   s    c          C   s    t  j   }  |  j t    d  S(   N(   R<   t   TextTestRunnert   runRA   (   t   runner(    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   testĘ   s    t   __main__(
   t   osR<   t   sqlite3R   t   TestCaseR    R)   RA   RE   R'   (    (    (    s>   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/sqlite3/test/hooks.pyt   <module>   s   dF		