From fc2f432d9d9864a8f7868c89f4617f80002f3f48 Mon Sep 17 00:00:00 2001 From: Pedro Aquilino Date: Thu, 13 Jul 2023 13:53:37 +0200 Subject: [PATCH] sqlalchemy 2.0 support - flake8 --- tests/drivers/asynch/test_cursor.py | 4 +++- tests/drivers/http/test_cursor.py | 8 ++++++-- tests/drivers/native/test_cursor.py | 4 +++- tests/engines/test_reflection.py | 18 +++++++++++++++--- tests/sql/test_schema.py | 7 +++++-- tests/test_ddl.py | 6 +++--- tests/testcase.py | 4 +++- 7 files changed, 38 insertions(+), 13 deletions(-) diff --git a/tests/drivers/asynch/test_cursor.py b/tests/drivers/asynch/test_cursor.py index 96a8861c..c2a723be 100644 --- a/tests/drivers/asynch/test_cursor.py +++ b/tests/drivers/asynch/test_cursor.py @@ -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) diff --git a/tests/drivers/http/test_cursor.py b/tests/drivers/http/test_cursor.py index 5832cd7b..b673c8a7 100644 --- a/tests/drivers/http/test_cursor.py +++ b/tests/drivers/http/test_cursor.py @@ -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)]) diff --git a/tests/drivers/native/test_cursor.py b/tests/drivers/native/test_cursor.py index 3ee07f87..e4239e8f 100644 --- a/tests/drivers/native/test_cursor.py +++ b/tests/drivers/native/test_cursor.py @@ -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)]) diff --git a/tests/engines/test_reflection.py b/tests/engines/test_reflection.py index 628f8775..d24756fe 100644 --- a/tests/engines/test_reflection.py +++ b/tests/engines/test_reflection.py @@ -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): @@ -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) @@ -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): diff --git a/tests/sql/test_schema.py b/tests/sql/test_schema.py index 331ad148..63f4abfb 100644 --- a/tests/sql/test_schema.py +++ b/tests/sql/test_schema.py @@ -82,7 +82,11 @@ 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): @@ -90,7 +94,6 @@ def test_reflect_subquery(self): '(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( diff --git a/tests/test_ddl.py b/tests/test_ddl.py index 8dc52605..10f8b932 100644 --- a/tests/test_ddl.py +++ b/tests/test_ddl.py @@ -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' @@ -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() ) @@ -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() ) diff --git a/tests/testcase.py b/tests/testcase.py index cfb4631f..f44c9025 100644 --- a/tests/testcase.py +++ b/tests/testcase.py @@ -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()