From: Daniele Varrazzo Date: Sat, 28 Aug 2021 02:12:08 +0000 (+0200) Subject: Add test to verify empty ranges can be copied in ok X-Git-Tag: 3.0.beta1~25 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6958165da602ff4f9b769c985334de46546dd658;p=thirdparty%2Fpsycopg.git Add test to verify empty ranges can be copied in ok --- diff --git a/tests/types/test_range.py b/tests/types/test_range.py index 2d44ca009..a63c286d9 100644 --- a/tests/types/test_range.py +++ b/tests/types/test_range.py @@ -273,6 +273,28 @@ def test_copy_in_empty_wrappers(conn, bounds, wrapper, format): assert rec[0] == r +@pytest.mark.parametrize("bounds", "() empty".split()) +@pytest.mark.parametrize( + "pgtype", + "int4range int8range numrange daterange tsrange tstzrange".split(), +) +@pytest.mark.parametrize("format", [pq.Format.TEXT, pq.Format.BINARY]) +def test_copy_in_empty_set_type(conn, bounds, pgtype, format): + cur = conn.cursor() + cur.execute(f"create table copyrange (id serial primary key, r {pgtype})") + + r = Range(empty=True) if bounds == "empty" else Range(None, None, bounds) + + with cur.copy( + f"copy copyrange (r) from stdin (format {format.name})" + ) as copy: + copy.set_types([pgtype]) + copy.write_row([r]) + + rec = cur.execute("select r from copyrange order by id").fetchone() + assert rec[0] == r + + @pytest.fixture(scope="session") def testrange(svcconn): svcconn.execute(