"""
+ if not dialect_names:
+ raise exc.ArgumentError("At least one dialect name is required")
for dialect_name in dialect_names:
if dialect_name in self._variant_mapping:
raise exc.ArgumentError(
- "Dialect '%s' is already present in "
- "the mapping for this %r" % (dialect_name, self)
+ f"Dialect {dialect_name!r} is already present in "
+ f"the mapping for this {self!r}"
)
new_type = self.copy()
- if isinstance(type_, type):
- type_ = type_()
- elif type_._variant_mapping:
+ type_ = to_instance(type_)
+ if type_._variant_mapping:
raise exc.ArgumentError(
"can't pass a type that already has variants as a "
"dialect-level type to with_variant()"
self.UTypeTwo = UTypeTwo
self.UTypeThree = UTypeThree
self.variant = self.UTypeOne().with_variant(
- self.UTypeTwo(), "postgresql"
+ self.UTypeTwo(), "postgresql", "mssql"
)
self.composite = self.variant.with_variant(self.UTypeThree(), "mysql")
+ def test_one_dialect_is_req(self):
+ with expect_raises_message(
+ exc.ArgumentError, "At least one dialect name is required"
+ ):
+ String().with_variant(VARCHAR())
+
def test_illegal_dupe(self):
v = self.UTypeOne().with_variant(self.UTypeTwo(), "postgresql")
assert_raises_message(
self.assert_compile(
self.variant, "UTYPETWO", dialect=dialects.postgresql.dialect()
)
+ self.assert_compile(
+ self.variant, "UTYPETWO", dialect=dialects.mssql.dialect()
+ )
def test_to_instance(self):
self.assert_compile(