f ž _0ã@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@seZdZdd„ZdS)Ú MyConnectioncOstjj|g|¢Ri|¤ŽdS©N)ÚsqliteÚ ConnectionÚ__init__©ÚselfÚargsÚkwargs©r ú-/usr/lib64/python3.10/sqlite3/test/factory.pyrszMyConnection.__init__N©Ú__name__Ú __module__Ú __qualname__rr r r r rsrcCs,i}t|jƒD]\}}||||d<q|S)Nr)Ú enumerateÚ description)ÚcursorÚrowÚdÚidxÚcolr r r Ú dict_factory src@seZdZdd„ZdS)ÚMyCursorcOs$tjj|g|¢Ri|¤Žt|_dSr)rÚCursorrrÚ row_factoryrr r r r'szMyCursor.__init__Nrr r r r r&src@s$eZdZdd„Zdd„Zdd„ZdS)ÚConnectionFactoryTestscCstjdtd|_dS)Nú:memory:©Úfactory)rÚconnectrÚcon©r r r r ÚsetUp,szConnectionFactoryTests.setUpcCs|j ¡dSr©r"Úcloser#r r r ÚtearDown/szConnectionFactoryTests.tearDowncCs| |jt¡dSr)ÚassertIsInstancer"rr#r r r ÚCheckIsInstance2sz&ConnectionFactoryTests.CheckIsInstanceN)rrrr$r'r)r r r r r+src@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) ÚCursorFactoryTestscCst d¡|_dS©Nr©rr!r"r#r r r r$6szCursorFactoryTests.setUpcCs|j ¡dSrr%r#r r r r'9szCursorFactoryTests.tearDowncCsR|j ¡}| |tj¡|j t¡}| |t¡|jjdd„d}| |t¡dS)NcSst|ƒSr)r©r"r r r ÚAóz4CursorFactoryTests.CheckIsInstance..r)r"rr(rrr)r Úcurr r r r)<s    z"CursorFactoryTests.CheckIsInstancecCsB| t|jjd¡| t|jjdd„¡| t|jjdd„¡dS)NcSsdSrr r r r r r.Hr/z8CursorFactoryTests.CheckInvalidFactory..cSsdSrr r-r r r r.Jr/)Ú assertRaisesÚ TypeErrorr"rr#r r r ÚCheckInvalidFactoryDsz&CursorFactoryTests.CheckInvalidFactoryN)rrrr$r'r)r3r r r r r*5sr*c@s$eZdZdd„Zdd„Zdd„ZdS)ÚRowFactoryTestsBackwardsCompatcCst d¡|_dSr+r,r#r r r r$Msz$RowFactoryTestsBackwardsCompat.setUpcCs8|jjtd}| d¡| ¡}| |t¡| ¡dS)Nrzselect 4+5 as foo)r"rrÚexecuteÚfetchoner(Údictr&)r r0rr r r ÚCheckIsProducedByFactoryPs   z7RowFactoryTestsBackwardsCompat.CheckIsProducedByFactorycCs|j ¡dSrr%r#r r r r'Wsz'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)ÚRowFactoryTestscCst d¡|_dSr+r,r#r r r r$[szRowFactoryTests.setUpcCs,dd„|j_|j d¡ ¡}| |t¡dS)NcSst|ƒSr)Úlist)r0rr r r r._r/z4RowFactoryTests.CheckCustomFactory..z select 1, 2)r"rr5r6r(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'ÚBz$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 -2Úcza_za1éýÿÿÿiè) rÚRowr"rr5r6r(Ú assertEqualr1Ú IndexErrorr;r r r ÚCheckSqliteRowIndexcs.  & ( ( ( ( z#RowFactoryTests.CheckSqliteRowIndexcCs’tj|j_|j d¡ ¡}| |dd¡| t¡|dWdƒn1sR0Y| t¡|dWdƒn1s„0YdS)Nuselect 1 as ÿõÿr=uŸõß) rrEr"rr5r6rFr1rGr;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?rL)r?rLé)r=r?rLrBrA)rL)rLrMrMr?)r=rL)rMr?)rrEr"rr5r6rFr;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)rrEr"rr5r6)r rrr r r ÚCheckSqliteRowIter›s z"RowFactoryTests.CheckSqliteRowItercCs>tj|j_|j d¡ ¡}t|ƒ}| ||d|df¡dS)z4Checks if the row object can be converted to a tuplerOÚar>N)rrEr"rr5r6ÚtuplerF)r rÚtr r r ÚCheckSqliteRowAsTuple¢s z%RowFactoryTests.CheckSqliteRowAsTuplecCsNtj|j_|j d¡ ¡}t|ƒ}| |d|d¡| |d|d¡dS)zCChecks if the row object can be correctly converted to a dictionaryrOrQr>N)rrEr"rr5r6r7rF)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 correctlyrOzselect 1 as a, 3 as bzselect 1 as b, 2 as azselect 2 as b, 1 as aN) rrEr"rr5r6Ú assertTrueZ assertFalseÚobjectr1r2rFÚhash)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 rON) rrEr"rr5r6rRrFr:Úreversedr(r)r rZas_tupler r r ÚCheckSqliteRowAsSequenceÓs  z(RowFactoryTests.CheckSqliteRowAsSequencecCsDGdd„dtƒ}tj|j_| t|jj|¡| ttj|ƒd¡dS)Nc@seZdZejZdS)z8RowFactoryTests.CheckFakeCursorClass..FakeCursorN)rrrrrÚ __class__r r r r Ú FakeCursoràsr]r )ÚstrrrEr"rr1r2r)r r]r r r ÚCheckFakeCursorClassÜs z$RowFactoryTests.CheckFakeCursorClasscCs|j ¡dSrr%r#r r r r'æszRowFactoryTests.tearDownN)rrrr$r<rHrKrNrPrTrUrYr[r_r'r r r r r9Zs "  r9c@s<eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)ÚTextFactoryTestscCst d¡|_dSr+r,r#r r r r$êszTextFactoryTests.setUpcCs2d}|j d|f¡ ¡}| t|dƒtd¡dS)Nõ Österreichúselect ?rútype of row[0] must be unicode)r"r5r6rFÚtyper^©r Úaustriarr r r Ú CheckUnicodeíszTextFactoryTests.CheckUnicodecCsRt|j_d}|j d|f¡ ¡}| t|dƒtd¡| |d| d¡d¡dS)Nrarbrztype of row[0] must be bytesúutf-8z(column must equal original data in UTF-8)Úbytesr"Ú text_factoryr5r6rFrdÚencoderer r r Ú CheckStringòs zTextFactoryTests.CheckStringcCsTdd„|j_d}|j d|f¡ ¡}| t|dƒtd¡| |d d¡d¡dS) NcSs t|ddƒS)NrhÚignore)r^©Úxr r r r.úr/z.TextFactoryTests.CheckCustom..rarbrrcZreichz!column must contain original data) r"rjr5r6rFrdr^rVÚendswithrer r r Ú CheckCustomùs  zTextFactoryTests.CheckCustomcCsjtj|j_d}d}|j d|f¡ ¡}|j d|f¡ ¡}| t|dƒtd¡| t|dƒtd¡dS)NraZ Deutchlandrbrz!type of non-ASCII row must be strz"type of ASCII-only row must be str) rZOptimizedUnicoder"rjr5r6rFrdr^)r rfZgermanyZa_rowZd_rowr r r ÚCheckOptimizedUnicodes z&TextFactoryTests.CheckOptimizedUnicodecCs|j ¡dSrr%r#r r r r' szTextFactoryTests.tearDownN) rrrr$rgrlrqrrr'r r r r r`és  r`c@s<eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)Ú%TextFactoryTestsWithEmbeddedZeroBytescCs*t d¡|_|j d¡|j dd¡dS)Nrzcreate table test (value text)z#insert into test (value) values (?))úab)rr!r"r5r#r r r r$s  z+TextFactoryTestsWithEmbeddedZeroBytes.setUpcCs8|j d¡ ¡}| t|dƒt¡| |dd¡dS)Núselect value from testrrt)r"r5r6ÚassertIsrdr^rFr;r r r rlsz1TextFactoryTestsWithEmbeddedZeroBytes.CheckStringcCs@t|j_|j d¡ ¡}| t|dƒt¡| |dd¡dS©Nruróab)rir"rjr5r6rvrdrFr;r r r Ú CheckBytessz0TextFactoryTestsWithEmbeddedZeroBytes.CheckBytescCs@t|j_|j d¡ ¡}| t|dƒt¡| |dd¡dSrw)Ú bytearrayr"rjr5r6rvrdrFr;r r r ÚCheckBytearray sz4TextFactoryTestsWithEmbeddedZeroBytes.CheckBytearraycCsDdd„|j_|j d¡ ¡}| t|dƒt¡| |dd¡dS)NcSs|Srr rnr r r r.(r/zCTextFactoryTestsWithEmbeddedZeroBytes.CheckCustom..rurrx)r"rjr5r6rvrdrirFr;r r r rq&s z1TextFactoryTestsWithEmbeddedZeroBytes.CheckCustomcCs|j ¡dSrr%r#r r r r'-sz.TextFactoryTestsWithEmbeddedZeroBytes.tearDownN) rrrr$rlryr{rqr'r r r r rss rscCs^t td¡}t td¡}t td¡}t td¡}t td¡}t td¡}t ||||||f¡S)NZCheck) ÚunittestZ makeSuiterr*r4r9r`rsZ TestSuite)Zconnection_suiteZ cursor_suiteZrow_suite_compatZ row_suiteZ text_suiteZtext_zero_bytes_suiter r r Úsuite0s      r}cCst ¡}| tƒ¡dSr)r|ZTextTestRunnerÚrunr})Zrunnerr r r Útest9srÚ__main__)r|Zsqlite3rÚcollections.abcrrrrrrZTestCaserr*r4r9r`rsr}rrr r r r Ús   %"