summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-06-26 16:15:19 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-07-08 11:05:11 -0400
commit91f376692d472a5bf0c4b4033816250ec1ce3ab6 (patch)
tree31f7f72cbe981eb73ed0ba11808d4fb5ae6b7d51 /lib/sqlalchemy/testing
parent3dc9a4a2392d033f9d1bd79dd6b6ecea6281a61c (diff)
downloadsqlalchemy-91f376692d472a5bf0c4b4033816250ec1ce3ab6.tar.gz
Add future=True to create_engine/Session; unify select()
Several weeks of using the future_select() construct has led to the proposal there be just one select() construct again which features the new join() method, and otherwise accepts both the 1.x and 2.x argument styles. This would make migration simpler and reduce confusion. However, confusion may be increased by the fact that select().join() is different Current thinking is we may be better off with a few hard behavioral changes to old and relatively unknown APIs rather than trying to play both sides within two extremely similar but subtly different APIs. At the moment, the .join() thing seems to be the only behavioral change that occurs without the user taking any explicit steps. Session.execute() will still behave the old way as we are adding a future flag. This change also adds the "future" flag to Session() and session.execute(), so that interpretation of the incoming statement, as well as that the new style result is returned, does not occur for existing applications unless they add the use of this flag. The change in general is moving the "removed in 2.0" system further along where we want the test suite to fully pass even if the SQLALCHEMY_WARN_20 flag is set. Get many tests to pass when SQLALCHEMY_WARN_20 is set; this should be ongoing after this patch merges. Improve the RemovedIn20 warning; these are all deprecated "since" 1.4, so ensure that's what the messages read. Make sure the inforamtion link is on all warnings. Add deprecation warnings for parameters present and add warnings to all FromClause.select() types of methods. Fixes: #5379 Fixes: #5284 Change-Id: I765a0b912b3dcd0e995426427d8bb7997cbffd51 References: #5159
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/assertions.py6
-rw-r--r--lib/sqlalchemy/testing/suite/test_types.py78
-rw-r--r--lib/sqlalchemy/testing/warnings.py3
3 files changed, 39 insertions, 48 deletions
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index 998dde66b..1ce59431e 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -170,7 +170,11 @@ def _expect_warnings(
with mock.patch("warnings.warn", our_warn), mock.patch(
"sqlalchemy.util.SQLALCHEMY_WARN_20", True
- ), mock.patch("sqlalchemy.engine.row.LegacyRow._default_key_style", 2):
+ ), mock.patch(
+ "sqlalchemy.util.deprecations.SQLALCHEMY_WARN_20", True
+ ), mock.patch(
+ "sqlalchemy.engine.row.LegacyRow._default_key_style", 2
+ ):
yield
if assert_ and (not py2konly or not compat.py3k):
diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py
index 00b5fab27..48144f885 100644
--- a/lib/sqlalchemy/testing/suite/test_types.py
+++ b/lib/sqlalchemy/testing/suite/test_types.py
@@ -114,9 +114,7 @@ class _UnicodeFixture(_LiteralRoundTripFixture, fixtures.TestBase):
connection.execute(unicode_table.insert(), {"unicode_data": self.data})
- row = connection.execute(
- select([unicode_table.c.unicode_data])
- ).first()
+ row = connection.execute(select(unicode_table.c.unicode_data)).first()
eq_(row, (self.data,))
assert isinstance(row[0], util.text_type)
@@ -130,7 +128,7 @@ class _UnicodeFixture(_LiteralRoundTripFixture, fixtures.TestBase):
)
rows = connection.execute(
- select([unicode_table.c.unicode_data])
+ select(unicode_table.c.unicode_data)
).fetchall()
eq_(rows, [(self.data,) for i in range(3)])
for row in rows:
@@ -140,18 +138,14 @@ class _UnicodeFixture(_LiteralRoundTripFixture, fixtures.TestBase):
unicode_table = self.tables.unicode_table
connection.execute(unicode_table.insert(), {"unicode_data": None})
- row = connection.execute(
- select([unicode_table.c.unicode_data])
- ).first()
+ row = connection.execute(select(unicode_table.c.unicode_data)).first()
eq_(row, (None,))
def _test_empty_strings(self, connection):
unicode_table = self.tables.unicode_table
connection.execute(unicode_table.insert(), {"unicode_data": u("")})
- row = connection.execute(
- select([unicode_table.c.unicode_data])
- ).first()
+ row = connection.execute(select(unicode_table.c.unicode_data)).first()
eq_(row, (u(""),))
def test_literal(self):
@@ -214,7 +208,7 @@ class TextTest(_LiteralRoundTripFixture, fixtures.TablesTest):
text_table = self.tables.text_table
connection.execute(text_table.insert(), {"text_data": "some text"})
- row = connection.execute(select([text_table.c.text_data])).first()
+ row = connection.execute(select(text_table.c.text_data)).first()
eq_(row, ("some text",))
@testing.requires.empty_strings_text
@@ -222,14 +216,14 @@ class TextTest(_LiteralRoundTripFixture, fixtures.TablesTest):
text_table = self.tables.text_table
connection.execute(text_table.insert(), {"text_data": ""})
- row = connection.execute(select([text_table.c.text_data])).first()
+ row = connection.execute(select(text_table.c.text_data)).first()
eq_(row, ("",))
def test_text_null_strings(self, connection):
text_table = self.tables.text_table
connection.execute(text_table.insert(), {"text_data": None})
- row = connection.execute(select([text_table.c.text_data])).first()
+ row = connection.execute(select(text_table.c.text_data)).first()
eq_(row, (None,))
def test_literal(self):
@@ -302,7 +296,7 @@ class _DateFixture(_LiteralRoundTripFixture, fixtures.TestBase):
connection.execute(date_table.insert(), {"date_data": self.data})
- row = connection.execute(select([date_table.c.date_data])).first()
+ row = connection.execute(select(date_table.c.date_data)).first()
compare = self.compare or self.data
eq_(row, (compare,))
@@ -313,7 +307,7 @@ class _DateFixture(_LiteralRoundTripFixture, fixtures.TestBase):
connection.execute(date_table.insert(), {"date_data": None})
- row = connection.execute(select([date_table.c.date_data])).first()
+ row = connection.execute(select(date_table.c.date_data)).first()
eq_(row, (None,))
@testing.requires.datetime_literals
@@ -332,7 +326,7 @@ class _DateFixture(_LiteralRoundTripFixture, fixtures.TestBase):
date_table.insert(), {"date_data": self.data}
)
id_ = result.inserted_primary_key[0]
- stmt = select([date_table.c.id]).where(
+ stmt = select(date_table.c.id).where(
case(
[
(
@@ -438,7 +432,7 @@ class IntegerTest(_LiteralRoundTripFixture, fixtures.TestBase):
connection.execute(int_table.insert(), {"integer_data": data})
- row = connection.execute(select([int_table.c.integer_data])).first()
+ row = connection.execute(select(int_table.c.integer_data)).first()
eq_(row, (data,))
@@ -545,7 +539,7 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase):
def test_float_coerce_round_trip(self, connection):
expr = 15.7563
- val = connection.scalar(select([literal(expr)]))
+ val = connection.scalar(select(literal(expr)))
eq_(val, expr)
# this does not work in MySQL, see #4036, however we choose not
@@ -556,14 +550,14 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase):
def test_decimal_coerce_round_trip(self, connection):
expr = decimal.Decimal("15.7563")
- val = connection.scalar(select([literal(expr)]))
+ val = connection.scalar(select(literal(expr)))
eq_(val, expr)
@testing.emits_warning(r".*does \*not\* support Decimal objects natively")
def test_decimal_coerce_round_trip_w_cast(self, connection):
expr = decimal.Decimal("15.7563")
- val = connection.scalar(select([cast(expr, Numeric(10, 4))]))
+ val = connection.scalar(select(cast(expr, Numeric(10, 4))))
eq_(val, expr)
@testing.requires.precision_numerics_general
@@ -665,9 +659,7 @@ class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest):
)
row = connection.execute(
- select(
- [boolean_table.c.value, boolean_table.c.unconstrained_value]
- )
+ select(boolean_table.c.value, boolean_table.c.unconstrained_value)
).first()
eq_(row, (True, False))
@@ -683,9 +675,7 @@ class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest):
)
row = connection.execute(
- select(
- [boolean_table.c.value, boolean_table.c.unconstrained_value]
- )
+ select(boolean_table.c.value, boolean_table.c.unconstrained_value)
).first()
eq_(row, (None, None))
@@ -705,13 +695,13 @@ class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest):
eq_(
conn.scalar(
- select([boolean_table.c.id]).where(boolean_table.c.value)
+ select(boolean_table.c.id).where(boolean_table.c.value)
),
1,
)
eq_(
conn.scalar(
- select([boolean_table.c.id]).where(
+ select(boolean_table.c.id).where(
boolean_table.c.unconstrained_value
)
),
@@ -719,13 +709,13 @@ class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest):
)
eq_(
conn.scalar(
- select([boolean_table.c.id]).where(~boolean_table.c.value)
+ select(boolean_table.c.id).where(~boolean_table.c.value)
),
2,
)
eq_(
conn.scalar(
- select([boolean_table.c.id]).where(
+ select(boolean_table.c.id).where(
~boolean_table.c.unconstrained_value
)
),
@@ -760,7 +750,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
data_table.insert(), {"name": "row1", "data": data_element}
)
- row = connection.execute(select([data_table.c.data])).first()
+ row = connection.execute(select(data_table.c.data)).first()
eq_(row, (data_element,))
@@ -806,7 +796,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
expr = data_table.c.data["key1"]
expr = getattr(expr, "as_%s" % datatype)()
- roundtrip = conn.scalar(select([expr]))
+ roundtrip = conn.scalar(select(expr))
eq_(roundtrip, value)
if util.py3k: # skip py2k to avoid comparing unicode to str etc.
is_(type(roundtrip), type(value))
@@ -828,7 +818,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
expr = data_table.c.data["key1"]
expr = getattr(expr, "as_%s" % datatype)()
- row = conn.execute(select([expr]).where(expr == value)).first()
+ row = conn.execute(select(expr).where(expr == value)).first()
# make sure we get a row even if value is None
eq_(row, (value,))
@@ -850,7 +840,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
expr = data_table.c.data[("key1", "subkey1")]
expr = getattr(expr, "as_%s" % datatype)()
- row = conn.execute(select([expr]).where(expr == value)).first()
+ row = conn.execute(select(expr).where(expr == value)).first()
# make sure we get a row even if value is None
eq_(row, (value,))
@@ -882,7 +872,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
)
row = conn.execute(
- select([data_table.c.data, data_table.c.nulldata])
+ select(data_table.c.data, data_table.c.nulldata)
).first()
eq_(row, (data_element, data_element))
@@ -903,7 +893,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
conn.execute(
data_table.insert(), {"name": "row1", "data": data_element}
)
- row = conn.execute(select([data_table.c.data])).first()
+ row = conn.execute(select(data_table.c.data)).first()
eq_(row, (data_element,))
eq_(js.mock_calls, [mock.call(data_element)])
@@ -919,12 +909,12 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
eq_(
conn.scalar(
- select([self.tables.data_table.c.name]).where(col.is_(null()))
+ select(self.tables.data_table.c.name).where(col.is_(null()))
),
"r1",
)
- eq_(conn.scalar(select([col])), None)
+ eq_(conn.scalar(select(col)), None)
def test_round_trip_json_null_as_json_null(self, connection):
col = self.tables.data_table.c["data"]
@@ -936,14 +926,14 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
eq_(
conn.scalar(
- select([self.tables.data_table.c.name]).where(
+ select(self.tables.data_table.c.name).where(
cast(col, String) == "null"
)
),
"r1",
)
- eq_(conn.scalar(select([col])), None)
+ eq_(conn.scalar(select(col)), None)
def test_round_trip_none_as_json_null(self):
col = self.tables.data_table.c["data"]
@@ -955,14 +945,14 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
eq_(
conn.scalar(
- select([self.tables.data_table.c.name]).where(
+ select(self.tables.data_table.c.name).where(
cast(col, String) == "null"
)
),
"r1",
)
- eq_(conn.scalar(select([col])), None)
+ eq_(conn.scalar(select(col)), None)
def test_unicode_round_trip(self):
# note we include Unicode supplementary characters as well
@@ -979,7 +969,7 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
)
eq_(
- conn.scalar(select([self.tables.data_table.c.data])),
+ conn.scalar(select(self.tables.data_table.c.data)),
{
util.u("réve🐍 illé"): util.u("réve🐍 illé"),
"data": {"k1": util.u("drôl🐍e")},
@@ -1087,7 +1077,7 @@ class JSONStringCastIndexTest(_LiteralRoundTripFixture, fixtures.TablesTest):
def _test_index_criteria(self, crit, expected, test_literal=True):
self._criteria_fixture()
with config.db.connect() as conn:
- stmt = select([self.tables.data_table.c.name]).where(crit)
+ stmt = select(self.tables.data_table.c.name).where(crit)
eq_(conn.scalar(stmt), expected)
diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py
index 3850f65c8..298b20c11 100644
--- a/lib/sqlalchemy/testing/warnings.py
+++ b/lib/sqlalchemy/testing/warnings.py
@@ -31,9 +31,6 @@ def setup_filters():
"ignore", category=DeprecationWarning, message=".*inspect.get.*argspec"
)
- # ignore 2.0 warnings unless we are explicitly testing for them
- warnings.filterwarnings("ignore", category=sa_exc.RemovedIn20Warning)
-
# ignore things that are deprecated *as of* 2.0 :)
warnings.filterwarnings(
"ignore",