summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-02-06 23:30:58 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2023-02-07 08:58:33 -0500
commite6c67ae42284a711eaae64aabe14c722d9eeed54 (patch)
treeb0b5a0e486b46832cdcabdad859541dcd423cad6 /tests
parent08266a49db1ce69224e62fa89f34f03a2f0f9529 (diff)
downloadalembic-e6c67ae42284a711eaae64aabe14c722d9eeed54.tar.gz
add variant render step for user-defined types
due to SQLA 2.0's variant being integrated into types, the variant rendering conditional would no longer take effect as the type was not under the "sqlalchemy" module namespace. Fixed issue where rendering of user-defined types that then went onto use the ``.with_variant()`` method would fail to render, if using SQLAlchemy 2.0's version of variants. Change-Id: I3c6f14325d6dffb2ddc1bf955753ee5a2de2cedd Fixes: #1167
Diffstat (limited to 'tests')
-rw-r--r--tests/test_autogen_render.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/tests/test_autogen_render.py b/tests/test_autogen_render.py
index 0a2fc87..f138df5 100644
--- a/tests/test_autogen_render.py
+++ b/tests/test_autogen_render.py
@@ -1757,19 +1757,38 @@ class AutogenRenderTest(TestBase):
" # ### end Alembic commands ###",
)
- def test_repr_custom_type_w_sqla_prefix(self):
+ @testing.combinations("sqlaname", "nonsqlaname", argnames="modname")
+ @testing.combinations("usevariant", "plain", argnames="construct")
+ def test_repr_custom_type(self, modname, construct):
+ """test #1167 as well as other user defined type variations"""
+
self.autogen_context.opts["user_module_prefix"] = None
class MyType(UserDefinedType):
pass
- MyType.__module__ = "sqlalchemy_util.types"
+ if modname == "sqlaname":
+ MyType.__module__ = mod = "sqlalchemy_util.types"
+ elif modname == "nonsqlaname":
+ MyType.__module__ = mod = "mymodule"
+ else:
+ assert False
- type_ = MyType()
+ if construct == "usevariant":
+ type_ = MyType().with_variant(String(), "mysql")
+ elif construct == "plain":
+ type_ = MyType()
+ else:
+ assert False
eq_ignore_whitespace(
autogenerate.render._repr_type(type_, self.autogen_context),
- "sqlalchemy_util.types.MyType()",
+ f"{mod}.MyType()"
+ + (
+ ".with_variant(sa.String(), 'mysql')"
+ if construct == "usevariant"
+ else ""
+ ),
)
def test_render_variant(self):