Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/sqlite3/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/sqlite3/test/__pycache__/regression.cpython-35.opt-1.pyc



��Yf 8�@slddlZddlZddlZGdd�dej�Zdd�Zdd�Zedkrhe�dS)	�Nc@s{eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
jej
d=kd�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Z d8d9�Z!d:d;�Z"d<S)>�RegressionTestscCstjd�|_dS)Nz:memory:)�sqlite�connect�con)�self�r�</opt/alt/python35/lib64/python3.5/sqlite3/test/regression.py�setUpszRegressionTests.setUpcCs|jj�dS)N)r�close)rrrr�tearDown szRegressionTests.tearDowncCs |jj�}|jd�dS)Nzpragma user_version)r�cursor�execute)r�currrr�CheckPragmaUserVersion#sz&RegressionTests.CheckPragmaUserVersionc
CsTtjddtj�}z |jj�}|jd�Wd|j�|j�XdS)Nz:memory:�detect_typeszpragma schema_version)rrZPARSE_COLNAMESrrr
r
)rrrrrr�CheckPragmaSchemaVersion(s
z(RegressionTests.CheckPragmaSchemaVersioncs�tjddd���fdd�td�D�}|djd�x;td�D]-}|djd	d
d�td�D��qRWx-td�D]}||jd|d�q�W�j�dS)
Nz:memory:Zcached_statements�csg|]}�j��qSr)r)�.0�x)rrr�
<listcomp>7s	z7RegressionTests.CheckStatementReset.<locals>.<listcomp>rzcreate table test(x)�
zinsert into test(x) values (?)cSsg|]}|f�qSrr)rrrrrr:s	� zselect x from test)rr�ranger
�executemany�rollback)r�cursors�ir)rr�CheckStatementReset2s+z#RegressionTests.CheckStatementResetcCsc|jj�}|jd�|j|jddd�|jd�|j|jddd�dS)Nz select 1 as "foo bar [datetime]"rzfoo barzselect 1 as "foo baz"zfoo baz)rrr
�assertEqualZdescription)rrrrr�CheckColumnNameWithSpacesAs


z)RegressionTests.CheckColumnNameWithSpacescCsjtjd�}g}xDtd�D]6}|j�}|j|�|jdt|��q"W|j�dS)Nz:memory:�izselect 1 x union select )rrrr�appendr
�strr
)rrrrrrrr�#CheckStatementFinalizationOnCloseDbIs
z3RegressionTests.CheckStatementFinalizationOnCloseDb��zneeds sqlite 3.2.2 or newercCs�tjd�}|jd�|jd�y|jd�Wntjk
rQYnX|jd�y|j�Wn"tjk
r�|jd�YnXdS)Nz:memory:z3create table foo(x, unique(x) on conflict rollback)zinsert into foo(x) values (1)zinsert into foo(x) values (2)z1pysqlite knew nothing about the implicit ROLLBACK)rrr
Z
DatabaseError�commit�OperationalErrorZfail)rrrrr�CheckOnConflictRollbackWs


z'RegressionTests.CheckOnConflictRollbackcCs4|jjd�|jjd�|jjd�dS)zm
        pysqlite would crash with older SQLite versions unless
        a workaround is implemented.
        zcreate table foo(bar)zdrop table fooN)rr
)rrrr�-CheckWorkaroundForBuggySqliteTransferBindingsfsz=RegressionTests.CheckWorkaroundForBuggySqliteTransferBindingscCs|jjd�dS)z
        pysqlite used to segfault with SQLite versions 3.5.x. These return NULL
        for "no-operation" statements
        �N)rr
)rrrr�CheckEmptyStatementosz#RegressionTests.CheckEmptyStatementcCs�d}tjddtj�}|jd�|jdtjj�f�|j|�|jd�|jd�|jd�|j|�d	S)
z�
        pysqlite until 2.4.1 did not rebuild the row_cast_map when recompiling
        a statement. This test exhibits the problem.
        zselect * from fooz:memory:rzcreate table foo(bar timestamp)zinsert into foo(bar) values (?)zdrop table foozcreate table foo(bar integer)zinsert into foo(bar) values (5)N)rr�PARSE_DECLTYPESr
�datetimeZnow)rZSELECTrrrr�CheckTypeMapUsagevs




z!RegressionTests.CheckTypeMapUsagecCsj|jtj��2}|jjdttdg��f�j�WdQRXd}|j|t	|j
��dS)Nz"select 'xxx' || ? || 'yyy' colname�z9Could not decode to UTF-8 column 'colname' with text 'xxx)�assertRaisesrr'rr
�bytes�	bytearray�fetchoneZassertInr"Z	exception)r�cm�msgrrr�CheckErrorMsgDecodeError�s
&z(RegressionTests.CheckErrorMsgDecodeErrorcCs|jttjid�dS)z!
        See issue 3312.
        N)r0�	TypeErrorrZregister_adapter)rrrr�CheckRegisterAdapter�sz$RegressionTests.CheckRegisterAdaptercsBG�fdd�dt�}tjd��d�_x^dD]V}|jd|��;|�_|j��_|j��_||��_WdQRXq;Wd�_d�_d	tfd
