summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2023-05-09 14:39:18 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2023-05-09 14:39:18 +0000
commita7d8063171d87eef0f89e114e919ea8e07023db3 (patch)
treee0858fc9c2218aaf71a3dbee1a2540beb432b7b3 /lib/sqlalchemy/testing
parenta517e14ee4c44488a2a765c588fa9a2a440b0662 (diff)
parentf45f4a3afc3c260d50773c647eb7b1c270bb8e00 (diff)
downloadsqlalchemy-a7d8063171d87eef0f89e114e919ea8e07023db3.tar.gz
Merge "Improve oracle index reflection" into main
Diffstat (limited to 'lib/sqlalchemy/testing')
-rw-r--r--lib/sqlalchemy/testing/requirements.py6
-rw-r--r--lib/sqlalchemy/testing/suite/test_reflection.py30
2 files changed, 33 insertions, 3 deletions
diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py
index ec19e4252..a2a9dc822 100644
--- a/lib/sqlalchemy/testing/requirements.py
+++ b/lib/sqlalchemy/testing/requirements.py
@@ -770,6 +770,12 @@ class SuiteRequirements(Requirements):
return exclusions.open()
@property
+ def reflect_indexes_with_ascdesc_as_expression(self):
+ """target database supports reflecting INDEX with per-column
+ ASC/DESC but reflects them as expressions (like oracle)."""
+ return exclusions.closed()
+
+ @property
def indexes_with_expressions(self):
"""target database supports CREATE INDEX against SQL expressions."""
return exclusions.closed()
diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py
index 119ef9a36..0162799d7 100644
--- a/lib/sqlalchemy/testing/suite/test_reflection.py
+++ b/lib/sqlalchemy/testing/suite/test_reflection.py
@@ -1114,6 +1114,10 @@ class ComponentReflectionTest(ComparesTables, OneConnectionTablesTest):
):
fk_req = testing.requires.foreign_keys_reflect_as_index
dup_req = testing.requires.unique_constraints_reflect_as_index
+ sorting_expression = (
+ testing.requires.reflect_indexes_with_ascdesc_as_expression
+ )
+
if (fk and not fk_req.enabled) or (
duplicates and not dup_req.enabled
):
@@ -1126,7 +1130,13 @@ class ComponentReflectionTest(ComparesTables, OneConnectionTablesTest):
"include_columns": [],
}
if column_sorting:
- res["column_sorting"] = {"q": ("desc",)}
+ res["column_sorting"] = column_sorting
+ if sorting_expression.enabled:
+ res["expressions"] = orig = res["column_names"]
+ res["column_names"] = [
+ None if c in column_sorting else c for c in orig
+ ]
+
if duplicates:
res["duplicates_constraint"] = name
return [res]
@@ -2070,6 +2080,15 @@ class ComponentReflectionTest(ComparesTables, OneConnectionTablesTest):
insp.clear_cache()
eq_(insp.get_multi_table_comment(**kw), exp)
+ def _check_expressions(self, result, exp, err_msg):
+ def _clean(text: str):
+ return re.sub(r"['\" ]", "", text).lower()
+
+ if isinstance(exp, dict):
+ eq_({_clean(e): v for e, v in result.items()}, exp, err_msg)
+ else:
+ eq_([_clean(e) for e in result], exp, err_msg)
+
def _check_list(self, result, exp, req_keys=None, msg=None):
if req_keys is None:
eq_(result, exp, msg)
@@ -2078,7 +2097,11 @@ class ComponentReflectionTest(ComparesTables, OneConnectionTablesTest):
for r, e in zip(result, exp):
for k in set(r) | set(e):
if k in req_keys or (k in r and k in e):
- eq_(r[k], e[k], f"{msg} - {k} - {r}")
+ err_msg = f"{msg} - {k} - {r}"
+ if k in ("expressions", "column_sorting"):
+ self._check_expressions(r[k], e[k], err_msg)
+ else:
+ eq_(r[k], e[k], err_msg)
def _check_table_dict(self, result, exp, req_keys=None, make_lists=False):
eq_(set(result.keys()), set(exp.keys()))
@@ -2471,8 +2494,9 @@ class ComponentReflectionTestExtra(ComparesIndexes, fixtures.TestBase):
class lower_index_str(str):
def __eq__(self, other):
+ ol = other.lower()
# test that lower and x or y are in the string
- return "lower" in other and ("x" in other or "y" in other)
+ return "lower" in ol and ("x" in ol or "y" in ol)
class coalesce_index_str(str):
def __eq__(self, other):