Skip to content

Commit

Permalink
sqlalchemy 2.0 support
Browse files Browse the repository at this point in the history
- flake8
  • Loading branch information
PedroAquilino committed Jul 13, 2023
1 parent 1d441b6 commit fc2f432
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
4 changes: 3 additions & 1 deletion tests/drivers/asynch/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ async def test_execute_without_context(self):

@run_async
async def test_execute_with_context(self):
rv = await self.session.execute(text('SELECT * FROM system.numbers LIMIT 1'))
rv = await self.session.execute(
text('SELECT * FROM system.numbers LIMIT 1')
)

self.assertEqual(len(rv.fetchall()), 1)

Expand Down
8 changes: 6 additions & 2 deletions tests/drivers/http/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

class CursorTestCase(HttpSessionTestCase, HttpEngineTestCase):
def test_check_iter_cursor_by_session(self):
rv = self.session.execute(text('SELECT number FROM system.numbers LIMIT 5'))
rv = self.session.execute(
text('SELECT number FROM system.numbers LIMIT 5')
)
self.assertListEqual(list(rv), [(x,) for x in range(5)])

def test_check_iter_cursor_by_engine(self):
with self.engine.connect() as conn:
rv = conn.execute(text('SELECT number FROM system.numbers LIMIT 5'))
rv = conn.execute(
text('SELECT number FROM system.numbers LIMIT 5')
)
self.assertListEqual(list(rv), [(x,) for x in range(5)])
4 changes: 3 additions & 1 deletion tests/drivers/native/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ def test_execute_with_context(self):
self.assertEqual(len(rv.fetchall()), 1)

def test_check_iter_cursor(self):
rv = self.session.execute(text('SELECT number FROM system.numbers LIMIT 5'))
rv = self.session.execute(
text('SELECT number FROM system.numbers LIMIT 5')
)
self.assertListEqual(list(rv), [(x,) for x in range(5)])
18 changes: 15 additions & 3 deletions tests/engines/test_reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def _test_table(self, engine, *columns):
with self.create_table(table):
metadata.clear() # reflect from clean state
self.assertFalse(metadata.tables)
table = Table('test_reflect', metadata, autoload_with=self.session.bind)
table = Table(
'test_reflect',
metadata,
autoload_with=self.session.bind
)
yield table, table.engine

def assertColumns(self, first, second, msg=None):
Expand Down Expand Up @@ -188,7 +192,11 @@ def test_create_reflected(self):
with self.create_table(table):
metadata.clear() # reflect from clean state
self.assertFalse(metadata.tables)
table = Table('test_reflect', metadata, autoload_with=self.session.connection())
table = Table(
'test_reflect',
metadata,
autoload_with=self.session.connection()
)

exists_query = text('EXISTS TABLE test_reflect')
table.drop(bind=self.session.bind)
Expand All @@ -215,7 +223,11 @@ def test_disable_engine_reflection(self):
with self.create_table(table):
metadata.clear() # reflect from clean state
self.assertFalse(metadata.tables)
table = Table('test_reflect', metadata, autoload_with=session.connection())
table = Table(
'test_reflect',
metadata,
autoload_with=session.connection()
)
self.assertIsNone(getattr(table, 'engine', None))

def test_exists_describe_escaping(self):
Expand Down
7 changes: 5 additions & 2 deletions tests/sql/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ def test_reflect_generic_table(self):
metadata.clear() # reflect from clean state
self.assertFalse(metadata.tables)

table = Table('test_reflect', metadata, autoload_with=self.session.bind)
table = Table(
'test_reflect',
metadata,
autoload_with=self.session.bind
)
self.assertListEqual([c.name for c in table.columns], ['x'])

def test_reflect_subquery(self):
table_node_sql = (
'(select arrayJoin([1, 2]) as a, arrayJoin([3, 4]) as b)')
table_node = TextClause(table_node_sql)

metadata = self.metadata()
# Cannot use `Table` as it only works with a simple string.
columns = inspect(self.session.bind).get_columns(table_node)
self.assertListEqual(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class GroupedStatistics(Base):

def test_create_table_with_comment(self):
table = Table(
't1', self.metadata(session=self.session),
't1', self.metadata(),
Column('x', types.Int32, primary_key=True),
engines.Memory(),
comment='table_comment'
Expand All @@ -472,7 +472,7 @@ def test_create_table_with_comment(self):

def test_create_table_with_column_comment(self):
table = Table(
't1', self.metadata(session=self.session),
't1', self.metadata(),
Column('x', types.Int32, primary_key=True, comment='col_comment'),
engines.Memory()
)
Expand All @@ -484,7 +484,7 @@ def test_create_table_with_column_comment(self):

def test_do_not_render_fk(self):
table = Table(
't1', self.metadata(session=self.session),
't1', self.metadata(),
Column('x', types.Int32, ForeignKey('t2.x'), primary_key=True),
engines.Memory()
)
Expand Down
4 changes: 3 additions & 1 deletion tests/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def setUpClass(cls):
text('CREATE DATABASE {}'.format(cls.database))
)

version = system_native_session.execute(text('SELECT version()')).fetchall()
version = system_native_session.execute(
text('SELECT version()')
).fetchall()
cls.server_version = tuple(int(x) for x in version[0][0].split('.'))

super().setUpClass()
Expand Down

0 comments on commit fc2f432

Please sign in to comment.