summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>2010-01-18 13:41:41 +0100
committerAlexandre Fayolle <alexandre.fayolle@logilab.fr>2010-01-18 13:41:41 +0100
commit435b390054edbfd78ade9ce2f2e572253e70d0f0 (patch)
treed297b7d516f9e7c1cd0c9a8327f24204748a4e33
parent62d06751a77df59be62577f032e9d0c2befaf6df (diff)
downloadlogilab-common-435b390054edbfd78ade9ce2f2e572253e70d0f0.tar.gz
catch importerrors for adodbapi and pyodbc test cases
The relevant tests are only run if these modules are installed.
-rw-r--r--test/unittest_db.py113
1 files changed, 60 insertions, 53 deletions
diff --git a/test/unittest_db.py b/test/unittest_db.py
index 701cd91..c3f67e5 100644
--- a/test/unittest_db.py
+++ b/test/unittest_db.py
@@ -245,7 +245,7 @@ class BaseSqlServer(TestCase):
for length in data_length:
data = buffer('\x00'*length)
print "inserting string of length", len(data)
- cursor.execute('insert into TestBlob(id, data) VALUES(%(id)s, %(data)s)',
+ cursor.execute('insert into TestBlob(id, data) VALUES(%(id)s, %(data)s)',
{'id': length, 'data': data})
self.cnx.commit()
cursor.execute('select count(*) from TestBlob')
@@ -258,7 +258,7 @@ class BaseSqlServer(TestCase):
for length in data_length:
data = '1'*length
print "inserting string of length", len(data)
- cursor.execute('insert into TestLargeString(id, data) VALUES(%(id)s, %(data)s)',
+ cursor.execute('insert into TestLargeString(id, data) VALUES(%(id)s, %(data)s)',
{'id': length, 'data': data})
self.cnx.commit()
cursor.execute('select count(*) from TestLargeString')
@@ -280,59 +280,66 @@ class BaseSqlServer(TestCase):
cursor.execute('select * from TestBlob where id=42')
print cursor.fetchall()
cursor.close()
-
-
-class pyodbcTC(BaseSqlServer):
- def setUp(self):
- import pyodbc
- try:
- self.cnx = get_connection(driver='sqlserver2005', database='alf',
- host='localhost', extra_args='Trusted_Connection')
- except pyodbc.Error, exc:
- self.skip(str(exc))
- cursor = self.cnx.cursor()
- try:
- cursor.execute('create table TestLargeString (id int, data varchar(max))')
- cursor.execute('create table TestBlob (id int, data varbinary(max))')
- except Exception, exc:
- print exc
- cursor.close()
-
- def test_blob(self):
- self.blob()
-
- def test_large_string(self):
- self.large_string()
-
- def test_varbinary_none(self):
- self.varbinary_none()
-
-class adodbapiTC(BaseSqlServer):
- def setUp(self):
- import adodbapi as adb
- try:
- self.cnx = get_connection(driver='sqlserver2005', database='alf',
- host='localhost', extra_args='Trusted_Connection')
- except adb.Error, exc:
- self.skip(str(exc))
- cursor = self.cnx.cursor()
- try:
-
- cursor.execute('create table TestLargeString (id int, data varchar(max))')
- cursor.execute('create table TestBlob (id int, data varbinary(max))')
- except Exception, exc:
- print exc
- cursor.close()
-
- def test_blob(self):
- self.blob()
-
- def test_large_string(self):
- self.large_string()
- def test_varbinary_none(self):
- self.varbinary_none()
+try:
+ import pyodbc
+except ImportError:
+ print "pyodbc tests skipped"
+else:
+ class pyodbcTC(BaseSqlServer):
+ def setUp(self):
+ try:
+ self.cnx = get_connection(driver='sqlserver2005', database='alf',
+ host='localhost', extra_args='Trusted_Connection')
+ except pyodbc.Error, exc:
+ self.skip(str(exc))
+ cursor = self.cnx.cursor()
+ try:
+ cursor.execute('create table TestLargeString (id int, data varchar(max))')
+ cursor.execute('create table TestBlob (id int, data varbinary(max))')
+ except Exception, exc:
+ print exc
+ cursor.close()
+
+ def test_blob(self):
+ self.blob()
+
+ def test_large_string(self):
+ self.large_string()
+
+ def test_varbinary_none(self):
+ self.varbinary_none()
+
+try:
+ import adodbapi as adb
+except ImportError:
+ print "adodbapi tests skipped"
+else:
+ class adodbapiTC(BaseSqlServer):
+ def setUp(self):
+ try:
+ self.cnx = get_connection(driver='sqlserver2005', database='alf',
+ host='localhost', extra_args='Trusted_Connection')
+ except adb.Error, exc:
+ self.skip(str(exc))
+ cursor = self.cnx.cursor()
+ try:
+
+ cursor.execute('create table TestLargeString (id int, data varchar(max))')
+ cursor.execute('create table TestBlob (id int, data varbinary(max))')
+ except Exception, exc:
+ print exc
+ cursor.close()
+
+ def test_blob(self):
+ self.blob()
+
+ def test_large_string(self):
+ self.large_string()
+
+ def test_varbinary_none(self):
+ self.varbinary_none()
if __name__ == '__main__':