Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/sqlite3/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/sqlite3/test/__pycache__/regression.cpython-34.pyc

�
e fx2�@soddlZddlZddlZGdd�dej�Zdd�Zdd�Zedkrke�ndS)	�Nc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7S)8�RegressionTestscCstjd�|_dS)Nz:memory:)�sqlite�connect�con)�self�r�</opt/alt/python34/lib64/python3.4/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.CheckStatementFinalizationOnCloseDbcCs�tjdkrdStjd�}|jd�|jd�y|jd�Wntjk
rdYnX|jd�y|j�Wn"tjk
r�|jd�YnXdS)	N��z: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)r$r%r%)rZsqlite_version_inforr
Z
DatabaseErrorZcommit�OperationalError�fail)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�-CheckWorkaroundForBuggySqliteTransferBindingsgsz=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�CheckEmptyStatementpsz#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�CheckTypeMapUsagews




z!RegressionTests.CheckTypeMapUsagecCs�d}y5|jjdttdg��f�j�d}WnMtjk
r�}z*|jd}|jd�sxd}nWYdd}~XnX|r�|j	|�ndS)Nz"select 'xxx' || ? || 'yyy' colname�z@should have raised an OperationalError with detailed descriptionrz9Could not decode to UTF-8 column 'colname' with text 'xxxz7OperationalError did not have expected description text)
rr
�bytes�	bytearray�fetchonerr&�args�
startswithr')r�failure�e�msgrrr�CheckErrorMsgDecodeError�s

z(RegressionTests.CheckErrorMsgDecodeErrorcCs|jttjid�dS)z!
        See issue 3312.
        N)�assertRaises�	TypeErrorrZregister_adapter)rrrr�CheckRegisterAdapter�sz$RegressionTests.CheckRegisterAdaptercCs#tjd�}t|dd�dS)z!
        See issue 3312.
        z:memory:�isolation_level�éN)rr�setattr)rrrrr�CheckSetIsolationLevel�sz&RegressionTests.CheckSetIsolationLevelcCs�Gdd�dtj�}tjd�}||�}y$|jd�j�|jd�Wn)tjk
roYn|jd�YnXdS)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)�__name__�
__module__�__qualname__r@rrrr�Cursor�srDz:memory:z
select 4+5z#should have raised ProgrammingErrorN)rrDrr
�fetchallr'�ProgrammingError)rrDrrrrr�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)rArBrCrrrr�MyStr�srHzselect ?�abcN)r"rr
)rrHrrr�CheckStrSubclass�sz RegressionTests.CheckStrSubclasscCsrGdd�dtj�}|d�}y|j�}|jd�Wn)tjk
rYYn|jd�YnXdS)zh
        Verifies that connection methods check whether base class __init__ was
        called.
        c@seZdZdd�ZdS)zGRegressionTests.CheckConnectionConstructorCallCheck.<locals>.ConnectioncSsdS)Nr)r�namerrrr@�szPRegressionTests.CheckConnectionConstructorCallCheck.<locals>.Connection.__init__N)rArBrCr@rrrr�
Connection�srLz:memory:z#should have raised ProgrammingErrorN)rrLrr'rF)rrLrrrrr�#CheckConnectionConstructorCallCheck�sz3RegressionTests.CheckConnectionConstructorCallCheckcs�G�fdd�dtj�}Gdd�dtj��|d�}|j�}|jd�|jddddg�|jd�|j�y|j�|jd�Wn)tj	k
r�Yn|jd�YnXd
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)rDrrr�szBRegressionTests.CheckCursorRegistration.<locals>.Connection.cursorN)rArBrCrr)rDrrrL�srLc@seZdZdd�ZdS)z7RegressionTests.CheckCursorRegistration.<locals>.CursorcSstjj||�dS)N)rrDr@)rrrrrr@�sz@RegressionTests.CheckCursorRegistration.<locals>.Cursor.__init__N)rArBrCr@rrrrrD�srDz:memory:zcreate table foo(x)zinsert into foo(x) values (?)r$�rzselect x from fooz!should have raised InterfaceErrorN)r$)rN)r)
rrLrDrr
rrrEr'ZInterfaceError)rrLrrr)rDr�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
r2)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)rr3�kwrrr�__call__sz:RegressionTests.CheckSetDict.<locals>.NotHashable.__call__cSs
t��dS)N)r:)rrrr�__hash__sz:RegressionTests.CheckSetDict.<locals>.NotHashable.__hash__N)rArBrCrTrUrrrr�NotHashablesrVN)r9r:rZcreate_functionZcreate_aggregateZset_authorizerZset_progress_handler)rrV�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.
        �N)r9r�Warningr)rrrr�CheckConnectionCallsz#RegressionTests.CheckConnectionCallcCs/dd�}|jtj|jjd|�dS)NcSsdS)NrYr)�a�brrr�collation_cbsz4RegressionTests.CheckCollation.<locals>.collation_cbu�)r9rrFrZcreate_collation)rr^rrr�CheckCollationszRegressionTests.CheckCollationcs�tjd�}|j���jd��jd��fdd�}|jtj��%�jddd�|�D��Wd	QXd	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 (?)rY)rY)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
r9rFr)rrr`r)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�rN��ri@�i@�N)rrr,rr
rErr-)rrr�valuesrrr�'CheckConvertTimestampMicrosecondPadding3s



	z7RegressionTests.CheckConvertTimestampMicrosecondPaddingcCs |jttjddd�dS)Nz:memory:r<�{)r9r:rr)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)rrr9�
ValueErrorrr
)rrrrrr�CheckNullCharacterSsz"RegressionTests.CheckNullCharacterN)rArBrCr	rrrrrr#r(r)r+r.r8r;r?rGrJrMrOrPrRrXr[r_rbrfrhrjrrrrrs6
	rcCs"tjtd�}tj|f�S)NZCheck)�unittestZ	makeSuiterZ	TestSuite)Zregression_suiterrr�suite]srlcCs tj�}|jt��dS)N)rkZTextTestRunnerZrunrl)Zrunnerrrr�testasrm�__main__)	r-rkZsqlite3rZTestCaserrlrmrArrrr�<module>s�B