Ñò
ïžòKc           @   s„   d  d k  Z  d  d k Z d  d k Z d e i f d „  ƒ  YZ d e i f d „  ƒ  YZ d „  Z d „  Z e	 d j o e ƒ  n d S(	   iÿÿÿÿNt   CollationTestsc           B   sG   e  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(   scripts/common/Lib/sqlite3/test/hooks.pyt   setUp   s    c         C   s   d  S(   N(    (   R   (    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyt   tearDown   s    c         C   sc   t  i d ƒ } y! | i d d ƒ |  i d ƒ Wn, t j
 o  } |  i | i 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   failUnlessEqualt   args(   R   t   cont   e(    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyt   CheckCreateCollationNotCallable"   s    c         C   sO   t  i d ƒ } y! | i d t ƒ |  i d ƒ Wn t  i j
 o	 } n Xd  S(   Ns   :memory:s   colläs%   should have raised a ProgrammingError(   R   R   R   t   cmpR   t   ProgrammingError(   R   R   R   (    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyt   CheckCreateCollationNotAscii*   s    c         C   s  t  i d j  o d  Sd „  } t  i d ƒ } | i d | ƒ d } | i | ƒ i ƒ  } | d d d	 j p* | d d d
 j p | d d d j o |  i d ƒ n | i d d  ƒ y& | i | ƒ i ƒ  } |  i d ƒ Wn5 t  i j
 o& } |  i	 | i
 d i ƒ  d ƒ n Xd  S(   Ni   i   i   c         S   s   t  |  | ƒ S(   N(   R   (   t   xt   y(    (    s(   scripts/common/Lib/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(   scripts/common/Lib/sqlite3/test/hooks.pyt   CheckCollationIsUsed2   s    		?c         C   s†   t  i d ƒ } | i d t ƒ | i d d „  ƒ | i d ƒ i ƒ  } | d d d j p | d d d j o |  i 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(    (   R   (   R   R   (    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyt   <lambda>V   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(   scripts/common/Lib/sqlite3/test/hooks.pyt   CheckCollationRegisterTwiceO   s    *c         C   s”   t  i d ƒ } | i d t ƒ | i d d ƒ y | i d ƒ |  i d ƒ Wn@ t  i j
 o1 } | i d i	 d ƒ p |  i 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(   scripts/common/Lib/sqlite3/test/hooks.pyt   CheckDeregisterCollation]   s    (	   t   __name__t
   __module__R   R   R   R   R    R"   R$   (    (    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyR       s   						t   ProgressTestsc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c            sR   t  i d ƒ } g  ‰  ‡  f d †  } | i | d ƒ | i d ƒ |  i ˆ  ƒ d S(   sK   
        Test that the progress handler is invoked once it is set.
        s   :memory:c              s   ˆ  i  d  ƒ d S(   Ni    (   t   appendR   (    (   t   progress_calls(    s(   scripts/common/Lib/sqlite3/test/hooks.pyt   progresss   s    i   s0   
            create table foo(a, b)
            N(   R   R   t   set_progress_handlerR   t
   failUnless(   R   R   R*   (    (   R)   s(   scripts/common/Lib/sqlite3/test/hooks.pyt   CheckProgressHandlerUsedm   s    c            sŸ   t  i d ƒ } g  ‰  ‡  f d †  } | i | d ƒ | i ƒ  } | i d ƒ t ˆ  ƒ } g  ‰  | i | d ƒ | i d ƒ t ˆ  ƒ } |  i | | j ƒ d S(   s=   
        Test that the opcode argument is respected.
        s   :memory:c              s   ˆ  i  d  ƒ d S(   Ni    (   R(   R   (    (   R)   (    s(   scripts/common/Lib/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   lenR,   (   R   R   R*   t   curst   first_countt   second_count(    (   R)   s(   scripts/common/Lib/sqlite3/test/hooks.pyt   CheckOpcodeCount}   s    c            s]   t  i d ƒ } g  ‰  ‡  f d †  } | i | d ƒ | i ƒ  } |  i t  i | i d ƒ d S(   sW   
        Test that returning a non-zero value stops the operation in progress.
        s   :memory:c              s   ˆ  i  d  ƒ d S(   Ni   (   R(   R   (    (   R)   (    s(   scripts/common/Lib/sqlite3/test/hooks.pyR*   š   s    i   s   create table bar (a, b)N(   R   R   R+   R.   t   assertRaisesR   R   (   R   R   R*   R0   (    (   R)   s(   scripts/common/Lib/sqlite3/test/hooks.pyt   CheckCancelOperation”   s    c         C   sh   t  i d ƒ } d } d „  } | i | d ƒ | i d d ƒ | i d ƒ i ƒ  |  i | d d ƒ d S(   sc   
        Test that setting the progress handler to None clears the previously set handler.
        s   :memory:i    c          S   s
   d }  d S(   Ni   i    (    (   t   action(    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyR*   ª   s    i   s&   select 1 union select 2 union select 3s    progress handler was not clearedN(   R   R   R+   R   R   R   R
   (   R   R   R6   R*   (    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyt   CheckClearHandler¤   s    	(   R%   R&   R-   R3   R5   R7   (    (    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyR'   l   s   			c          C   s7   t  i t d ƒ }  t  i t d ƒ } t  i |  | f ƒ S(   Nt   Check(   t   unittestt	   makeSuiteR    R'   t	   TestSuite(   t   collation_suitet   progress_suite(    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyt   suite²   s    c          C   s    t  i ƒ  }  |  i t ƒ  ƒ d  S(   N(   R9   t   TextTestRunnert   runR>   (   t   runner(    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyt   test·   s    t   __main__(
   t   osR9   t   sqlite3R   t   TestCaseR    R'   R>   RB   R%   (    (    (    s(   scripts/common/Lib/sqlite3/test/hooks.pyt   <module>   s   QF		