diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-05-30 11:31:03 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-06-20 13:50:41 -0400 |
| commit | 190e0139e834e4271268652e058c280787ae69eb (patch) | |
| tree | 21e93907a58cd2f390f687ddc5e0c1da1eb25454 /test/sql | |
| parent | ff8e7732b9f656f8cea05544660c18d57dd37864 (diff) | |
| download | sqlalchemy-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/sql')
| -rw-r--r-- | test/sql/test_compare.py | 29 | ||||
| -rw-r--r-- | test/sql/test_constraints.py | 2 | ||||
| -rw-r--r-- | test/sql/test_deprecations.py | 10 | ||||
| -rw-r--r-- | test/sql/test_generative.py | 39 | ||||
| -rw-r--r-- | test/sql/test_metadata.py | 8 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 21 | ||||
| -rw-r--r-- | test/sql/test_text.py | 4 |
7 files changed, 49 insertions, 64 deletions
diff --git a/test/sql/test_compare.py b/test/sql/test_compare.py index f2feea757..f9decc58a 100644 --- a/test/sql/test_compare.py +++ b/test/sql/test_compare.py @@ -444,8 +444,6 @@ class CompareAndCopyTest(fixtures.TestBase): stmt2 = union(select([table_a]), select([table_b])) - stmt3 = select([table_b]) - equivalents = {table_a.c.a: [table_b.c.a]} is_false( @@ -577,8 +575,7 @@ class CompareClausesTest(fixtures.TestBase): def test_compare_binds(self): b1 = bindparam("foo", type_=Integer()) b2 = bindparam("foo", type_=Integer()) - b3 = bindparam("bar", type_=Integer()) - b4 = bindparam("foo", type_=String()) + b3 = bindparam("foo", type_=String()) def c1(): return 5 @@ -586,26 +583,26 @@ class CompareClausesTest(fixtures.TestBase): def c2(): return 6 - b5 = bindparam("foo", type_=Integer(), callable_=c1) - b6 = bindparam("foo", type_=Integer(), callable_=c2) - b7 = bindparam("foo", type_=Integer(), callable_=c1) + b4 = bindparam("foo", type_=Integer(), callable_=c1) + b5 = bindparam("foo", type_=Integer(), callable_=c2) + b6 = bindparam("foo", type_=Integer(), callable_=c1) - b8 = bindparam("foo", type_=Integer, value=5) - b9 = bindparam("foo", type_=Integer, value=6) + b7 = bindparam("foo", type_=Integer, value=5) + b8 = bindparam("foo", type_=Integer, value=6) - is_false(b1.compare(b5)) - is_true(b5.compare(b7)) - is_false(b5.compare(b6)) + is_false(b1.compare(b4)) + is_true(b4.compare(b6)) + is_false(b4.compare(b5)) is_true(b1.compare(b2)) # currently not comparing "key", as we often have to compare # anonymous names. however we should really check for that # is_true(b1.compare(b3)) - is_false(b1.compare(b4)) - is_false(b1.compare(b8)) - is_false(b8.compare(b9)) - is_true(b8.compare(b8)) + is_false(b1.compare(b3)) + is_false(b1.compare(b7)) + is_false(b7.compare(b8)) + is_true(b7.compare(b7)) def test_compare_tables(self): is_true(table_a.compare(table_a_2)) diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index fdc973156..d22388f44 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -850,7 +850,7 @@ class ConstraintCompilationTest(fixtures.TestBase, AssertsCompiledSQL): def test_index_against_text_inline(self): metadata = MetaData() idx = Index("y", text("some_function(q)")) - x = Table("x", metadata, Column("q", String(50)), idx) + Table("x", metadata, Column("q", String(50)), idx) self.assert_compile( schema.CreateIndex(idx), "CREATE INDEX y ON x (some_function(q))" diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 90646c41d..6bf0e8962 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -102,14 +102,14 @@ class DeprecationWarningsTest(fixtures.TestBase): "The select.autocommit parameter is deprecated and " "will be removed in a future release." ): - stmt = select([column("x")], autocommit=True) + select([column("x")], autocommit=True) def test_select_for_update(self): with testing.expect_deprecated( "The select.for_update parameter is deprecated and " "will be removed in a future release." ): - stmt = select([column("x")], for_update=True) + select([column("x")], for_update=True) @testing.provide_metadata def test_table_useexisting(self): @@ -153,7 +153,7 @@ class DDLListenerDeprecationsTest(fixtures.TestBase): ) def test_append_listener(self): - metadata, table, bind = self.metadata, self.table, self.bind + metadata, table = self.metadata, self.table def fn(*a): return None @@ -209,7 +209,7 @@ class DDLListenerDeprecationsTest(fixtures.TestBase): assert "fnord" in canary def test_deprecated_append_ddl_listener_metadata(self): - metadata, users, engine = self.metadata, self.users, self.engine + metadata, engine = self.metadata, self.engine canary = [] with testing.expect_deprecated(".* is deprecated .*"): metadata.append_ddl_listener( @@ -551,7 +551,7 @@ class TextTest(fixtures.TestBase, AssertsCompiledSQL): with testing.expect_deprecated( "The text.autocommit parameter is deprecated" ): - t = text("select id, name from user", autocommit=True) + text("select id, name from user", autocommit=True) table1 = table( diff --git a/test/sql/test_generative.py b/test/sql/test_generative.py index da139d7c0..3bf6c7056 100644 --- a/test/sql/test_generative.py +++ b/test/sql/test_generative.py @@ -366,7 +366,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): assert str(clause2) == str(t1.join(t2, t1.c.col2 == t2.c.col3)) def test_aliased_column_adapt(self): - clause = t1.select() + t1.select() aliased = t1.select().alias() aliased2 = t1.alias() @@ -1218,14 +1218,6 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( - select([literal_column("*")], t1.c.col1 == t2.c.col2), - "SELECT * FROM table1, table2 WHERE table1.col1 = table2.col2", - ) - - def test_table_to_alias_4(self): - t1alias = t1.alias("t1alias") - vis = sql_util.ClauseAdapter(t1alias) - self.assert_compile( vis.traverse( select([literal_column("*")], t1.c.col1 == t2.c.col2) ), @@ -1233,7 +1225,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "WHERE t1alias.col1 = table2.col2", ) - def test_table_to_alias_5(self): + def test_table_to_alias_4(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( @@ -1248,7 +1240,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "WHERE t1alias.col1 = table2.col2", ) - def test_table_to_alias_6(self): + def test_table_to_alias_5(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( @@ -1270,7 +1262,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "(SELECT * FROM table2 WHERE t1alias.col1 = table2.col2)", ) - def test_table_to_alias_7(self): + def test_table_to_alias_6(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( @@ -1294,7 +1286,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "WHERE t1alias.col1 = table2.col2)", ) - def test_table_to_alias_8(self): + def test_table_to_alias_7(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( @@ -1303,7 +1295,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "t1alias.col2 ELSE t1alias.col1 END", ) - def test_table_to_alias_9(self): + def test_table_to_alias_8(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) self.assert_compile( @@ -1314,13 +1306,13 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "t1alias.col2 ELSE t1alias.col1 END", ) - def test_table_to_alias_10(self): + def test_table_to_alias_9(self): s = select([literal_column("*")], from_obj=[t1]).alias("foo") self.assert_compile( s.select(), "SELECT foo.* FROM (SELECT * FROM table1) " "AS foo" ) - def test_table_to_alias_11(self): + def test_table_to_alias_10(self): s = select([literal_column("*")], from_obj=[t1]).alias("foo") t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) @@ -1329,13 +1321,13 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "SELECT foo.* FROM (SELECT * FROM table1 " "AS t1alias) AS foo", ) - def test_table_to_alias_12(self): + def test_table_to_alias_11(self): s = select([literal_column("*")], from_obj=[t1]).alias("foo") self.assert_compile( s.select(), "SELECT foo.* FROM (SELECT * FROM table1) " "AS foo" ) - def test_table_to_alias_13(self): + def test_table_to_alias_12(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) ff = vis.traverse(func.count(t1.c.col1).label("foo")) @@ -1350,7 +1342,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): # .col1).l abel('foo')]), clone=True), "SELECT # count(t1alias.col1) AS foo FROM table1 AS t1alias") - def test_table_to_alias_14(self): + def test_table_to_alias_13(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) t2alias = t2.alias("t2alias") @@ -1364,7 +1356,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "t2alias.col2", ) - def test_table_to_alias_15(self): + def test_table_to_alias_14(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) t2alias = t2.alias("t2alias") @@ -1378,7 +1370,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "t2alias.col2", ) - def test_table_to_alias_16(self): + def test_table_to_alias_15(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) t2alias = t2.alias("t2alias") @@ -1400,7 +1392,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "WHERE t1alias.col1 = t2alias.col2)", ) - def test_table_to_alias_17(self): + def test_table_to_alias_16(self): t1alias = t1.alias("t1alias") vis = sql_util.ClauseAdapter(t1alias) t2alias = t2.alias("t2alias") @@ -1649,9 +1641,6 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): "WHERE c.bid = anon_1.b_aid", ) - t1 = table("table1", column("col1"), column("col2"), column("col3")) - t2 = table("table2", column("col1"), column("col2"), column("col3")) - def test_label_anonymize_one(self): t1a = t1.alias() adapter = sql_util.ClauseAdapter(t1a, anonymize_labels=True) diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 3f9667609..0d3a04430 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -398,7 +398,7 @@ class MetaDataTest(fixtures.TestBase, ComparesTables): a = Table("a", meta, Column("a", Integer)) a.append_constraint(ForeignKeyConstraint(["a"], ["b.x"])) - b = Table("b", meta, Column("b", Integer)) + Table("b", meta, Column("b", Integer)) assert_raises_message( exc.NoReferencedColumnError, @@ -477,7 +477,7 @@ class MetaDataTest(fixtures.TestBase, ComparesTables): def test_sequence_attach_to_table(self): m1 = MetaData() s1 = Sequence("s") - t = Table("a", m1, Column("x", Integer, s1)) + Table("a", m1, Column("x", Integer, s1)) assert s1.metadata is m1 def test_sequence_attach_to_existing_table(self): @@ -2044,7 +2044,7 @@ class SchemaTypeTest(fixtures.TestBase): type_ = self.WrapBoolean() y = Column("y", type_) y_copy = y.copy() - t1 = Table("x", m, y_copy) + Table("x", m, y_copy) is_true(y_copy.type._create_events) @@ -3750,7 +3750,7 @@ class ColumnOptionsTest(fixtures.TestBase): def _no_error(self, col): m = MetaData() - b = Table("bar", m, Column("id", Integer)) + Table("bar", m, Column("id", Integer)) t = Table("t", m, col) schema.CreateTable(t).compile() diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index f525703f1..bfa96d766 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -235,7 +235,6 @@ class SelectableTest( s1c1 = s1._clone() s1c2 = s1._clone() s2c1 = s2._clone() - s2c2 = s2._clone() s3c1 = s3._clone() eq_( @@ -658,7 +657,7 @@ class SelectableTest( def test_scalar_cloned_comparator(self): sel = select([table1.c.col1]).scalar_subquery() - expr = sel == table1.c.col1 + sel == table1.c.col1 sel2 = visitors.ReplacingCloningVisitor().traverse(sel) @@ -773,7 +772,7 @@ class SelectableTest( c1 = Column("c1", Integer) c2 = Column("c2", Integer) - s = select([c1]) + select([c1]) t = Table("t", MetaData(), c1, c2) @@ -787,7 +786,7 @@ class SelectableTest( c1 = Column("c1", Integer) c2 = Column("c2", Integer) - s = select([c1]).where(c1 == 5) + select([c1]).where(c1 == 5) t = Table("t", MetaData(), c1, c2) @@ -802,7 +801,7 @@ class SelectableTest( t1 = Table("t1", m, Column("x", Integer)) c1 = Column("c1", Integer) - s = select([c1]).where(c1 == 5).select_from(t1) + select([c1]).where(c1 == 5).select_from(t1) t2 = Table("t2", MetaData(), c1) @@ -1094,7 +1093,7 @@ class AnonLabelTest(fixtures.TestBase): assert c1.label(None) is not c1 eq_(str(select([c1])), "SELECT count(:count_2) AS count_1") - c2 = select([c1]).compile() + select([c1]).compile() eq_(str(select([c1.label(None)])), "SELECT count(:count_2) AS count_1") @@ -2008,7 +2007,7 @@ class AnnotationsTest(fixtures.TestBase): pass col = MyColumn("x", Integer) - binary_1 = col == 5 + col == 5 col_anno = MyColumn("x", Integer)._annotate({"foo": "bar"}) binary_2 = col_anno == 5 eq_(binary_2.left._annotations, {"foo": "bar"}) @@ -2275,10 +2274,10 @@ class AnnotationsTest(fixtures.TestBase): c = column("a") c1 = c._annotate({"foo": "bar"}) - comp1 = c1.comparator + c1.comparator c2 = c1._annotate({"bat": "hoho"}) - comp2 = c2.comparator + c2.comparator assert (c2 == 5).left._annotations == {"foo": "bar", "bat": "hoho"} @@ -2491,7 +2490,7 @@ class ResultMapTest(fixtures.TestBase): def test_select_table_alias_column(self): t = self._fixture() - x, y = t.c.x, t.c.y + x = t.c.x ta = t.alias() s = select([ta.c.x, ta.c.y]) @@ -2500,7 +2499,7 @@ class ResultMapTest(fixtures.TestBase): def test_select_label_alt_name_table_alias_column(self): t = self._fixture() - x, y = t.c.x, t.c.y + x = t.c.x ta = t.alias() l1, l2 = ta.c.x.label("a"), ta.c.y.label("b") diff --git a/test/sql/test_text.py b/test/sql/test_text.py index f6b3b0519..4be53b2eb 100644 --- a/test/sql/test_text.py +++ b/test/sql/test_text.py @@ -514,7 +514,7 @@ class AsFromTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_table_alias_column(self): t = self._xy_table_fixture() - x, y = t.c.x, t.c.y + x = t.c.x ta = t.alias() s = text("select ta.x, ta.y FROM t AS ta").columns(ta.c.x, ta.c.y) @@ -523,7 +523,7 @@ class AsFromTest(fixtures.TestBase, AssertsCompiledSQL): def test_select_label_alt_name_table_alias_column(self): t = self._xy_table_fixture() - x, y = t.c.x, t.c.y + x = t.c.x ta = t.alias() l1, l2 = ta.c.x.label("a"), ta.c.y.label("b") |
