summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-03-24 21:06:04 +0100
committerFederico Caselli <cfederico87@gmail.com>2020-04-06 20:02:28 +0200
commita902660f711da0b428fd2b9abf9b281a1ef6a118 (patch)
tree81bf42dd358d36b2f159c331529f15e5c6ea65e3 /test
parent49b6c50016c8a038a6df7104560bb3945debe064 (diff)
downloadsqlalchemy-a902660f711da0b428fd2b9abf9b281a1ef6a118.tar.gz
Add length parameter in `Enum`
The `Enum` type now supports the parameter `Enum.length` to specify the length of the VARCHAR column to create when using non native enums by setting `Enum.native_enum` to `False` Fixes: #5183 Change-Id: Iea05dc8cd9e33959bb968b394fb10a7dd068c873
Diffstat (limited to 'test')
-rw-r--r--test/sql/test_types.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/sql/test_types.py b/test/sql/test_types.py
index 2af8cb325..0590bb5e3 100644
--- a/test/sql/test_types.py
+++ b/test/sql/test_types.py
@@ -1876,6 +1876,35 @@ class EnumTest(AssertsCompiledSQL, fixtures.TablesTest):
"inherit_schema=True, native_enum=False)",
)
+ def test_length_native(self):
+ e = Enum("x", "y", "long", length=42)
+
+ eq_(e.length, len("long"))
+
+ # no error is raised
+ e = Enum("x", "y", "long", length=1)
+ eq_(e.length, len("long"))
+
+ def test_length_raises(self):
+ assert_raises_message(
+ ValueError,
+ "When provided, length must be larger or equal.*",
+ Enum,
+ "x",
+ "y",
+ "long",
+ native_enum=False,
+ length=1,
+ )
+
+ def test_no_length_non_native(self):
+ e = Enum("x", "y", "long", native_enum=False)
+ eq_(e.length, len("long"))
+
+ def test_length_non_native(self):
+ e = Enum("x", "y", "long", native_enum=False, length=42)
+ eq_(e.length, 42)
+
binary_table = MyPickleType = metadata = None