Permalink
Browse files

pgtests: Added --unicode

PostgreSQL ODBC driver 9.x on OS/X seems to return all string values as Unicode.  Added
--unicode to the test to allow for this.
  • Loading branch information...
1 parent 738cd01 commit 734f261d1c4f0b030c4faf0e386fc0f1dedb9b1f @mkleehammer committed Aug 17, 2012
View
0 tests2/accesstests.py 100644 → 100755
No changes.
View
0 tests2/dbapi20.py 100644 → 100755
No changes.
View
0 tests2/dbapitests.py 100644 → 100755
No changes.
View
0 tests2/exceltests.py 100644 → 100755
No changes.
View
0 tests2/freetdstests.py 100644 → 100755
No changes.
View
0 tests2/informixtests.py 100644 → 100755
No changes.
View
0 tests2/mysqltests.py 100644 → 100755
No changes.
View
24 tests2/pgtests.py 100644 → 100755
@@ -41,10 +41,11 @@ class PGTestCase(unittest.TestCase):
SMALL_STRING = _generate_test_string(SMALL_READ)
LARGE_STRING = _generate_test_string(LARGE_READ)
- def __init__(self, connection_string, ansi, method_name):
+ def __init__(self, connection_string, ansi, unicode_results, method_name):
unittest.TestCase.__init__(self, method_name)
self.connection_string = connection_string
- self.ansi = ansi
+ self.ansi = ansi
+ self.unicode = unicode_results
def setUp(self):
self.cnxn = pyodbc.connect(self.connection_string, ansi=self.ansi)
@@ -110,13 +111,17 @@ def _test_strtype(self, sqltype, value, colsize=None):
self.cursor.execute(sql)
self.cursor.execute("insert into t1 values(?)", value)
- v = self.cursor.execute("select * from t1").fetchone()[0]
- self.assertEqual(type(v), type(value))
+ result = self.cursor.execute("select * from t1").fetchone()[0]
+
+ if self.unicode and value != None:
+ self.assertEqual(type(result), unicode)
+ else:
+ self.assertEqual(type(result), type(value))
if value is not None:
- self.assertEqual(len(v), len(value))
+ self.assertEqual(len(result), len(value))
- self.assertEqual(v, value)
+ self.assertEqual(result, value)
#
# varchar
@@ -211,7 +216,7 @@ def test_fixed_str(self):
self.cursor.execute("create table t1(s char(7))")
self.cursor.execute("insert into t1 values(?)", "testing")
v = self.cursor.execute("select * from t1").fetchone()[0]
- self.assertEqual(type(v), str)
+ self.assertEqual(type(v), self.unicode and unicode or str)
self.assertEqual(len(v), len(value)) # If we alloc'd wrong, the test below might work because of an embedded NULL
self.assertEqual(v, value)
@@ -374,6 +379,7 @@ def main():
parser.add_option("-d", "--debug", action="store_true", default=False, help="Print debugging items")
parser.add_option("-t", "--test", help="Run only the named test")
parser.add_option('-a', '--ansi', help='ANSI only', default=False, action='store_true')
+ parser.add_option('-u', '--unicode', help='Expect results in Unicode', default=False, action='store_true')
(options, args) = parser.parse_args()
@@ -403,13 +409,13 @@ def main():
if not options.test.startswith('test_'):
options.test = 'test_%s' % (options.test)
- s = unittest.TestSuite([ PGTestCase(connection_string, options.ansi, options.test) ])
+ s = unittest.TestSuite([ PGTestCase(connection_string, options.ansi, options.unicode, options.test) ])
else:
# Run all tests in the class
methods = [ m for m in dir(PGTestCase) if m.startswith('test_') ]
methods.sort()
- s = unittest.TestSuite([ PGTestCase(connection_string, options.ansi, m) for m in methods ])
+ s = unittest.TestSuite([ PGTestCase(connection_string, options.ansi, options.unicode, m) for m in methods ])
testRunner = unittest.TextTestRunner(verbosity=options.verbose)
result = testRunner.run(s)
View
0 tests2/sqlitetests.py 100644 → 100755
No changes.
View
0 tests2/sqlservertests.py 100644 → 100755
No changes.
View
0 tests2/testbase.py 100644 → 100755
No changes.
View
0 tests2/testutils.py 100644 → 100755
No changes.

0 comments on commit 734f261

Please sign in to comment.