]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(crdb): adapt text tests
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 6 Jun 2022 01:43:01 +0000 (03:43 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 12 Jul 2022 11:58:34 +0000 (12:58 +0100)
With this changeset, all fast tests pass on CRDB.

psycopg/psycopg/crdb.py
tests/types/test_string.py

index b99ae6844a6127c85316f4e36b238895111ee1e9..70fbb4bd0cb897d4b5025e4a4e4f15ff2e3db234 100644 (file)
@@ -206,6 +206,7 @@ def register_postgres_adapters(context: AdaptContext) -> None:
 
 
 def register_crdb_adapters(context: AdaptContext) -> None:
+    from . import dbapi20
     from .types import array
 
     register_postgres_adapters(context)
@@ -217,6 +218,8 @@ def register_crdb_adapters(context: AdaptContext) -> None:
     register_crdb_net_adapters(context)
     register_crdb_none_adapters(context)
 
+    dbapi20.register_dbapi20_adapters(adapters)
+
     array.register_all_arrays(adapters)
 
 
index 132006c577099e0afd95f4e6a204c11a4ee814bf..be20672044321fa853d4d4eaefdd73c66aed0393 100644 (file)
@@ -8,12 +8,17 @@ from psycopg.adapt import PyFormat
 from psycopg import Binary
 
 from ..utils import eur
+from ..fix_crdb import crdb_encoding, crdb_scs_off
 
 #
 # tests with text
 #
 
 
+def crdb_bpchar(*args):
+    return pytest.param(*args, marks=pytest.mark.crdb("skip", reason="bpchar"))
+
+
 @pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_1char(conn, fmt_in):
     cur = conn.cursor()
@@ -22,7 +27,7 @@ def test_dump_1char(conn, fmt_in):
         assert cur.fetchone()[0] is True, chr(i)
 
 
-@pytest.mark.parametrize("scs", ["on", "off"])
+@pytest.mark.parametrize("scs", ["on", crdb_scs_off("off")])
 def test_quote_1char(conn, scs):
     messages = []
     conn.add_notice_handler(lambda msg: messages.append(msg.message_primary))
@@ -41,6 +46,7 @@ def test_quote_1char(conn, scs):
     assert not messages
 
 
+@pytest.mark.crdb("skip", reason="can deal with 0 strings")
 @pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_zero(conn, fmt_in):
     cur = conn.cursor()
@@ -72,7 +78,9 @@ def test_quote_percent(conn):
     assert cur.fetchone()[0] is True
 
 
-@pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar", '"char"'])
+@pytest.mark.parametrize(
+    "typename", ["text", "varchar", "name", crdb_bpchar("bpchar"), '"char"']
+)
 @pytest.mark.parametrize("fmt_out", pq.Format)
 def test_load_1char(conn, typename, fmt_out):
     cur = conn.cursor(binary=fmt_out)
@@ -89,7 +97,9 @@ def test_load_1char(conn, typename, fmt_out):
 
 
 @pytest.mark.parametrize("fmt_in", PyFormat)
-@pytest.mark.parametrize("encoding", ["utf8", "latin9", "sql_ascii"])
+@pytest.mark.parametrize(
+    "encoding", ["utf8", crdb_encoding("latin9"), crdb_encoding("sql_ascii")]
+)
 def test_dump_enc(conn, fmt_in, encoding):
     cur = conn.cursor()
 
@@ -98,6 +108,7 @@ def test_dump_enc(conn, fmt_in, encoding):
     assert res == ord(eur)
 
 
+@pytest.mark.crdb("skip", reason="encoding")
 @pytest.mark.parametrize("fmt_in", PyFormat)
 def test_dump_badenc(conn, fmt_in):
     cur = conn.cursor()
@@ -132,6 +143,7 @@ def test_dump_enum(conn, fmt_in):
     assert res == "foo"
 
 
+@pytest.mark.crdb("skip")
 @pytest.mark.parametrize("fmt_in", [PyFormat.AUTO, PyFormat.TEXT])
 def test_dump_text_oid(conn, fmt_in):
     conn.autocommit = True
@@ -145,8 +157,9 @@ def test_dump_text_oid(conn, fmt_in):
     assert cur.fetchone()[0] == "foobar"
 
 
+@pytest.mark.crdb("skip", reason="copy")
 @pytest.mark.parametrize("fmt_out", pq.Format)
-@pytest.mark.parametrize("encoding", ["utf8", "latin9"])
+@pytest.mark.parametrize("encoding", ["utf8", crdb_encoding("latin9")])
 @pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar"])
 def test_load_enc(conn, typename, encoding, fmt_out):
     cur = conn.cursor(binary=fmt_out)
@@ -165,6 +178,7 @@ def test_load_enc(conn, typename, encoding, fmt_out):
     assert res == eur
 
 
+@pytest.mark.crdb("skip", reason="encoding")
 @pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar"])
 def test_load_badenc(conn, typename, fmt_out):
@@ -184,6 +198,7 @@ def test_load_badenc(conn, typename, fmt_out):
             copy.read_row()
 
 
+@pytest.mark.crdb("skip", reason="encoding")
 @pytest.mark.parametrize("fmt_out", pq.Format)
 @pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar"])
 def test_load_ascii(conn, typename, fmt_out):
@@ -205,7 +220,7 @@ def test_load_ascii(conn, typename, fmt_out):
 
 @pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("fmt_out", pq.Format)
-@pytest.mark.parametrize("typename", ["text", "varchar", "name", "bpchar"])
+@pytest.mark.parametrize("typename", ["text", "varchar", "name", crdb_bpchar("bpchar")])
 def test_text_array(conn, typename, fmt_in, fmt_out):
     cur = conn.cursor(binary=fmt_out)
     a = list(map(chr, range(1, 256))) + [eur]
@@ -214,6 +229,7 @@ def test_text_array(conn, typename, fmt_in, fmt_out):
     assert res == a
 
 
+@pytest.mark.crdb("skip", reason="encoding")
 @pytest.mark.parametrize("fmt_in", PyFormat)
 @pytest.mark.parametrize("fmt_out", pq.Format)
 def test_text_array_ascii(conn, fmt_in, fmt_out):
@@ -243,7 +259,7 @@ def test_dump_1byte(conn, fmt_in, pytype):
     assert cur.fetchone()[0] is True
 
 
-@pytest.mark.parametrize("scs", ["on", "off"])
+@pytest.mark.parametrize("scs", ["on", crdb_scs_off("off")])
 @pytest.mark.parametrize("pytype", [bytes, bytearray, memoryview, Binary])
 def test_quote_1byte(conn, scs, pytype):
     messages = []