Format: application/x-python-code
⬇ Download File (20.8 KB)
   1  o
   2  
   3  ��hE��@s>dZddd�ZdZddlZddlZdZGdd	�d	ej�ZdS)
   4  a�Python DB API 2.0 driver compliance unit test suite.
   5  
   6     This software is Public Domain and may be used without restrictions.
   7  
   8  "Now we have booze and barflies entering the discussion, plus rumours of
   9   DBAs on drugs... and I won't tell you what flashes through my mind each
  10   time I read the subject line with 'Anal Compliance' in it.  All around
  11   this is turning out to be a thoroughly unwholesome unit test."
  12  
  13     -- Ian Bicking
  14  z$Revision: 1.15.0 $������z'Stuart Bishop <stuart@stuartbishop.net>�NFc@s�eZdZdZdZdZiZdZdeZdeZ	deZ
  15  deZd	Zd
  16  d�Z
  17  dd
  18  �Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd	Zd,d-�Zd.d/�Z d0d1�Z!d2d3�Z"d4d5�Z#d6d7�Z$gd8�Z%d9d:�Z&d;d<�Z'd=d>�Z(d?d@�Z)dAdB�Z*dCdD�Z+dEdF�Z,dGdH�Z-dIdJ�Z.dKdL�Z/dMdN�Z0dOdP�Z1dQdR�Z2dSdT�Z3dUdV�Z4dWdX�Z5dYdZ�Z6d[d\�Z7d]d^�Z8d_d`�Z9dadb�Z:dS)c�DatabaseAPI20Testa	Test a database self.driver for DB API 2.0 compatibility.
  19      This implementation tests Gadfly, but the TestCase
  20      is structured so that other self.drivers can subclass this
  21      test case to ensure compiliance with the DB-API. It is
  22      expected that this TestCase may be expanded in the future
  23      if ambiguities or edge conditions are discovered.
  24  
  25      The 'Optional Extensions' are not yet being tested.
  26  
  27      self.drivers should subclass this test, overriding setUp, tearDown,
  28      self.driver, connect_args and connect_kw_args. Class specification
  29      should be as follows:
  30  
  31      import dbapi20
  32      class mytest(dbapi20.DatabaseAPI20Test):
  33         [...]
  34  
  35      Don't 'import DatabaseAPI20Test from dbapi20', or you will
  36      confuse the unit tester - just 'import dbapi20'.
  37      N�Zdbapi20test_z'create table %sbooze (name varchar(20))z<create table %sbarflys (name varchar(20), drink varchar(30))zdrop table %sboozezdrop table %sbarflys�lowercC�|�|j�dS�N)�execute�ddl1��self�cursorrr�Kc:\Users\shubh\Videos\agent\nova\Lib\site-packages\adodbapi/test/dbapi20.py�executeDDL1|�zDatabaseAPI20Test.executeDDL1cCrr)r	�ddl2rrrr�executeDDL2rzDatabaseAPI20Test.executeDDL2cCsdS)z�self.drivers should override this method to perform required setup
  38          if any is necessary, such as creating the database.
  39          Nr�rrrr�setUp�szDatabaseAPI20Test.setUpc	Cs�z5|��}z+|��}|j|jfD]}z|�|�|��Wq|jjy(YqwW|��WdS|��wt	y?YdSw)z�self.drivers should override this method to perform required cleanup
  40          if any is necessary, such as deleting the test database.
  41          The default drops the tables that may be created.
  42          N)
  43  �_connectr
  44  �xddl1�xddl2r	�commit�driver�Error�close�	Exception)r�con�curZddlrrr�tearDown�s 
  45  ��	�zDatabaseAPI20Test.tearDowncCs<z|jj|ji|j��}W|Sty|�d�Y|Sw)Nz-No connect method found in self.driver module)r�connect�connect_args�connect_kw_args�AttributeError�fail)r�rrrrr�s��zDatabaseAPI20Test._connectcCs|��}|��dSr)rr�rrrrr�test_connect�szDatabaseAPI20Test.test_connectcCs:z
  46  |jj}|�|d�WdSty|�d�YdSw)Nz2.0zDriver doesn't define apilevel)r�apilevel�assertEqualr#r$)rr(rrr�
  47  test_apilevel�s�zDatabaseAPI20Test.test_apilevelcC�<z|jj}|�|dv�WdSty|�d�YdSw)N)r���z"Driver doesn't define threadsafety)r�threadsafety�
  48  assertTruer#r$)rr/rrr�test_threadsafety�s�z#DatabaseAPI20Test.test_threadsafetycCr+)N)�qmark�numeric�named�format�pyformatz Driver doesn't define paramstyle)r�
  49  paramstyler0r#r$)rr7rrr�test_paramstyle�s
  50  ��z!DatabaseAPI20Test.test_paramstylecCs�|�t|jjt��|�t|jjt��|�t|jj|jj��|�t|jj|jj��|�t|jj|jj��|�t|jj	|jj��|�t|jj
  51  |jj��|�t|jj|jj��|�t|jj|jj��dSr)
  52  r0�
  53  issubclassr�Warningrr�InterfaceError�
  54  DatabaseError�OperationalError�IntegrityError�
  55  InternalError�ProgrammingError�NotSupportedErrorrrrr�test_Exceptions�sz!DatabaseAPI20Test.test_ExceptionscCs�|��}|j}|�|j|ju�|�|j|ju�|�|j|ju�|�|j|ju�|�|j|ju�|�|j|ju�|�|j	|j	u�|�|j
  56  |j
  57  u�|�|j|ju�dSr)rrr0r:rr;r<r=r>r?r@rA)rr�drvrrr�%test_ExceptionsAsConnectionAttributes�sz7DatabaseAPI20Test.test_ExceptionsAsConnectionAttributescCs*|��}z|��W|��dS|��wr)rrrr&rrr�test_commit�s
  58  zDatabaseAPI20Test.test_commitcCs>|��}t|d�rz|��WdS|jjyYdSwdS)N�rollback)r�hasattrrFrrAr&rrr�
  59  test_rollback�s
  60  ��zDatabaseAPI20Test.test_rollbackcCs*|��}z|��}W|��dS|��wr)rr
  61  r�rrrrrr�test_cursor�s
  62  zDatabaseAPI20Test.test_cursorcCs�|��}zD|��}|��}|�|�|�d|j�|�d|j�|��}|�t|�d�|�t|d�d�|�|ddd�W|��dS|��w)N�.insert into %sbooze values ('Victoria Bitter')�select name from %sboozer,r�Victoria Bitter�	rr
  63  rr	�table_prefix�fetchallr)�lenr)rrZcur1Zcur2Zboozerrr�test_cursor_isolation�s
  64  �z'DatabaseAPI20Test.test_cursor_isolationcCs�|��}zf|��}|�|�|�|jdd�|�d|j�|�t|j�dd�|�t|jd�dd�|�|jdd��dd	�|�|jdd|j	j
  65  d
  66  |jdd�|�|�|�|jdd�W|��dS|��w)Nzccursor.description should be none after executing a statement that can return no rows (such as DDL)rLr,z-cursor.description describes too many columnsr�z1cursor.description[x] tuples must have 7 elements�namez0cursor.description[x][0] must return column namez8cursor.description[x][1] must return column type. Got %rzVcursor.description not being set to None when executing no-result statements (eg. DDL))
  67  rr
  68  rr)�descriptionr	rOrQrr�STRINGrrrIrrr�test_descriptionsJ
  69  ������
  70  �z"DatabaseAPI20Test.test_descriptioncCs�|��}zH|��}|�|�|�|jdvd�|�d|j�|�|jdvd�|�d|j�|�|jdvd�|�|�|�|jdd	�W|�	�dS|�	�w)
  71  N������rzFcursor.rowcount should be -1 or 0 after executing no-result statementsrK�rYr,zccursor.rowcount should == number or rows inserted, or set to -1 after executing an insert statementrLzbcursor.rowcount should == number of rows returned, or set to -1 after executing a select statementrYzJcursor.rowcount not being reset to -1 after executing no-result statements)
  72  rr
  73  rr0�rowcountr	rOrr)rrIrrr�
  74  test_rowcount=s6
  75  ����
  76  �zDatabaseAPI20Test.test_rowcountcCs�|��}z[|��}|jrRt|d�rY|�|jd�}|�t|�d�|�|dd�|��}|�t|�dd�|�t|d�dd�|�|dddd	�W|��dSW|��dSW|��dS|��w)
  77  N�callproc)�FOOr,rr^zcallproc produced no result setz$callproc produced invalid result setZfooz!callproc produced invalid results)	rr
  78  �
  79  lower_funcrGr]r)rQrPr�rrrr%rrr�
  80  test_callprocas �	�	zDatabaseAPI20Test.test_callproccCsv|��}z
  81  |��}W|��n|��w|�|jj|j|�|�|jj|j�tr4|�|jj|j�dS|�	d�dS)Nz>Non-idempotent close is considered a bad thing by some people.)
  82  rr
  83  r�assertRaisesrrrr�TEST_FOR_NON_IDEMPOTENT_CLOSEZskipTestrIrrr�
  84  test_closeps
  85  �zDatabaseAPI20Test.test_closecCs4|��}z|��}|�|�W|��dS|��wr)rr
  86  �_paraminsertrrIrrr�test_execute�s
  87  zDatabaseAPI20Test.test_executecCs�|�|�|�d|j�|�|jdv�|jjdkr%|�d|jd�nI|jjdkr5|�d|jd�n9|jjdkrG|�d	|jd
  88  di�n'|jjdkrW|�d
  89  |jd�n|jjdkri|�d|jd
  90  di�n|�d�|�|jdv�|�d|j�|��}|�	t
  91  |�dd�|dd|ddg}|��|�	|ddd�|�	|ddd�d}|�	|dd|d|dd�d|���|�	|dd|d|dd�d|���dS)NzSinsert into %sbarflys values ('Victoria Bitter', 'thi%%s :may ca%%(u)se? troub:1e')rZr2zCinsert into %sbarflys values (?, 'thi%%s :may ca%%(u)se? troub:1e')��Cooper'sr3zDinsert into %sbarflys values (:1, 'thi%%s :may ca%%(u)se? troub:1e')r4zGinsert into %sbarflys values (:beer, 'thi%%s :may ca%%(u)se? troub:1e')�beerrhr5zEinsert into %sbarflys values (%%s, 'thi%%s :may ca%%(u)se? troub:1e')r6zKinsert into %sbarflys values (%%(beer)s, 'thi%%s :may ca%%(u)se? troub:1e')zInvalid paramstylez!select name, drink from %sbarflysr-z%cursor.fetchall returned too few rowsrr,zFcursor.fetchall retrieved incorrect data, or data inserted incorrectlyrMzthi%s :may ca%(u)se? troub:1ezLcursor.fetchall retrieved incorrect data, or data inserted incorrectly. Got=z, Expected=)rr	rOr0r[rr7r$rPr)rQ�sort)rr�res�beersZtroublerrrre�s�
  92  ������������
  93  ��
  94  
  95  ���
  96  
  97  ���zDatabaseAPI20Test._paraminsertcCs�|��}z�|��}|�|�ddg}ddiddig}|jjdkr*|�d|j|�nE|jjdkr:|�d	|j|�n5|jjd
  98  krJ|�d|j|�n%|jjdkrZ|�d
  99  |j|�n|jjdkrj|�d|j|�n|�d�|�|j	dvd|j	�|�
 100  d|j�|��}|�t
 101  |�dd�|dd|ddg}|��|�|ddd|d�|�|ddd�W|��dS|��w)Nrg)�Boag'srirhrmr2zinsert into %sbooze values (?)r3zinsert into %sbooze values (:1)r4z"insert into %sbooze values (:beer)r5z insert into %sbooze values (%%s)r6z&insert into %sbooze values (%%(beer)s)zUnknown paramstyle)rYr-zIinsert using cursor.executemany set cursor.rowcount to incorrect value %rrLr-z2cursor.fetchall retrieved incorrect number of rowsrr,zincorrect data "%s" retrievedzincorrect data retrieved)rr
 102  rrr7ZexecutemanyrOr$r0r[r	rPr)rQrjr)rrr�largsZmargsrkrlrrr�test_executemany�s\
 103  
 104  �
 105  �
 106  �
 107  ��
 108  ��
 109  ��z"DatabaseAPI20Test.test_executemanycCs
 110  |��}z{|��}|�|jj|j�|�|�|�|jj|j�|�d|j�|�	|��dd�|�
 111  |jdv�|�d|j�|�|jj|j�|�d|j�|��}|�	t|�dd�|�	|ddd	�|�	|��dd
 112  �|�
 113  |jdv�W|�
 114  �dS|�
 115  �w)NrLz?cursor.fetchone should return None if a query retrieves no rowsrXrKr,z2cursor.fetchone should have retrieved a single rowrrMz(cursor.fetchone retrieved incorrect dataz<cursor.fetchone should return None if no more rows availablerZ)rr
 116  rbrr�fetchonerr	rOr)r0r[rQrr`rrr�
 117  test_fetchones@
 118  ��
 119  �
 120  ��zDatabaseAPI20Test.test_fetchone)zCarlton Coldz
 121  Carlton Draftz
 122  Mountain GoatZRedbackrMZXXXXcs�fdd��jD�}|S)zSReturn a list of sql commands to setup the DB for the fetch
 123          tests.
 124          csg|]	}d�j|f�qS)z!insert into %sbooze values ('%s'))rO)�.0�srrr�
 125  <listcomp>Cs��z/DatabaseAPI20Test._populate.<locals>.<listcomp>)�samples)rZpopulaterrr�	_populate?s
 126  �zDatabaseAPI20Test._populatecCs`|��}�z%|��}|�|jj|jd�|�|�|��D]}|�|�q|�d|j	�|��}|�
 127  t|�dd�d|_|�d�}|�
 128  t|�dd�|�d�}|�
 129  t|�dd�|�d�}|�
 130  t|�d	d
 131  �|�
 132  |jdv�d|_|�d|j	�|��}|�
 133  t|�dd�|��}|�
 134  t|�d�|��}|�
 135  t|�d	�|�
 136  |jdv�d
 137  |_|�d|j	�|��}|�
 138  |jdv�|�
 139  t|�d
 140  �|�
 141  t|�d
 142  �dd�|D�}|��td	d
 143  �D]}|�
 144  |||j|d�q�|��}|�
 145  t|�d	d�|�
 146  |jdv�|�|�|�d|j	�|��}|�
 147  t|�d	d�|�
 148  |jdv�W|��dS|��w)N�rLr,zQcursor.fetchmany retrieved incorrect number of rows, default of arraysize is one.�
 149  r.z3cursor.fetchmany retrieved incorrect number of rowsr-rzLcursor.fetchmany should return an empty sequence after results are exhausted�rY�z0cursor.arraysize not being honoured by fetchmanyrzcS�g|]}|d�qS�rr�rrr%rrrrt��z4DatabaseAPI20Test.test_fetchmany.<locals>.<listcomp>z,incorrect data retrieved by cursor.fetchmanyzfcursor.fetchmany should return an empty sequence if called after the whole result set has been fetched�select name from %sbarflyszKcursor.fetchmany should return an empty sequence if query retrieved no rowsrX)rr
 150  rbrr�	fetchmanyrrvr	rOr)rQ�	arraysizer0r[rj�rangerurr)rrr�sqlr%�rows�irrr�test_fetchmanyIs�
 151  �
 152  
 153  �
 154  
 155  �
 156  �
 157  ���
 158  �z DatabaseAPI20Test.test_fetchmanycCsv|��}z�|��}|�|jj|j�|�|�|��D]}|�|�q|�|jj|j�|�d|j	�|��}|�
 159  |jdt|j
 160  �fv�|�t|�t|j
 161  �d�dd�|D�}|��tdt|j
 162  ��D]}|�|||j
 163  |d�qd|��}|�t|�dd�|�
 164  |jdt|j
 165  �fv�|�|�|�d	|j	�|��}|�
 166  |jd
 167  v�|�t|�dd�W|��dS|��w)NrLrYz)cursor.fetchall did not retrieve all rowscSr{r|rr}rrrrt�r~z3DatabaseAPI20Test.test_fetchall.<locals>.<listcomp>rz(cursor.fetchall retrieved incorrect rowszacursor.fetchall should return an empty list if called after the whole result set has been fetchedrrXzMcursor.fetchall should return an empty list if a select query returns no rows)rr
 168  rbrrrPrrvr	rOr0r[rQrur)rjr�rr)rrrr�r�r�rrr�
 169  test_fetchall�sN
 170  ���
 171  �zDatabaseAPI20Test.test_fetchallc
 172  Cs<|��}z�|��}|�|�|��D]}|�|�q|�d|j�|��}|�d�}|��}|��}|�	|j
 173  dv�|�t|�dd�|�t|�dd�|dg}|�
 174  |dd|ddg�|�|d�|�
 175  |dd|ddg�|��tdt|j��D]}	|�||	|j|	d�q�W|��dS|��w)	NrLr-ryz+fetchmany returned incorrect number of rowsz*fetchall returned incorrect number of rowsrr,z$incorrect data retrieved or inserted)rr
 176  rrvr	rOrpr�rPr0r[r)rQ�extend�appendrjr�rur)
 177  rrrr�Zrows1Zrows23Zrows4Zrows56r�r�rrr�test_mixedfetch�s:
 178  
 179  
 180  �
 181  �
 182  ��z!DatabaseAPI20Test.test_mixedfetchcC�td��)z�Should create a procedure called deleteme
 183          that returns two result sets, first the
 184          number of rows in booze then "name from booze"
 185          �Helper not implemented��NotImplementedError�rrrrr�help_nextset_setUp�sz$DatabaseAPI20Test.help_nextset_setUpcCr�)z*If cleaning up is needed after nextSetTestr�r�r�rrr�help_nextset_tearDown�z'DatabaseAPI20Test.help_nextset_tearDowncCr�)Nz"Drivers need to override this testr�rrrr�test_nextsetszDatabaseAPI20Test.test_nextsetcCs<|��}z|��}|�t|d�d�W|��dS|��w)Nr�z cursor.arraysize must be defined)rr
 186  r0rGrrIrrr�test_arraysizes
 187  �z DatabaseAPI20Test.test_arraysizecCs>|��}z|��}|�d�|�|�W|��dS|��w)N)�)rr
 188  Z
 189  setinputsizesrerrIrrr�test_setinputsizess
 190  z$DatabaseAPI20Test.test_setinputsizescCsJ|��}z|��}|�d�|�dd�|�|�W|��dS|��w)Ni�i�r)rr
 191  Z
 192  setoutputsizererrIrrr�test_setoutputsize_basic's
 193  z*DatabaseAPI20Test.test_setoutputsize_basiccCr�)Nz#Driver needed to override this testr�rrrr�test_setoutputsize2r�z$DatabaseAPI20Test.test_setoutputsizecCs�|��}zA|��}|�|�|�d|j�|�d|j�|��}|�t|�d�|�t|d�d�|�|dddd�W|��dS|��w)Nz!insert into %sbooze values (NULL)rLr,rzNULL value not returned as NonerNr`rrr�	test_None6s
 194  zDatabaseAPI20Test.test_NonecC�&|j�ddd�}|j�t�d��}dS)N���r�)	r�r�r�rrrrrr)r�DateZ
 195  DateFromTicks�time�mktime)rZd1Zd2rrr�	test_DateD�zDatabaseAPI20Test.test_DatecCr�)N�
 196  �-�)	i�r,r,r�r�r�rrr)rZTimeZ
 197  TimeFromTicksr�r��r�t1�t2rrr�	test_TimeJr�zDatabaseAPI20Test.test_TimecCs,|j�dddddd�}|j�t�d��}dS)Nr�r�r�r�r�r�)	r�r�r�r�r�r�rrr)r�	TimestampZTimestampFromTicksr�r�r�rrr�test_TimestampPs�z DatabaseAPI20Test.test_TimestampcCs|j�d�}|j�d�}dS)Ns	Something�)r�Binary)r�brrr�test_BinaryXszDatabaseAPI20Test.test_BinarycC�|�t|jd�d�dS)NrVzmodule.STRING must be defined�r0rGrrrrr�test_STRING\�zDatabaseAPI20Test.test_STRINGcCr�)N�BINARYzmodule.BINARY must be defined.r�rrrr�test_BINARY_��zDatabaseAPI20Test.test_BINARYcCr�)N�NUMBERzmodule.NUMBER must be defined.r�rrrr�test_NUMBERdr�zDatabaseAPI20Test.test_NUMBERcCr�)NZDATETIMEz module.DATETIME must be defined.r�rrrr�
 198  test_DATETIMEir�zDatabaseAPI20Test.test_DATETIMEcCr�)NZROWIDzmodule.ROWID must be defined.r�rrrr�
 199  test_ROWIDnr�zDatabaseAPI20Test.test_ROWID);�__name__�
 200  __module__�__qualname__�__doc__rr!r"rOr
 201  rrrZ	lowerfuncrrrrrr'r*r1r8rBrDrErHrJrRrWr\r_rardrfrerorqrurvr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrVsr		
 202  
 203  +"G1.	
 204  \6!	r)r��__version__�
 205  __author__r�ZunittestrcZTestCaserrrrr�<module>sA