tfdtfdtfd
tfg}xa|D]Y\}}|jd|��8|j	|��|�_WdQRX|j
�jd�WdQRXq�WdS)Ncs.eZdZdd�Z�fdd�ZdS)z9RegressionTests.CheckSetIsolationLevel.<locals>.CustomStrcSsdS)Nr)rrrr�upper�sz?RegressionTests.CheckSetIsolationLevel.<locals>.CustomStr.uppercs
d�_dS)Nr*)�isolation_level)r)rrr�__del__�szARegressionTests.CheckSetIsolationLevel.<locals>.CustomStr.__del__N)�__name__�
__module__�__qualname__r9r;r)rrr�	CustomStr�sr?z:memory:r*�DEFERRED�	IMMEDIATE�	EXCLUSIVE�level���abczIMMEDIATEEXCLUSIVE�é)r*r@rArB)r"rrr:�subTest�lower�
capitalizer7�
ValueErrorr0r)rr?rCZpairs�value�excr)rr�CheckSetIsolationLevel�s$	
			z&RegressionTests.CheckSetIsolationLevelc	CseGdd�dtj�}tjd�}||�}|jtj��|jd�j�WdQRXdS)zd
        Verifies that cursor methods check whether base class __init__ was
        called.
        c@seZdZdd�ZdS)z?RegressionTests.CheckCursorConstructorCallCheck.<locals>.CursorcSsdS)Nr)rrrrr�__init__�szHRegressionTests.CheckCursorConstructorCallCheck.<locals>.Cursor.__init__N)r<r=r>rOrrrr�Cursor�srPz:memory:z
select 4+5N)rrPrr0�ProgrammingErrorr
�fetchall)rrPrrrrr�CheckCursorConstructorCallCheck�s
z/RegressionTests.CheckCursorConstructorCallCheckcCs6Gdd�dt�}|jjd|d�f�dS)za
        The Python 3.0 port of the module didn't cope with values of subclasses of str.
        c@seZdZdS)z/RegressionTests.CheckStrSubclass.<locals>.MyStrN)r<r=r>rrrr�MyStr�srTzselect ?rFN)r"rr
)rrTrrr�CheckStrSubclass�sz RegressionTests.CheckStrSubclassc	CsOGdd�dtj�}|d�}|jtj��|j�}WdQRXdS)zh
        Verifies that connection methods check whether base class __init__ was
        called.
        c@seZdZdd�ZdS)zGRegressionTests.CheckConnectionConstructorCallCheck.<locals>.ConnectioncSsdS)Nr)r�namerrrrO�szPRegressionTests.CheckConnectionConstructorCallCheck.<locals>.Connection.__init__N)r<r=r>rOrrrr�
Connection�srWz:memory:N)rrWr0rQr)rrWrrrrr�#CheckConnectionConstructorCallCheck�sz3RegressionTests.CheckConnectionConstructorCallCheckc	s�G�fdd�dtj�}Gdd�dtj��|d�}|j�}|jd�|jdd
ddg�|jd�|j�|jtj��|j	�WdQRXdS)z�
        Verifies that subclassed cursor classes are correctly registered with
        the connection object, too.  (fetch-across-rollback problem)
        cs"eZdZ�fdd�ZdS)z;RegressionTests.CheckCursorRegistration.<locals>.Connectioncs
�|�S)Nr)r)rPrrr�szBRegressionTests.CheckCursorRegistration.<locals>.Connection.cursorN)r<r=r>rr)rPrrrW�srWc@seZdZdd�ZdS)z7RegressionTests.CheckCursorRegistration.<locals>.CursorcSstjj||�dS)N)rrPrO)rrrrrrO�sz@RegressionTests.CheckCursorRegistration.<locals>.Cursor.__init__N)r<r=r>rOrrrrrP�srPz:memory:zcreate table foo(x)zinsert into foo(x) values (?)r$�rzselect x from fooN)r$)rY)r)
rrWrPrr
rrr0ZInterfaceErrorrR)rrWrrr)rPr�CheckCursorRegistration�s


z'RegressionTests.CheckCursorRegistrationcCstjddd�}dS)z�
        Verifies that creating a connection in autocommit mode works.
        2.5.3 introduced a regression so that these could no longer
        be created.
        z:memory:r:N)rr)rrrrr�CheckAutoCommit�szRegressionTests.CheckAutoCommitcCsF|jj�}|jd�|jd�|jd�|j�}dS)z�
        Verifies that running a PRAGMA statement that does an autocommit does
        work. This did not work in 2.5.3/2.5.4.
        zcreate table foo(bar)zinsert into foo(bar) values (5)zpragma page_sizeN)rrr
r3)rr�rowrrr�CheckPragmaAutocommit�s



