From: Daniele Varrazzo Date: Mon, 6 Jun 2022 00:00:29 +0000 (+0200) Subject: test(crdb): adapt numeric tests X-Git-Tag: 3.1~49^2~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=559c3eec1d10678f7222a3546effe0faf1ec0207;p=thirdparty%2Fpsycopg.git test(crdb): adapt numeric tests --- diff --git a/tests/types/test_numeric.py b/tests/types/test_numeric.py index 8f3ac6ac3..183f4c4a0 100644 --- a/tests/types/test_numeric.py +++ b/tests/types/test_numeric.py @@ -10,6 +10,7 @@ from psycopg import sql from psycopg.adapt import Transformer, PyFormat from psycopg.types.numeric import FloatLoader +from ..fix_crdb import is_crdb # # Tests with int @@ -137,6 +138,8 @@ def test_quote_int(conn, val, expr): ) @pytest.mark.parametrize("fmt_out", pq.Format) def test_load_int(conn, val, pgtype, want, fmt_out): + if pgtype == "integer" and is_crdb(conn): + pgtype = "int4" # "integer" is "int8" on crdb cur = conn.cursor(binary=fmt_out) cur.execute(f"select %s::{pgtype}", (val,)) assert cur.pgresult.fformat(0) == fmt_out @@ -211,8 +214,8 @@ def test_quote_float(conn, val, expr): @pytest.mark.parametrize( "val, expr", [ - (exp(1), "exp(1)"), - (-exp(1), "-exp(1)"), + (exp(1), "exp(1.0)"), + (-exp(1), "-exp(1.0)"), (1e30, "'1e30'"), (1e-30, "1e-30"), (-1e30, "'-1e30'"), @@ -279,10 +282,10 @@ def test_load_float(conn, val, pgtype, want, fmt_out): @pytest.mark.parametrize( "expr, pgtype, want", [ - ("exp(1)", "float4", 2.71828), - ("-exp(1)", "float4", -2.71828), - ("exp(1)", "float8", 2.71828182845905), - ("-exp(1)", "float8", -2.71828182845905), + ("exp(1.0)", "float4", 2.71828), + ("-exp(1.0)", "float4", -2.71828), + ("exp(1.0)", "float8", 2.71828182845905), + ("-exp(1.0)", "float8", -2.71828182845905), ("1.42e10", "float4", 1.42e10), ("-1.42e10", "float4", -1.42e10), ("1.42e40", "float8", 1.42e40), @@ -298,6 +301,7 @@ def test_load_float_approx(conn, expr, pgtype, want, fmt_out): assert result == pytest.approx(want) +@pytest.mark.crdb("skip", reason="copy") def test_load_float_copy(conn): cur = conn.cursor(binary=False) with cur.copy("copy (select 3.14::float8, 'hi'::text) to stdout;") as copy: @@ -365,6 +369,7 @@ def test_quote_numeric(conn, val, expr): assert r == (val, -val) +@pytest.mark.crdb("skip", reason="numeric precision not maintained? TODOCRDB") @pytest.mark.parametrize( "expr", ["NaN", "1", "1.0", "-1", "0.0", "0.01", "11", "1.1", "1.01", "0", "0.00"] @@ -591,6 +596,7 @@ def test_dump_wrapper_oid(wrapper): assert repr(wrapper(n)) == f"{wrapper.__name__}({n})" +@pytest.mark.crdb("skip", reason="all types returned as bigint? TODOCRDB") @pytest.mark.parametrize("wrapper", "Int2 Int4 Int8 Oid Float4 Float8".split()) @pytest.mark.parametrize("fmt_in", PyFormat) def test_repr_wrapper(conn, wrapper, fmt_in):