Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/sqlite3/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/sqlite3/test/__pycache__/hooks.cpython-34.pyo

�
e f�$�@s�ddlZddlZGdd�dej�ZGdd�dej�ZGdd�dej�Zdd	�Zd
d�Ze	dkr�e�ndS)
�Nc@s�eZdZdd�Zdd�Zdd�Zdd�Zeje	j
dkd�d
d��Zdd�Zdd�Z
dd�ZdS)�CollationTestscCsdS)N�)�selfrr�7/opt/alt/python34/lib64/python3.4/sqlite3/test/hooks.py�setUpszCollationTests.setUpcCsdS)Nr)rrrr�tearDownszCollationTests.tearDowncCsstjd�}y!|jdd�|jd�Wn<tk
rn}z|j|jdd�WYdd}~XnXdS)Nz:memory:�X�*zshould have raised a TypeErrorrzparameter must be callable)�sqlite�connect�create_collation�fail�	TypeError�assertEqual�args)r�con�errr�CheckCreateCollationNotCallable"sz.CollationTests.CheckCreateCollationNotCallablecCsetjd�}y'|jddd��|jd�Wn(tjk
r`}zWYdd}~XnXdS)Nz:memory:ucolläcSs||k||kS)Nr)�x�yrrr�<lambda>-sz=CollationTests.CheckCreateCollationNotAscii.<locals>.<lambda>z%should have raised a ProgrammingError)r
rrr
ZProgrammingError)rrrrrr�CheckCreateCollationNotAscii*sz+CollationTests.CheckCreateCollationNotAscii���z&old SQLite versions crash on this testcCsdd�}tjd�}|jd|�d}|j|�j�}|dddks�|ddd	ks�|d
ddkr�|jd�n|jdd�y&|j|�j�}|jd
�WnEtjk
r}z"|j|jdj	�d�WYdd}~XnXdS)NcSs||k||kS)Nr)rrrrr�mycoll5sz3CollationTests.CheckCollationIsUsed.<locals>.mycollz:memory:rz�
            select x from (
            select 'a' as x
            union
            select 'b' as x
            union
            select 'c' as x
            ) order by x collate mycoll
            r�cr�br�az#the expected order was not returnedz&should have raised an OperationalErrorz"no such collation sequence: mycoll)
r
rr�execute�fetchallr
�OperationalErrorrr�lower)rrr�sql�resultrrrr�CheckCollationIsUsed2s	<z#CollationTests.CheckCollationIsUsedcCsidd�}tjd�}|jd|�d}|j|�j�}|j|ddd
gd	d
�dS)NcSs||k||kdS)Nr� lr)rrrrrrPsz@CollationTests.CheckCollationReturnsLargeInteger.<locals>.mycollz:memory:rz�
            select x from (
            select 'a' as x
            union
            select 'b' as x
            union
            select 'c' as x
            ) order by x collate mycoll
            rrr�msgz#the expected order was not returned)r)r)r)r
rrrr r)rrrr#r$rrr�!CheckCollationReturnsLargeIntegerOs	z0CollationTests.CheckCollationReturnsLargeIntegercCs�tjd�}|jddd��|jddd��|jd�j�}|dddksx|d	dd
kr�|jd�ndS)
z�
        Register two different collation functions under the same name.
        Verify that the last one is actually used.
        z:memory:rcSs||k||kS)Nr)rrrrrrhsz<CollationTests.CheckCollationRegisterTwice.<locals>.<lambda>cSs||k||kS)Nr)rrrrrriszi
            select x from (select 'a' as x union select 'b' as x) order by x collate mycoll
            rrrrz wrong collation function is usedN)r
rrrr r
)rrr$rrr�CheckCollationRegisterTwicebs(z*CollationTests.CheckCollationRegisterTwicecCs�tjd�}|jddd��|jdd�y|jd�|jd�WnNtjk
r�}z+|jdjd	�s�|jd
�nWYdd}~XnXdS)zu
        Register a collation, then deregister it. Make sure an error is raised if we try
        to use it.
        z:memory:rcSs||k||kS)Nr)rrrrrrvsz9CollationTests.CheckDeregisterCollation.<locals>.<lambda>Nz?select 'a' as x union select 'b' as x order by x collate mycollz&should have raised an OperationalErrorrzno such collation sequencezwrong OperationalError raised)r
rrrr
r!r�
startswith)rrrrrr�CheckDeregisterCollationps
z'CollationTests.CheckDeregisterCollationN)rrr)�__name__�
__module__�__qualname__rrrr�unittestZskipIfr
Zsqlite_version_infor%r(r)r+rrrrrsrc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
ProgressTestscsUtjd�}g��fdd�}|j|d�|jd�|j��dS)zK
        Test that the progress handler is invoked once it is set.
        z:memory:cs�jd�dS)Nr)�appendr)�progress_callsrr�progress�s
z8ProgressTests.CheckProgressHandlerUsed.<locals>.progressrz0
            create table foo(a, b)
            N)r
r�set_progress_handlerr�
assertTrue)rrr3r)r2r�CheckProgressHandlerUsed�sz&ProgressTests.CheckProgressHandlerUsedcs�tjd�}g��fdd�}|j|d�|j�}|jd�t��}g�|j|d�|jd�t��}|j||�dS)	z=
        Test that the opcode argument is respected.
        z:memory:cs�jd�dS)Nr)r1r)r2rrr3�s
z0ProgressTests.CheckOpcodeCount.<locals>.progressrz1
            create table foo (a, b)
            rz1
            create table bar (a, b)
            N)r
rr4�cursorr�lenZassertGreaterEqual)rrr3�cursZfirst_countZsecond_countr)r2r�CheckOpcodeCount�szProgressTests.CheckOpcodeCountcs`tjd�}g��fdd�}|j|d�|j�}|jtj|jd�dS)zW
        Test that returning a non-zero value stops the operation in progress.
        z:memory:cs�jd�dS)Nr)r1r)r2rrr3�s
