From: Daniele Varrazzo Date: Mon, 19 Dec 2022 15:01:39 +0000 (+0000) Subject: test(numpy): add dump tests with list of numpy values X-Git-Tag: pool-3.2.0~70^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=232ae28f479f8126fe3352521b1be1e9e7233d28;p=thirdparty%2Fpsycopg.git test(numpy): add dump tests with list of numpy values --- diff --git a/tests/types/test_numpy.py b/tests/types/test_numpy.py index 0d283392c..fac83ed84 100644 --- a/tests/types/test_numpy.py +++ b/tests/types/test_numpy.py @@ -92,6 +92,9 @@ def test_dump_int(conn, val, nptype, expr, fmt_in): cur.execute(f"select {expr} = %{fmt_in.value}", (val,)) assert cur.fetchone()[0] is True + cur.execute(f"select array[{expr}] = %{fmt_in.value}", ([val],)) + assert cur.fetchone()[0] is True + @pytest.mark.parametrize( "nptype, val, pgtype", @@ -128,11 +131,20 @@ def test_dump_float(conn, nptype, val, pgtype, fmt_in): else: assert rec[0] == rec[1] + cur.execute( + f"select array['{val}']::{pgtype}[], %(obj){fmt_in.value}", {"obj": [val]} + ) + rec = cur.fetchone() + if nptype is np.float16: + assert rec[0][0] == pytest.approx(rec[1][0], 1e-3) + else: + assert rec[0][0] == rec[1][0] + @pytest.mark.slow @pytest.mark.parametrize("fmt", PyFormat) def test_random(conn, faker, fmt): - faker.types = [t for t in faker.types if issubclass(t, np.generic)] + faker.types = [t for t in faker.types if issubclass(t, (list, np.generic))] faker.format = fmt faker.choose_schema(ncols=20) faker.make_records(50)