API refactor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-07 16:25:52 +09:00
parent 76d0d86211
commit 91c7e04474
1171 changed files with 81940 additions and 44117 deletions

View File

@@ -1,5 +1,5 @@
# testing/fixtures/__init__.py
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under

View File

@@ -1,5 +1,5 @@
# testing/fixtures/base.py
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
@@ -14,6 +14,7 @@ from .. import assertions
from .. import config
from ..assertions import eq_
from ..util import drop_all_tables_from_metadata
from ..util import picklers
from ... import Column
from ... import func
from ... import Integer
@@ -194,6 +195,10 @@ class TestBase:
return go
@config.fixture(params=picklers())
def picklers(self, request):
yield request.param
@config.fixture()
def metadata(self, request):
"""Provide bound MetaData for a single test, dropping afterwards."""

View File

@@ -1,5 +1,5 @@
# testing/fixtures/mypy.py
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
@@ -86,9 +86,11 @@ class MypyTest(TestBase):
"--config-file",
os.path.join(
use_cachedir,
"sqla_mypy_config.cfg"
if use_plugin
else "plain_mypy_config.cfg",
(
"sqla_mypy_config.cfg"
if use_plugin
else "plain_mypy_config.cfg"
),
),
]
@@ -141,7 +143,9 @@ class MypyTest(TestBase):
from sqlalchemy.ext.mypy.util import mypy_14
expected_messages = []
expected_re = re.compile(r"\s*# EXPECTED(_MYPY)?(_RE)?(_TYPE)?: (.+)")
expected_re = re.compile(
r"\s*# EXPECTED(_MYPY)?(_RE)?(_ROW)?(_TYPE)?: (.+)"
)
py_ver_re = re.compile(r"^#\s*PYTHON_VERSION\s?>=\s?(\d+\.\d+)")
with open(path) as file_:
current_assert_messages = []
@@ -159,9 +163,24 @@ class MypyTest(TestBase):
if m:
is_mypy = bool(m.group(1))
is_re = bool(m.group(2))
is_type = bool(m.group(3))
is_row = bool(m.group(3))
is_type = bool(m.group(4))
expected_msg = re.sub(r"# noqa[:]? ?.*", "", m.group(5))
if is_row:
expected_msg = re.sub(
r"Row\[([^\]]+)\]",
lambda m: f"tuple[{m.group(1)}, fallback=s"
f"qlalchemy.engine.row.{m.group(0)}]",
expected_msg,
)
# For some reason it does not use or syntax (|)
expected_msg = re.sub(
r"Optional\[(.*)\]",
lambda m: f"Union[{m.group(1)}, None]",
expected_msg,
)
expected_msg = re.sub(r"# noqa[:]? ?.*", "", m.group(4))
if is_type:
if not is_re:
# the goal here is that we can cut-and-paste
@@ -208,9 +227,11 @@ class MypyTest(TestBase):
# skip first character which could be capitalized
# "List item x not found" type of message
expected_msg = expected_msg[0] + re.sub(
r"\b(List|Tuple|Dict|Set)\b"
if is_type
else r"\b(List|Tuple|Dict|Set|Type)\b",
(
r"\b(List|Tuple|Dict|Set)\b"
if is_type
else r"\b(List|Tuple|Dict|Set|Type)\b"
),
lambda m: m.group(1).lower(),
expected_msg[1:],
)
@@ -239,7 +260,9 @@ class MypyTest(TestBase):
return expected_messages
def _check_output(self, path, expected_messages, stdout, stderr, exitcode):
def _check_output(
self, path, expected_messages, stdout: str, stderr, exitcode
):
not_located = []
filename = os.path.basename(path)
if expected_messages:
@@ -259,7 +282,8 @@ class MypyTest(TestBase):
):
while raw_lines:
ol = raw_lines.pop(0)
if not re.match(r".+\.py:\d+: note: +def \[.*", ol):
if not re.match(r".+\.py:\d+: note: +def .*", ol):
raw_lines.insert(0, ol)
break
elif re.match(
r".+\.py:\d+: note: .*(?:perhaps|suggestion)", e, re.I

View File

@@ -1,5 +1,5 @@
# testing/fixtures/orm.py
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under

View File

@@ -1,5 +1,5 @@
# testing/fixtures/sql.py
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
@@ -459,6 +459,10 @@ def insertmanyvalues_fixture(
# by not having the other methods we assert that those aren't being
# used
@property
def description(self):
return self.cursor.description
def fetchall(self):
rows = self.cursor.fetchall()
rows = list(rows)
@@ -466,22 +470,29 @@ def insertmanyvalues_fixture(
return rows
def _deliver_insertmanyvalues_batches(
cursor, statement, parameters, generic_setinputsizes, context
connection,
cursor,
statement,
parameters,
generic_setinputsizes,
context,
):
if randomize_rows:
cursor = RandomCursor(cursor)
for batch in orig_dialect(
cursor, statement, parameters, generic_setinputsizes, context
connection,
cursor,
statement,
parameters,
generic_setinputsizes,
context,
):
if warn_on_downgraded and batch.is_downgraded:
util.warn("Batches were downgraded for sorted INSERT")
yield batch
def _exec_insertmany_context(
dialect,
context,
):
def _exec_insertmany_context(dialect, context):
with mock.patch.object(
dialect,
"_deliver_insertmanyvalues_batches",