]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test(crdb): adapt numeric tests
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 6 Jun 2022 00:00:29 +0000 (02:00 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 12 Jul 2022 11:58:34 +0000 (12:58 +0100)
tests/types/test_numeric.py

index 8f3ac6ac36a1cbbe1456e889877977c4dd692dbd..183f4c4a02aea90f766a283677848426e5472583 100644 (file)
@@ -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):