From d15cc28a18869718a66224b31a2eb17c93dc77bc Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 17 Apr 2023 23:52:06 +0200 Subject: [PATCH] test(json): fix dict registration test on crdb --- tests/types/test_json.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/types/test_json.py b/tests/types/test_json.py index 24970c712..ba476adb7 100644 --- a/tests/types/test_json.py +++ b/tests/types/test_json.py @@ -48,7 +48,7 @@ def test_dump(conn, val, wrapper, fmt_in): @pytest.mark.parametrize( - "fmt_in, type, dumper_name", + "fmt_in, pgtype, dumper_name", [ ("t", "json", "JsonDumper"), ("b", "json", "JsonBinaryDumper"), @@ -56,13 +56,24 @@ def test_dump(conn, val, wrapper, fmt_in): ("b", "jsonb", "JsonbBinaryDumper"), ], ) -def test_dump_dict(conn, fmt_in, type, dumper_name): +def test_dump_dict(conn, fmt_in, pgtype, dumper_name): obj = {"foo": "bar"} cur = conn.cursor() - cur.adapters.register_dumper(dict, getattr(psycopg.types.json, dumper_name)) + dumper = getattr(psycopg.types.json, dumper_name) + + # Skip json on CRDB as the oid doesn't exist. + try: + conn.adapters.types[dumper.oid] + except KeyError: + pytest.skip( + f"{type(conn).__name__} doesn't have the oid {dumper.oid}" + f" used by {dumper.__name__}" + ) + + cur.adapters.register_dumper(dict, dumper) cur.execute(f"select %{fmt_in}", (obj,)) assert cur.fetchone()[0] == obj - assert cur.description[0].type_code == conn.adapters.types[type].oid + assert cur.description[0].type_code == conn.adapters.types[pgtype].oid @pytest.mark.crdb_skip("json array") -- 2.47.2