]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Parametrize input format too
authorJacopo Farina <jacopo.farina@flixbus.com>
Thu, 16 Sep 2021 09:19:35 +0000 (11:19 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 21 Sep 2021 18:02:18 +0000 (19:02 +0100)
tests/test_shapely.py

index b01d320e106122f3fd0bdce7d29b486b8613124d..8f776044975bc631be70b279aa363620883029e7 100644 (file)
@@ -2,6 +2,7 @@ import pytest
 
 from psycopg.pq import Format
 from psycopg.types import TypeInfo
+from psycopg.adapt import PyFormat
 
 from psycopg import ProgrammingError
 
@@ -91,15 +92,14 @@ def test_with_adapter(shapely_conn):
     )
 
 
+@pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("fmt_out", [Format.TEXT, Format.BINARY])
-def test_write_read_shape(shapely_conn, fmt_out):
+def test_write_read_shape(shapely_conn, fmt_in, fmt_out):
     from shapely.geometry import Point, Polygon
 
     SAMPLE_POINT = Point(1.2, 3.4)
     SAMPLE_POLYGON = Polygon([(0, 0), (1, 1), (1, 0)])
 
-    fmt_placeholder = "%b" if fmt_out == Format.BINARY else "%t"
-
     with shapely_conn.cursor(binary=fmt_out) as cur:
         cur.execute(
             """
@@ -110,11 +110,11 @@ def test_write_read_shape(shapely_conn, fmt_out):
         """
         )
         cur.execute(
-            f"insert into sample_geoms(id, geom) VALUES(1, {fmt_placeholder})",
+            f"insert into sample_geoms(id, geom) VALUES(1, %{fmt_in})",
             (SAMPLE_POINT,),
         )
         cur.execute(
-            f"insert into sample_geoms(id, geom) VALUES(2, {fmt_placeholder})",
+            f"insert into sample_geoms(id, geom) VALUES(2, %{fmt_in})",
             (SAMPLE_POLYGON,),
         )