z%RegressionTests.CheckPragmaAutocommitcCs�Gdd�d�}|�}|jt|jj|�|jt|jj|�|jt|jj|�|jt|jj|�dS)z�
        See http://bugs.python.org/issue7478

        It was possible to successfully register callbacks that could not be
        hashed. Return codes of PyDict_SetItem were not checked properly.
        c@s(eZdZdd�Zdd�ZdS)z1RegressionTests.CheckSetDict.<locals>.NotHashablec_sdS)Nr)r�args�kwrrr�__call__sz:RegressionTests.CheckSetDict.<locals>.NotHashable.__call__cSs
t��dS)N)r7)rrrr�__hash__sz:RegressionTests.CheckSetDict.<locals>.NotHashable.__hash__N)r<r=r>r`rarrrr�NotHashablesrbN)r0r7rZcreate_functionZcreate_aggregateZset_authorizerZset_progress_handler)rrb�varrrr�CheckSetDict�s	zRegressionTests.CheckSetDictcCs|jtj|jd�dS)z}
        Call a connection with a non-string SQL request: check error handling
        of the statement constructor.
        rDN)r0r�Warningr)rrrr�CheckConnectionCallsz#RegressionTests.CheckConnectionCallcCs/dd�}|jtj|jjd|�dS)NcSsdS)NrDr)�a�brrr�collation_cbsz4RegressionTests.CheckCollation.<locals>.collation_cbu�)r0rrQrZcreate_collation)rrirrr�CheckCollationszRegressionTests.CheckCollationcs�tjd�}|j���jd��jd��fdd�}|jtj��%�jddd�|�D��Wd	QRXd	S)
z�
        http://bugs.python.org/issue10811

        Recursively using a cursor, such as when reusing it from a generator led to segfaults.
        Now we catch recursive cursor usage and raise a ProgrammingError.
        z:memory:zcreate table a (bar)zcreate table b (baz)c3s�jdd�dVdS)Nzinsert into a (bar) values (?)rD)rD)r
r)rrr�foo+sz4RegressionTests.CheckRecursiveCursorUse.<locals>.foozinsert into b (baz) values (?)css|]}|fVqdS)Nr)rrrrr�	<genexpr>1sz:RegressionTests.CheckRecursiveCursorUse.<locals>.<genexpr>N)rrrr
r0rQr)rrrkr)rr�CheckRecursiveCursorUses

	z'RegressionTests.CheckRecursiveCursorUsecCs�tjddtj�}|j�}|jd�|jd�|jd�|jd�dd�|j�D�}|j|tjd	d
d
ddd
d�tjd	d
d
ddd
d�g�dS)z�
        http://bugs.python.org/issue14720

        The microsecond parsing of convert_timestamp() should pad with zeros,
        since the microsecond string "456" actually represents "456000".
        z:memory:rzCREATE TABLE t (x TIMESTAMP)z4INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.456')z:INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.123456789')zSELECT * FROM tcSsg|]}|d�qS)rr)rrrrrrFs	zKRegressionTests.CheckConvertTimestampMicrosecondPadding.<locals>.<listcomp>i�rY��ri@�i@�N)rrr,rr
rRrr-)rrr�valuesrrr�'CheckConvertTimestampMicrosecondPadding3s



	z7RegressionTests.CheckConvertTimestampMicrosecondPaddingcCs |jttjddd�dS)Nz:memory:r:�{)r0r7rr)rrrr�CheckInvalidIsolationLevelTypeMs	z.RegressionTests.CheckInvalidIsolationLevelTypecCsqtjd�}|jt|d�|jt|d�|j�}|jt|jd�|jt|jd�dS)Nz:memory:z	select 1z	select 1z
 select 2z	select 2)rrr0rKrr
)rrrrrr�CheckNullCharacterSsz"RegressionTests.CheckNullCharactercCstjd�}|jd�|j|jd�d}x�t|jd��D]�\}}|jd|d|���|jd|f�|j�|dkr�|j|dd�nC|d	kr�|j|dd	�n |d
kr�|j|dd
�|d	7}WdQRXqKW|j|dd
�dS)z�
        Connection.commit() did reset cursors, which made sqlite3
        to return rows multiple times when fetched from cursors
        after commit. See issues 10513 and 23129 for details.
        z:memory:z�
        create table t(c);
        create table t2(c);
        insert into t values(0);
        insert into t values(1);
        insert into t values(2);
        r*rzselect c from trr\zinsert into t2(c) values (?)rDr%Nr$z'should have returned exactly three rows)	rrZ
executescriptrr:�	enumerater
rHr&)rrZcounterrr\rrr�CheckCommitCursorReset\s""
z&RegressionTests.CheckCommitCursorResetN)r$r%r%)#r<r=r>r	rrrrrr#�unittestZskipIfrZsqlite_version_infor(r)r+r.r6r8rNrSrUrXrZr[r]rdrfrjrmrqrsrtrvrrrrrs8
'		
	rcCs"tjtd�}tj|f�S)NZCheck)rwZ	makeSuiterZ	TestSuite)Zregression_suiterrr�suite|srxcCs tj�}|jt��dS)N)rwZTextTestRunnerZrunrx)Zrunnerrrr�test�sry�__main__)	r-rwZsqlite3rZTestCaserrxryr<rrrr�<module>s�a