From: Mike Bayer Date: Tue, 21 Jun 2022 18:07:49 +0000 (-0400) Subject: add more pg ENUM tests X-Git-Tag: rel_2_0_0b1~222^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=13f59a6376ff8f44bdaa13f678146ac29fbbd798;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git add more pg ENUM tests given 017fd9ae0645eaf2a0fbdd067d10c has changed 'name' to be required for ENUM, add some more adapt from Enum types of tests. Change-Id: I447983e640d6466f969aa51c8dff5a0cb8074ca8 --- diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index 5c3935d446..41bd1f5e7b 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -164,7 +164,9 @@ class FloatCoercionTest(fixtures.TablesTest, AssertsExecutionResults): eq_(row, ([5], [5], [6], [7], [decimal.Decimal("6.4")])) -class NamedTypeTest(fixtures.TestBase, AssertsExecutionResults): +class NamedTypeTest( + AssertsCompiledSQL, fixtures.TestBase, AssertsExecutionResults +): __backend__ = True __only_on__ = "postgresql > 8.3" @@ -449,6 +451,7 @@ class NamedTypeTest(fixtures.TestBase, AssertsExecutionResults): assert False @testing.combinations( + (Enum("one", "two", "three")), (ENUM("one", "two", "three", name=None)), ( DOMAIN( @@ -460,11 +463,46 @@ class NamedTypeTest(fixtures.TestBase, AssertsExecutionResults): argnames="datatype", ) def test_name_required(self, metadata, connection, datatype): + assert_raises(exc.CompileError, datatype.create, connection) assert_raises( exc.CompileError, datatype.compile, dialect=connection.dialect ) + def test_enum_doesnt_construct_ENUM(self): + """in 2.0 we made ENUM name required. check that Enum adapt to + ENUM doesnt call this constructor.""" + + e1 = Enum("x", "y") + eq_(e1.name, None) + e2 = e1.adapt(ENUM) + eq_(e2.name, None) + + # no name + assert_raises( + exc.CompileError, e2.compile, dialect=postgresql.dialect() + ) + + def test_py_enum_name_is_used(self): + class MyEnum(_PY_Enum): + x = "1" + y = "2" + + e1 = Enum(MyEnum) + eq_(e1.name, "myenum") + e2 = e1.adapt(ENUM) + + # note that by making "name" required, we are now not supporting this: + # e2 = ENUM(MyEnum) + # they'd need ENUM(MyEnum, name="myenum") + # I might be OK with that. Use of pg.ENUM directly is not as + # common and it suggests more explicitness on the part of the + # programmer in any case + + eq_(e2.name, "myenum") + + self.assert_compile(e2, "myenum") + def test_enum_unicode_labels(self, connection, metadata): t1 = Table( "table",