Skip to content

Commit

Permalink
Adjust test_columns() in tests3/pgtests.py for newer driver versions
Browse files Browse the repository at this point in the history
Fixes: #1003
  • Loading branch information
gordthompson authored and mkleehammer committed Mar 27, 2022
1 parent b7cbf90 commit 8228dbc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tests3/pgtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,15 @@ def test_cnxn_set_attr(self):
SQL_MODE_READ_ONLY = 1
self.cnxn.set_attr(SQL_ATTR_ACCESS_MODE, SQL_MODE_READ_ONLY)


def test_columns(self):

def _get_column_size(row):
driver_version = tuple(
int(x) for x in self.cnxn.getinfo(pyodbc.SQL_DRIVER_VER).split(".")
)
return row.column_size if driver_version >= (13, 2, 0) else row.precision

# When using aiohttp, `await cursor.primaryKeys('t1')` was raising the error
#
# Error: TypeError: argument 2 must be str, not None
Expand All @@ -575,10 +583,10 @@ def test_columns(self):
assert row.type_name == 'int4', row.type_name
row = results['b']
assert row.type_name == 'varchar'
assert row.precision == 3, row.precision
assert _get_column_size(row) == 3, _get_column_size(row)
row = results['xΏz']
assert row.type_name == 'varchar'
assert row.precision == 4, row.precision
assert _get_column_size(row) == 4, _get_column_size(row)

# Now do the same, but specifically pass in None to one of the keywords. Old versions
# were parsing arguments incorrectly and would raise an error. (This crops up when
Expand All @@ -590,7 +598,7 @@ def test_columns(self):
assert row.type_name == 'int4', row.type_name
row = results['b']
assert row.type_name == 'varchar'
assert row.precision == 3
assert _get_column_size(row) == 3

def test_cancel(self):
# I'm not sure how to reliably cause a hang to cancel, so for now we'll settle with
Expand Down Expand Up @@ -695,7 +703,7 @@ def convert(value):
self.cnxn.add_output_converter(pyodbc.SQL_WVARCHAR, None)
value = self.cursor.execute("select v from t1").fetchone()[0]
self.assertEqual(value, '123.45')

def main():
from optparse import OptionParser
parser = OptionParser(usage="usage: %prog [options] connection_string")
Expand Down

0 comments on commit 8228dbc

Please sign in to comment.