diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-06-10 12:42:54 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-06-10 13:21:26 -0400 |
| commit | 4274981156a554fb4b8340d2fa4d8c4afed7c86c (patch) | |
| tree | 5c20a6f9102f2a75e6d5c799e0ec9ec3ba9e784c /test/sql | |
| parent | b171f5d2e488c46a664847644e65d5dc03759840 (diff) | |
| download | sqlalchemy-4274981156a554fb4b8340d2fa4d8c4afed7c86c.tar.gz | |
honor enum length in all cases
The :paramref:`.Enum.length` parameter, which sets the length of the
``VARCHAR`` column for non-native enumeration types, is now used
unconditionally when emitting DDL for the ``VARCHAR`` datatype, including
when the :paramref:`.Enum.native_enum` parameter is set to ``True`` for
target backends that continue to use ``VARCHAR``. Previously the parameter
would be erroneously ignored in this case. The warning previously emitted
for this case is now removed.
Fixes: #7791
Change-Id: I91764546b56e9416479949be8a118cdc91ac5ed9
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_types.py | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/test/sql/test_types.py b/test/sql/test_types.py index b2afa2dba..ef3915726 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -83,7 +83,6 @@ from sqlalchemy.testing import AssertsExecutionResults from sqlalchemy.testing import engines from sqlalchemy.testing import eq_ from sqlalchemy.testing import expect_raises -from sqlalchemy.testing import expect_warnings from sqlalchemy.testing import fixtures from sqlalchemy.testing import is_ from sqlalchemy.testing import is_not @@ -2394,18 +2393,26 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest): eq_(e1_vc.adapt(ENUM).name, "someotherenum") eq_(e1_vc.adapt(ENUM).enums, ["1", "2", "3", "a", "b"]) - def test_adapt_length(self): + @testing.combinations(True, False, argnames="native_enum") + def test_adapt_length(self, native_enum): from sqlalchemy.dialects.postgresql import ENUM - e1 = Enum("one", "two", "three", length=50, native_enum=False) - eq_(e1.adapt(ENUM).length, 50) + e1 = Enum("one", "two", "three", length=50, native_enum=native_enum) + + if not native_enum: + eq_(e1.adapt(ENUM).length, 50) + eq_(e1.adapt(Enum).length, 50) + self.assert_compile(e1, "VARCHAR(50)", dialect="default") + e1 = Enum("one", "two", "three") eq_(e1.length, 5) eq_(e1.adapt(ENUM).length, 5) eq_(e1.adapt(Enum).length, 5) + self.assert_compile(e1, "VARCHAR(5)", dialect="default") + @testing.provide_metadata def test_create_metadata_bound_no_crash(self): m1 = self.metadata @@ -2502,32 +2509,20 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest): ) def test_repr_four(self): - with expect_warnings( - "Enum 'length' argument is currently ignored unless native_enum" - ): - e = Enum("x", "y", length=255) - # length is currently ignored if native_enum is not False + e = Enum("x", "y", length=255) eq_( repr(e), - "Enum('x', 'y')", + "Enum('x', 'y', length=255)", ) def test_length_native(self): - with expect_warnings( - "Enum 'length' argument is currently ignored unless native_enum" - ): - e = Enum("x", "y", "long", length=42) - - eq_(e.length, len("long")) + e = Enum("x", "y", "long", length=42) + eq_(e.length, 42) - # no error is raised - with expect_warnings( - "Enum 'length' argument is currently ignored unless native_enum" - ): - e = Enum("x", "y", "long", length=1) + e = Enum("x", "y", "long") eq_(e.length, len("long")) - def test_length_raises(self): + def test_length_too_short_raises(self): assert_raises_message( ValueError, "When provided, length must be larger or equal.*", |