z4ProgressTests.CheckCancelOperation.<locals>.progressrzcreate table bar (a, b)N)r
rr4r7ZassertRaisesr!r)rrr3r9r)r2r�CheckCancelOperation�sz"ProgressTests.CheckCancelOperationcsqtjd�}d��fdd�}|j|d�|jdd�|jd�j�|j�dd�dS)	zc
        Test that setting the progress handler to None clears the previously set handler.
        z:memory:rcs
d�dS)Nrrrr)�actionrrr3�sz1ProgressTests.CheckClearHandler.<locals>.progressrNz&select 1 union select 2 union select 3z progress handler was not cleared)r
rr4rr r)rrr3r)r<r�CheckClearHandler�szProgressTests.CheckClearHandlerN)r,r-r.r6r:r;r=rrrrr0sr0c@s4eZdZdd�Zdd�Zdd�ZdS)�TraceCallbackTestscsrtjd�}g��fdd�}|j|�|jd�|j��|jtdd��D���dS)zI
        Test that the trace callback is invoked once it is set.
        z:memory:cs�j|�dS)N)r1)�	statement)�traced_statementsrr�trace�sz8TraceCallbackTests.CheckTraceCallbackUsed.<locals>.tracezcreate table foo(a, b)css|]}d|kVqdS)zcreate table fooNr)�.0�stmtrrr�	<genexpr>�sz<TraceCallbackTests.CheckTraceCallbackUsed.<locals>.<genexpr>N)r
r�set_trace_callbackrr5�any)rrrAr)r@r�CheckTraceCallbackUsed�s


z)TraceCallbackTests.CheckTraceCallbackUsedcsbtjd�}g��fdd�}|j|�|jd�|jd�|j�d�dS)zb
        Test that setting the trace callback to None clears the previously set callback.
        z:memory:cs�j|�dS)N)r1)r?)r@rrrA�sz9TraceCallbackTests.CheckClearTraceCallback.<locals>.traceNzcreate table foo(a, b)ztrace callback was not cleared)r
rrErZassertFalse)rrrAr)r@r�CheckClearTraceCallback�s


z*TraceCallbackTests.CheckClearTraceCallbackcs�d�tjd�}g��fdd�}|j|�|jd�|jd��|j�|jt�fdd��D��d	t��d
jt	t���f�dS)zG
        Test that the statement can contain unicode literals.
        uöäüÖÄÜ߀z:memory:cs�j|�dS)N)r1)r?)r@rrrA�sz5TraceCallbackTests.CheckUnicodeContent.<locals>.tracezcreate table foo(x)z insert into foo(x) values ("%s")c3s|]}�|kVqdS)Nr)rBrC)�
unicode_valuerrrD�sz9TraceCallbackTests.CheckUnicodeContent.<locals>.<genexpr>z-Unicode data %s garbled in trace callback: %sz, N)
r
rrErZcommitr5rF�ascii�join�map)rrrAr)r@rIr�CheckUnicodeContent�s


"z&TraceCallbackTests.CheckUnicodeContentN)r,r-r.rGrHrMrrrrr>�s

r>cCsLtjtd�}tjtd�}tjtd�}tj|||f�S)NZCheck)r/Z	makeSuiterr0r>Z	TestSuite)Zcollation_suiteZprogress_suiteZtrace_suiterrr�suite�srNcCs tj�}|jt��dS)N)r/ZTextTestRunnerZrunrN)Zrunnerrrr�test�srO�__main__)
r/Zsqlite3r
ZTestCaserr0r>rNrOr,rrrr�<module>sdG1