Skip to content

Commit d67178e

Browse files
committed
test: add example test for double creation of enums
1 parent 16b24c6 commit d67178e

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
# snapshottest: v1 - https://goo.gl/zC4yUc
3+
from __future__ import unicode_literals
4+
5+
from snapshottest import Snapshot
6+
7+
snapshots = Snapshot()
8+
9+
snapshots["test_enum 1"] = """
10+
CREATE TYPE severity AS ENUM ( 'LOW', 'MEDIUM', 'HIGH' );
11+
12+
13+
CREATE TABLE bugs(severity ENUM('LOW', 'MEDIUM', 'HIGH'), PRIMARY KEY(severity));
14+
15+
16+
17+
18+
"""

duckdb_engine/tests/test_datatypes.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import decimal
2+
import enum
23
import json
34
import warnings
5+
from pathlib import Path
46
from typing import Any, Dict, Type
57
from uuid import uuid4
68

9+
import sqlalchemy as sa
710
from packaging.version import Version
811
from pytest import importorskip, mark
912
from snapshottest.module import SnapshotTest
@@ -248,3 +251,26 @@ def test_div_is_floordiv(engine: Engine) -> None:
248251
stmt = test_table.c.value / test_table.c.eur2usd_rate
249252

250253
assert str(stmt.compile(engine)) == "test_table.value / test_table.eur2usd_rate"
254+
255+
256+
def test_enum(
257+
engine: Engine, session: Session, tmp_path: Path, snapshot: SnapshotTest
258+
) -> None:
259+
base = declarative_base()
260+
261+
class Severity(enum.Enum):
262+
LOW = enum.auto()
263+
MEDIUM = enum.auto()
264+
HIGH = enum.auto()
265+
266+
class Bug(base):
267+
__tablename__ = "bugs"
268+
269+
severity = sa.Column(sa.Enum(Severity), primary_key=True)
270+
271+
base.metadata.create_all(bind=engine)
272+
session.execute(sa.text(f"EXPORT DATABASE '{tmp_path}'"))
273+
ddl_sql = (tmp_path / "schema.sql").read_text()
274+
# n_enum_defs = ddl_sql.count("'LOW', 'MEDIUM', 'HIGH'")
275+
# assert n_enum_defs == 1, ddl_sql
276+
snapshot.assert_match(ddl_sql)

0 commit comments

Comments
 (0)