]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Drop rename of PyFormat import in tests
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 15 Sep 2021 18:19:26 +0000 (19:19 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 15 Sep 2021 18:27:30 +0000 (19:27 +0100)
It was to minimise a diff when it got renamed, but it's confusing using
old tests as template for new ones.

16 files changed:
tests/test_adapt.py
tests/test_cursor.py
tests/test_cursor_async.py
tests/test_query.py
tests/test_sql.py
tests/types/test_array.py
tests/types/test_bool.py
tests/types/test_composite.py
tests/types/test_datetime.py
tests/types/test_json.py
tests/types/test_net.py
tests/types/test_none.py
tests/types/test_numeric.py
tests/types/test_range.py
tests/types/test_string.py
tests/types/test_uuid.py

index 41a86c75e49166207e5cb61fe236aa5e8f5a3802..09edfceaf538d399e92bb02ffa621ba855e73c0c 100644 (file)
@@ -6,7 +6,7 @@ import pytest
 import psycopg
 from psycopg import pq, sql, postgres
 from psycopg import errors as e
-from psycopg.adapt import Transformer, PyFormat as Format, Dumper, Loader
+from psycopg.adapt import Transformer, PyFormat, Dumper, Loader
 from psycopg._cmodule import _psycopg
 from psycopg.postgres import types as builtins, TEXT_OID
 
@@ -14,16 +14,16 @@ from psycopg.postgres import types as builtins, TEXT_OID
 @pytest.mark.parametrize(
     "data, format, result, type",
     [
-        (1, Format.TEXT, b"1", "int2"),
-        ("hello", Format.TEXT, b"hello", "text"),
-        ("hello", Format.BINARY, b"hello", "text"),
+        (1, PyFormat.TEXT, b"1", "int2"),
+        ("hello", PyFormat.TEXT, b"hello", "text"),
+        ("hello", PyFormat.BINARY, b"hello", "text"),
     ],
 )
 def test_dump(data, format, result, type):
     t = Transformer()
     dumper = t.get_dumper(data, format)
     assert dumper.dump(data) == result
-    if type == "text" and format != Format.BINARY:
+    if type == "text" and format != PyFormat.BINARY:
         assert dumper.oid == 0
     else:
         assert dumper.oid == builtins[type].oid
@@ -41,24 +41,24 @@ def test_dump(data, format, result, type):
 )
 def test_quote(data, result):
     t = Transformer()
-    dumper = t.get_dumper(data, Format.TEXT)
+    dumper = t.get_dumper(data, PyFormat.TEXT)
     assert dumper.quote(data) == result
 
 
 def test_register_dumper_by_class(conn):
     dumper = make_dumper("x")
-    assert conn.adapters.get_dumper(MyStr, Format.TEXT) is not dumper
+    assert conn.adapters.get_dumper(MyStr, PyFormat.TEXT) is not dumper
     conn.adapters.register_dumper(MyStr, dumper)
-    assert conn.adapters.get_dumper(MyStr, Format.TEXT) is dumper
+    assert conn.adapters.get_dumper(MyStr, PyFormat.TEXT) is dumper
 
 
 def test_register_dumper_by_class_name(conn):
     dumper = make_dumper("x")
-    assert conn.adapters.get_dumper(MyStr, Format.TEXT) is not dumper
+    assert conn.adapters.get_dumper(MyStr, PyFormat.TEXT) is not dumper
     conn.adapters.register_dumper(
         f"{MyStr.__module__}.{MyStr.__qualname__}", dumper
     )
-    assert conn.adapters.get_dumper(MyStr, Format.TEXT) is dumper
+    assert conn.adapters.get_dumper(MyStr, PyFormat.TEXT) is dumper
 
 
 def test_dump_global_ctx(dsn, global_adapters):
@@ -110,8 +110,7 @@ def test_dump_cursor_ctx(conn):
     assert cur.fetchone() == ("hellob",)
 
 
-@pytest.mark.parametrize("fmt_out", [Format.TEXT, Format.BINARY])
-def test_dump_subclass(conn, fmt_out):
+def test_dump_subclass(conn):
     class MyString(str):
         pass
 
@@ -276,7 +275,7 @@ def test_cow_loaders(conn):
     "sql, obj",
     [("'{hello}'::text[]", ["helloc"]), ("row('hello'::text)", ("helloc",))],
 )
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_cursor_ctx_nested(conn, sql, obj, fmt_out):
     cur = conn.cursor(binary=fmt_out == pq.Format.BINARY)
     if fmt_out == pq.Format.TEXT:
@@ -289,10 +288,10 @@ def test_load_cursor_ctx_nested(conn, sql, obj, fmt_out):
     assert res == obj
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_array_dumper(conn, fmt_out):
     t = Transformer(conn)
-    fmt_in = Format.from_pq(fmt_out)
+    fmt_in = PyFormat.from_pq(fmt_out)
     dint = t.get_dumper([0], fmt_in)
     if fmt_out == pq.Format.BINARY:
         assert dint.oid == builtins["int2"].array_oid
@@ -302,7 +301,7 @@ def test_array_dumper(conn, fmt_out):
         assert dint.sub_dumper is None
 
     dstr = t.get_dumper([""], fmt_in)
-    if fmt_in == Format.BINARY:
+    if fmt_in == PyFormat.BINARY:
         assert dstr.oid == builtins["text"].array_oid
         assert dstr.sub_dumper.oid == builtins["text"].oid
     else:
@@ -341,7 +340,7 @@ def test_last_dumper_registered_ctx(conn):
     assert cur.execute("select %s", ["hello"]).fetchone()[0] == "hellob"
 
 
-@pytest.mark.parametrize("fmt_in", [Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", [PyFormat.TEXT, PyFormat.BINARY])
 def test_none_type_argument(conn, fmt_in):
     cur = conn.cursor()
     cur.execute("create table none_args (id serial primary key, num integer)")
@@ -351,7 +350,7 @@ def test_none_type_argument(conn, fmt_in):
     assert cur.fetchone()[0]
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_return_untyped(conn, fmt_in):
     # Analyze and check for changes using strings in untyped/typed contexts
     cur = conn.cursor()
@@ -362,7 +361,7 @@ def test_return_untyped(conn, fmt_in):
     assert cur.fetchone() == ("hello", 10)
 
     cur.execute("create table testjson(data jsonb)")
-    if fmt_in != Format.BINARY:
+    if fmt_in != PyFormat.BINARY:
         cur.execute(f"insert into testjson (data) values (%{fmt_in})", ["{}"])
         assert cur.execute("select data from testjson").fetchone() == ({},)
     else:
@@ -373,7 +372,7 @@ def test_return_untyped(conn, fmt_in):
             )
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat.AUTO)
 def test_no_cast_needed(conn, fmt_in):
     # Verify that there is no need of cast in certain common scenario
     cur = conn.execute("select '2021-01-01'::date + %s", [3])
