From: Daniele Varrazzo Date: Thu, 10 Aug 2023 00:16:31 +0000 (+0100) Subject: refactor(tests): auto-generate test_client_cursor from async counterpart X-Git-Tag: pool-3.2.0~12^2~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21607339df2d6307920dcf6ec597babf6471f1c9;p=thirdparty%2Fpsycopg.git refactor(tests): auto-generate test_client_cursor from async counterpart --- diff --git a/tests/test_client_cursor.py b/tests/test_client_cursor.py index d8b4e5abf..ee6a69ee7 100644 --- a/tests/test_client_cursor.py +++ b/tests/test_client_cursor.py @@ -1,3 +1,6 @@ +# WARNING: this file is auto-generated by 'async_to_sync.py' +# from the original file 'test_client_cursor_async.py' +# DO NOT CHANGE! Change the original file instead. import datetime as dt import pytest @@ -9,7 +12,7 @@ from .fix_crdb import crdb_encoding @pytest.fixture -def conn(conn): +def conn(conn, anyio_backend): conn.cursor_factory = psycopg.ClientCursor return conn @@ -133,12 +136,12 @@ def test_mogrify(conn, query, params, want): @pytest.mark.parametrize("encoding", ["utf8", crdb_encoding("latin9")]) def test_mogrify_encoding(conn, encoding): conn.execute(f"set client_encoding to {encoding}") - q = conn.cursor().mogrify("select %(s)s", {"s": "\u20ac"}) - assert q == "select '\u20ac'" + q = conn.cursor().mogrify("select %(s)s", {"s": "€"}) + assert q == "select '€'" @pytest.mark.parametrize("encoding", [crdb_encoding("latin1")]) def test_mogrify_badenc(conn, encoding): conn.execute(f"set client_encoding to {encoding}") with pytest.raises(UnicodeEncodeError): - conn.cursor().mogrify("select %(s)s", {"s": "\u20ac"}) + conn.cursor().mogrify("select %(s)s", {"s": "€"}) diff --git a/tools/async_to_sync.py b/tools/async_to_sync.py index 25d627363..706dc66b8 100755 --- a/tools/async_to_sync.py +++ b/tools/async_to_sync.py @@ -116,6 +116,7 @@ class RenameAsyncToSync(ast.NodeTransformer): "aconn_set": "conn_set", "alist": "list", "anext": "next", + "find_insert_problem_async": "find_insert_problem", } def visit_Module(self, node: ast.Module) -> ast.AST: diff --git a/tools/convert_async_to_sync.sh b/tools/convert_async_to_sync.sh index 8727c5406..637cd6083 100755 --- a/tools/convert_async_to_sync.sh +++ b/tools/convert_async_to_sync.sh @@ -8,6 +8,7 @@ dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "${dir}/.." for async in \ + tests/test_client_cursor_async.py \ tests/test_connection_async.py \ tests/test_cursor_async.py \ tests/test_pipeline_async.py