3 ^<c @sddlZddlZddlZy ddlZWnek r<dZYnXGdddejZGdddejZGdddejZ ej ej dkd Gd d d ejZ Gd ddejZ ejedGdddejZGdddejZddZddZedkredS)Nc@LeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)SqliteTypeTestscC(tjd|_|jj|_|jjddS)N:memory:z9create table test(i integer, s varchar, f number, b blob)sqliteconnectconcursorcurexecuteselfr*/usr/lib64/python3.6/sqlite3/test/types.pysetUp"  zSqliteTypeTests.setUpcC|jj|jjdSNr closerr rrrtearDown' zSqliteTypeTests.tearDowncC8|jjdd|jjd|jj}|j|dddS)Ninsert into test(s) values (?) Österreichzselect s from testr)rr r fetchone assertEqualr rowrrr CheckString+  zSqliteTypeTests.CheckStringcCrNinsert into test(i) values (?)*select i from testr)r$rrrrr CheckSmallInt1r!zSqliteTypeTests.CheckSmallIntcC>d}|jjd|f|jjd|jj}|j|d|dSNi(r#r%rlrr Znumrrrr CheckLargeInt7   zSqliteTypeTests.CheckLargeIntcC>d}|jjd|f|jjd|jj}|j|d|dS)NQ @insert into test(f) values (?)select f from testrrr valrrrr CheckFloat>r,zSqliteTypeTests.CheckFloatcCFd}t|}|jjd|f|jjd|jj}|j|d|dS)NGuglhupfinsert into test(b) values (?)select b from testr memoryviewr r rrr Zsampler2rrrr CheckBlobEs   zSqliteTypeTests.CheckBlobcCs*|jjd|jj}|j|dddS)Nuselect 'Österreich'rrrrrrrCheckUnicodeExecuteMs  z#SqliteTypeTests.CheckUnicodeExecuteN) __name__ __module__ __qualname__rrr r&r+r3r;r<rrrrr!src@seZdZGdddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdS) DeclTypesTestsc@s,eZdZddZddZddZddZd S) zDeclTypesTests.FoocCst|tr|jd}||_dS)Nzutf-8) isinstanceZbytesdecoder2)r Z_valrrr__init__Ts  zDeclTypesTests.Foo.__init__cCst|tjstS|j|jkSr)rAr@FooZNotImplementedr2)r Zotherrrr__eq__[s zDeclTypesTests.Foo.__eq__cCs|tjkr|jSdSdSr)rPrepareProtocolr2)r Zprotocolrrr __conform__`s zDeclTypesTests.Foo.__conform__cCs d|jS)N<%s>)r2r rrr__str__fzDeclTypesTests.Foo.__str__N)r=r>r?rCrErGrIrrrrrDSsrDcCsntjdtjd|_|jj|_|jjdddtjd<ddtjd<tj tjd <d dtjd <t tjd <dS) NrZ detect_typeszgcreate table test(i int, s str, f float, b bool, u unicode, foo foo, bin blob, n1 number, n2 number(5))cSdS)N皙G@rxrrroz&DeclTypesTests.setUp..FLOATcSs tt|Sr)ZboolintrNrrrrPrrQBOOLFOOcSrL)NWRONGrrNrrrrPtrQrVNUMBER) rrPARSE_DECLTYPESrr r r convertersr@rDfloatr rrrris   zDeclTypesTests.setUpcC8tjd=tjd=tjd=tjd=|jj|jjdS)NrRrTrUrWrrYr rrr rrrrw  zDeclTypesTests.tearDowncCr)Nrfooz!select s as "s [WRONG]" from testr)r^rrrrrr   zDeclTypesTests.CheckStringcCrr"rrrrrr&r_zDeclTypesTests.CheckSmallIntcCr'r(rr*rrrr+   zDeclTypesTests.CheckLargeIntcCs>d}|jjd|f|jjd|jj}|j|dddS)Nr.r/r0rrMrr1rrrr3r`zDeclTypesTests.CheckFloatcCsx|jjdd|jjd|jj}|j|dd|jjd|jjdd|jjd|jj}|j|dddS) Nr6Fr7rzdelete from testT)F)Trrrrr CheckBools     zDeclTypesTests.CheckBoolcCr-)Nrzinsert into test(u) values (?)zselect u from testrrr1rrr CheckUnicoder`zDeclTypesTests.CheckUnicodecCsDtjd}|jjd|f|jjd|jj}|j|d|dS)NZblaz insert into test(foo) values (?)zselect foo from testr)r@rDr r rrr1rrrCheckFoos    zDeclTypesTests.CheckFooc Cs@Gddd}|}|jtj|jjd|fWdQRXdS)Nc@ eZdZdS)z/DeclTypesTests.CheckUnsupportedSeq..BarNr=r>r?rrrrBarrfr/Z assertRaisesrZInterfaceErrorr r r rfr2rrrCheckUnsupportedSeqz"DeclTypesTests.CheckUnsupportedSeqc CsBGddd}|}|jtj|jjdd|iWdQRXdS)Nc@rd)z0DeclTypesTests.CheckUnsupportedDict..BarNrerrrrrfrgrfz!insert into test(f) values (:val)r2rhrirrrCheckUnsupportedDictrkz#DeclTypesTests.CheckUnsupportedDictcCr4)Nr5z insert into test(bin) values (?)zselect bin from testrr8r:rrrr;s   zDeclTypesTests.CheckBlobcCs4|jjd|jjdjd}|jt|tdS)Nzinsert into test(n1) values (5)zselect n1 from testrr r rrtyperZr Zvaluerrr CheckNumber1s zDeclTypesTests.CheckNumber1cCs4|jjd|jjdjd}|jt|tdS)zr?rDrrr r&r+r3rarbrcrjrlr;rprqrrrrr@Rs  r@c@r) ColNamesTestscCsftjdtjd|_|jj|_|jjdddtjd<ddtjd<d dtjd <d dtjd <dS) NrrKcreate table test(x foo)cSd|jdS)Nz[%s]asciirBrNrrrrPrQz%ColNamesTests.setUp..rUcSrt)NrHrurvrNrrrrPrQBARcSsddS)NirrrNrrrrPrQEXCcSrL)NMARKERrrNrrrrPrQB1B1)rrPARSE_COLNAMESrr r r rYr rrrrs  zColNamesTests.setUpcCr[)NrUrwrxrzr\r rrrrr]zColNamesTests.tearDowncCs8|jjdd|jjd|jjd}|j|ddS)ze Assures that the declared type is not used when PARSE_DECLTYPES is not set. insert into test(x) values (?)xxxselect x from testrNr}rr r2rrrCheckDeclTypeNotUseds z"ColNamesTests.CheckDeclTypeNotUsedcCs8|jjdd|jjd|jjd}|j|ddS)Nr|r~rrrrrrr CheckNones zColNamesTests.CheckNonecCsP|jjdd|jjd|jjd}|j|d|j|jjddddS)Nr|r}zselect x as "x [bar]" from testrzrOr)r r rr descriptionrrrr CheckColNames   zColNamesTests.CheckColNamecCs*|jjd|jjd}|j|ddS)Nzselect 'other' as "x [b1b1]"rryrrrrrCheckCaseInConverterName z&ColNamesTests.CheckCaseInConverterNamecCs(|jjd|j|jjddddS)zq cursor.description should at least provide the column name(s), even if no row returned. zselect * from test where 0 = 1rrON)r r rrr rrrCheckCursorDescriptionNoRow s z)ColNamesTests.CheckCursorDescriptionNoRowcCs|jjd|j|jjdS)Ninsert into test values (1))r r Z assertIsNonerr rrrCheckCursorDescriptionInserts z*ColNamesTests.CheckCursorDescriptionInsertN) r=r>r?rrrrrrrrrrrrrrs   rrzCTEs not supportedc@s4eZdZddZddZddZddZd d Zd S) CommonTableExpressionTestscCr)Nrrsrr rrrrrz CommonTableExpressionTests.setUpcCrrrr rrrr"rz#CommonTableExpressionTests.tearDowncCs6|jjd|j|jj|j|jjddddS)Nz(with one as (select 1) select * from onerZ1r r ZassertIsNotNonerrr rrrCheckCursorDescriptionCTESimple&rz:CommonTableExpressionTests.CheckCursorDescriptionCTESimplecCsN|jjd|jjd|jjd|j|jj|j|jjddddS)Nzinsert into test values(1)zinsert into test values(2)z:with testCTE as (select * from test) select * from testCTErrOrr rrr)CheckCursorDescriptionCTESMultipleColumns+s    zDCommonTableExpressionTests.CheckCursorDescriptionCTESMultipleColumnscCst|jjd|jjd|j|jj|j|jjddd|jjd|j|jj|j|jjddddS)Nrz?with bar as (select * from test) select * from test where x = 1rrOz?with bar as (select * from test) select * from test where x = 2rr rrrCheckCursorDescriptionCTE2s   z4CommonTableExpressionTests.CheckCursorDescriptionCTEN)r=r>r?rrrrrrrrrrs rc@4eZdZddZeeZddZddZddZd S) ObjectAdaptationTestscCst|Sr)rZ)Zobjrrrcast=rJzObjectAdaptationTests.castc CsDtjd|_y tjt=Wn YnXtjttj|jj|_ dS)Nr) rrradaptersrSZregister_adapterrrr r r rrrrAs  zObjectAdaptationTests.setUpcCs&tjttjf=|jj|jjdSr)rrrSrFr rrr rrrrJs zObjectAdaptationTests.tearDowncCs0|jjdd|jjd}|jt|tdS)Nzselect ?r)rrmrrrrCheckCasterIsUsedOsz'ObjectAdaptationTests.CheckCasterIsUsedN)r=r>r?r staticmethodrrrrrrrr<s  rz requires zlibc@r) BinaryConverterTestscCs tj|Sr)zlibZ decompress)ZsrrrconvertVrJzBinaryConverterTests.convertcCs$tjdtjd|_tjdtjdS)NrrKZbin)rrr{rZregister_converterrrr rrrrZszBinaryConverterTests.setUpcCs|jjdSr)rrr rrrr^rJzBinaryConverterTests.tearDowncCs:dd}|jjdttj|fjd}|j||dS)Nsabcdefgi zselect ? as "x [bin]"r)rr r9rZcompressrr)r ZtestdataZresultrrrCheckBinaryInputForConverteras"z1BinaryConverterTests.CheckBinaryInputForConverterN)r=r>r?rrrrrrrrrrTs rc@sVeZdZddZddZddZddZeje j dkd d d Z ddZ ddZ dS) DateTimeTestscCs.tjdtjd|_|jj|_|jjddS)NrrKz'create table test(d date, ts timestamp))rrrXrr r r r rrrrgs zDateTimeTests.setUpcCrrrr rrrrlrzDateTimeTests.tearDowncCsHtjddd}|jjd|f|jjd|jjd}|j||dS)Nr)zinsert into test(d) values (?)zselect d from testr)rZDater r rr)r ZdZd2rrrCheckSqliteDateps  zDateTimeTests.CheckSqliteDatecCsNtjdddddd}|jjd|f|jjd|jjd}|j||dS) Nrr)rrinsert into test(ts) values (?)select ts from testrZ Timestampr r rrr tsZts2rrrCheckSqliteTimestampws  z"DateTimeTests.CheckSqliteTimestamprz0the date functions are available on 3.1 or latercCsVtjj}|jjd|jjd|jjd}|jt|tj|j|j|jdS)Nz/insert into test(ts) values (current_timestamp)rr)datetimeZutcnowr r rrrnZyear)r ZnowrrrrCheckSqlTimestamp~s    zDateTimeTests.CheckSqlTimestampcCPtjddddddd}|jjd|f|jjd |jjd}|j||dS) Nrr)rrrri rrrrrrrCheckDateTimeSubSeconds  z%DateTimeTests.CheckDateTimeSubSecondscCr) Nrr)rrrri!rrrrrrr$CheckDateTimeSubSecondsFloatingPointrz2DateTimeTests.CheckDateTimeSubSecondsFloatingPointN)rr)r=r>r?rrrrunittestskipIfrsqlite_version_inforrrrrrrrfs  rcCsltjtd}tjtd}tjtd}tjtd}tjtd}tjtd}tjtd}tj |||||||fS)NZCheck) rZ makeSuiterr@rrrrrrZ TestSuite)Zsqlite_type_suiteZdecltypes_type_suiteZcolnames_type_suiteZadaptation_suiteZ bin_suiteZ date_suiteZ cte_suiterrrsuites       rcCstj}|jtdSr)rZTextTestRunnerZrunr)ZrunnerrrrtestsrZ__main__)rrr)rrZsqlite3rrZ ImportErrorZTestCaserr@rrrrrrZ skipUnlessrrrrr=rrrrZs(  1 ? ! 0