3 ^< @sddlZddlZddlZy ddlZWnek r<dZYnXGdddejZGdddejZGdddejZ ej ej dkd Gd d d ejZ Gd ddejZ ejedGdddejZGdddejZddZddZedkredS)Nc@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)SqliteTypeTestscCs(tjd|_|jj|_|jjddS)Nz:memory:z9create table test(i integer, s varchar, f number, b blob))sqliteconnectconcursorcurexecute)selfr */usr/lib64/python3.6/sqlite3/test/types.pysetUp"s  zSqliteTypeTests.setUpcCs|jj|jjdS)N)rcloser)r r r r tearDown's zSqliteTypeTests.tearDowncCs8|jjdd|jjd|jj}|j|dddS)Nzinsert into test(s) values (?) Österreichzselect s from testr)r)rrfetchone assertEqual)r rowr r r CheckString+s  zSqliteTypeTests.CheckStringcCs8|jjdd|jjd|jj}|j|dddS)Nzinsert into test(i) values (?)*zselect i from testr)r)rrrr)r rr r r CheckSmallInt1s  zSqliteTypeTests.CheckSmallIntcCs>d}|jjd|f|jjd|jj}|j|d|dS)N(zinsert into test(i) values (?)zselect i from testrl)rrrr)r numrr r r CheckLargeInt7s   zSqliteTypeTests.CheckLargeIntcCs>d}|jjd|f|jjd|jj}|j|d|dS)NgQ @zinsert into test(f) values (?)zselect f from testr)rrrr)r valrr r r CheckFloat>s   zSqliteTypeTests.CheckFloatcCsFd}t|}|jjd|f|jjd|jj}|j|d|dS)NsGuglhupfzinsert into test(b) values (?)zselect b from testr) memoryviewrrrr)r samplerrr r r CheckBlobEs   zSqliteTypeTests.CheckBlobcCs*|jjd|jj}|j|dddS)Nuselect 'Österreich'ru Österreich)rrrr)r rr r r CheckUnicodeExecuteMs  z#SqliteTypeTests.CheckUnicodeExecuteN) __name__ __module__ __qualname__r rrrrrrrr r r r r!src@seZdZGdddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdS) DeclTypesTestsc@s,eZdZddZddZddZddZd S) zDeclTypesTests.FoocCst|tr|jd}||_dS)Nzutf-8) isinstancebytesdecoder)r Z_valr r r __init__Ts  zDeclTypesTests.Foo.__init__cCst|tjstS|j|jkS)N)r$r#FooNotImplementedr)r otherr r r __eq__[s zDeclTypesTests.Foo.__eq__cCs|tjkr|jSdSdS)N)rPrepareProtocolr)r Zprotocolr r r __conform__`s zDeclTypesTests.Foo.__conform__cCs d|jS)Nz<%s>)r)r r r r __str__fszDeclTypesTests.Foo.__str__N)r r!r"r'r+r-r.r r r r r(Ssr(cCsntjdtjd|_|jj|_|jjdddtjd<ddtjd<tj tjd <d dtjd <t tjd <dS) Nz:memory:) detect_typeszgcreate table test(i int, s str, f float, b bool, u unicode, foo foo, bin blob, n1 number, n2 number(5))cSsdS)NgG@r )xr r r osz&DeclTypesTests.setUp..FLOATcSs tt|S)N)boolint)r0r r r r1rsBOOLFOOcSsdS)NWRONGr )r0r r r r1tsr7NUMBER) rrPARSE_DECLTYPESrrrr convertersr#r(float)r r r r r is   zDeclTypesTests.setUpcCs8tjd=tjd=tjd=tjd=|jj|jjdS)Nr2r5r6r8)rr:rr r)r r r r rws  zDeclTypesTests.tearDowncCs8|jjdd|jjd|jj}|j|dddS)Nzinsert into test(s) values (?)fooz!select s as "s [WRONG]" from testr)r<)rrrr)r rr r r rs  zDeclTypesTests.CheckStringcCs8|jjdd|jjd|jj}|j|dddS)Nzinsert into test(i) values (?)rzselect i from testr)r)rrrr)r rr r r rs  zDeclTypesTests.CheckSmallIntcCs>d}|jjd|f|jjd|jj}|j|d|dS)Nrrzinsert into test(i) values (?)zselect i from testrl)rrrr)r rrr r r rs   zDeclTypesTests.CheckLargeIntcCs>d}|jjd|f|jjd|jj}|j|dddS)NgQ @zinsert into test(f) values (?)zselect f from testrgG@)rrrr)r rrr r r rs   zDeclTypesTests.CheckFloatcCsx|jjdd|jjd|jj}|j|dd|jjd|jjdd|jjd|jj}|j|dddS) Nzinsert into test(b) values (?)Fzselect b from testrzdelete from testT)F)T)rrrr)r rr r r CheckBools     zDeclTypesTests.CheckBoolcCs>d}|jjd|f|jjd|jj}|j|d|dS)Nu Österreichzinsert into test(u) values (?)zselect u from testr)rrrr)r rrr r r CheckUnicodes   zDeclTypesTests.CheckUnicodecCsDtjd}|jjd|f|jjd|jj}|j|d|dS)NZblaz insert into test(foo) values (?)zselect foo from testr)r#r(rrrr)r rrr r r CheckFoos    zDeclTypesTests.CheckFooc Cs@Gddd}|}|jtj|jjd|fWdQRXdS)Nc@s eZdZdS)z/DeclTypesTests.CheckUnsupportedSeq..BarN)r r!r"r r r r Barsr@zinsert into test(f) values (?)) assertRaisesrInterfaceErrorrr)r r@rr r r CheckUnsupportedSeqsz"DeclTypesTests.CheckUnsupportedSeqc CsBGddd}|}|jtj|jjdd|iWdQRXdS)Nc@s eZdZdS)z0DeclTypesTests.CheckUnsupportedDict..BarN)r r!r"r r r r r@sr@z!insert into test(f) values (:val)r)rArrBrr)r r@rr r r CheckUnsupportedDictsz#DeclTypesTests.CheckUnsupportedDictcCsFd}t|}|jjd|f|jjd|jj}|j|d|dS)NsGuglhupfz insert into test(bin) values (?)zselect bin from testr)rrrrr)r rrrr r r rs   zDeclTypesTests.CheckBlobcCs4|jjd|jjdjd}|jt|tdS)Nzinsert into test(n1) values (5)zselect n1 from testr)rrrrtyper;)r valuer r r CheckNumber1s zDeclTypesTests.CheckNumber1cCs4|jjd|jjdjd}|jt|tdS)zr?rCrDrrGrHr r r r r#Rs  r#c@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS) ColNamesTestscCsftjdtjd|_|jj|_|jjdddtjd<ddtjd<d dtjd <d dtjd <dS) Nz:memory:)r/zcreate table test(x foo)cSsd|jdS)Nz[%s]ascii)r&)r0r r r r1sz%ColNamesTests.setUp..r6cSsd|jdS)Nz<%s>rJ)r&)r0r r r r1sBARcSsddS)Nrr )r0r r r r1sEXCcSsdS)NMARKERr )r0r r r r1sB1B1)rrPARSE_COLNAMESrrrrr:)r r r r r s  zColNamesTests.setUpcCs8tjd=tjd=tjd=tjd=|jj|jjdS)Nr6rKrMrO)rr:rr r)r r r r rs  zColNamesTests.tearDowncCs8|jjdd|jjd|jjd}|j|ddS)ze Assures that the declared type is not used when PARSE_DECLTYPES is not set. zinsert into test(x) values (?)xxxzselect x from testrN)rQ)rrrr)r rr r r CheckDeclTypeNotUseds z"ColNamesTests.CheckDeclTypeNotUsedcCs8|jjdd|jjd|jjd}|j|ddS)Nzinsert into test(x) values (?)zselect x from testr)N)rrrr)r rr r r CheckNones zColNamesTests.CheckNonecCsP|jjdd|jjd|jjd}|j|d|j|jjddddS)Nzinsert into test(x) values (?)rQzselect x as "x [bar]" from testrzr0)rQ)rrrr description)r rr r r CheckColNames   zColNamesTests.CheckColNamecCs*|jjd|jjd}|j|ddS)Nzselect 'other' as "x [b1b1]"rrN)rrrr)r rr r r CheckCaseInConverterNames 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 = 1rr0N)rrrrT)r r r r CheckCursorDescriptionNoRow s z)ColNamesTests.CheckCursorDescriptionNoRowcCs|jjd|j|jjdS)Nzinsert into test values (1))rrZ assertIsNonerT)r r r r CheckCursorDescriptionInserts z*ColNamesTests.CheckCursorDescriptionInsertN) r r!r"r rrRrSrUrVrWrXr r r r rIs   rIzCTEs not supportedc@s4eZdZddZddZddZddZd d Zd S) CommonTableExpressionTestscCs(tjd|_|jj|_|jjddS)Nz:memory:zcreate table test(x foo))rrrrrr)r r r r r s  z CommonTableExpressionTests.setUpcCs|jj|jjdS)N)rr r)r r r r r"s z#CommonTableExpressionTests.tearDowncCs6|jjd|j|jj|j|jjddddS)Nz(with one as (select 1) select * from oner1)rrassertIsNotNonerTr)r r r r CheckCursorDescriptionCTESimple&s z: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 testCTErr0)rrr]rTr)r r r r )CheckCursorDescriptionCTESMultipleColumns+s    zDCommonTableExpressionTests.CheckCursorDescriptionCTESMultipleColumnscCst|jjd|jjd|j|jj|j|jjddd|jjd|j|jj|j|jjddddS)Nzinsert into test values (1)z?with bar as (select * from test) select * from test where x = 1rr0z?with bar as (select * from test) select * from test where x = 2)rrr]rTr)r r r r CheckCursorDescriptionCTE2s   z4CommonTableExpressionTests.CheckCursorDescriptionCTEN)r r!r"r rr^r_r`r r r r r[s r[c@s4eZdZddZeeZddZddZddZd S) ObjectAdaptationTestscCst|S)N)r;)objr r r cast=szObjectAdaptationTests.castc CsDtjd|_y tjt=Wn YnXtjttj|jj|_ dS)Nz:memory:) rrradaptersr4Zregister_adapterrarcrr)r r r r r As  zObjectAdaptationTests.setUpcCs&tjttjf=|jj|jjdS)N)rrdr4r,rr r)r r r r rJs zObjectAdaptationTests.tearDowncCs0|jjdd|jjd}|jt|tdS)Nzselect ?r)re)rrrrrEr;)r rr r r CheckCasterIsUsedOsz'ObjectAdaptationTests.CheckCasterIsUsedN)r r!r"rc staticmethodr rrfr r r r ra<s  raz requires zlibc@s4eZdZddZeeZddZddZddZd S) BinaryConverterTestscCs tj|S)N)zlibZ decompress)sr r r convertVszBinaryConverterTests.convertcCs$tjdtjd|_tjdtjdS)Nz:memory:)r/bin)rrrPrZregister_converterrhrk)r r r r r ZszBinaryConverterTests.setUpcCs|jjdS)N)rr )r r r r r^szBinaryConverterTests.tearDowncCs:dd}|jjdttj|fjd}|j||dS)Nsabcdefg zselect ? as "x [bin]"r)rrrricompressrr)r Ztestdataresultr r r CheckBinaryInputForConverteras"z1BinaryConverterTests.CheckBinaryInputForConverterN)r r!r"rkrgr rrpr r r r rhTs rhc@sVeZdZddZddZddZddZeje j dkd d d Z ddZ ddZ dS) DateTimeTestscCs.tjdtjd|_|jj|_|jjddS)Nz:memory:)r/z'create table test(d date, ts timestamp))rrr9rrrr)r r r r r gs zDateTimeTests.setUpcCs|jj|jjdS)N)rr r)r r r r rls zDateTimeTests.tearDowncCsHtjddd}|jjd|f|jjd|jjd}|j||dS)Nirzinsert into test(d) values (?)zselect d from testr)rZDaterrrr)r dZd2r r r CheckSqliteDateps  zDateTimeTests.CheckSqliteDatecCsNtjdddddd}|jjd|f|jjd|jjd}|j||dS) Nirrrrzinsert into test(ts) values (?)zselect ts from test)r Timestamprrrr)r tsts2r r r CheckSqliteTimestampws  z"DateTimeTests.CheckSqliteTimestamprYz0the 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)zselect ts from testr)datetimeZutcnowrrrrrEZyear)r Znowrxr r r CheckSqlTimestamp~s    zDateTimeTests.CheckSqlTimestampcCsPtjddddddd}|jjd|f|jjd |jjd}|j||dS) Nirrrrurvri zinsert into test(ts) values (?)zselect ts from test)rrwrrrr)r rxryr r r CheckDateTimeSubSecondss  z%DateTimeTests.CheckDateTimeSubSecondscCsPtjddddddd}|jjd|f|jjd |jjd}|j||dS) Nirrrrurvri!zinsert into test(ts) values (?)zselect ts from test)rrwrrrr)r rxryr r r $CheckDateTimeSubSecondsFloatingPoints  z2DateTimeTests.CheckDateTimeSubSecondsFloatingPointN)rYr{)r r!r"r rrtrzunittestskipIfrsqlite_version_infor}r~rr r r r rqfs  rqcCsltjtd}tjtd}tjtd}tjtd}tjtd}tjtd}tjtd}tj |||||||fS)NZCheck) rZ makeSuiterr#rIrarhrqr[Z TestSuite)Zsqlite_type_suiteZdecltypes_type_suiteZcolnames_type_suiteZadaptation_suiteZ bin_suiteZ date_suiteZ cte_suiter r r suites       rcCstj}|jtdS)N)rZTextTestRunnerZrunr)Zrunnerr r r testsr__main__)rYrZrY)r|rZsqlite3rri ImportErrorZTestCaserr#rIrrr[raZ skipUnlessrhrqrrr r r r r s(  1 ? ! 0