@@ -433,7 +432,7 @@ def test_optimised_adapters():
 
 
 @pytest.mark.slow
-@pytest.mark.parametrize("fmt", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt", PyFormat)
 @pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
 def test_random(conn, faker, fmt, fmt_out):
     faker.format = fmt
index 3032dbaea6e7822508d855af6844c909b1291be2..07827732007668ceb477f7029a6c5bb8ef7ac95d 100644 (file)
@@ -7,7 +7,7 @@ import pytest
 
 import psycopg
 from psycopg import pq, sql, rows
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 from psycopg.postgres import types as builtins
 
 from .utils import gc_collect
@@ -222,7 +222,7 @@ def test_executemany_badquery(conn, query):
         cur.executemany(query, [(10, "hello"), (20, "world")])
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_executemany_null_first(conn, fmt_in):
     cur = conn.cursor()
     cur.execute("create table testmany (a bigint, b bigint)")
@@ -620,8 +620,8 @@ def test_str(conn):
 
 
 @pytest.mark.slow
-@pytest.mark.parametrize("fmt", [Format.AUTO, Format.TEXT, Format.BINARY])
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt", PyFormat)
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("fetch", ["one", "many", "all", "iter"])
 @pytest.mark.parametrize(
     "row_factory", ["tuple_row", "dict_row", "namedtuple_row"]
index e069f8bd106c6f54be573a6c9c502a0a0c251bea..54c2a99c7fa832c784fe8b10455a6e169f02aee3 100644 (file)
@@ -5,7 +5,7 @@ import datetime as dt
 
 import psycopg
 from psycopg import pq, sql, rows
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 
 from .utils import gc_collect
 from .test_cursor import my_row_factory
@@ -222,7 +222,7 @@ async def test_executemany_badquery(aconn, query):
         await cur.executemany(query, [(10, "hello"), (20, "world")])
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 async def test_executemany_null_first(aconn, fmt_in):
     cur = aconn.cursor()
     await cur.execute("create table testmany (a bigint, b bigint)")
@@ -519,8 +519,8 @@ async def test_str(aconn):
 
 
 @pytest.mark.slow
-@pytest.mark.parametrize("fmt", [Format.AUTO, Format.TEXT, Format.BINARY])
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt", PyFormat)
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("fetch", ["one", "many", "all", "iter"])
 @pytest.mark.parametrize(
     "row_factory", ["tuple_row", "dict_row", "namedtuple_row"]
index 0314dd8cf64f179b03b458d8cd6a66031cfce4a6..7263a8045518a9c63626c51fd1ab7712cbebdaca 100644 (file)
@@ -2,43 +2,43 @@ import pytest
 
 import psycopg
 from psycopg import pq
-from psycopg.adapt import Transformer, PyFormat as Format
+from psycopg.adapt import Transformer, PyFormat
 from psycopg._queries import PostgresQuery, _split_query
 
 
 @pytest.mark.parametrize(
     "input, want",
     [
-        (b"", [(b"", 0, Format.AUTO)]),
-        (b"foo bar", [(b"foo bar", 0, Format.AUTO)]),
-        (b"foo %% bar", [(b"foo % bar", 0, Format.AUTO)]),
-        (b"%s", [(b"", 0, Format.AUTO), (b"", 0, Format.AUTO)]),
-        (b"%s foo", [(b"", 0, Format.AUTO), (b" foo", 0, Format.AUTO)]),
-        (b"%b foo", [(b"", 0, Format.BINARY), (b" foo", 0, Format.AUTO)]),
-        (b"foo %s", [(b"foo ", 0, Format.AUTO), (b"", 0, Format.AUTO)]),
+        (b"", [(b"", 0, PyFormat.AUTO)]),
+        (b"foo bar", [(b"foo bar", 0, PyFormat.AUTO)]),
+        (b"foo %% bar", [(b"foo % bar", 0, PyFormat.AUTO)]),
+        (b"%s", [(b"", 0, PyFormat.AUTO), (b"", 0, PyFormat.AUTO)]),
+        (b"%s foo", [(b"", 0, PyFormat.AUTO), (b" foo", 0, PyFormat.AUTO)]),
+        (b"%b foo", [(b"", 0, PyFormat.BINARY), (b" foo", 0, PyFormat.AUTO)]),
+        (b"foo %s", [(b"foo ", 0, PyFormat.AUTO), (b"", 0, PyFormat.AUTO)]),
         (
             b"foo %%%s bar",
-            [(b"foo %", 0, Format.AUTO), (b" bar", 0, Format.AUTO)],
+            [(b"foo %", 0, PyFormat.AUTO), (b" bar", 0, PyFormat.AUTO)],
         ),
         (
             b"foo %(name)s bar",
-            [(b"foo ", "name", Format.AUTO), (b" bar", 0, Format.AUTO)],
+            [(b"foo ", "name", PyFormat.AUTO), (b" bar", 0, PyFormat.AUTO)],
         ),
         (
             b"foo %(name)s %(name)b bar",
             [
-                (b"foo ", "name", Format.AUTO),
-                (b" ", "name", Format.BINARY),
-                (b" bar", 0, Format.AUTO),
+                (b"foo ", "name", PyFormat.AUTO),
+                (b" ", "name", PyFormat.BINARY),
+                (b" bar", 0, PyFormat.AUTO),
             ],
         ),
         (
             b"foo %s%b bar %s baz",
             [
-                (b"foo ", 0, Format.AUTO),
-                (b"", 1, Format.BINARY),
-                (b" bar ", 2, Format.AUTO),
-                (b" baz", 0, Format.AUTO),
+                (b"foo ", 0, PyFormat.AUTO),
+                (b"", 1, PyFormat.BINARY),
+                (b" bar ", 2, PyFormat.AUTO),
+                (b" baz", 0, PyFormat.AUTO),
             ],
         ),
     ],
index dcdd058c064747e5265a9e595419d8916ac3813c..b2c6264c8793f0cd8d74df699c1e9be846dde770 100644 (file)
@@ -8,7 +8,7 @@ import datetime as dt
 import pytest
 
 from psycopg import pq, sql, ProgrammingError
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 
 eur = "\u20ac"
 
@@ -495,16 +495,16 @@ class TestPlaceholder:
     def test_class(self):
         assert issubclass(sql.Placeholder, sql.Composable)
 
-    @pytest.mark.parametrize("format", Format)
+    @pytest.mark.parametrize("format", PyFormat)
     def test_repr_format(self, conn, format):
         ph = sql.Placeholder(format=format)
-        add = f"format={format.name}" if format != Format.AUTO else ""
+        add = f"format={format.name}" if format != PyFormat.AUTO else ""
         assert str(ph) == repr(ph) == f"Placeholder({add})"
 
-    @pytest.mark.parametrize("format", Format)
+    @pytest.mark.parametrize("format", PyFormat)
     def test_repr_name_format(self, conn, format):
         ph = sql.Placeholder("foo", format=format)
-        add = f", format={format.name}" if format != Format.AUTO else ""
+        add = f", format={format.name}" if format != PyFormat.AUTO else ""
         assert str(ph) == repr(ph) == f"Placeholder('foo'{add})"
 
     def test_bad_name(self):
@@ -519,7 +519,7 @@ class TestPlaceholder:
         assert sql.Placeholder("foo") != sql.Placeholder()
         assert sql.Placeholder("foo") != sql.Literal("foo")
 
-    @pytest.mark.parametrize("format", Format)
+    @pytest.mark.parametrize("format", PyFormat)
     def test_as_string(self, conn, format):
         ph = sql.Placeholder(format=format)
         assert ph.as_string(conn) == f"%{format}"
@@ -527,7 +527,7 @@ class TestPlaceholder:
         ph = sql.Placeholder(name="foo", format=format)
         assert ph.as_string(conn) == f"%(foo){format}"
 
-    @pytest.mark.parametrize("format", Format)
+    @pytest.mark.parametrize("format", PyFormat)
     def test_as_bytes(self, conn, format):
         ph = sql.Placeholder(format=format)
         assert ph.as_bytes(conn) == f"%{format}".encode("ascii")
index 194b0f21573f1f90cda6b2b716f904ec735d994c..54207d0ed66279146723fd04414ff289657272a7 100644 (file)
@@ -5,7 +5,7 @@ import pytest
 import psycopg
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import PyFormat as Format, Transformer, Dumper
+from psycopg.adapt import PyFormat, Transformer, Dumper
 from psycopg.types import TypeInfo
 from psycopg.postgres import types as builtins
 
@@ -27,10 +27,8 @@ tests_str = [
     ),
 ]
 
-fmts_in = [Format.AUTO, Format.TEXT, Format.BINARY]
 
-
-@pytest.mark.parametrize("fmt_in", fmts_in)
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("obj, want", tests_str)
 def test_dump_list_str(conn, obj, want, fmt_in):
     cur = conn.cursor()
@@ -38,7 +36,7 @@ def test_dump_list_str(conn, obj, want, fmt_in):
     assert cur.fetchone()[0]
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("want, obj", tests_str)
 def test_load_list_str(conn, obj, want, fmt_out):
     cur = conn.cursor(binary=fmt_out)
@@ -46,8 +44,8 @@ def test_load_list_str(conn, obj, want, fmt_out):
     assert cur.fetchone()[0] == want
 
 
-@pytest.mark.parametrize("fmt_in", fmts_in)
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_all_chars(conn, fmt_in, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     for i in range(1, 256):
@@ -93,10 +91,10 @@ def test_dump_list_int(conn, obj, want):
 def test_bad_binary_array(input):
     tx = Transformer()
     with pytest.raises(psycopg.DataError):
-        tx.get_dumper(input, Format.BINARY).dump(input)
+        tx.get_dumper(input, PyFormat.BINARY).dump(input)
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("want, obj", tests_int)
 def test_load_list_int(conn, obj, want, fmt_out):
     cur = conn.cursor(binary=fmt_out)
@@ -146,7 +144,7 @@ def test_array_of_unknown_builtin(conn):
 )
 def test_array_mixed_numbers(array, type):
     tx = Transformer()
-    dumper = tx.get_dumper(array, Format.BINARY)
+    dumper = tx.get_dumper(array, PyFormat.BINARY)
     dumper.dump(array)
     assert dumper.oid == builtins[type].array_oid
 
@@ -154,8 +152,8 @@ def test_array_mixed_numbers(array, type):
 @pytest.mark.parametrize(
     "wrapper", "Int2 Int4 Int8 Float4 Float8 Decimal".split()
 )
-@pytest.mark.parametrize("fmt_in", fmts_in)
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_list_number_wrapper(conn, wrapper, fmt_in, fmt_out):
     wrapper = getattr(psycopg.types.numeric, wrapper)
     if wrapper is Decimal:
@@ -182,7 +180,7 @@ def test_mix_types(conn):
     assert cur.description[0].type_code == builtins["numeric"].array_oid
 
 
-@pytest.mark.parametrize("fmt_in", fmts_in)
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_empty_list_mix(conn, fmt_in):
     objs = list(range(3))
     conn.execute("create table testarrays (col1 bigint[], col2 bigint[])")
@@ -195,7 +193,7 @@ def test_empty_list_mix(conn, fmt_in):
     assert f2 == []
 
 
-@pytest.mark.parametrize("fmt_in", fmts_in)
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_empty_list(conn, fmt_in):
     cur = conn.cursor()
     cur.execute("create table test (id serial primary key, data date[])")
@@ -211,7 +209,7 @@ def test_empty_list(conn, fmt_in):
     assert not cur.fetchone()
 
 
-@pytest.mark.parametrize("fmt_in", fmts_in)
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_empty_list_after_choice(conn, fmt_in):
     cur = conn.cursor()
     cur.execute("create table test (id serial primary key, data float[])")
index 27dddaa15596e8fb39fce05861738b7bf5d700f2..85a62b48892b1e485b069d8d1461b9f97dfe60c7 100644 (file)
@@ -2,12 +2,12 @@ import pytest
 
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import Transformer, PyFormat as Format
+from psycopg.adapt import Transformer, PyFormat
 from psycopg.postgres import types as builtins
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("b", [True, False])
 def test_roundtrip_bool(conn, b, fmt_in, fmt_out):
     cur = conn.cursor(binary=fmt_out)
@@ -28,7 +28,7 @@ def test_roundtrip_bool(conn, b, fmt_in, fmt_out):
 def test_quote_bool(conn, val):
 
     tx = Transformer()
-    assert tx.get_dumper(val, Format.TEXT).quote(val) == str(
+    assert tx.get_dumper(val, PyFormat.TEXT).quote(val) == str(
         val
     ).lower().encode("ascii")
 
@@ -40,7 +40,7 @@ def test_quote_bool(conn, val):
 def test_quote_none(conn):
 
     tx = Transformer()
-    assert tx.get_dumper(None, Format.TEXT).quote(None) == b"NULL"
+    assert tx.get_dumper(None, PyFormat.TEXT).quote(None) == b"NULL"
 
     cur = conn.cursor()
     cur.execute(sql.SQL("select {v}").format(v=sql.Literal(None)))
index 2c314e9cfc076c05ed8337f4c9acd49a5ff1657c..cfc2c91e3202ca017c00070f0ad41bab80d7dbd0 100644 (file)
@@ -2,7 +2,7 @@ import pytest
 
 from psycopg import pq, postgres
 from psycopg.sql import Identifier
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 from psycopg.postgres import types as builtins
 from psycopg.types.range import Range
 from psycopg.types.composite import CompositeInfo, register_composite
@@ -46,7 +46,7 @@ def test_dump_tuple(conn, rec, obj):
     assert res == obj
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_all_chars(conn, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     for i in range(1, 256):
@@ -64,7 +64,7 @@ def test_load_all_chars(conn, fmt_out):
     assert res == (s,)
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_builtin_empty_range(conn, fmt_in):
     conn.execute(
         """
@@ -177,7 +177,7 @@ async def test_fetch_info_async(aconn, testcomp, name, fields):
         assert info.field_types[i] == builtins[t].oid
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT])
+@pytest.mark.parametrize("fmt_in", [PyFormat.AUTO, PyFormat.TEXT])
 def test_dump_tuple_all_chars(conn, fmt_in, testcomp):
     cur = conn.cursor()
     for i in range(1, 256):
@@ -188,7 +188,7 @@ def test_dump_tuple_all_chars(conn, fmt_in, testcomp):
         assert res is True
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_composite_all_chars(conn, fmt_in, testcomp):
     cur = conn.cursor()
     register_composite(testcomp, cur)
@@ -201,7 +201,7 @@ def test_dump_composite_all_chars(conn, fmt_in, testcomp):
         assert res is True
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_composite_null(conn, fmt_in, testcomp):
     cur = conn.cursor()
     register_composite(testcomp, cur)
@@ -217,7 +217,7 @@ def test_dump_composite_null(conn, fmt_in, testcomp):
     assert rec[0] is True, rec[1]
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_composite(conn, testcomp, fmt_out):
     info = CompositeInfo.fetch(conn, "testcomp")
     register_composite(info, conn)
@@ -237,7 +237,7 @@ def test_load_composite(conn, testcomp, fmt_out):
     assert isinstance(res[0].baz, float)
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_composite_factory(conn, testcomp, fmt_out):
     info = CompositeInfo.fetch(conn, "testcomp")
 
@@ -265,23 +265,23 @@ def test_load_composite_factory(conn, testcomp, fmt_out):
 def test_register_scope(conn, testcomp):
     info = CompositeInfo.fetch(conn, "testcomp")
     register_composite(info)
-    for fmt in (pq.Format.TEXT, pq.Format.BINARY):
+    for fmt in pq.Format:
         for oid in (info.oid, info.array_oid):
             assert postgres.adapters._loaders[fmt].pop(oid)
 
-    for fmt in Format:
+    for fmt in PyFormat:
         assert postgres.adapters._dumpers[fmt].pop(info.python_type)
 
     cur = conn.cursor()
     register_composite(info, cur)
-    for fmt in (pq.Format.TEXT, pq.Format.BINARY):
+    for fmt in pq.Format:
         for oid in (info.oid, info.array_oid):
             assert oid not in postgres.adapters._loaders[fmt]
             assert oid not in conn.adapters._loaders[fmt]
             assert oid in cur.adapters._loaders[fmt]
 
     register_composite(info, conn)
-    for fmt in (pq.Format.TEXT, pq.Format.BINARY):
+    for fmt in pq.Format:
         for oid in (info.oid, info.array_oid):
             assert oid not in postgres.adapters._loaders[fmt]
             assert oid in conn.adapters._loaders[fmt]
index a4b756354a5e1838f39f160327f1804687c25f00..a5484db7242e3b42fc82703883ba8265aaa14586 100644 (file)
@@ -4,7 +4,7 @@ import datetime as dt
 import pytest
 
 from psycopg import DataError, pq, sql
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 
 
 class TestDate:
@@ -19,9 +19,7 @@ class TestDate:
             ("max", "9999-12-31"),
         ],
     )
-    @pytest.mark.parametrize(
-        "fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY]
-    )
+    @pytest.mark.parametrize("fmt_in", PyFormat)
     def test_dump_date(self, conn, val, expr, fmt_in):
         val = as_date(val)
         cur = conn.cursor()
@@ -54,7 +52,7 @@ class TestDate:
             ("max", "9999-12-31"),
         ],
     )
-    @pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+    @pytest.mark.parametrize("fmt_out", pq.Format)
     def test_load_date(self, conn, val, expr, fmt_out):
         cur = conn.cursor(binary=fmt_out)
         cur.execute(f"select '{expr}'::date")
@@ -111,9 +109,7 @@ class TestDatetime:
             ("max", "9999-12-31 23:59:59.999999"),
         ],
     )
-    @pytest.mark.parametrize(
-        "fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY]
-    )
+    @pytest.mark.parametrize("fmt_in", PyFormat)
     def test_dump_datetime(self, conn, val, expr, fmt_in):
         cur = conn.cursor()
         cur.execute("set timezone to '+02:00'")
@@ -230,9 +226,7 @@ class TestDateTimeTz:
             ("max~2", "9999-12-31 23:59:59.999999"),
         ],
     )
-    @pytest.mark.parametrize(
-        "fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY]
-    )
+    @pytest.mark.parametrize("fmt_in", PyFormat)
     def test_dump_datetimetz(self, conn, val, expr, fmt_in):
         cur = conn.cursor()
         cur.execute("set timezone to '-02:00'")
@@ -309,7 +303,7 @@ class TestDateTimeTz:
             ("NOSUCH0", "2000-1-1", 0),
         ],
     )
-    @pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+    @pytest.mark.parametrize("fmt_out", pq.Format)
     def test_load_datetimetz_tz(self, conn, fmt_out, tzname, expr, tzoff):
         if "/" in tzname and sys.platform == "win32":
             pytest.skip("no IANA db on Windows")
@@ -326,9 +320,7 @@ class TestDateTimeTz:
             ("2000,1,2,3,4,5,6~2", "timestamptz"),
         ],
     )
-    @pytest.mark.parametrize(
-        "fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY]
-    )
+    @pytest.mark.parametrize("fmt_in", PyFormat)
     def test_dump_datetime_tz_or_not_tz(self, conn, val, type, fmt_in):
         val = as_dt(val)
         cur = conn.cursor()
@@ -371,7 +363,7 @@ class TestDateTimeTz:
             pytest.param("min", "+09:18:59", "Asia/Tokyo", marks=[tz_sec]),
         ],
     )
-    @pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+    @pytest.mark.parametrize("fmt_out", pq.Format)
     def test_max_with_timezone(self, conn, fmt_out, valname, tzval, tzname):
         # This happens e.g. in Django when it caches forever.
         # e.g. see Django test cache.tests.DBCacheTests.test_forever_timeout
@@ -404,9 +396,7 @@ class TestTime:
             ("max", "23:59:59.999999"),
         ],
     )
-    @pytest.mark.parametrize(
-        "fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY]
-    )
+    @pytest.mark.parametrize("fmt_in", PyFormat)
     def test_dump_time(self, conn, val, expr, fmt_in):
         cur = conn.cursor()
         cur.execute(
@@ -430,13 +420,13 @@ class TestTime:
             ("max", "23:59:59.999999"),
         ],
     )
-    @pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+    @pytest.mark.parametrize("fmt_out", pq.Format)
     def test_load_time(self, conn, val, expr, fmt_out):
         cur = conn.cursor(binary=fmt_out)
         cur.execute(f"select '{expr}'::time")
         assert cur.fetchone()[0] == as_time(val)
 
-    @pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+    @pytest.mark.parametrize("fmt_out", pq.Format)
     def test_load_time_24(self, conn, fmt_out):
         cur = conn.cursor(binary=fmt_out)
         cur.execute("select '24:00'::time")
@@ -457,9 +447,7 @@ class TestTimeTz:
             ("max~+12", "23:59:59.999999+12:00"),
         ],
     )
-    @pytest.mark.parametrize(
-        "fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY]
-    )
+    @pytest.mark.parametrize("fmt_in", PyFormat)
     def test_dump_timetz(self, conn, val, expr, fmt_in):
         cur = conn.cursor()
         cur.execute("set timezone to '-02:00'")
@@ -477,14 +465,14 @@ class TestTimeTz:
             ("3,0,0,456789~-2", "03:00:00.456789", "+02:00"),
         ],
     )
-    @pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+    @pytest.mark.parametrize("fmt_out", pq.Format)
     def test_load_timetz(self, conn, val, timezone, expr, fmt_out):
         cur = conn.cursor(binary=fmt_out)
         cur.execute(f"set timezone to '{timezone}'")
         cur.execute(f"select '{expr}'::timetz")
         assert cur.fetchone()[0] == as_time(val)
 
-    @pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+    @pytest.mark.parametrize("fmt_out", pq.Format)
     def test_load_timetz_24(self, conn, fmt_out):
         cur = conn.cursor()
         cur.execute("select '24:00'::timetz")
@@ -499,9 +487,7 @@ class TestTimeTz:
             ("3,4,5,6~2", "timetz"),
         ],
     )
-    @pytest.mark.parametrize(
-        "fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY]
-    )
+    @pytest.mark.parametrize("fmt_in", PyFormat)
     def test_dump_time_tz_or_not_tz(self, conn, val, type, fmt_in):
         val = as_time(val)
         cur = conn.cursor()
@@ -589,7 +575,7 @@ class TestInterval:
             ("-90d", "-3 month"),
         ],
     )
-    @pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+    @pytest.mark.parametrize("fmt_out", pq.Format)
     def test_load_interval(self, conn, val, expr, fmt_out):
         cur = conn.cursor(binary=fmt_out)
         cur.execute(f"select '{expr}'::interval")
index 2b2bfe79f23ec704d3b7aa6a4d83a9a32e1baf25..790a37c076ea4745f9d1f9d15119a24fef6346ad 100644 (file)
@@ -6,7 +6,7 @@ import pytest
 import psycopg.types
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 from psycopg.types.json import Json, Jsonb, set_json_dumps, set_json_loads
 
 samples = [
@@ -22,7 +22,7 @@ samples = [
 
 
 @pytest.mark.parametrize("val", samples)
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_json_dump(conn, val, fmt_in):
     obj = json.loads(val)
     cur = conn.cursor()
@@ -32,7 +32,7 @@ def test_json_dump(conn, val, fmt_in):
     assert cur.fetchone()[0] is True
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("val", samples)
 def test_jsonb_dump(conn, val, fmt_in):
     obj = json.loads(val)
@@ -43,7 +43,7 @@ def test_jsonb_dump(conn, val, fmt_in):
 
 @pytest.mark.parametrize("val", samples)
 @pytest.mark.parametrize("jtype", ["json", "jsonb"])
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_json_load(conn, val, jtype, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     cur.execute(f"select %s::{jtype}", (val,))
@@ -52,7 +52,7 @@ def test_json_load(conn, val, jtype, fmt_out):
 
 @pytest.mark.parametrize("val", samples)
 @pytest.mark.parametrize("jtype", ["json", "jsonb"])
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_json_load_copy(conn, val, jtype, fmt_out):
     cur = conn.cursor()
     stmt = sql.SQL("copy (select {}::{}) to stdout (format {})").format(
@@ -65,7 +65,7 @@ def test_json_load_copy(conn, val, jtype, fmt_out):
     assert got == json.loads(val)
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("wrapper", ["Json", "Jsonb"])
 def test_json_dump_customise(conn, wrapper, fmt_in):
     wrapper = getattr(psycopg.types.json, wrapper)
@@ -80,7 +80,7 @@ def test_json_dump_customise(conn, wrapper, fmt_in):
         set_json_dumps(json.dumps)
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("wrapper", ["Json", "Jsonb"])
 def test_json_dump_customise_context(conn, wrapper, fmt_in):
     wrapper = getattr(psycopg.types.json, wrapper)
@@ -95,7 +95,7 @@ def test_json_dump_customise_context(conn, wrapper, fmt_in):
     assert cur2.fetchone()[0] == "qux"
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("wrapper", ["Json", "Jsonb"])
 def test_json_dump_customise_wrapper(conn, wrapper, fmt_in):
     wrapper = getattr(psycopg.types.json, wrapper)
index fdc6263399b16c248cccaf1861dd0b4bf1939480..9a465681e82dd1c9310d67ad790885882ae20cd8 100644 (file)
@@ -6,10 +6,10 @@ import pytest
 
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("val", ["192.168.0.1", "2001:db8::"])
 def test_address_dump(conn, fmt_in, val):
     cur = conn.cursor()
@@ -24,7 +24,7 @@ def test_address_dump(conn, fmt_in, val):
     assert cur.fetchone()[0] is True
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("val", ["127.0.0.1/24", "::ffff:102:300/128"])
 def test_interface_dump(conn, fmt_in, val):
     cur = conn.cursor()
@@ -40,7 +40,7 @@ def test_interface_dump(conn, fmt_in, val):
     assert cur.fetchone()[0] is True
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("val", ["127.0.0.0/24", "::ffff:102:300/128"])
 def test_network_dump(conn, fmt_in, val):
     cur = conn.cursor()
@@ -55,7 +55,7 @@ def test_network_dump(conn, fmt_in, val):
     assert cur.fetchone()[0] is True
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_network_mixed_size_array(conn, fmt_in):
     val = [
         ipaddress.IPv4Network("192.168.0.1/32"),
@@ -67,7 +67,7 @@ def test_network_mixed_size_array(conn, fmt_in):
     assert val == got
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("val", ["127.0.0.1/32", "::ffff:102:300/128"])
 def test_inet_load_address(conn, fmt_out, val):
     addr = ipaddress.ip_address(val.split("/", 1)[0])
@@ -89,7 +89,7 @@ def test_inet_load_address(conn, fmt_out, val):
     assert got == addr
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("val", ["127.0.0.1/24", "::ffff:102:300/127"])
 def test_inet_load_network(conn, fmt_out, val):
     pyval = ipaddress.ip_interface(val)
@@ -111,7 +111,7 @@ def test_inet_load_network(conn, fmt_out, val):
     assert got == pyval
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("val", ["127.0.0.0/24", "::ffff:102:300/128"])
 def test_cidr_load(conn, fmt_out, val):
     pyval = ipaddress.ip_network(val)
index fd12f278fcabda5b7e402b73b9ca10559a3716d3..4c008fd786d1edd8906eb62cfbfc450fbc8178fb 100644 (file)
@@ -1,11 +1,11 @@
 from psycopg import sql
-from psycopg.adapt import Transformer, PyFormat as Format
+from psycopg.adapt import Transformer, PyFormat
 
 
 def test_quote_none(conn):
 
     tx = Transformer()
-    assert tx.get_dumper(None, Format.TEXT).quote(None) == b"NULL"
+    assert tx.get_dumper(None, PyFormat.TEXT).quote(None) == b"NULL"
 
     cur = conn.cursor()
     cur.execute(sql.SQL("select {v}").format(v=sql.Literal(None)))
index f4621dcafccaa14d961a5bf041ac2e5fc7686327..61ef60fe8948d8e5fff8b069301021d1839778ff 100644 (file)
@@ -6,7 +6,7 @@ import pytest
 import psycopg
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import Transformer, PyFormat as Format
+from psycopg.adapt import Transformer, PyFormat
 from psycopg.types.numeric import FloatLoader
 
 
@@ -27,7 +27,7 @@ from psycopg.types.numeric import FloatLoader
         (int(-(2 ** 63)), "'-9223372036854775808'::bigint"),
     ],
 )
-@pytest.mark.parametrize("fmt_in", [Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_int(conn, val, expr, fmt_in):
     assert isinstance(val, int)
     cur = conn.cursor()
@@ -57,7 +57,7 @@ def test_dump_int(conn, val, expr, fmt_in):
         (int(-(2 ** 63) - 1), f"'{-2 ** 63 - 1}'::numeric"),
     ],
 )
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_int_subtypes(conn, val, expr, fmt_in):
     cur = conn.cursor()
     cur.execute(f"select pg_typeof({expr}) = pg_typeof(%{fmt_in})", (val,))
@@ -71,7 +71,7 @@ def test_dump_int_subtypes(conn, val, expr, fmt_in):
     assert ok
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_enum(conn, fmt_in):
     import enum
 
@@ -101,7 +101,7 @@ def test_dump_enum(conn, fmt_in):
 )
 def test_quote_int(conn, val, expr):
     tx = Transformer()
-    assert tx.get_dumper(val, Format.TEXT).quote(val) == expr
+    assert tx.get_dumper(val, PyFormat.TEXT).quote(val) == expr
 
     cur = conn.cursor()
     cur.execute(sql.SQL("select {v}, -{v}").format(v=sql.Literal(val)))
@@ -129,7 +129,7 @@ def test_quote_int(conn, val, expr):
         ("4294967295", "oid", 4294967295),
     ],
 )
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_int(conn, val, pgtype, want, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     cur.execute(f"select %s::{pgtype}", (val,))
@@ -164,7 +164,7 @@ def test_load_int(conn, val, pgtype, want, fmt_out):
         (float("-inf"), "'-Infinity'"),
     ],
 )
-@pytest.mark.parametrize("fmt_in", [Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_float(conn, val, expr, fmt_in):
     assert isinstance(val, float)
     cur = conn.cursor()
@@ -188,7 +188,7 @@ def test_dump_float(conn, val, expr, fmt_in):
 )
 def test_quote_float(conn, val, expr):
     tx = Transformer()
-    assert tx.get_dumper(val, Format.TEXT).quote(val) == expr
+    assert tx.get_dumper(val, PyFormat.TEXT).quote(val) == expr
 
     cur = conn.cursor()
     cur.execute(sql.SQL("select {v}, -{v}").format(v=sql.Literal(val)))
@@ -246,7 +246,7 @@ def test_dump_float_approx(conn, val, expr):
         ("-inf", "float8", -float("inf")),
     ],
 )
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_float(conn, val, pgtype, want, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     cur.execute(f"select %s::{pgtype}", (val,))
@@ -287,7 +287,7 @@ def test_load_float(conn, val, pgtype, want, fmt_out):
         ("-1.42e40", "float8", -1.42e40),
     ],
 )
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_float_approx(conn, expr, pgtype, want, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     cur.execute("select %s::%s" % (expr, pgtype))
@@ -323,8 +323,8 @@ def test_load_float_copy(conn):
         "snan",
     ],
 )
-@pytest.mark.parametrize("fmt_in", [Format.TEXT, Format.BINARY])
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_roundtrip_numeric(conn, val, fmt_in, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     val = Decimal(val)
@@ -351,7 +351,7 @@ def test_roundtrip_numeric(conn, val, fmt_in, fmt_out):
 def test_quote_numeric(conn, val, expr):
     val = Decimal(val)
     tx = Transformer()
-    assert tx.get_dumper(val, Format.TEXT).quote(val) == expr
+    assert tx.get_dumper(val, PyFormat.TEXT).quote(val) == expr
 
     cur = conn.cursor()
     cur.execute(sql.SQL("select {v}, -{v}").format(v=sql.Literal(val)))
@@ -392,7 +392,7 @@ def test_dump_numeric_binary(conn, expr):
 
 
 @pytest.mark.slow
-@pytest.mark.parametrize("fmt_in", [Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_numeric_exhaustive(conn, fmt_in):
     cur = conn.cursor()
 
@@ -469,7 +469,7 @@ def test_load_numeric_binary(conn, expr):
 
 
 @pytest.mark.slow
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_numeric_exhaustive(conn, fmt_out):
     cur = conn.cursor(binary=fmt_out)
 
@@ -580,7 +580,7 @@ def test_dump_wrapper_oid(wrapper):
 
 
 @pytest.mark.parametrize("wrapper", "Int2 Int4 Int8 Oid Float4 Float8".split())
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_repr_wrapper(conn, wrapper, fmt_in):
     wrapper = getattr(psycopg.types.numeric, wrapper)
     cur = conn.execute(f"select pg_typeof(%{fmt_in})::oid", [wrapper(0)])
index a63c286d9d80eac3a4806799597ddca7b3a1a9ae..9ed018c15bcc40a0a0943fc970b5a3aad161774a 100644 (file)
@@ -7,7 +7,7 @@ import pytest
 import psycopg.errors
 from psycopg import pq
 from psycopg.sql import Identifier
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 from psycopg.types import range as range_module
 from psycopg.types.range import Range, RangeInfo, register_range
 
@@ -53,7 +53,7 @@ samples = [
     "pgtype",
     "int4range int8range numrange daterange tsrange tstzrange".split(),
 )
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_builtin_empty(conn, pgtype, fmt_in):
     r = Range(empty=True)
     cur = conn.execute(f"select 'empty'::{pgtype} = %{fmt_in}", (r,))
@@ -66,7 +66,7 @@ def test_dump_builtin_empty(conn, pgtype, fmt_in):
     Int4Range Int8Range NumericRange DateRange TimestampRange TimestamptzRange
     """.split(),
 )
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_builtin_empty_wrapper(conn, wrapper, fmt_in):
     wrapper = getattr(range_module, wrapper)
     r = wrapper(empty=True)
@@ -81,12 +81,12 @@ def test_dump_builtin_empty_wrapper(conn, wrapper, fmt_in):
 @pytest.mark.parametrize(
     "fmt_in",
     [
-        Format.AUTO,
-        Format.TEXT,
+        PyFormat.AUTO,
+        PyFormat.TEXT,
         # There are many ways to work around this (use text, use a cast on the
         # placeholder, use specific Range subclasses).
         pytest.param(
-            Format.BINARY,
+            PyFormat.BINARY,
             marks=pytest.mark.xfail(
                 reason="can't dump an array of untypes binary range without cast"
             ),
@@ -107,7 +107,7 @@ def test_dump_builtin_array(conn, pgtype, fmt_in):
     "pgtype",
     "int4range int8range numrange daterange tsrange tstzrange".split(),
 )
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_builtin_array_with_cast(conn, pgtype, fmt_in):
     r1 = Range(empty=True)
     r2 = Range(bounds="()")
@@ -124,7 +124,7 @@ def test_dump_builtin_array_with_cast(conn, pgtype, fmt_in):
     Int4Range Int8Range NumericRange DateRange TimestampRange TimestamptzRange
     """.split(),
 )
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_builtin_array_wrapper(conn, wrapper, fmt_in):
     wrapper = getattr(range_module, wrapper)
     r1 = wrapper(empty=True)
@@ -136,7 +136,7 @@ def test_dump_builtin_array_wrapper(conn, wrapper, fmt_in):
 
 
 @pytest.mark.parametrize("pgtype, min, max, bounds", samples)
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_builtin_range(conn, pgtype, min, max, bounds, fmt_in):
     r = Range(min, max, bounds)
     sub = type2sub[pgtype]
@@ -151,7 +151,7 @@ def test_dump_builtin_range(conn, pgtype, min, max, bounds, fmt_in):
     "pgtype",
     "int4range int8range numrange daterange tsrange tstzrange".split(),
 )
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_builtin_empty(conn, pgtype, fmt_out):
     r = Range(empty=True)
     cur = conn.cursor(binary=fmt_out)
@@ -166,7 +166,7 @@ def test_load_builtin_empty(conn, pgtype, fmt_out):
     "pgtype",
     "int4range int8range numrange daterange tsrange tstzrange".split(),
 )
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_builtin_inf(conn, pgtype, fmt_out):
     r = Range(bounds="()")
     cur = conn.cursor(binary=fmt_out)
@@ -183,7 +183,7 @@ def test_load_builtin_inf(conn, pgtype, fmt_out):
     "pgtype",
     "int4range int8range numrange daterange tsrange tstzrange".split(),
 )
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_builtin_array(conn, pgtype, fmt_out):
     r1 = Range(empty=True)
     r2 = Range(bounds="()")
@@ -195,7 +195,7 @@ def test_load_builtin_array(conn, pgtype, fmt_out):
 
 
 @pytest.mark.parametrize("pgtype, min, max, bounds", samples)
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_builtin_range(conn, pgtype, min, max, bounds, fmt_out):
     r = Range(min, max, bounds)
     sub = type2sub[pgtype]
@@ -220,7 +220,7 @@ def test_load_builtin_range(conn, pgtype, min, max, bounds, fmt_out):
         (None, None, "empty"),
     ],
 )
-@pytest.mark.parametrize("format", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("format", pq.Format)
 def test_copy_in_empty(conn, min, max, bounds, format):
     cur = conn.cursor()
     cur.execute("create table copyrange (id serial primary key, r daterange)")
@@ -256,7 +256,7 @@ def test_copy_in_empty(conn, min, max, bounds, format):
     Int4Range Int8Range NumericRange DateRange TimestampRange TimestamptzRange
     """.split(),
 )
-@pytest.mark.parametrize("format", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("format", pq.Format)
 def test_copy_in_empty_wrappers(conn, bounds, wrapper, format):
     cur = conn.cursor()
     cur.execute("create table copyrange (id serial primary key, r daterange)")
@@ -278,7 +278,7 @@ def test_copy_in_empty_wrappers(conn, bounds, wrapper, format):
     "pgtype",
     "int4range int8range numrange daterange tsrange tstzrange".split(),
 )
-@pytest.mark.parametrize("format", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("format", pq.Format)
 def test_copy_in_empty_set_type(conn, bounds, pgtype, format):
     cur = conn.cursor()
     cur.execute(f"create table copyrange (id serial primary key, r {pgtype})")
@@ -370,7 +370,7 @@ def test_dump_quoting(conn, testrange):
         assert cur.fetchone()[0] is True
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_custom_empty(conn, testrange, fmt_out):
     info = RangeInfo.fetch(conn, "testrange")
     register_range(info, conn)
@@ -381,7 +381,7 @@ def test_load_custom_empty(conn, testrange, fmt_out):
     assert got.isempty
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_quoting(conn, testrange, fmt_out):
     info = RangeInfo.fetch(conn, "testrange")
     register_range(info, conn)
@@ -397,7 +397,7 @@ def test_load_quoting(conn, testrange, fmt_out):
         assert ord(got.upper) == i + 1
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_mixed_array_types(conn, fmt_out):
     conn.execute("create table testmix (a daterange[], b tstzrange[])")
     r1 = Range(dt.date(2000, 1, 1), dt.date(2001, 1, 1), "[)")
index de32b9aa5e88586dd5aca88eea0e7f63ced86819..21e66d696b500e78576c7715c76c8fff9c146fac 100644 (file)
@@ -4,18 +4,17 @@ import psycopg
 from psycopg import pq
 from psycopg import sql
 from psycopg import errors as e
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 from psycopg import Binary
 
 eur = "\u20ac"
 
-
 #
 # tests with text
 #
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_1char(conn, fmt_in):
     cur = conn.cursor()
     for i in range(1, 256):
@@ -42,7 +41,7 @@ def test_quote_1char(conn, scs):
     assert not messages
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_zero(conn, fmt_in):
     cur = conn.cursor()
     s = "foo\x00bar"
@@ -76,7 +75,7 @@ def test_quote_percent(conn):
 @pytest.mark.parametrize(
     "typename", ["text", "varchar", "name", "bpchar", '"char"']
 )
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_1char(conn, typename, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     for i in range(1, 256):
@@ -91,7 +90,7 @@ def test_load_1char(conn, typename, fmt_out):
     assert cur.pgresult.fformat(0) == fmt_out
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("encoding", ["utf8", "latin9", "ascii"])
 def test_dump_enc(conn, fmt_in, encoding):
     cur = conn.cursor()
@@ -101,7 +100,7 @@ def test_dump_enc(conn, fmt_in, encoding):
     assert res == ord(eur)
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_badenc(conn, fmt_in):
     cur = conn.cursor()
 
@@ -110,7 +109,7 @@ def test_dump_badenc(conn, fmt_in):
         cur.execute(f"select %{fmt_in}::bytea", (eur,))
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_utf8_badenc(conn, fmt_in):
     cur = conn.cursor()
 
@@ -119,7 +118,7 @@ def test_dump_utf8_badenc(conn, fmt_in):
         cur.execute(f"select %{fmt_in}", ("\uddf8",))
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT])
+@pytest.mark.parametrize("fmt_in", [PyFormat.AUTO, PyFormat.TEXT])
 def test_dump_enum(conn, fmt_in):
     from enum import Enum
 
@@ -135,7 +134,7 @@ def test_dump_enum(conn, fmt_in):
     assert res == "foo"
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT])
+@pytest.mark.parametrize("fmt_in", [PyFormat.AUTO, PyFormat.TEXT])
 def test_dump_text_oid(conn, fmt_in):
     conn.autocommit = True
 
@@ -146,7 +145,7 @@ def test_dump_text_oid(conn, fmt_in):
     assert cur.fetchone()[0] == "foobar"
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("encoding", ["utf8", "latin9"])
 @pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar"])
 def test_load_enc(conn, typename, encoding, fmt_out):
@@ -166,7 +165,7 @@ def test_load_enc(conn, typename, encoding, fmt_out):
     assert res == eur
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar"])
 def test_load_badenc(conn, typename, fmt_out):
     conn.autocommit = True
@@ -185,7 +184,7 @@ def test_load_badenc(conn, typename, fmt_out):
             copy.read_row()
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar"])
 def test_load_ascii(conn, typename, fmt_out):
     cur = conn.cursor(binary=fmt_out)
@@ -204,8 +203,8 @@ def test_load_ascii(conn, typename, fmt_out):
     assert res == eur.encode()
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
+@pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar"])
 def test_text_array(conn, typename, fmt_in, fmt_out):
     cur = conn.cursor(binary=fmt_out)
@@ -215,8 +214,8 @@ def test_text_array(conn, typename, fmt_in, fmt_out):
     assert res == a
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_text_array_ascii(conn, fmt_in, fmt_out):
     conn.client_encoding = "ascii"
     cur = conn.cursor(binary=fmt_out)
@@ -231,7 +230,7 @@ def test_text_array_ascii(conn, fmt_in, fmt_out):
 #
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("pytype", [bytes, bytearray, memoryview, Binary])
 def test_dump_1byte(conn, fmt_in, pytype):
     cur = conn.cursor()
@@ -263,7 +262,7 @@ def test_quote_1byte(conn, scs, pytype):
     assert not messages
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_1byte(conn, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     for i in range(0, 256):
@@ -273,8 +272,8 @@ def test_load_1byte(conn, fmt_out):
     assert cur.pgresult.fformat(0) == fmt_out
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_bytea_array(conn, fmt_in, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     a = [bytes(range(0, 256))]
index 34d5d08edc8bcb7af2e845491295b0cc4db7861e..9ddc0bbbe530efbb36b936d6411113e700deb1e6 100644 (file)
@@ -6,10 +6,10 @@ import pytest
 
 from psycopg import pq
 from psycopg import sql
-from psycopg.adapt import PyFormat as Format
+from psycopg.adapt import PyFormat
 
 
-@pytest.mark.parametrize("fmt_in", [Format.AUTO, Format.TEXT, Format.BINARY])
+@pytest.mark.parametrize("fmt_in", PyFormat)
 def test_uuid_dump(conn, fmt_in):
     val = "12345678123456781234567812345679"
     cur = conn.cursor()
@@ -17,7 +17,7 @@ def test_uuid_dump(conn, fmt_in):
     assert cur.fetchone()[0] is True
 
 
-@pytest.mark.parametrize("fmt_out", [pq.Format.TEXT, pq.Format.BINARY])
+@pytest.mark.parametrize("fmt_out", pq.Format)
 def test_uuid_load(conn, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     val = "12345678123456781234567812345679"