1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Проверка 09.02.2025

This commit is contained in:
MoonTestUse1
2025-02-09 01:11:49 +06:00
parent ce52f8a23a
commit 0aa3ef8fc2
5827 changed files with 14316 additions and 1906434 deletions

View File

@@ -1,5 +1,5 @@
# testing/suite/__init__.py
# Copyright (C) 2005-2024 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/suite/test_cte.py
# Copyright (C) 2005-2024 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/suite/test_ddl.py
# Copyright (C) 2005-2024 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/suite/test_deprecations.py
# Copyright (C) 2005-2024 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/suite/test_dialect.py
# Copyright (C) 2005-2024 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/suite/test_insert.py
# Copyright (C) 2005-2024 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,11 +1,12 @@
# testing/suite/test_reflection.py
# Copyright (C) 2005-2024 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
# the MIT License: https://www.opensource.org/licenses/mit-license.php
# mypy: ignore-errors
import contextlib
import operator
import re
@@ -2454,62 +2455,158 @@ class TableNoColumnsTest(fixtures.TestBase):
class ComponentReflectionTestExtra(ComparesIndexes, fixtures.TestBase):
__backend__ = True
@testing.combinations(
(True, testing.requires.schemas), (False,), argnames="use_schema"
)
@testing.requires.check_constraint_reflection
def test_get_check_constraints(self, metadata, connection, use_schema):
if use_schema:
schema = config.test_schema
@testing.fixture(params=[True, False])
def use_schema_fixture(self, request):
if request.param:
return config.test_schema
else:
schema = None
return None
Table(
"sa_cc",
metadata,
Column("a", Integer()),
sa.CheckConstraint("a > 1 AND a < 5", name="cc1"),
sa.CheckConstraint(
"a = 1 OR (a > 2 AND a < 5)", name="UsesCasing"
),
schema=schema,
)
Table(
"no_constraints",
metadata,
Column("data", sa.String(20)),
schema=schema,
)
@testing.fixture()
def inspect_for_table(self, metadata, connection, use_schema_fixture):
@contextlib.contextmanager
def go(tablename):
yield use_schema_fixture, inspect(connection)
metadata.create_all(connection)
metadata.create_all(connection)
insp = inspect(connection)
reflected = sorted(
insp.get_check_constraints("sa_cc", schema=schema),
key=operator.itemgetter("name"),
)
return go
def ck_eq(self, reflected, expected):
# trying to minimize effect of quoting, parenthesis, etc.
# may need to add more to this as new dialects get CHECK
# constraint reflection support
def normalize(sqltext):
return " ".join(
re.findall(r"and|\d|=|a|or|<|>", sqltext.lower(), re.I)
re.findall(r"and|\d|=|a|b|c|or|<|>", sqltext.lower(), re.I)
)
reflected = [
{"name": item["name"], "sqltext": normalize(item["sqltext"])}
for item in reflected
]
eq_(
reflected = sorted(
[
{"name": item["name"], "sqltext": normalize(item["sqltext"])}
for item in reflected
],
key=lambda item: (item["sqltext"]),
)
expected = sorted(
expected,
key=lambda item: (item["sqltext"]),
)
eq_(reflected, expected)
@testing.requires.check_constraint_reflection
def test_check_constraint_no_constraint(self, metadata, inspect_for_table):
with inspect_for_table("no_constraints") as (schema, inspector):
Table(
"no_constraints",
metadata,
Column("data", sa.String(20)),
schema=schema,
)
self.ck_eq(
inspector.get_check_constraints("no_constraints", schema=schema),
[],
)
@testing.requires.inline_check_constraint_reflection
@testing.combinations(
"my_inline", "MyInline", None, argnames="constraint_name"
)
def test_check_constraint_inline(
self, metadata, inspect_for_table, constraint_name
):
with inspect_for_table("sa_cc") as (schema, inspector):
Table(
"sa_cc",
metadata,
Column("id", Integer(), primary_key=True),
Column(
"a",
Integer(),
sa.CheckConstraint(
"a > 1 AND a < 5", name=constraint_name
),
),
Column("data", String(50)),
schema=schema,
)
reflected = inspector.get_check_constraints("sa_cc", schema=schema)
self.ck_eq(
reflected,
[
{"name": "UsesCasing", "sqltext": "a = 1 or a > 2 and a < 5"},
{"name": "cc1", "sqltext": "a > 1 and a < 5"},
{
"name": constraint_name or mock.ANY,
"sqltext": "a > 1 and a < 5",
},
],
)
@testing.requires.check_constraint_reflection
@testing.combinations(
"my_ck_const", "MyCkConst", None, argnames="constraint_name"
)
def test_check_constraint_standalone(
self, metadata, inspect_for_table, constraint_name
):
with inspect_for_table("sa_cc") as (schema, inspector):
Table(
"sa_cc",
metadata,
Column("a", Integer()),
sa.CheckConstraint(
"a = 1 OR (a > 2 AND a < 5)", name=constraint_name
),
schema=schema,
)
reflected = inspector.get_check_constraints("sa_cc", schema=schema)
self.ck_eq(
reflected,
[
{
"name": constraint_name or mock.ANY,
"sqltext": "a = 1 or a > 2 and a < 5",
},
],
)
@testing.requires.inline_check_constraint_reflection
def test_check_constraint_mixed(self, metadata, inspect_for_table):
with inspect_for_table("sa_cc") as (schema, inspector):
Table(
"sa_cc",
metadata,
Column("id", Integer(), primary_key=True),
Column("a", Integer(), sa.CheckConstraint("a > 1 AND a < 5")),
Column(
"b",
Integer(),
sa.CheckConstraint("b > 1 AND b < 5", name="my_inline"),
),
Column("c", Integer()),
Column("data", String(50)),
sa.UniqueConstraint("data", name="some_uq"),
sa.CheckConstraint("c > 1 AND c < 5", name="cc1"),
sa.UniqueConstraint("c", name="some_c_uq"),
schema=schema,
)
reflected = inspector.get_check_constraints("sa_cc", schema=schema)
self.ck_eq(
reflected,
[
{"name": "cc1", "sqltext": "c > 1 and c < 5"},
{"name": "my_inline", "sqltext": "b > 1 and b < 5"},
{"name": mock.ANY, "sqltext": "a > 1 and a < 5"},
],
)
no_cst = "no_constraints"
eq_(insp.get_check_constraints(no_cst, schema=schema), [])
@testing.requires.indexes_with_expressions
def test_reflect_expression_based_indexes(self, metadata, connection):

View File

@@ -1,5 +1,5 @@
# testing/suite/test_results.py
# Copyright (C) 2005-2024 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
@@ -7,6 +7,7 @@
# mypy: ignore-errors
import datetime
import re
from .. import engines
from .. import fixtures
@@ -273,6 +274,8 @@ class ServerSideCursorsTest(
return getattr(cursor, "server_side", False)
elif self.engine.dialect.driver == "psycopg":
return bool(getattr(cursor, "name", False))
elif self.engine.dialect.driver == "oracledb":
return getattr(cursor, "server_side", False)
else:
return False
@@ -293,11 +296,26 @@ class ServerSideCursorsTest(
)
return self.engine
def stringify(self, str_):
return re.compile(r"SELECT (\d+)", re.I).sub(
lambda m: str(select(int(m.group(1))).compile(testing.db)), str_
)
@testing.combinations(
("global_string", True, "select 1", True),
("global_text", True, text("select 1"), True),
("global_string", True, lambda stringify: stringify("select 1"), True),
(
"global_text",
True,
lambda stringify: text(stringify("select 1")),
True,
),
("global_expr", True, select(1), True),
("global_off_explicit", False, text("select 1"), False),
(
"global_off_explicit",
False,
lambda stringify: text(stringify("select 1")),
False,
),
(
"stmt_option",
False,
@@ -315,15 +333,22 @@ class ServerSideCursorsTest(
(
"for_update_string",
True,
"SELECT 1 FOR UPDATE",
lambda stringify: stringify("SELECT 1 FOR UPDATE"),
True,
testing.skip_if(["sqlite", "mssql"]),
),
("text_no_ss", False, text("select 42"), False),
(
"text_no_ss",
False,
lambda stringify: text(stringify("select 42")),
False,
),
(
"text_ss_option",
False,
text("select 42").execution_options(stream_results=True),
lambda stringify: text(stringify("select 42")).execution_options(
stream_results=True
),
True,
),
id_="iaaa",
@@ -334,6 +359,11 @@ class ServerSideCursorsTest(
):
engine = self._fixture(engine_ss_arg)
with engine.begin() as conn:
if callable(statement):
statement = testing.resolve_lambda(
statement, stringify=self.stringify
)
if isinstance(statement, str):
result = conn.exec_driver_sql(statement)
else:
@@ -348,7 +378,7 @@ class ServerSideCursorsTest(
# should be enabled for this one
result = conn.execution_options(
stream_results=True
).exec_driver_sql("select 1")
).exec_driver_sql(self.stringify("select 1"))
assert self._is_server_side(result.cursor)
# the connection has autobegun, which means at the end of the
@@ -402,7 +432,9 @@ class ServerSideCursorsTest(
test_table = Table(
"test_table",
md,
Column("id", Integer, primary_key=True),
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
Column("data", String(50)),
)
@@ -442,7 +474,9 @@ class ServerSideCursorsTest(
test_table = Table(
"test_table",
md,
Column("id", Integer, primary_key=True),
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
Column("data", String(50)),
)

View File

@@ -1,5 +1,5 @@
# testing/suite/test_rowcount.py
# Copyright (C) 2005-2024 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/suite/test_select.py
# Copyright (C) 2005-2024 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
@@ -1886,3 +1886,114 @@ class IsOrIsNotDistinctFromTest(fixtures.TablesTest):
len(result),
expected_row_count_for_is_not,
)
class WindowFunctionTest(fixtures.TablesTest):
__requires__ = ("window_functions",)
__backend__ = True
@classmethod
def define_tables(cls, metadata):
Table(
"some_table",
metadata,
Column("id", Integer, primary_key=True),
Column("col1", Integer),
Column("col2", Integer),
)
@classmethod
def insert_data(cls, connection):
connection.execute(
cls.tables.some_table.insert(),
[{"id": i, "col1": i, "col2": i * 5} for i in range(1, 50)],
)
def test_window(self, connection):
some_table = self.tables.some_table
rows = connection.execute(
select(
func.max(some_table.c.col2).over(
order_by=[some_table.c.col1.desc()]
)
).where(some_table.c.col1 < 20)
).all()
eq_(rows, [(95,) for i in range(19)])
def test_window_rows_between(self, connection):
some_table = self.tables.some_table
# note the rows are part of the cache key right now, not handled
# as binds. this is issue #11515
rows = connection.execute(
select(
func.max(some_table.c.col2).over(
order_by=[some_table.c.col1],
rows=(-5, 0),
)
)
).all()
eq_(rows, [(i,) for i in range(5, 250, 5)])
class BitwiseTest(fixtures.TablesTest):
__backend__ = True
run_inserts = run_deletes = "once"
inserted_data = [{"a": i, "b": i + 1} for i in range(10)]
@classmethod
def define_tables(cls, metadata):
Table("bitwise", metadata, Column("a", Integer), Column("b", Integer))
@classmethod
def insert_data(cls, connection):
connection.execute(cls.tables.bitwise.insert(), cls.inserted_data)
@testing.combinations(
(
lambda a: a.bitwise_xor(5),
[i for i in range(10) if i != 5],
testing.requires.supports_bitwise_xor,
),
(
lambda a: a.bitwise_or(1),
list(range(10)),
testing.requires.supports_bitwise_or,
),
(
lambda a: a.bitwise_and(4),
list(range(4, 8)),
testing.requires.supports_bitwise_and,
),
(
lambda a: (a - 2).bitwise_not(),
[0],
testing.requires.supports_bitwise_not,
),
(
lambda a: a.bitwise_lshift(1),
list(range(1, 10)),
testing.requires.supports_bitwise_shift,
),
(
lambda a: a.bitwise_rshift(2),
list(range(4, 10)),
testing.requires.supports_bitwise_shift,
),
argnames="case, expected",
)
def test_bitwise(self, case, expected, connection):
tbl = self.tables.bitwise
a = tbl.c.a
op = testing.resolve_lambda(case, a=a)
stmt = select(tbl).where(op > 0).order_by(a)
res = connection.execute(stmt).mappings().all()
eq_(res, [self.inserted_data[i] for i in expected])

View File

@@ -1,5 +1,5 @@
# testing/suite/test_sequence.py
# Copyright (C) 2005-2024 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/suite/test_types.py
# Copyright (C) 2005-2024 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
@@ -32,6 +32,7 @@ from ... import case
from ... import cast
from ... import Date
from ... import DateTime
from ... import Enum
from ... import Float
from ... import Integer
from ... import Interval
@@ -1918,6 +1919,74 @@ class JSONLegacyStringCastIndexTest(
)
class EnumTest(_LiteralRoundTripFixture, fixtures.TablesTest):
__backend__ = True
enum_values = "a", "b", "a%", "b%percent", "réveillé"
datatype = Enum(*enum_values, name="myenum")
@classmethod
def define_tables(cls, metadata):
Table(
"enum_table",
metadata,
Column("id", Integer, primary_key=True),
Column("enum_data", cls.datatype),
)
@testing.combinations(*enum_values, argnames="data")
def test_round_trip(self, data, connection):
connection.execute(
self.tables.enum_table.insert(), {"id": 1, "enum_data": data}
)
eq_(
connection.scalar(
select(self.tables.enum_table.c.enum_data).where(
self.tables.enum_table.c.id == 1
)
),
data,
)
def test_round_trip_executemany(self, connection):
connection.execute(
self.tables.enum_table.insert(),
[
{"id": 1, "enum_data": "b%percent"},
{"id": 2, "enum_data": "réveillé"},
{"id": 3, "enum_data": "b"},
{"id": 4, "enum_data": "a%"},
],
)
eq_(
connection.scalars(
select(self.tables.enum_table.c.enum_data).order_by(
self.tables.enum_table.c.id
)
).all(),
["b%percent", "réveillé", "b", "a%"],
)
@testing.requires.insert_executemany_returning
def test_round_trip_executemany_returning(self, connection):
result = connection.execute(
self.tables.enum_table.insert().returning(
self.tables.enum_table.c.enum_data
),
[
{"id": 1, "enum_data": "b%percent"},
{"id": 2, "enum_data": "réveillé"},
{"id": 3, "enum_data": "b"},
{"id": 4, "enum_data": "a%"},
],
)
eq_(result.scalars().all(), ["b%percent", "réveillé", "b", "a%"])
class UuidTest(_LiteralRoundTripFixture, fixtures.TablesTest):
__backend__ = True
@@ -2066,6 +2135,7 @@ __all__ = (
"DateHistoricTest",
"StringTest",
"BooleanTest",
"EnumTest",
"UuidTest",
"NativeUUIDTest",
)

View File

@@ -1,5 +1,5 @@
# testing/suite/test_unicode_ddl.py
# Copyright (C) 2005-2024 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/suite/test_update_delete.py
# Copyright (C) 2005-2024 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