Skip to content

Commit

Permalink
Upgrade Python syntax with pyupgrade --py38-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored and mkleehammer committed Oct 10, 2023
1 parent d84993b commit 36148c3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 25 deletions.
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# If pyodbc has not been installed in this virtual environment, add the appropriate build
# directory. This allows us to compile and run pytest without an install step in between
# slowing things down. If you are going to use this, do not install pyodbc. If you already
Expand Down
2 changes: 1 addition & 1 deletion tests/mysql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def test_emoticons_as_literal(cursor: pyodbc.Cursor):
assert result == v


@lru_cache()
@lru_cache
def _generate_str(length, encoding=None):
"""
Returns either a string or bytes, depending on whether encoding is provided,
Expand Down
16 changes: 8 additions & 8 deletions tests/old/accesstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ def _test_strtype(self, sqltype, value, colsize=None):
"""
The implementation for string, Unicode, and binary tests.
"""
assert colsize is None or (value is None or colsize >= len(value)), 'colsize=%s value=%s' % (colsize, (value is None) and 'none' or len(value))
assert colsize is None or (value is None or colsize >= len(value)), 'colsize={} value={}'.format(colsize, (value is None) and 'none' or len(value))

if colsize:
sql = "create table t1(n1 int not null, s1 %s(%s), s2 %s(%s))" % (sqltype, colsize, sqltype, colsize)
sql = "create table t1(n1 int not null, s1 {}({}), s2 {}({}))".format(sqltype, colsize, sqltype, colsize)
else:
sql = "create table t1(n1 int not null, s1 %s, s2 %s)" % (sqltype, sqltype)
sql = "create table t1(n1 int not null, s1 {}, s2 {})".format(sqltype, sqltype)

self.cursor.execute(sql)
self.cursor.execute("insert into t1 values(1, ?, ?)", (value, value))
Expand Down Expand Up @@ -263,7 +263,7 @@ def test_close_cnxn(self):


def test_unicode_query(self):
self.cursor.execute(u"select 1")
self.cursor.execute("select 1")

def test_negative_row_index(self):
self.cursor.execute("create table t1(s varchar(20))")
Expand Down Expand Up @@ -400,7 +400,7 @@ def test_bit_null(self):
self.assertEqual(False, result)

def test_guid(self):
value = u"de2ac9c6-8676-4b0b-b8a6-217a8580cbee"
value = "de2ac9c6-8676-4b0b-b8a6-217a8580cbee"
self.cursor.execute("create table t1(g1 uniqueidentifier)")
self.cursor.execute("insert into t1 values (?)", value)
v = self.cursor.execute("select * from t1").fetchone()[0]
Expand Down Expand Up @@ -566,8 +566,8 @@ def test_row_repr(self):


def test_concatenation(self):
v2 = u'0123456789' * 25
v3 = u'9876543210' * 25
v2 = '0123456789' * 25
v3 = '9876543210' * 25
value = v2 + 'x' + v3

self.cursor.execute("create table t1(c2 varchar(250), c3 varchar(250))")
Expand Down Expand Up @@ -609,7 +609,7 @@ def main():
shutil.copy(src, dest)

global CNXNSTRING
CNXNSTRING = 'DRIVER={%s};DBQ=%s;ExtendedAnsiSQL=1' % (DRIVERS[args.type], dest)
CNXNSTRING = 'DRIVER={{{}}};DBQ={};ExtendedAnsiSQL=1'.format(DRIVERS[args.type], dest)
print(CNXNSTRING)

if args.verbose:
Expand Down
5 changes: 2 additions & 3 deletions tests/old/sparktests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

usage = """\
%(prog)s [options] connection_string
Expand Down Expand Up @@ -150,7 +149,7 @@ def _test_strtype(self, sqltype, value, colsize=None, resulttype=None):
assert colsize is None or (value is None or colsize >= len(value))

if colsize:
sql = "create table t1(s %s(%s))" % (sqltype, colsize)
sql = "create table t1(s {}({}))".format(sqltype, colsize)
else:
sql = "create table t1(s %s)" % sqltype

Expand Down Expand Up @@ -326,7 +325,7 @@ def test_long_column_name(self):
self.cursor = self.cnxn.cursor()

self.cursor.execute("create table t1(c1 int, c2 int)")
self.cursor.execute("select c1 as {}, c2 as {} from t1".format(c1, c2))
self.cursor.execute(f"select c1 as {c1}, c2 as {c2} from t1")

