diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2022-11-03 20:52:21 +0100 |
|---|---|---|
| committer | Federico Caselli <cfederico87@gmail.com> | 2022-11-16 23:03:04 +0100 |
| commit | 4eb4ceca36c7ce931ea65ac06d6ed08bf459fc66 (patch) | |
| tree | 4970cff3f78489a4a0066cd27fd4bae682402957 /test/sql | |
| parent | 3fc6c40ea77c971d3067dab0fdf57a5b5313b69b (diff) | |
| download | sqlalchemy-4eb4ceca36c7ce931ea65ac06d6ed08bf459fc66.tar.gz | |
Try running pyupgrade on the code
command run is "pyupgrade --py37-plus --keep-runtime-typing --keep-percent-format <files...>"
pyupgrade will change assert_ to assertTrue. That was reverted since assertTrue does not
exists in sqlalchemy fixtures
Change-Id: Ie1ed2675c7b11d893d78e028aad0d1576baebb55
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_compare.py | 4 | ||||
| -rw-r--r-- | test/sql/test_compiler.py | 26 | ||||
| -rw-r--r-- | test/sql/test_computed.py | 1 | ||||
| -rw-r--r-- | test/sql/test_constraints.py | 16 | ||||
| -rw-r--r-- | test/sql/test_defaults.py | 6 | ||||
| -rw-r--r-- | test/sql/test_delete.py | 2 | ||||
| -rw-r--r-- | test/sql/test_deprecations.py | 2 | ||||
| -rw-r--r-- | test/sql/test_external_traversal.py | 16 | ||||
| -rw-r--r-- | test/sql/test_functions.py | 2 | ||||
| -rw-r--r-- | test/sql/test_insert.py | 29 | ||||
| -rw-r--r-- | test/sql/test_labels.py | 2 | ||||
| -rw-r--r-- | test/sql/test_metadata.py | 30 | ||||
| -rw-r--r-- | test/sql/test_operators.py | 16 | ||||
| -rw-r--r-- | test/sql/test_query.py | 78 | ||||
| -rw-r--r-- | test/sql/test_quote.py | 10 | ||||
| -rw-r--r-- | test/sql/test_resultset.py | 16 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 54 | ||||
| -rw-r--r-- | test/sql/test_text.py | 10 | ||||
| -rw-r--r-- | test/sql/test_types.py | 21 | ||||
| -rw-r--r-- | test/sql/test_update.py | 4 |
20 files changed, 140 insertions, 205 deletions
diff --git a/test/sql/test_compare.py b/test/sql/test_compare.py index 30ca5c569..f18c79c7b 100644 --- a/test/sql/test_compare.py +++ b/test/sql/test_compare.py @@ -1261,7 +1261,7 @@ class CompareAndCopyTest(CoreFixtures, fixtures.TestBase): also included in the fixtures above. """ - need = set( + need = { cls for cls in class_hierarchy(ClauseElement) if issubclass(cls, (ColumnElement, Selectable, LambdaElement)) @@ -1275,7 +1275,7 @@ class CompareAndCopyTest(CoreFixtures, fixtures.TestBase): and "compiler" not in cls.__module__ and "crud" not in cls.__module__ and "dialects" not in cls.__module__ # TODO: dialects? - ).difference({ColumnElement, UnaryExpression}) + }.difference({ColumnElement, UnaryExpression}) for fixture in self.fixtures + self.dont_compare_values_fixtures: case_a = fixture() diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 4eea11795..e5a149c49 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -1,5 +1,3 @@ -#! coding:utf-8 - """ compiler tests. @@ -2099,10 +2097,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_custom_order_by_clause(self): class CustomCompiler(PGCompiler): def order_by_clause(self, select, **kw): - return ( - super(CustomCompiler, self).order_by_clause(select, **kw) - + " CUSTOMIZED" - ) + return super().order_by_clause(select, **kw) + " CUSTOMIZED" class CustomDialect(PGDialect): name = "custom" @@ -2119,10 +2114,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): def test_custom_group_by_clause(self): class CustomCompiler(PGCompiler): def group_by_clause(self, select, **kw): - return ( - super(CustomCompiler, self).group_by_clause(select, **kw) - + " CUSTOMIZED" - ) + return super().group_by_clause(select, **kw) + " CUSTOMIZED" class CustomDialect(PGDialect): name = "custom" @@ -3777,9 +3769,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): class MyCompiler(compiler.SQLCompiler): def bindparam_string(self, name, **kw): kw["escaped_from"] = name - return super(MyCompiler, self).bindparam_string( - '"%s"' % name, **kw - ) + return super().bindparam_string('"%s"' % name, **kw) dialect = default.DefaultDialect() dialect.statement_compiler = MyCompiler @@ -3863,7 +3853,7 @@ class BindParameterTest(AssertsCompiledSQL, fixtures.TestBase): total_params = 100000 in_clause = [":in%d" % i for i in range(total_params)] - params = dict(("in%d" % i, i) for i in range(total_params)) + params = {"in%d" % i: i for i in range(total_params)} t = text("text clause %s" % ", ".join(in_clause)) eq_(len(t.bindparams), total_params) c = t.compile() @@ -6590,7 +6580,7 @@ class ResultMapTest(fixtures.TestBase): comp = stmt.compile() eq_( set(comp._create_result_map()), - set(["t1_1_b", "t1_1_a", "t1_a", "t1_b"]), + {"t1_1_b", "t1_1_a", "t1_a", "t1_b"}, ) is_(comp._create_result_map()["t1_a"][1][2], t1.c.a) @@ -6643,14 +6633,12 @@ class ResultMapTest(fixtures.TestBase): if stmt is stmt2.element: with self._nested_result() as nested: contexts[stmt2.element] = nested - text = super(MyCompiler, self).visit_select( + text = super().visit_select( stmt2.element, ) self._add_to_result_map("k1", "k1", (1, 2, 3), int_) else: - text = super(MyCompiler, self).visit_select( - stmt, *arg, **kw - ) + text = super().visit_select(stmt, *arg, **kw) self._add_to_result_map("k2", "k2", (3, 4, 5), int_) return text diff --git a/test/sql/test_computed.py b/test/sql/test_computed.py index 886aa13b9..8fcfeff73 100644 --- a/test/sql/test_computed.py +++ b/test/sql/test_computed.py @@ -1,4 +1,3 @@ -# coding: utf-8 from sqlalchemy import Column from sqlalchemy import Computed from sqlalchemy import Integer diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index b1b731d66..dbdab3307 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -705,15 +705,13 @@ class ConstraintGenTest(fixtures.TestBase, AssertsExecutionResults): Index("idx_winners", events.c.winner) eq_( - set(ix.name for ix in events.indexes), - set( - [ - "ix_events_name", - "ix_events_location", - "sport_announcer", - "idx_winners", - ] - ), + {ix.name for ix in events.indexes}, + { + "ix_events_name", + "ix_events_location", + "sport_announcer", + "idx_winners", + }, ) self.assert_sql_execution( diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index 1249529f3..cc7daf401 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -552,14 +552,14 @@ class DefaultRoundTripTest(fixtures.TablesTest): assert r.lastrow_has_defaults() eq_( set(r.context.postfetch_cols), - set([t.c.col3, t.c.col5, t.c.col4, t.c.col6]), + {t.c.col3, t.c.col5, t.c.col4, t.c.col6}, ) r = connection.execute(t.insert().inline()) assert r.lastrow_has_defaults() eq_( set(r.context.postfetch_cols), - set([t.c.col3, t.c.col5, t.c.col4, t.c.col6]), + {t.c.col3, t.c.col5, t.c.col4, t.c.col6}, ) connection.execute(t.insert()) @@ -599,7 +599,7 @@ class DefaultRoundTripTest(fixtures.TablesTest): eq_( set(r.context.postfetch_cols), - set([t.c.col3, t.c.col5, t.c.col4, t.c.col6]), + {t.c.col3, t.c.col5, t.c.col4, t.c.col6}, ) eq_( diff --git a/test/sql/test_delete.py b/test/sql/test_delete.py index f98e7297d..5b7e5ebbe 100644 --- a/test/sql/test_delete.py +++ b/test/sql/test_delete.py @@ -1,5 +1,3 @@ -#! coding:utf-8 - from sqlalchemy import and_ from sqlalchemy import delete from sqlalchemy import exc diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index ae34b0c0f..fdfb87f72 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -1,5 +1,3 @@ -#! coding: utf-8 - from sqlalchemy import alias from sqlalchemy import and_ from sqlalchemy import bindparam diff --git a/test/sql/test_external_traversal.py b/test/sql/test_external_traversal.py index 5e46808b3..158707c6a 100644 --- a/test/sql/test_external_traversal.py +++ b/test/sql/test_external_traversal.py @@ -344,7 +344,7 @@ class TraversalTest( foo, bar = CustomObj("foo", String), CustomObj("bar", String) bin_ = foo == bar set(ClauseVisitor().iterate(bin_)) - assert set(ClauseVisitor().iterate(bin_)) == set([foo, bar, bin_]) + assert set(ClauseVisitor().iterate(bin_)) == {foo, bar, bin_} class BinaryEndpointTraversalTest(fixtures.TestBase): @@ -726,7 +726,7 @@ class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): assert c1 == str(clause) assert str(clause2) == c1 + " SOME MODIFIER=:lala" assert list(clause._bindparams.keys()) == ["bar"] - assert set(clause2._bindparams.keys()) == set(["bar", "lala"]) + assert set(clause2._bindparams.keys()) == {"bar", "lala"} def test_select(self): s2 = select(t1) @@ -2209,8 +2209,8 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): e = sql_util.ClauseAdapter( b, - include_fn=lambda x: x in set([a.c.id]), - equivalents={a.c.id: set([a.c.id])}, + include_fn=lambda x: x in {a.c.id}, + equivalents={a.c.id: {a.c.id}}, ).traverse(e) assert str(e) == "a_1.id = a.xxx_id" @@ -2225,7 +2225,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): # asking for a nonexistent col. corresponding_column should prevent # endless depth. adapt = sql_util.ClauseAdapter( - b, equivalents={a.c.x: set([c.c.x]), c.c.x: set([a.c.x])} + b, equivalents={a.c.x: {c.c.x}, c.c.x: {a.c.x}} ) assert adapt._corresponding_column(a.c.x, False) is None @@ -2240,7 +2240,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): # two levels of indirection from c.x->b.x->a.x, requires recursive # corresponding_column call adapt = sql_util.ClauseAdapter( - alias, equivalents={b.c.x: set([a.c.x]), c.c.x: set([b.c.x])} + alias, equivalents={b.c.x: {a.c.x}, c.c.x: {b.c.x}} ) assert adapt._corresponding_column(a.c.x, False) is alias.c.x assert adapt._corresponding_column(c.c.x, False) is alias.c.x @@ -2535,9 +2535,9 @@ class SpliceJoinsTest(fixtures.TestBase, AssertsCompiledSQL): def _table(name): return table(name, column("col1"), column("col2"), column("col3")) - table1, table2, table3, table4 = [ + table1, table2, table3, table4 = ( _table(name) for name in ("table1", "table2", "table3", "table4") - ] + ) def test_splice(self): t1, t2, t3, t4 = table1, table2, table1.alias(), table2.alias() diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index f92dd8496..c97c13624 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -388,7 +388,7 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): def __init__(self, *args): args = args + (3,) - super(MyFunction, self).__init__(*args) + super().__init__(*args) self.assert_compile( func.my_func(1, 2), "my_func(:my_func_1, :my_func_2, :my_func_3)" diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py index 395fe16d3..ac9ac4022 100644 --- a/test/sql/test_insert.py +++ b/test/sql/test_insert.py @@ -1,4 +1,3 @@ -#! coding:utf-8 from __future__ import annotations from typing import Tuple @@ -1609,14 +1608,12 @@ class MultirowTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): stmt = table.insert().values(values) eq_( - dict( - [ - (k, v.type._type_affinity) - for (k, v) in stmt.compile( - dialect=postgresql.dialect() - ).binds.items() - ] - ), + { + k: v.type._type_affinity + for (k, v) in stmt.compile( + dialect=postgresql.dialect() + ).binds.items() + }, { "foo": Integer, "data_m2": String, @@ -1757,14 +1754,12 @@ class MultirowTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): stmt = table.insert().values(values) eq_( - dict( - [ - (k, v.type._type_affinity) - for (k, v) in stmt.compile( - dialect=postgresql.dialect() - ).binds.items() - ] - ), + { + k: v.type._type_affinity + for (k, v) in stmt.compile( + dialect=postgresql.dialect() + ).binds.items() + }, { "foo": Integer, "data_m2": String, diff --git a/test/sql/test_labels.py b/test/sql/test_labels.py index a74c5811c..40ae2a65c 100644 --- a/test/sql/test_labels.py +++ b/test/sql/test_labels.py @@ -795,7 +795,7 @@ class LabelLengthTest(fixtures.TestBase, AssertsCompiledSQL): compiled = stmt.compile(dialect=dialect) eq_( set(compiled._create_result_map()), - set(["tablename_columnn_1", "tablename_columnn_2"]), + {"tablename_columnn_1", "tablename_columnn_2"}, ) diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 6d93cb234..af8c15f98 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -124,10 +124,10 @@ class MetaDataTest(fixtures.TestBase, ComparesTables): class MyColumn(schema.Column): def __init__(self, *args, **kw): self.widget = kw.pop("widget", None) - super(MyColumn, self).__init__(*args, **kw) + super().__init__(*args, **kw) def _copy(self, *arg, **kw): - c = super(MyColumn, self)._copy(*arg, **kw) + c = super()._copy(*arg, **kw) c.widget = self.widget return c @@ -160,7 +160,7 @@ class MetaDataTest(fixtures.TestBase, ComparesTables): Table("t2", metadata, Column("x", Integer), schema="bar") Table("t3", metadata, Column("x", Integer)) - eq_(metadata._schemas, set(["foo", "bar"])) + eq_(metadata._schemas, {"foo", "bar"}) eq_(len(metadata.tables), 3) def test_schema_collection_remove(self): @@ -171,11 +171,11 @@ class MetaDataTest(fixtures.TestBase, ComparesTables): t3 = Table("t3", metadata, Column("x", Integer), schema="bar") metadata.remove(t3) - eq_(metadata._schemas, set(["foo", "bar"])) + eq_(metadata._schemas, {"foo", "bar"}) eq_(len(metadata.tables), 2) metadata.remove(t1) - eq_(metadata._schemas, set(["bar"])) + eq_(metadata._schemas, {"bar"}) eq_(len(metadata.tables), 1) def test_schema_collection_remove_all(self): @@ -1778,15 +1778,15 @@ class TableTest(fixtures.TestBase, AssertsCompiledSQL): fk3 = ForeignKeyConstraint(["b", "c"], ["r.x", "r.y"]) t1.append_column(Column("b", Integer, fk1)) - eq_(t1.foreign_key_constraints, set([fk1.constraint])) + eq_(t1.foreign_key_constraints, {fk1.constraint}) t1.append_column(Column("c", Integer, fk2)) - eq_(t1.foreign_key_constraints, set([fk1.constraint, fk2.constraint])) + eq_(t1.foreign_key_constraints, {fk1.constraint, fk2.constraint}) t1.append_constraint(fk3) eq_( t1.foreign_key_constraints, - set([fk1.constraint, fk2.constraint, fk3]), + {fk1.constraint, fk2.constraint, fk3}, ) def test_c_immutable(self): @@ -2167,20 +2167,16 @@ class SchemaTypeTest(fixtures.TestBase): evt_targets = () def _set_table(self, column, table): - super(SchemaTypeTest.TrackEvents, self)._set_table(column, table) + super()._set_table(column, table) self.column = column self.table = table def _on_table_create(self, target, bind, **kw): - super(SchemaTypeTest.TrackEvents, self)._on_table_create( - target, bind, **kw - ) + super()._on_table_create(target, bind, **kw) self.evt_targets += (target,) def _on_metadata_create(self, target, bind, **kw): - super(SchemaTypeTest.TrackEvents, self)._on_metadata_create( - target, bind, **kw - ) + super()._on_metadata_create(target, bind, **kw) self.evt_targets += (target,) # TODO: Enum and Boolean put TypeEngine first. Changing that here @@ -2951,7 +2947,7 @@ class ConstraintTest(fixtures.TestBase): return t1, t2, t3 def _assert_index_col_x(self, t, i, columns=True): - eq_(t.indexes, set([i])) + eq_(t.indexes, {i}) if columns: eq_(list(i.columns), [t.c.x]) else: @@ -3075,7 +3071,7 @@ class ConstraintTest(fixtures.TestBase): idx = Index("bar", MyThing(), t.c.y) - eq_(set(t.indexes), set([idx])) + eq_(set(t.indexes), {idx}) def test_clauseelement_extraction_three(self): t = Table("t", MetaData(), Column("x", Integer), Column("y", Integer)) diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py index 79ca00e14..e00cacad8 100644 --- a/test/sql/test_operators.py +++ b/test/sql/test_operators.py @@ -702,7 +702,7 @@ class CustomComparatorTest(_CustomComparatorTests, fixtures.TestBase): class MyInteger(Integer): class comparator_factory(TypeEngine.Comparator): def __init__(self, expr): - super(MyInteger.comparator_factory, self).__init__(expr) + super().__init__(expr) def __add__(self, other): return self.expr.op("goofy")(other) @@ -721,7 +721,7 @@ class TypeDecoratorComparatorTest(_CustomComparatorTests, fixtures.TestBase): class comparator_factory(TypeDecorator.Comparator): def __init__(self, expr): - super(MyInteger.comparator_factory, self).__init__(expr) + super().__init__(expr) def __add__(self, other): return self.expr.op("goofy")(other) @@ -742,7 +742,7 @@ class TypeDecoratorTypeDecoratorComparatorTest( class comparator_factory(TypeDecorator.Comparator): def __init__(self, expr): - super(MyIntegerOne.comparator_factory, self).__init__(expr) + super().__init__(expr) def __add__(self, other): return self.expr.op("goofy")(other) @@ -764,9 +764,7 @@ class TypeDecoratorWVariantComparatorTest( class SomeOtherInteger(Integer): class comparator_factory(TypeEngine.Comparator): def __init__(self, expr): - super(SomeOtherInteger.comparator_factory, self).__init__( - expr - ) + super().__init__(expr) def __add__(self, other): return self.expr.op("not goofy")(other) @@ -780,7 +778,7 @@ class TypeDecoratorWVariantComparatorTest( class comparator_factory(TypeDecorator.Comparator): def __init__(self, expr): - super(MyInteger.comparator_factory, self).__init__(expr) + super().__init__(expr) def __add__(self, other): return self.expr.op("goofy")(other) @@ -798,7 +796,7 @@ class CustomEmbeddedinTypeDecoratorTest( class MyInteger(Integer): class comparator_factory(TypeEngine.Comparator): def __init__(self, expr): - super(MyInteger.comparator_factory, self).__init__(expr) + super().__init__(expr) def __add__(self, other): return self.expr.op("goofy")(other) @@ -818,7 +816,7 @@ class NewOperatorTest(_CustomComparatorTests, fixtures.TestBase): class MyInteger(Integer): class comparator_factory(TypeEngine.Comparator): def __init__(self, expr): - super(MyInteger.comparator_factory, self).__init__(expr) + super().__init__(expr) def foob(self, other): return self.expr.op("foob")(other) diff --git a/test/sql/test_query.py b/test/sql/test_query.py index ef94cc089..54943897e 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -1586,10 +1586,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(t1.c.name == "t1 #10") .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1599,10 +1597,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(t1.c.t1_id < 12) .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1617,10 +1613,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(t2.c.name == "t2 #20") .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1630,10 +1624,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(t2.c.t2_id < 29) .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1648,10 +1640,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(t3.c.name == "t3 #30") .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1661,10 +1651,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(t3.c.t3_id < 39) .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1692,10 +1680,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(and_(t1.c.t1_id < 19, t3.c.t3_id < 39)) .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1711,10 +1697,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(and_(t1.c.name == "t1 #10", t2.c.name == "t2 #20")) .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1724,10 +1708,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(and_(t1.c.t1_id < 12, t2.c.t2_id < 39)) .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1748,10 +1730,8 @@ class JoinTest(fixtures.TablesTest): ) ) .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1761,10 +1741,8 @@ class JoinTest(fixtures.TablesTest): select(t1.c.t1_id, t2.c.t2_id, t3.c.t3_id) .where(and_(t1.c.t1_id < 19, t2.c.t2_id < 29, t3.c.t3_id < 39)) .select_from( - ( - t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( - t3, criteria - ) + t1.outerjoin(t2, t1.c.t1_id == t2.c.t1_id).outerjoin( + t3, criteria ) ) ) @@ -1791,7 +1769,7 @@ class JoinTest(fixtures.TablesTest): .where( t1.c.name == "t1 #10", ) - .select_from((t1.join(t2).outerjoin(t3, criteria))) + .select_from(t1.join(t2).outerjoin(t3, criteria)) ) self.assertRows(expr, [(10, 20, 30)]) @@ -1800,7 +1778,7 @@ class JoinTest(fixtures.TablesTest): .where( t2.c.name == "t2 #20", ) - .select_from((t1.join(t2).outerjoin(t3, criteria))) + .select_from(t1.join(t2).outerjoin(t3, criteria)) ) self.assertRows(expr, [(10, 20, 30)]) @@ -1809,7 +1787,7 @@ class JoinTest(fixtures.TablesTest): .where( t3.c.name == "t3 #30", ) - .select_from((t1.join(t2).outerjoin(t3, criteria))) + .select_from(t1.join(t2).outerjoin(t3, criteria)) ) self.assertRows(expr, [(10, 20, 30)]) @@ -1818,7 +1796,7 @@ class JoinTest(fixtures.TablesTest): .where( and_(t1.c.name == "t1 #10", t2.c.name == "t2 #20"), ) - .select_from((t1.join(t2).outerjoin(t3, criteria))) + .select_from(t1.join(t2).outerjoin(t3, criteria)) ) self.assertRows(expr, [(10, 20, 30)]) @@ -1827,7 +1805,7 @@ class JoinTest(fixtures.TablesTest): .where( and_(t2.c.name == "t2 #20", t3.c.name == "t3 #30"), ) - .select_from((t1.join(t2).outerjoin(t3, criteria))) + .select_from(t1.join(t2).outerjoin(t3, criteria)) ) self.assertRows(expr, [(10, 20, 30)]) @@ -1840,7 +1818,7 @@ class JoinTest(fixtures.TablesTest): t3.c.name == "t3 #30", ), ) - .select_from((t1.join(t2).outerjoin(t3, criteria))) + .select_from(t1.join(t2).outerjoin(t3, criteria)) ) self.assertRows(expr, [(10, 20, 30)]) diff --git a/test/sql/test_quote.py b/test/sql/test_quote.py index 7d90bc67b..62ec00750 100644 --- a/test/sql/test_quote.py +++ b/test/sql/test_quote.py @@ -1,5 +1,3 @@ -#!coding: utf-8 - from sqlalchemy import CheckConstraint from sqlalchemy import Column from sqlalchemy import column @@ -886,9 +884,7 @@ class PreparerTest(fixtures.TestBase): def test_unformat_custom(self): class Custom(compiler.IdentifierPreparer): def __init__(self, dialect): - super(Custom, self).__init__( - dialect, initial_quote="`", final_quote="`" - ) + super().__init__(dialect, initial_quote="`", final_quote="`") def _escape_identifier(self, value): return value.replace("`", "``") @@ -1003,13 +999,13 @@ class QuotedIdentTest(fixtures.TestBase): def test_apply_map_quoted(self): q1 = _anonymous_label(quoted_name("x%s", True)) - q2 = q1.apply_map(("bar")) + q2 = q1.apply_map("bar") eq_(q2, "xbar") eq_(q2.quote, True) def test_apply_map_plain(self): q1 = _anonymous_label(quoted_name("x%s", None)) - q2 = q1.apply_map(("bar")) + q2 = q1.apply_map("bar") eq_(q2, "xbar") self._assert_not_quoted(q2) diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index fa86d75ee..b856acfd3 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -1195,13 +1195,11 @@ class CursorResultTest(fixtures.TablesTest): row = result.first() eq_( - set( - [ - users.c.user_id in row._mapping, - addresses.c.user_id in row._mapping, - ] - ), - set([True]), + { + users.c.user_id in row._mapping, + addresses.c.user_id in row._mapping, + }, + {True}, ) @testing.combinations( @@ -3357,7 +3355,7 @@ class AlternateCursorResultTest(fixtures.TablesTest): def test_handle_error_in_fetch(self, strategy_cls, method_name): class cursor: def raise_(self): - raise IOError("random non-DBAPI error during cursor operation") + raise OSError("random non-DBAPI error during cursor operation") def fetchone(self): self.raise_() @@ -3390,7 +3388,7 @@ class AlternateCursorResultTest(fixtures.TablesTest): def test_buffered_row_close_error_during_fetchone(self): def raise_(**kw): - raise IOError("random non-DBAPI error during cursor operation") + raise OSError("random non-DBAPI error during cursor operation") with self._proxy_fixture(_cursor.BufferedRowCursorFetchStrategy): with self.engine.connect() as conn: diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index a467bb0a3..baa8d8961 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -269,15 +269,11 @@ class SelectableTest( eq_( s1.selected_columns.foo.proxy_set, - set( - [s1.selected_columns.foo, scalar_select, scalar_select.element] - ), + {s1.selected_columns.foo, scalar_select, scalar_select.element}, ) eq_( s2.selected_columns.foo.proxy_set, - set( - [s2.selected_columns.foo, scalar_select, scalar_select.element] - ), + {s2.selected_columns.foo, scalar_select, scalar_select.element}, ) assert ( @@ -295,11 +291,11 @@ class SelectableTest( eq_( s1.c.foo.proxy_set, - set([s1.c.foo, scalar_select, scalar_select.element]), + {s1.c.foo, scalar_select, scalar_select.element}, ) eq_( s2.c.foo.proxy_set, - set([s2.c.foo, scalar_select, scalar_select.element]), + {s2.c.foo, scalar_select, scalar_select.element}, ) assert s1.corresponding_column(scalar_select) is s1.c.foo @@ -616,7 +612,7 @@ class SelectableTest( s2c1 = s2._clone() s3c1 = s3._clone() - eq_(base._cloned_intersection([s1c1, s3c1], [s2c1, s1c2]), set([s1c1])) + eq_(base._cloned_intersection([s1c1, s3c1], [s2c1, s1c2]), {s1c1}) def test_cloned_difference(self): t1 = table("t1", column("x")) @@ -633,7 +629,7 @@ class SelectableTest( eq_( base._cloned_difference([s1c1, s2c1, s3c1], [s2c1, s1c2]), - set([s3c1]), + {s3c1}, ) def test_distance_on_aliases(self): @@ -1940,13 +1936,13 @@ class RefreshForNewColTest(fixtures.TestBase): q = Column("q", Integer) a.append_column(q) a._refresh_for_new_column(q) - eq_(a.foreign_keys, set([fk])) + eq_(a.foreign_keys, {fk}) fk2 = ForeignKey("g.id") p = Column("p", Integer, fk2) a.append_column(p) a._refresh_for_new_column(p) - eq_(a.foreign_keys, set([fk, fk2])) + eq_(a.foreign_keys, {fk, fk2}) def test_fk_join(self): m = MetaData() @@ -1960,13 +1956,13 @@ class RefreshForNewColTest(fixtures.TestBase): q = Column("q", Integer) b.append_column(q) j._refresh_for_new_column(q) - eq_(j.foreign_keys, set([fk])) + eq_(j.foreign_keys, {fk}) fk2 = ForeignKey("g.id") p = Column("p", Integer, fk2) b.append_column(p) j._refresh_for_new_column(p) - eq_(j.foreign_keys, set([fk, fk2])) + eq_(j.foreign_keys, {fk, fk2}) class AnonLabelTest(fixtures.TestBase): @@ -2641,10 +2637,10 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): ) s1 = select(t1, t2) s2 = s1.reduce_columns(only_synonyms=False) - eq_(set(s2.selected_columns), set([t1.c.x, t1.c.y, t2.c.q])) + eq_(set(s2.selected_columns), {t1.c.x, t1.c.y, t2.c.q}) s2 = s1.reduce_columns() - eq_(set(s2.selected_columns), set([t1.c.x, t1.c.y, t2.c.z, t2.c.q])) + eq_(set(s2.selected_columns), {t1.c.x, t1.c.y, t2.c.z, t2.c.q}) def test_reduce_only_synonym_fk(self): m = MetaData() @@ -2664,13 +2660,11 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): s1 = s1.reduce_columns(only_synonyms=True) eq_( set(s1.selected_columns), - set( - [ - s1.selected_columns.x, - s1.selected_columns.y, - s1.selected_columns.q, - ] - ), + { + s1.selected_columns.x, + s1.selected_columns.y, + s1.selected_columns.q, + }, ) def test_reduce_only_synonym_lineage(self): @@ -2688,7 +2682,7 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): s2 = select(t1, s1).where(t1.c.x == s1.c.x).where(s1.c.y == t1.c.z) eq_( set(s2.reduce_columns().selected_columns), - set([t1.c.x, t1.c.y, t1.c.z, s1.c.y, s1.c.z]), + {t1.c.x, t1.c.y, t1.c.z, s1.c.y, s1.c.z}, ) # reverse order, s1.c.x wins @@ -2696,7 +2690,7 @@ class ReduceTest(fixtures.TestBase, AssertsExecutionResults): s2 = select(s1, t1).where(t1.c.x == s1.c.x).where(s1.c.y == t1.c.z) eq_( set(s2.reduce_columns().selected_columns), - set([s1.c.x, t1.c.y, t1.c.z, s1.c.y, s1.c.z]), + {s1.c.x, t1.c.y, t1.c.z, s1.c.y, s1.c.z}, ) def test_reduce_aliased_join(self): @@ -2994,7 +2988,7 @@ class AnnotationsTest(fixtures.TestBase): for obj in [t, t.c.x, a, t.c.x > 1, (t.c.x > 1).label(None)]: annot = obj._annotate({}) - eq_(set([obj]), set([annot])) + eq_({obj}, {annot}) def test_clone_annotations_dont_hash(self): t = table("t", column("x")) @@ -3005,7 +2999,7 @@ class AnnotationsTest(fixtures.TestBase): for obj in [s, s2]: annot = obj._annotate({}) - ne_(set([obj]), set([annot])) + ne_({obj}, {annot}) def test_replacement_traverse_preserve(self): """test that replacement traverse that hits an unannotated column @@ -3802,11 +3796,11 @@ class ResultMapTest(fixtures.TestBase): def _mapping(self, stmt): compiled = stmt.compile() - return dict( - (elem, key) + return { + elem: key for key, elements in compiled._create_result_map().items() for elem in elements[1] - ) + } def test_select_label_alt_name(self): t = self._fixture() diff --git a/test/sql/test_text.py b/test/sql/test_text.py index 805eacec6..b5d9ae740 100644 --- a/test/sql/test_text.py +++ b/test/sql/test_text.py @@ -374,7 +374,7 @@ class BindParamTest(fixtures.TestBase, AssertsCompiledSQL): ) def _assert_type_map(self, t, compare): - map_ = dict((b.key, b.type) for b in t._bindparams.values()) + map_ = {b.key: b.type for b in t._bindparams.values()} for k in compare: assert compare[k]._type_affinity is map_[k]._type_affinity @@ -642,11 +642,11 @@ class AsFromTest(fixtures.TestBase, AssertsCompiledSQL): def _mapping(self, stmt): compiled = stmt.compile() - return dict( - (elem, key) + return { + elem: key for key, elements in compiled._create_result_map().items() for elem in elements[1] - ) + } def test_select_label_alt_name(self): t = self._xy_table_fixture() @@ -815,7 +815,7 @@ class AsFromTest(fixtures.TestBase, AssertsCompiledSQL): t = t.bindparams(bar=String) t = t.bindparams(bindparam("bat", value="bat")) - eq_(set(t.element._bindparams), set(["bat", "foo", "bar"])) + eq_(set(t.element._bindparams), {"bat", "foo", "bar"}) class TextErrorsTest(fixtures.TestBase, AssertsCompiledSQL): diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 3b1df3498..d1b32186e 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -1,4 +1,3 @@ -# coding: utf-8 import datetime import decimal import importlib @@ -511,9 +510,9 @@ class _UserDefinedTypeFixture: cache_ok = True def bind_processor(self, dialect): - impl_processor = super(MyDecoratedType, self).bind_processor( - dialect - ) or (lambda value: value) + impl_processor = super().bind_processor(dialect) or ( + lambda value: value + ) def process(value): if value is None: @@ -523,7 +522,7 @@ class _UserDefinedTypeFixture: return process def result_processor(self, dialect, coltype): - impl_processor = super(MyDecoratedType, self).result_processor( + impl_processor = super().result_processor( dialect, coltype ) or (lambda value: value) @@ -577,9 +576,9 @@ class _UserDefinedTypeFixture: cache_ok = True def bind_processor(self, dialect): - impl_processor = super(MyUnicodeType, self).bind_processor( - dialect - ) or (lambda value: value) + impl_processor = super().bind_processor(dialect) or ( + lambda value: value + ) def process(value): if value is None: @@ -590,7 +589,7 @@ class _UserDefinedTypeFixture: return process def result_processor(self, dialect, coltype): - impl_processor = super(MyUnicodeType, self).result_processor( + impl_processor = super().result_processor( dialect, coltype ) or (lambda value: value) @@ -1070,7 +1069,7 @@ class UserDefinedTest( if dialect.name == "sqlite": return String(50) else: - return super(MyType, self).load_dialect_impl(dialect) + return super().load_dialect_impl(dialect) sl = dialects.sqlite.dialect() pg = dialects.postgresql.dialect() @@ -1143,7 +1142,7 @@ class UserDefinedTest( def test_user_defined_dialect_specific_args(self): class MyType(types.UserDefinedType): def __init__(self, foo="foo", **kwargs): - super(MyType, self).__init__() + super().__init__() self.foo = foo self.dialect_specific_args = kwargs diff --git a/test/sql/test_update.py b/test/sql/test_update.py index e93900bbd..cd7f992e2 100644 --- a/test/sql/test_update.py +++ b/test/sql/test_update.py @@ -1525,7 +1525,7 @@ class UpdateFromMultiTableUpdateDefaultsTest( .where(users.c.name == "ed") ) - eq_(set(ret.prefetch_cols()), set([users.c.some_update])) + eq_(set(ret.prefetch_cols()), {users.c.some_update}) expected = [ (2, 8, "updated"), @@ -1552,7 +1552,7 @@ class UpdateFromMultiTableUpdateDefaultsTest( eq_( set(ret.prefetch_cols()), - set([users.c.some_update, foobar.c.some_update]), + {users.c.some_update, foobar.c.some_update}, ) expected = [ |
