summaryrefslogtreecommitdiff
path: root/test/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-05-30 11:31:03 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-06-20 13:50:41 -0400
commit190e0139e834e4271268652e058c280787ae69eb (patch)
tree21e93907a58cd2f390f687ddc5e0c1da1eb25454 /test/engine
parentff8e7732b9f656f8cea05544660c18d57dd37864 (diff)
downloadsqlalchemy-190e0139e834e4271268652e058c280787ae69eb.tar.gz
Enable F841
This is a very useful assertion which prevents unused variables from being set up allows code to be more readable and sometimes even more efficient. test suites seem to be where the most problems are and there do not seem to be documentation examples that are using this, or at least the linter is not taking effect within rst blocks. Change-Id: I2b3341d8dd14da34879d8425838e66a4b9f8e27d
Diffstat (limited to 'test/engine')
-rw-r--r--test/engine/test_ddlevents.py46
-rw-r--r--test/engine/test_deprecations.py6
-rw-r--r--test/engine/test_execute.py4
-rw-r--r--test/engine/test_reconnect.py13
-rw-r--r--test/engine/test_reflection.py4
-rw-r--r--test/engine/test_transaction.py6
6 files changed, 37 insertions, 42 deletions
diff --git a/test/engine/test_ddlevents.py b/test/engine/test_ddlevents.py
index c9177e6ad..2fc054915 100644
--- a/test/engine/test_ddlevents.py
+++ b/test/engine/test_ddlevents.py
@@ -10,6 +10,7 @@ from sqlalchemy.schema import AddConstraint
from sqlalchemy.schema import CheckConstraint
from sqlalchemy.schema import DDL
from sqlalchemy.schema import DropConstraint
+from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import engines
from sqlalchemy.testing import eq_
@@ -494,7 +495,7 @@ class DDLExecutionTest(fixtures.TestBase):
assert "fnord" in strings
def test_conditional_constraint(self):
- metadata, users, engine = self.metadata, self.users, self.engine
+ metadata, users = self.metadata, self.users
nonpg_mock = engines.mock_engine(dialect_name="sqlite")
pg_mock = engines.mock_engine(dialect_name="postgresql")
constraint = CheckConstraint(
@@ -531,7 +532,7 @@ class DDLExecutionTest(fixtures.TestBase):
@testing.uses_deprecated(r".*use the DDLEvents")
def test_conditional_constraint_deprecated(self):
- metadata, users, engine = self.metadata, self.users, self.engine
+ metadata, users = self.metadata, self.users
nonpg_mock = engines.mock_engine(dialect_name="sqlite")
pg_mock = engines.mock_engine(dialect_name="postgresql")
constraint = CheckConstraint(
@@ -567,31 +568,32 @@ class DDLExecutionTest(fixtures.TestBase):
table = self.users
ddl = DDL("SELECT 1")
- for py in (
- "engine.execute(ddl)",
- "engine.execute(ddl, table)",
- "cx.execute(ddl)",
- "cx.execute(ddl, table)",
- "ddl.execute(engine)",
- "ddl.execute(engine, table)",
- "ddl.execute(cx)",
- "ddl.execute(cx, table)",
+ for spec in (
+ (engine.execute, ddl),
+ (engine.execute, ddl, table),
+ (cx.execute, ddl),
+ (cx.execute, ddl, table),
+ (ddl.execute, engine),
+ (ddl.execute, engine, table),
+ (ddl.execute, cx),
+ (ddl.execute, cx, table),
):
- r = eval(py)
- assert list(r) == [(1,)], py
+ fn = spec[0]
+ arg = spec[1:]
+ r = fn(*arg)
+ eq_(list(r), [(1,)])
- for py in ("ddl.execute()", "ddl.execute(target=table)"):
- try:
- r = eval(py)
- assert False
- except tsa.exc.UnboundExecutionError:
- pass
+ for fn, kw in ((ddl.execute, {}), (ddl.execute, dict(target=table))):
+ assert_raises(tsa.exc.UnboundExecutionError, fn, **kw)
for bind in engine, cx:
ddl.bind = bind
- for py in ("ddl.execute()", "ddl.execute(target=table)"):
- r = eval(py)
- assert list(r) == [(1,)], py
+ for fn, kw in (
+ (ddl.execute, {}),
+ (ddl.execute, dict(target=table)),
+ ):
+ r = fn(**kw)
+ eq_(list(r), [(1,)])
def test_platform_escape(self):
"""test the escaping of % characters in the DDL construct."""
diff --git a/test/engine/test_deprecations.py b/test/engine/test_deprecations.py
index 29bda0ac2..8bae599a9 100644
--- a/test/engine/test_deprecations.py
+++ b/test/engine/test_deprecations.py
@@ -576,8 +576,8 @@ class TLTransactionTest(fixtures.TestBase):
r1 = tlengine.execute(select([1]))
r2 = tlengine.execute(select([1]))
- row1 = r1.fetchone()
- row2 = r2.fetchone()
+ r1.fetchone()
+ r2.fetchone()
r1.close()
assert r2.connection is r1.connection
assert not r2.connection.closed
@@ -600,7 +600,7 @@ class TLTransactionTest(fixtures.TestBase):
def test_dispose(self):
with _tlengine_deprecated():
eng = testing_engine(options=dict(strategy="threadlocal"))
- result = eng.execute(select([1]))
+ eng.execute(select([1]))
eng.dispose()
eng.execute(select([1]))
diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py
index 480da7122..20c8ae659 100644
--- a/test/engine/test_execute.py
+++ b/test/engine/test_execute.py
@@ -1306,7 +1306,7 @@ class EngineEventsTest(fixtures.TestBase):
Engine._has_events = False
def _assert_stmts(self, expected, received):
- orig = list(received)
+ list(received)
for stmt, params, posn in expected:
if not received:
assert False, "Nothing available for stmt: %s" % stmt
@@ -2162,7 +2162,7 @@ class HandleErrorTest(fixtures.TestBase):
r"is.*(?:i_dont_exist|does not exist)",
py2konly=True,
):
- with patch.object(conn.dialect, "do_rollback", boom) as patched:
+ with patch.object(conn.dialect, "do_rollback", boom):
assert_raises_message(
tsa.exc.OperationalError,
"rollback failed",
diff --git a/test/engine/test_reconnect.py b/test/engine/test_reconnect.py
index dd2ebb1c4..14f3a7fd5 100644
--- a/test/engine/test_reconnect.py
+++ b/test/engine/test_reconnect.py
@@ -286,8 +286,6 @@ class MockReconnectTest(fixtures.TestBase):
connection, and additionally dispose the previous connection
pool and recreate."""
- db_pool = self.db.pool
-
# make a connection
conn = self.db.connect()
@@ -540,8 +538,6 @@ class MockReconnectTest(fixtures.TestBase):
dbapi = self.dbapi
- mock_dialect = Mock()
-
class MyURL(URL):
def _get_entrypoint(self):
return Dialect
@@ -553,9 +549,9 @@ class MockReconnectTest(fixtures.TestBase):
initialize = Mock()
engine = create_engine(MyURL("foo://"), module=dbapi)
- c1 = engine.connect()
+ engine.connect()
engine.dispose()
- c2 = engine.connect()
+ engine.connect()
eq_(Dialect.initialize.call_count, 1)
def test_invalidate_conn_w_contextmanager_interrupt(self):
@@ -752,7 +748,6 @@ class RealReconnectTest(fixtures.TestBase):
eq_(c1.execute(select([1])).scalar(), 1)
- p1 = self.engine.pool
self.engine.test_shutdown()
_assert_invalidated(c1.execute, select([1]))
@@ -844,7 +839,7 @@ class RealReconnectTest(fixtures.TestBase):
@testing.requires.savepoints
def test_rollback_on_invalid_savepoint(self):
conn = self.engine.connect()
- trans = conn.begin()
+ conn.begin()
trans2 = conn.begin_nested()
conn.invalidate()
trans2.rollback()
@@ -879,8 +874,6 @@ class RealReconnectTest(fixtures.TestBase):
engine.dialect.initialize = broken_initialize
- p1 = engine.pool
-
def is_disconnect(e, conn, cursor):
return True
diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py
index b414e15ad..8830033b3 100644
--- a/test/engine/test_reflection.py
+++ b/test/engine/test_reflection.py
@@ -1922,9 +1922,9 @@ class SchemaTest(fixtures.TestBase):
@testing.requires.implicit_default_schema
@testing.provide_metadata
def test_reflect_all_schemas_default_overlap(self):
- t1 = Table("t", self.metadata, Column("id", Integer, primary_key=True))
+ Table("t", self.metadata, Column("id", Integer, primary_key=True))
- t2 = Table(
+ Table(
"t",
self.metadata,
Column("id1", sa.ForeignKey("t.id")),
diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py
index f6f5cd9fc..9d4dcda9f 100644
--- a/test/engine/test_transaction.py
+++ b/test/engine/test_transaction.py
@@ -144,7 +144,7 @@ class TransactionTest(fixtures.TestBase):
trans2.rollback()
raise
transaction.rollback()
- except Exception as e:
+ except Exception:
transaction.rollback()
raise
except Exception as e:
@@ -316,7 +316,7 @@ class TransactionTest(fixtures.TestBase):
connection.execute(users.insert(), user_id=2, user_name="user2")
try:
connection.execute(users.insert(), user_id=2, user_name="user2.5")
- except Exception as e:
+ except Exception:
trans.__exit__(*sys.exc_info())
assert not trans.is_active
@@ -583,7 +583,7 @@ class TransactionTest(fixtures.TestBase):
with eng.connect() as conn:
rec = conn.connection._connection_record
raw_dbapi_con = rec.connection
- xa = conn.begin_twophase()
+ conn.begin_twophase()
conn.execute(users.insert(), user_id=1, user_name="user1")
assert rec.connection is raw_dbapi_con