f ž _0c@sÖddlZddlZddlmZGdd„dejƒZdd„ZGdd„dejƒZ Gd d „d ej ƒZ Gd d „d ej ƒZ Gd d„dej ƒZ Gdd„dej ƒZGdd„dej ƒZGdd„dej ƒZdd„Zdd„ZedkrÒeƒdS)éN)ÚSequencec@óeZdZdd„ZdS)Ú MyConnectioncOstjj|g|¢Ri|¤ŽdS©N)ÚsqliteÚ ConnectionÚ__init__©ÚselfZargsZkwargs©r ú-/usr/lib64/python3.10/sqlite3/test/factory.pyrózMyConnection.__init__N©Ú__name__Ú __module__Ú __qualname__rr r r r rórcCs,i}t|jƒD]\}}||||d<q|S)Nr)Z enumerateZ description)ÚcursorÚrowÚdZidxÚcolr r r Ú dict_factory src@r)ÚMyCursorcOs$tjj|g|¢Ri|¤Žt|_dSr)rÚCursorrrÚ row_factoryrr r r r'szMyCursor.__init__Nr r r r r r&rrc@ó$eZdZdd„Zdd„Zdd„ZdS)ÚConnectionFactoryTestscCstjdtd|_dS)Nú:memory:©Zfactory)rÚconnectrÚcon©r r r r ÚsetUp,r zConnectionFactoryTests.setUpcCó|j ¡dSr©rÚcloser r r r ÚtearDown/r zConnectionFactoryTests.tearDowncCs| |jt¡dSr)ÚassertIsInstancerrr r r r ÚCheckIsInstance2r z&ConnectionFactoryTests.CheckIsInstanceN)rrrr!r%r'r r r r r+src@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) ÚCursorFactoryTestscCót d¡|_dS©Nr©rrrr r r r r!6r zCursorFactoryTests.setUpcCr"rr#r r r r r%9r zCursorFactoryTests.tearDowncCsR|j ¡}| |tj¡|j t¡}| |t¡|jjdd„d}| |t¡dS)NcSst|ƒSr)r©rr r r ÚAóz4CursorFactoryTests.CheckIsInstance..r)rrr&rrr)r Úcurr r r r'<s    z"CursorFactoryTests.CheckIsInstancecCsB| t|jjd¡| t|jjdd„¡| t|jjdd„¡dS)NcSódSrr r r r r r-Hr.z8CursorFactoryTests.CheckInvalidFactory..cSr0rr r,r r r r-Jr.)Ú assertRaisesÚ TypeErrorrrr r r r ÚCheckInvalidFactoryDsz&CursorFactoryTests.CheckInvalidFactoryN)rrrr!r%r'r3r r r r r(5sr(c@r)ÚRowFactoryTestsBackwardsCompatcCr)r*r+r r r r r!Mr z$RowFactoryTestsBackwardsCompat.setUpcCs8|jjtd}| d¡| ¡}| |t¡| ¡dS)Nrzselect 4+5 as foo)rrrÚexecuteÚfetchoner&Údictr$)r r/rr r r ÚCheckIsProducedByFactoryPs   z7RowFactoryTestsBackwardsCompat.CheckIsProducedByFactorycCr"rr#r r r r r%Wr z'RowFactoryTestsBackwardsCompat.tearDownN)rrrr!r8r%r r r r r4Lsr4c@sleZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„ZdS)ÚRowFactoryTestscCr)r*r+r r r r r![r zRowFactoryTests.setUpcCs,dd„|j_|j d¡ ¡}| |t¡dS)NcSst|ƒSr)Úlist)r/rr r r r-_r.z4RowFactoryTests.CheckCustomFactory..z select 1, 2)rrr5r6r&r:©r rr r r ÚCheckCustomFactory^s z"RowFactoryTests.CheckCustomFactorycCsötj|j_|j d¡ ¡}| |tj¡| |ddd¡| |ddd¡| |ddd ¡| |d dd ¡| |d dd ¡| |ddd¡| |ddd¡| |ddd¡| t ¡|dWdƒn1sà0Y| t ¡|dWdƒn1s0Y| t ¡|dWdƒn1sH0Y| t ¡|dWdƒn1s|0Y| t ¡|dWdƒn1s°0Y| t ¡|ddWdƒn1sè0YdS)Nzselect 1 as a_1, 2 as bZa_1éz&by name: wrong result for column 'a_1'Úbéz$by name: wrong result for column 'b'ZA_1z&by name: wrong result for column 'A_1'ZBz$by name: wrong result for column 'B'rz#by index: wrong result for column 0z#by index: wrong result for column 1éÿÿÿÿz$by index: wrong result for column -1éþÿÿÿz$by index: wrong result for column -2Zcza_za1iýÿÿÿiè) rÚRowrrr5r6r&Ú assertEqualr1Ú IndexErrorr;r r r ÚCheckSqliteRowIndexcs.  & ( ( ( ( z#RowFactoryTests.CheckSqliteRowIndexcCs’tj|j_|j d¡ ¡}| |dd¡| t¡|dWdƒn1sR0Y| t¡|dWdƒn1s„0YdS)Nuselect 1 as ÿuÿr=uŸuß) rrBrrr5r6rCr1rDr;r r r ÚCheckSqliteRowIndexUnicode€s  & z*RowFactoryTests.CheckSqliteRowIndexUnicodecCsêtj|j_|j d¡ ¡}| |dd…d¡| |dd…d¡| |dd…d¡| |dd…d¡| |dd…d¡| |dd…d ¡| |d d …d ¡| |d d…d ¡| |ddd…d¡| |ddd …d¡dS)Nzselect 1, 2, 3, 4rr r=)r=é)r?rG)r?rGé)r=r?rGrAr@)rG)rGrHrHr?)r=rG)rHr?)rrBrrr5r6rCr;r r r ÚCheckSqliteRowSlice‰s z#RowFactoryTests.CheckSqliteRowSlicecCs(tj|j_|j d¡ ¡}|D]}qdS)z$Checks if the row object is iterableúselect 1 as a, 2 as bN)rrBrrr5r6)r rrr r r ÚCheckSqliteRowIter›ó z"RowFactoryTests.CheckSqliteRowItercCs>tj|j_|j d¡ ¡}t|ƒ}| ||d|df¡dS)z4Checks if the row object can be converted to a tuplerJÚar>N)rrBrrr5r6ÚtuplerC)r rZtr r r ÚCheckSqliteRowAsTuple¢rLz%RowFactoryTests.CheckSqliteRowAsTuplecCsNtj|j_|j d¡ ¡}t|ƒ}| |d|d¡| |d|d¡dS)zCChecks if the row object can be correctly converted to a dictionaryrJrMr>N)rrBrrr5r6r7rC)r rrr r r ÚCheckSqliteRowAsDict©s  z$RowFactoryTests.CheckSqliteRowAsDictcCsîtj|j_|j d¡ ¡}|j d¡ ¡}|j d¡ ¡}|j d¡ ¡}|j d¡ ¡}| ||k¡| ||k¡| ||k¡| ||k¡| ||k¡| |tƒk¡| ||k¡| ||k¡| ||k¡| ||k¡| ||k¡| |tƒk¡|  t ¡||kWdƒn1s00Y|  t ¡||kWdƒn1sd0Y|  t ¡||kWdƒn1s˜0Y|  t ¡||kWdƒn1sÌ0Y|  t |ƒt |ƒ¡dS)z6Checks if the row object compares and hashes correctlyrJzselect 1 as a, 3 as bzselect 1 as b, 2 as azselect 2 as b, 1 as aN) rrBrrr5r6Ú assertTrueZ assertFalseZobjectr1r2rCZhash)r Zrow_1Zrow_2Zrow_3Zrow_4Zrow_5r r r ÚCheckSqliteRowHashCmp±s6  ( ( ( (z%RowFactoryTests.CheckSqliteRowHashCmpcCsNtj|j_|j d¡ ¡}t|ƒ}| tt |ƒƒtt |ƒƒ¡|  |t ¡dS)z2 Checks if the row object can act like a sequence rJN) rrBrrr5r6rNrCr:Zreversedr&r)r rZas_tupler r r ÚCheckSqliteRowAsSequenceÓs  z(RowFactoryTests.CheckSqliteRowAsSequencecCsDGdd„dtƒ}tj|j_| t|jj|¡| ttj|ƒd¡dS)Nc@seZdZejZdS)z8RowFactoryTests.CheckFakeCursorClass..FakeCursorN)rrrrrZ __class__r r r r Ú FakeCursoràrrTr )ÚstrrrBrrr1r2r)r rTr r r ÚCheckFakeCursorClassÜs z$RowFactoryTests.CheckFakeCursorClasscCr"rr#r r r r r%ær zRowFactoryTests.tearDownN)rrrr!r<rErFrIrKrOrPrRrSrVr%r r r r r9Zs "  r9c@ó<eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)ÚTextFactoryTestscCr)r*r+r r r r r!êr zTextFactoryTests.setUpcCs2d}|j d|f¡ ¡}| t|dƒtd¡dS)Nõ Österreichúselect ?rútype of row[0] must be unicode)rr5r6rCÚtyperU©r Úaustriarr r r Ú CheckUnicodeíszTextFactoryTests.CheckUnicodecCsRt|j_d}|j d|f¡ ¡}| t|dƒtd¡| |d| d¡d¡dS)NrYrZrztype of row[0] must be bytesúutf-8z(column must equal original data in UTF-8)ÚbytesrÚ text_factoryr5r6rCr\Zencoder]r r r Ú CheckStringòs zTextFactoryTests.CheckStringcCsTdd„|j_d}|j d|f¡ ¡}| t|dƒtd¡| |d d¡d¡dS) NcSs t|ddƒS)Nr`Zignore)rU©Zxr r r r-úr.z.TextFactoryTests.CheckCustom..rYrZrr[Zreichz!column must contain original data) rrbr5r6rCr\rUrQZendswithr]r r r Ú CheckCustomùs  zTextFactoryTests.CheckCustomcCsjtj|j_d}d}|j d|f¡ ¡}|j d|f¡ ¡}| t|dƒtd¡| t|dƒtd¡dS)NrYZ DeutchlandrZrz!type of non-ASCII row must be strz"type of ASCII-only row must be str) rZOptimizedUnicoderrbr5r6rCr\rU)r r^ZgermanyZa_rowZd_rowr r r ÚCheckOptimizedUnicodes z&TextFactoryTests.CheckOptimizedUnicodecCr"rr#r r r r r% r zTextFactoryTests.tearDownN) rrrr!r_rcrerfr%r r r r rXés  rXc@rW)Ú%TextFactoryTestsWithEmbeddedZeroBytescCs*t d¡|_|j d¡|j dd¡dS)Nrzcreate table test (value text)z#insert into test (value) values (?))úab)rrrr5r r r r r!s  z+TextFactoryTestsWithEmbeddedZeroBytes.setUpcCs8|j d¡ ¡}| t|dƒt¡| |dd¡dS)Núselect value from testrrh)rr5r6ÚassertIsr\rUrCr;r r r rcsz1TextFactoryTestsWithEmbeddedZeroBytes.CheckStringcCó@t|j_|j d¡ ¡}| t|dƒt¡| |dd¡dS©Nriróab)rarrbr5r6rjr\rCr;r r r Ú CheckBytesóz0TextFactoryTestsWithEmbeddedZeroBytes.CheckBytescCrkrl)Z bytearrayrrbr5r6rjr\rCr;r r r ÚCheckBytearray roz4TextFactoryTestsWithEmbeddedZeroBytes.CheckBytearraycCsDdd„|j_|j d¡ ¡}| t|dƒt¡| |dd¡dS)NcSs|Srr rdr r r r-(r.zCTextFactoryTestsWithEmbeddedZeroBytes.CheckCustom..rirrm)rrbr5r6rjr\rarCr;r r r re&s z1TextFactoryTestsWithEmbeddedZeroBytes.CheckCustomcCr"rr#r r r r r%-r z.TextFactoryTestsWithEmbeddedZeroBytes.tearDownN) rrrr!rcrnrprer%r r r r rgs rgcCs^t td¡}t td¡}t td¡}t td¡}t td¡}t td¡}t ||||||f¡S)NZCheck) ÚunittestZ makeSuiterr(r4r9rXrgZ TestSuite)Zconnection_suiteZ cursor_suiteZrow_suite_compatZ row_suiteZ text_suiteZtext_zero_bytes_suiter r r Úsuite0s      rrcCst ¡}| tƒ¡dSr)rqZTextTestRunnerZrunrr)Zrunnerr r r Útest9srsZ__main__)rqZsqlite3rZcollections.abcrrrrrrZTestCaserr(r4r9rXrgrrrsrr r r r Zs   %"