From: Daniele Varrazzo Date: Fri, 16 Dec 2022 16:17:02 +0000 (+0000) Subject: test(numpy) fix tests with approximative comparisons X-Git-Tag: pool-3.2.0~70^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a101260825a18aad9c18fbf0116f67affd029fa;p=thirdparty%2Fpsycopg.git test(numpy) fix tests with approximative comparisons --- diff --git a/tests/types/test_numpy.py b/tests/types/test_numpy.py index bf2558465..c967998f3 100644 --- a/tests/types/test_numpy.py +++ b/tests/types/test_numpy.py @@ -114,13 +114,7 @@ def test_dump_numpy_int64(conn, val, expr, fmt_in): assert cur.fetchone()[0] is True -@pytest.mark.parametrize( - "val, expr", - [ - (True, "'t'::bool"), - (False, "'f'::bool"), - ], -) +@pytest.mark.parametrize("val, expr", [(True, "'t'::bool"), (False, "'f'::bool")]) @pytest.mark.parametrize("fmt_in", PyFormat) def test_dump_numpy_bool8(conn, val, expr, fmt_in): @@ -138,10 +132,7 @@ def test_dump_numpy_bool8(conn, val, expr, fmt_in): assert cur.fetchone()[0] is True -@pytest.mark.parametrize( - "val, expr", - [(0, "'0'::int2"), (255, "'255'::int2")], -) +@pytest.mark.parametrize("val, expr", [(0, "'0'::int2"), (255, "'255'::int2")]) @pytest.mark.parametrize("fmt_in", PyFormat) def test_dump_numpy_uint8(conn, val, expr, fmt_in): @@ -159,13 +150,7 @@ def test_dump_numpy_uint8(conn, val, expr, fmt_in): assert cur.fetchone()[0] is True -@pytest.mark.parametrize( - "val, expr", - [ - (0, "'0'::int4"), - (65_535, "'65535'::int4"), - ], -) +@pytest.mark.parametrize("val, expr", [(0, "'0'::int4"), (65_535, "'65535'::int4")]) @pytest.mark.parametrize("fmt_in", PyFormat) def test_dump_numpy_uint16(conn, val, expr, fmt_in): @@ -184,11 +169,7 @@ def test_dump_numpy_uint16(conn, val, expr, fmt_in): @pytest.mark.parametrize( - "val, expr", - [ - (0, "'0'::int8"), - (4_294_967_295, "'4294967295'::int8"), - ], + "val, expr", [(0, "'0'::int8"), (4_294_967_295, "'4294967295'::int8")] ) @pytest.mark.parametrize("fmt_in", PyFormat) def test_dump_numpy_uint32(conn, val, expr, fmt_in): @@ -285,15 +266,7 @@ def test_dump_special_values(conn, val, expr, fmt_in): assert cur.fetchone()[0] is True -@pytest.mark.parametrize( - "val", - [ - "4e4", - # "4e-4", - "4000.0", - # "3.14", - ], -) +@pytest.mark.parametrize("val", ["4e4", "4e-4", "4000.0", "3.14"]) @pytest.mark.parametrize("fmt_in", PyFormat) def test_dump_numpy_float16(conn, val, fmt_in): @@ -303,20 +276,12 @@ def test_dump_numpy_float16(conn, val, fmt_in): cur.execute(f"select pg_typeof({val}::float4) = pg_typeof(%{fmt_in.value})", (val,)) assert cur.fetchone()[0] is True - cur.execute(f"select {val}::float4 = %{fmt_in.value}", (val,)) + cur.execute(f"select {val}::float4, %(obj){fmt_in.value}", {"obj": val}) + rec = cur.fetchone() + assert rec[0] == pytest.approx(rec[1], 1e-3) - assert cur.fetchone()[0] is True - -@pytest.mark.parametrize( - "val", - [ - "256e6", - "256e-6", - "2.7182817", - "3.1415927", - ], -) +@pytest.mark.parametrize("val", ["256e6", "256e-6", "2.7182817", "3.1415927"]) @pytest.mark.parametrize("fmt_in", PyFormat) def test_dump_numpy_float32(conn, val, fmt_in): @@ -331,13 +296,7 @@ def test_dump_numpy_float32(conn, val, fmt_in): @pytest.mark.parametrize( - "val", - [ - "256e12", - "256e-12", - "2.718281828459045", - "3.141592653589793", - ], + "val", ["256e12", "256e-12", "2.718281828459045", "3.141592653589793"] ) @pytest.mark.parametrize("fmt_in", PyFormat) def test_dump_numpy_float64(conn, val, fmt_in):