o =?h*@sddlZddlZddlZddlmZmZGdddejZGdddejZ GdddejZ d d Z d d Z e d kr@e dSdS)N)TESTFNunlinkc@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)CollationTestscCsJtd}|t|dddWddS1swYdS)N:memory:cS||k||kSNxyrr9/opt/alt/python310/lib64/python3.10/sqlite3/test/hooks.py"zACollationTests.test_create_collation_not_string..)sqliteconnect assertRaises TypeErrorcreate_collationselfconrrr test_create_collation_not_strings  "z/CollationTests.test_create_collation_not_stringcCsVtd}|t}|ddWdn1swY|t|jddS)NrX*zparameter must be callable)rrrrr assertEqualstr exceptionrrcmrrr "test_create_collation_not_callable$s  z1CollationTests.test_create_collation_not_callablecCsLtd}|tj|dddWddS1swYdS)NrucolläcSrrrr rrr r -rz@CollationTests.test_create_collation_not_ascii..)rrrZProgrammingErrorrrrrr test_create_collation_not_ascii*s "z.CollationTests.test_create_collation_not_asciicCslGdddt}td}dd}||d||d}||ddd ||d dd dS) Nc@seZdZddZdS)zCCollationTests.test_create_collation_bad_upper..BadUpperStrcSsdSrr)rrrr upper1zICollationTests.test_create_collation_bad_upper..BadUpperStr.upperN)__name__ __module__ __qualname__r!rrrr BadUpperStr0s r&rcS||k||k Srrr rrr r 4z@CollationTests.test_create_collation_bad_upper..mycollz select x from ( select 'a' as x union select 'b' as x ) order by x collate mycoll rba)rrrrexecutefetchallr)rr&rr)resultrrr test_create_collation_bad_upper/s z.CollationTests.test_create_collation_bad_uppercCsdd}td}|d|d}||}|j|gddd|dd|tj}||}Wdn1s@wY|t|j d dS) NcSr'rrr rrr r)Asz5CollationTests.test_collation_is_used..mycollrr) select x from ( select 'a' as x union select 'b' as x union select 'c' as x ) order by x collate mycoll )c)r*)r,#the expected order was not returnedmsg"no such collation sequence: mycoll) rrrr-r.rrOperationalErrorrr)rr)rsqlr/rrrr test_collation_is_used@s    z%CollationTests.test_collation_is_usedcCsHdd}td}|d|d}||}|j|gddddS) NcSs||k||k dS)Nlrr rrr r)ZszCCollationTests.test_collation_returns_large_integer..mycollrr)r1r2r4r5rrrr-r.r)rr)rr9r/rrr $test_collation_returns_large_integerYs    z3CollationTests.test_collation_returns_large_integercCsdtd}|ddd|ddd|d}||ddd||d dd d S) z Register two different collation functions under the same name. Verify that the last one is actually used. rr)cSrrrr rrr r rrz>CollationTests.test_collation_register_twice..cSr'rrr rrr r sr(zi select x from (select 'a' as x union select 'b' as x) order by x collate mycoll rr*r+r,Nr;)rrr/rrr test_collation_register_twicels z,CollationTests.test_collation_register_twicecCsrtd}|ddd|dd|tj }|dWdn1s)wY|t|jddS)zu Register a collation, then deregister it. Make sure an error is raised if we try to use it. rr)cSrrrr rrr r rz:CollationTests.test_deregister_collation..Nz?select 'a' as x union select 'b' as x order by x collate mycollr7) rrrrr8r-rrrrrrr test_deregister_collationzs   z(CollationTests.test_deregister_collationN) r#r$r%rrr r0r:r<r=r>rrrr rs rc@s,eZdZddZddZddZddZd S) ProgressTestscs>td}gfdd}||d|d|dS)zK Test that the progress handler is invoked once it is set. rcddSNrappendrZprogress_callsrr progress z:ProgressTests.test_progress_handler_used..progressr+z0 create table foo(a, b) N)rrset_progress_handlerr- assertTruerrrErrDr test_progress_handler_useds    z(ProgressTests.test_progress_handler_usedcsrtd}gfdd}||d|}|dt}g||d|dt}|||dS) z= Test that the opcode argument is respected. rcr@rArBrrDrr rErFz1ProgressTests.test_opcode_count..progressr+z1 create table foo (a, b) z1 create table bar (a, b) N)rrrGcursorr-lenZassertGreaterEqual)rrrEcursZ first_countZ second_countrrDr test_opcode_counts      zProgressTests.test_opcode_countcCs<td}dd}||d|}|tj|jddS)zW Test that returning a non-zero value stops the operation in progress. rcSsdS)Nr+rrrrr rEr"z5ProgressTests.test_cancel_operation..progressr+zcreate table bar (a, b)N)rrrGrLrr8r-)rrrErNrrr test_cancel_operations  z#ProgressTests.test_cancel_operationcsRtd}dfdd}||d|dd|d|dddS) zc Test that setting the progress handler to None clears the previously set handler. rrcsddS)Nr+rrractionrr rEsz2ProgressTests.test_clear_handler..progressr+Nz&select 1 union select 2 union select 3z progress handler was not cleared)rrrGr-r.rrIrrQr test_clear_handlers    z ProgressTests.test_clear_handlerN)r#r$r%rJrOrPrSrrrr r?s  r?c@sBeZdZejddZddZddZddZd d Z d d Z d S)TraceCallbackTestsc #sTzg|fdddVW|||ddS|||dw)Ncs |SrrB)stmtZtracedrr r s z5TraceCallbackTests.check_stmt_trace..)set_trace_callbackr)rcxexpectedrrVr check_stmt_traces  z#TraceCallbackTests.check_stmt_tracecsTtd}gfdd}|||d||tddDdS)zI Test that the trace callback is invoked once it is set. rc|dSrrBZ statementtraced_statementsrr tracez:TraceCallbackTests.test_trace_callback_used..tracecreate table foo(a, b)css|]}d|vVqdS)zcreate table fooNr.0rUrrr z>TraceCallbackTests.test_trace_callback_used..N)rrrWr-rHanyrrr_rr]r test_trace_callback_useds     z+TraceCallbackTests.test_trace_callback_usedcsHtd}gfdd}|||d|d|ddS)zb Test that setting the trace callback to None clears the previously set callback. rcr[rrBr\r]rr r_r`z;TraceCallbackTests.test_clear_trace_callback..traceNraztrace callback was not cleared)rrrWr-Z assertFalsergrr]r test_clear_trace_callbacks     z,TraceCallbackTests.test_clear_trace_callbackc sdtd}gfdd}|||d|d||tfddDd td t tfd S) zG Test that the statement can contain unicode literals. uöäüÖÄÜ߀rcr[rrBr\r]rr r_r`z6TraceCallbackTests.test_unicode_content..tracecreate table foo(x)z insert into foo(x) values ('%s')c3s|]}|vVqdSrrrb) unicode_valuerr rdrez:TraceCallbackTests.test_unicode_content..z-Unicode data %s garbled in trace callback: %sz, N) rrrWr-ZcommitrHrfasciijoinmaprgr)r^rkr test_unicode_contents    z'TraceCallbackTests.test_unicode_contentcsgfdd}ddg}|tttjtdd}tt}|||}||d|d||d||dS) Ncr[rrBr\r]rr r_r`z=TraceCallbackTests.test_trace_callback_content..tracerjzinsert into foo(x) values(1))Zisolation_levelrzcreate table bar(x)r+) Z addCleanuprrrrrWrLr-r)rr_ZqueriesZcon1Zcon2Zcurrr]r test_trace_callback_contents     z.TraceCallbackTests.test_trace_callback_contentc Csgd}td}|||5||d|dddtdDWdn1s/wYWddSWddS1sGwYdS)N)create table t(t)zBEGIN zinsert into t values(0)zinsert into t values(1)zinsert into t values(2)ZCOMMITrrqzinsert into t values(?)css|]}|fVqdSrr)rcvrrr rd sz=TraceCallbackTests.test_trace_expanded_sql..)rrrZr-Z executemanyrange)rrYrXrrr test_trace_expanded_sqls  "z*TraceCallbackTests.test_trace_expanded_sqlN) r#r$r% contextlibcontextmanagerrZrhrirorprurrrr rTs     rTcCstttg}tdd|DS)NcSsg|] }t|qSr)unittestZ TestLoaderZloadTestsFromTestCase)rctrrr *szsuite..)rr?rTrxZ TestSuite)Ztestsrrr suite#s r{cCst}|tdSr)rxZTextTestRunnerrunr{)Zrunnerrrr test-sr}__main__)rvrxZsqlite3rZtest.support.os_helperrrZTestCaserr?rTr{r}r#rrrr shEX