cdef public libpq.Oid oid
cdef pq.PGconn _pgconn
- def __init__(self, cls: type, context: Optional[AdaptContext] = None):
+ def __init__(self, cls, context: Optional[AdaptContext] = None):
self.cls = cls
conn = context.connection if context is not None else None
self._pgconn = conn.pgconn if conn is not None else None
cdef char *encoding
cdef bytes _bytes_encoding # needed to keep `encoding` alive
- def __init__(self, cls: type, context: Optional[AdaptContext] = None):
+ def __init__(self, cls, context: Optional[AdaptContext] = None):
super().__init__(cls, context)
self.is_utf8 = 0
assert cur.fetchone()[0] is True
+@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+def test_dump_enum(conn, fmt_in):
+ import enum
+
+ class MyEnum(enum.IntEnum):
+ foo = 42
+
+ cur = conn.cursor()
+ (res,) = cur.execute("select %s", (MyEnum.foo,)).fetchone()
+ assert res == 42
+
+
@pytest.mark.parametrize(
"val, expr",
[
cur.execute(f"select %{fmt_in}", ("\uddf8",))
+@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+def test_dump_enum(conn, fmt_in):
+ from enum import Enum
+
+ class MyEnum(str, Enum):
+ foo = "foo"
+
+ cur = conn.cursor()
+ (res,) = cur.execute("select %s", (MyEnum.foo,)).fetchone()
+ assert res == "foo"
+
+
@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
@pytest.mark.parametrize("encoding", ["utf8", "latin9"])
@pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar"])