names = [ t[0] for t in self.cursor.description ]
names.sort()
Expand Down
15 changes: 7 additions & 8 deletions tests/old/sqldwtests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

x = 1 # Getting an error if starting with usage for some reason.

Expand Down Expand Up @@ -74,7 +73,7 @@ def driver_type_is(self, type_name):
'freetds': 'FreeTDS ODBC',
}
if not type_name in recognized_types.keys():
raise KeyError('"{0}" is not a recognized driver type: {1}'.format(type_name, list(recognized_types.keys())))
raise KeyError(f'"{type_name}" is not a recognized driver type: {list(recognized_types.keys())}')
driver_name = self.cnxn.getinfo(pyodbc.SQL_DRIVER_NAME).lower()
if type_name == 'msodbcsql':
return ('msodbcsql' in driver_name) or ('sqlncli' in driver_name) or ('sqlsrv32.dll' == driver_name)
Expand Down Expand Up @@ -225,7 +224,7 @@ def _test_strtype(self, sqltype, value, resulttype=None, colsize=None):
assert colsize is None or (value is None or colsize >= len(value))

if colsize:
sql = "create table t1(s %s(%s))" % (sqltype, colsize)
sql = "create table t1(s {}({}))".format(sqltype, colsize)
else:
sql = "create table t1(s %s)" % sqltype
if colsize >= 2000 and (sqltype == 'nvarchar' or sqltype == 'varchar'):
Expand Down Expand Up @@ -280,7 +279,7 @@ def _test_strliketype(self, sqltype, value, resulttype=None, colsize=None):
assert colsize is None or (value is None or colsize >= len(value))

if colsize:
sql = "create table t1(s %s(%s))" % (sqltype, colsize)
sql = "create table t1(s {}({}))".format(sqltype, colsize)
else:
sql = "create table t1(s %s)" % sqltype

Expand Down Expand Up @@ -362,11 +361,11 @@ def t(self):

def test_chinese(self):
v = '我的'
self.cursor.execute(u"SELECT N'我的' AS [Name]")
self.cursor.execute("SELECT N'我的' AS [Name]")
row = self.cursor.fetchone()
self.assertEqual(row[0], v)

self.cursor.execute(u"SELECT N'我的' AS [Name]")
self.cursor.execute("SELECT N'我的' AS [Name]")
rows = self.cursor.fetchall()
self.assertEqual(rows[0][0], v)

Expand Down Expand Up @@ -443,7 +442,7 @@ def test_bit(self):
def _decimal(self, precision, scale, negative):
# From test provided by planders (thanks!) in Issue 91

self.cursor.execute("create table t1(d decimal(%s, %s))" % (precision, scale))
self.cursor.execute("create table t1(d decimal({}, {}))".format(precision, scale))

# Construct a decimal that uses the maximum precision and scale.
decStr = '9' * (precision - scale)
Expand Down Expand Up @@ -475,7 +474,7 @@ def t(self):
(38, 0, True),
(38, 10, True),
(38, 38, True) ]:
locals()['test_decimal_%s_%s_%s' % (p, s, n and 'n' or 'p')] = _maketest(p, s, n)
locals()['test_decimal_{}_{}_{}'.format(p, s, n and 'n' or 'p')] = _maketest(p, s, n)


def test_decimal_e(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/old/sqlitetests.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _test_strtype(self, sqltype, value, colsize=None):
assert colsize is None or (value is None or colsize >= len(value))

if colsize:
sql = "create table t1(s %s(%s))" % (sqltype, colsize)
sql = "create table t1(s {}({}))".format(sqltype, colsize)
else:
sql = "create table t1(s %s)" % sqltype

Expand Down Expand Up @@ -162,7 +162,7 @@ def _test_strliketype(self, sqltype, value, colsize=None):
assert colsize is None or (value is None or colsize >= len(value))

if colsize:
sql = "create table t1(s %s(%s))" % (sqltype, colsize)
sql = "create table t1(s {}({}))".format(sqltype, colsize)
else:
sql = "create table t1(s %s)" % sqltype

Expand Down
3 changes: 1 addition & 2 deletions tests/sqlserver_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, uuid, re, sys
from decimal import Decimal
Expand Down Expand Up @@ -1601,7 +1600,7 @@ def get_sqlserver_version(cursor: pyodbc.Cursor):
return int(row.Character_Value.split('.', 1)[0])


@lru_cache()
@lru_cache
def _generate_str(length, encoding=None):
"""
Returns either a string or bytes, depending on whether encoding is provided,
Expand Down

0 comments on commit 36148c3

Please sign in to comment.