From: Daniele Varrazzo Date: Sun, 28 Feb 2021 02:15:30 +0000 (+0100) Subject: Drop psycopg3.pq.PQerror X-Git-Tag: 3.0.dev0~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b05e4ffdbdb5984d52eaeaa9e531ec82973b605;p=thirdparty%2Fpsycopg.git Drop psycopg3.pq.PQerror Use an OperationalError instead (of which PQerror was a subclass), which is better documented. --- diff --git a/psycopg3/psycopg3/connection.py b/psycopg3/psycopg3/connection.py index d724cda51..02baea376 100644 --- a/psycopg3/psycopg3/connection.py +++ b/psycopg3/psycopg3/connection.py @@ -216,10 +216,7 @@ class BaseConnection(AdaptContext): functions waiting for readiness, such as the ones defined in the `selectors` module. """ - try: - return self.pgconn.socket - except pq.PQerror as exc: - raise e.OperationalError(str(exc)) + return self.pgconn.socket def cancel(self) -> None: """Cancel the current operation on the connection.""" diff --git a/psycopg3/psycopg3/conninfo.py b/psycopg3/psycopg3/conninfo.py index bf2ddf043..ccc728277 100644 --- a/psycopg3/psycopg3/conninfo.py +++ b/psycopg3/psycopg3/conninfo.py @@ -69,7 +69,7 @@ def _parse_conninfo(conninfo: str) -> List[pq.ConninfoOption]: """ try: return pq.Conninfo.parse(conninfo.encode("utf8")) - except pq.PQerror as ex: + except e.OperationalError as ex: raise e.ProgrammingError(str(ex)) diff --git a/psycopg3/psycopg3/pq/__init__.py b/psycopg3/psycopg3/pq/__init__.py index c9ed41c9a..18a959530 100644 --- a/psycopg3/psycopg3/pq/__init__.py +++ b/psycopg3/psycopg3/pq/__init__.py @@ -13,7 +13,7 @@ import os import logging from typing import Callable, List, Type -from .misc import ConninfoOption, PQerror, PGnotify, PGresAttDesc +from .misc import ConninfoOption, PGnotify, PGresAttDesc from .misc import error_message from ._enums import ConnStatus, DiagnosticField, ExecStatus, Format from ._enums import Ping, PollingStatus, TransactionStatus @@ -114,7 +114,6 @@ __all__ = ( "PGnotify", "Conninfo", "PGresAttDesc", - "PQerror", "error_message", "ConninfoOption", "version", diff --git a/psycopg3/psycopg3/pq/misc.py b/psycopg3/psycopg3/pq/misc.py index 117f77c67..7eb8d69be 100644 --- a/psycopg3/psycopg3/pq/misc.py +++ b/psycopg3/psycopg3/pq/misc.py @@ -6,15 +6,10 @@ Various functionalities to make easier to work with the libpq. from typing import cast, NamedTuple, Optional, Union -from ..errors import OperationalError from ._enums import DiagnosticField, ConnStatus, TransactionStatus from .proto import PGconn, PGresult -class PQerror(OperationalError): - __module__ = "psycopg3.pq" - - class PGnotify(NamedTuple): relname: bytes be_pid: int diff --git a/psycopg3/psycopg3/pq/pq_ctypes.py b/psycopg3/psycopg3/pq/pq_ctypes.py index 1a58bc98b..d0e067235 100644 --- a/psycopg3/psycopg3/pq/pq_ctypes.py +++ b/psycopg3/psycopg3/pq/pq_ctypes.py @@ -18,8 +18,9 @@ from ctypes import c_char_p, c_int, c_size_t, c_ulong from typing import Any, Callable, List, Optional, Sequence, Tuple from typing import cast as t_cast, TYPE_CHECKING +from .. import errors as e from . import _pq_ctypes as impl -from .misc import PGnotify, ConninfoOption, PQerror, PGresAttDesc +from .misc import PGnotify, ConninfoOption, PGresAttDesc from .misc import error_message, connection_summary from ._enums import Format, ExecStatus @@ -46,8 +47,8 @@ def notice_receiver( res = PGresult(result_ptr) try: pgconn.notice_handler(res) - except Exception as e: - logger.exception("error in notice receiver: %s", e) + except Exception as exc: + logger.exception("error in notice receiver: %s", exc) res.pgresult_ptr = None # avoid destroying the pgresult_ptr @@ -137,7 +138,7 @@ class PGconn: def reset_start(self) -> None: if not impl.PQresetStart(self.pgconn_ptr): - raise PQerror("couldn't reset connection") + raise e.OperationalError("couldn't reset connection") def reset_poll(self) -> int: return self._call_int(impl.PQresetPoll) @@ -242,7 +243,9 @@ class PGconn: raise TypeError(f"bytes expected, got {type(command)} instead") self._ensure_pgconn() if not impl.PQsendQuery(self.pgconn_ptr, command): - raise PQerror(f"sending query failed: {error_message(self)}") + raise e.OperationalError( + f"sending query failed: {error_message(self)}" + ) def exec_params( self, @@ -274,7 +277,7 @@ class PGconn: ) self._ensure_pgconn() if not impl.PQsendQueryParams(*args): - raise PQerror( + raise e.OperationalError( f"sending query and params failed: {error_message(self)}" ) @@ -296,7 +299,7 @@ class PGconn: if not impl.PQsendPrepare( self.pgconn_ptr, name, command, nparams, atypes ): - raise PQerror( + raise e.OperationalError( f"sending query and params failed: {error_message(self)}" ) @@ -316,7 +319,7 @@ class PGconn: self._ensure_pgconn() if not impl.PQsendQueryPrepared(*args): - raise PQerror( + raise e.OperationalError( f"sending prepared query failed: {error_message(self)}" ) @@ -471,7 +474,7 @@ class PGconn: raise TypeError(f"bytes expected, got {type(name)} instead") self._ensure_pgconn() if not impl.PQsendDescribePrepared(self.pgconn_ptr, name): - raise PQerror( + raise e.OperationalError( f"sending describe prepared failed: {error_message(self)}" ) @@ -489,7 +492,7 @@ class PGconn: raise TypeError(f"bytes expected, got {type(name)} instead") self._ensure_pgconn() if not impl.PQsendDescribePortal(self.pgconn_ptr, name): - raise PQerror( + raise e.OperationalError( f"sending describe portal failed: {error_message(self)}" ) @@ -499,7 +502,9 @@ class PGconn: def consume_input(self) -> None: if 1 != impl.PQconsumeInput(self.pgconn_ptr): - raise PQerror(f"consuming input failed: {error_message(self)}") + raise e.OperationalError( + f"consuming input failed: {error_message(self)}" + ) def is_busy(self) -> int: return impl.PQisBusy(self.pgconn_ptr) @@ -511,19 +516,23 @@ class PGconn: @nonblocking.setter def nonblocking(self, arg: int) -> None: if 0 > impl.PQsetnonblocking(self.pgconn_ptr, arg): - raise PQerror(f"setting nonblocking failed: {error_message(self)}") + raise e.OperationalError( + f"setting nonblocking failed: {error_message(self)}" + ) def flush(self) -> int: if not self.pgconn_ptr: - raise PQerror("flushing failed: the connection is closed") + raise e.OperationalError( + "flushing failed: the connection is closed" + ) rv: int = impl.PQflush(self.pgconn_ptr) if rv < 0: - raise PQerror(f"flushing failed: {error_message(self)}") + raise e.OperationalError(f"flushing failed: {error_message(self)}") return rv def set_single_row_mode(self) -> None: if not impl.PQsetSingleRowMode(self.pgconn_ptr): - raise PQerror("setting single row mode failed") + raise e.OperationalError("setting single row mode failed") def get_cancel(self) -> "PGcancel": """ @@ -533,7 +542,7 @@ class PGconn: """ rv = impl.PQgetCancel(self.pgconn_ptr) if not rv: - raise PQerror("couldn't create cancel object") + raise e.OperationalError("couldn't create cancel object") return PGcancel(rv) def notifies(self) -> Optional[PGnotify]: @@ -551,20 +560,26 @@ class PGconn: buffer = bytes(buffer) rv = impl.PQputCopyData(self.pgconn_ptr, buffer, len(buffer)) if rv < 0: - raise PQerror(f"sending copy data failed: {error_message(self)}") + raise e.OperationalError( + f"sending copy data failed: {error_message(self)}" + ) return rv def put_copy_end(self, error: Optional[bytes] = None) -> int: rv = impl.PQputCopyEnd(self.pgconn_ptr, error) if rv < 0: - raise PQerror(f"sending copy end failed: {error_message(self)}") + raise e.OperationalError( + f"sending copy end failed: {error_message(self)}" + ) return rv def get_copy_data(self, async_: int) -> Tuple[int, memoryview]: buffer_ptr = c_char_p() nbytes = impl.PQgetCopyData(self.pgconn_ptr, byref(buffer_ptr), async_) if nbytes == -2: - raise PQerror(f"receiving copy data failed: {error_message(self)}") + raise e.OperationalError( + f"receiving copy data failed: {error_message(self)}" + ) if buffer_ptr: # TODO: do it without copy data = string_at(buffer_ptr, nbytes) @@ -586,7 +601,7 @@ class PGconn: Call one of the pgconn libpq functions returning a bytes pointer. """ if not self.pgconn_ptr: - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") rv = func(self.pgconn_ptr) assert rv is not None return rv @@ -596,7 +611,7 @@ class PGconn: Call one of the pgconn libpq functions returning an int. """ if not self.pgconn_ptr: - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") return func(self.pgconn_ptr) def _call_bool(self, func: Callable[[impl.PGconn_struct], int]) -> bool: @@ -604,12 +619,12 @@ class PGconn: Call one of the pgconn libpq functions returning a logical value. """ if not self.pgconn_ptr: - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") return bool(func(self.pgconn_ptr)) def _ensure_pgconn(self) -> None: if not self.pgconn_ptr: - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") class PGresult: @@ -723,7 +738,7 @@ class PGresult: array = (impl.PGresAttDesc_struct * len(structs))(*structs) # type: ignore rv = impl.PQsetResultAttrs(self.pgresult_ptr, len(structs), array) if rv == 0: - raise PQerror("PQsetResultAttrs failed") + raise e.OperationalError("PQsetResultAttrs failed") class PGcancel: @@ -764,7 +779,7 @@ class PGcancel: self.pgcancel_ptr, pointer(buf), len(buf) # type: ignore ) if not res: - raise PQerror( + raise e.OperationalError( f"cancel failed: {buf.value.decode('utf8', 'ignore')}" ) @@ -797,7 +812,9 @@ class Conninfo: if not errmsg: raise MemoryError("couldn't allocate on conninfo parse") else: - exc = PQerror((errmsg.value or b"").decode("utf8", "replace")) + exc = e.OperationalError( + (errmsg.value or b"").decode("utf8", "replace") + ) impl.PQfreemem(errmsg) raise exc @@ -834,7 +851,9 @@ class Escaping: def escape_literal(self, data: "proto.Buffer") -> memoryview: if not self.conn: - raise PQerror("escape_literal failed: no connection provided") + raise e.OperationalError( + "escape_literal failed: no connection provided" + ) self.conn._ensure_pgconn() # TODO: might be done without copy (however C does that) @@ -842,7 +861,7 @@ class Escaping: data = bytes(data) out = impl.PQescapeLiteral(self.conn.pgconn_ptr, data, len(data)) if not out: - raise PQerror( + raise e.OperationalError( f"escape_literal failed: {error_message(self.conn)} bytes" ) rv = string_at(out) @@ -851,7 +870,9 @@ class Escaping: def escape_identifier(self, data: "proto.Buffer") -> memoryview: if not self.conn: - raise PQerror("escape_identifier failed: no connection provided") + raise e.OperationalError( + "escape_identifier failed: no connection provided" + ) self.conn._ensure_pgconn() @@ -859,7 +880,7 @@ class Escaping: data = bytes(data) out = impl.PQescapeIdentifier(self.conn.pgconn_ptr, data, len(data)) if not out: - raise PQerror( + raise e.OperationalError( f"escape_identifier failed: {error_message(self.conn)} bytes" ) rv = string_at(out) @@ -883,7 +904,7 @@ class Escaping: ) if error: - raise PQerror( + raise e.OperationalError( f"escape_string failed: {error_message(self.conn)} bytes" ) diff --git a/psycopg3_c/psycopg3_c/_psycopg3/generators.pyx b/psycopg3_c/psycopg3_c/_psycopg3/generators.pyx index 7f7f801ac..a44e7b7a6 100644 --- a/psycopg3_c/psycopg3_c/_psycopg3/generators.pyx +++ b/psycopg3_c/psycopg3_c/_psycopg3/generators.pyx @@ -10,7 +10,7 @@ import logging from typing import List from psycopg3 import errors as e -from psycopg3.pq import proto, error_message, PQerror +from psycopg3.pq import proto, error_message from psycopg3.proto import PQGen from psycopg3.waiting import Wait, Ready @@ -85,7 +85,7 @@ def execute(pq.PGconn pgconn) -> PQGen[List[proto.PGresult]]: # PGconn buffer and passed to Python later. cires = libpq.PQconsumeInput(pgconn_ptr) if 1 != cires: - raise PQerror( + raise e.OperationalError( f"consuming input failed: {error_message(pgconn)}") continue @@ -99,7 +99,7 @@ def execute(pq.PGconn pgconn) -> PQGen[List[proto.PGresult]]: ibres = libpq.PQisBusy(pgconn_ptr) if 1 != cires: - raise PQerror( + raise e.OperationalError( f"consuming input failed: {error_message(pgconn)}") if ibres: yield WAIT_R diff --git a/psycopg3_c/psycopg3_c/pq.pyx b/psycopg3_c/psycopg3_c/pq.pyx index 02a1564dc..cff949870 100644 --- a/psycopg3_c/psycopg3_c/pq.pyx +++ b/psycopg3_c/psycopg3_c/pq.pyx @@ -6,8 +6,9 @@ libpq Python wrapper using cython bindings. from psycopg3_c.pq cimport libpq +from psycopg3 import errors as e from psycopg3.pq import Format -from psycopg3.pq.misc import PQerror, error_message +from psycopg3.pq.misc import error_message __impl__ = 'c' diff --git a/psycopg3_c/psycopg3_c/pq/conninfo.pyx b/psycopg3_c/psycopg3_c/pq/conninfo.pyx index 103c88595..30814e75b 100644 --- a/psycopg3_c/psycopg3_c/pq/conninfo.pyx +++ b/psycopg3_c/psycopg3_c/pq/conninfo.pyx @@ -25,7 +25,7 @@ class Conninfo: if errmsg is NULL: raise MemoryError("couldn't allocate on conninfo parse") else: - exc = PQerror(errmsg.decode("utf8", "replace")) + exc = e.OperationalError(errmsg.decode("utf8", "replace")) libpq.PQfreemem(errmsg) raise exc diff --git a/psycopg3_c/psycopg3_c/pq/escaping.pyx b/psycopg3_c/psycopg3_c/pq/escaping.pyx index 41ad870a0..4eb6b57a8 100644 --- a/psycopg3_c/psycopg3_c/pq/escaping.pyx +++ b/psycopg3_c/psycopg3_c/pq/escaping.pyx @@ -21,15 +21,15 @@ cdef class Escaping: cdef Py_ssize_t length if self.conn is None: - raise PQerror("escape_literal failed: no connection provided") + raise e.OperationalError("escape_literal failed: no connection provided") if self.conn.pgconn_ptr is NULL: - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") _buffer_as_string_and_size(data, &ptr, &length) out = libpq.PQescapeLiteral(self.conn.pgconn_ptr, ptr, length) if out is NULL: - raise PQerror( + raise e.OperationalError( f"escape_literal failed: {error_message(self.conn)}" ) @@ -45,13 +45,13 @@ cdef class Escaping: _buffer_as_string_and_size(data, &ptr, &length) if self.conn is None: - raise PQerror("escape_identifier failed: no connection provided") + raise e.OperationalError("escape_identifier failed: no connection provided") if self.conn.pgconn_ptr is NULL: - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") out = libpq.PQescapeIdentifier(self.conn.pgconn_ptr, ptr, length) if out is NULL: - raise PQerror( + raise e.OperationalError( f"escape_identifier failed: {error_message(self.conn)}" ) @@ -73,14 +73,14 @@ cdef class Escaping: if self.conn is not None: if self.conn.pgconn_ptr is NULL: - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") len_out = libpq.PQescapeStringConn( self.conn.pgconn_ptr, PyByteArray_AS_STRING(rv), ptr, length, &error ) if error: - raise PQerror( + raise e.OperationalError( f"escape_string failed: {error_message(self.conn)}" ) @@ -98,7 +98,7 @@ cdef class Escaping: cdef Py_ssize_t length if self.conn is not None and self.conn.pgconn_ptr is NULL: - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") _buffer_as_string_and_size(data, &ptr, &length) @@ -122,7 +122,7 @@ cdef class Escaping: # if a connection is passed in, it must be valid. if self.conn is not None: if self.conn.pgconn_ptr is NULL: - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") cdef size_t len_out cdef unsigned char *out = libpq.PQunescapeBytea(data, &len_out) diff --git a/psycopg3_c/psycopg3_c/pq/pgcancel.pyx b/psycopg3_c/psycopg3_c/pq/pgcancel.pyx index 7d27bb647..93f126190 100644 --- a/psycopg3_c/psycopg3_c/pq/pgcancel.pyx +++ b/psycopg3_c/psycopg3_c/pq/pgcancel.pyx @@ -27,6 +27,6 @@ cdef class PGcancel: cdef char buf[256] cdef int res = libpq.PQcancel(self.pgcancel_ptr, buf, sizeof(buf)) if not res: - raise PQerror( + raise e.OperationalError( f"cancel failed: {buf.decode('utf8', 'ignore')}" ) diff --git a/psycopg3_c/psycopg3_c/pq/pgconn.pyx b/psycopg3_c/psycopg3_c/pq/pgconn.pyx index ccd431c1c..75c918f22 100644 --- a/psycopg3_c/psycopg3_c/pq/pgconn.pyx +++ b/psycopg3_c/psycopg3_c/pq/pgconn.pyx @@ -89,7 +89,7 @@ cdef class PGconn: def reset_start(self) -> None: if not libpq.PQresetStart(self.pgconn_ptr): - raise PQerror("couldn't reset connection") + raise e.OperationalError("couldn't reset connection") def reset_poll(self) -> int: return _call_int(self, libpq.PQresetPoll) @@ -162,7 +162,7 @@ cdef class PGconn: def socket(self) -> int: rv = _call_int(self, libpq.PQsocket) if rv == -1: - raise PQerror("the connection is lost") + raise e.OperationalError("the connection is lost") return rv @property @@ -197,7 +197,7 @@ cdef class PGconn: with nogil: rv = libpq.PQsendQuery(self.pgconn_ptr, command) if not rv: - raise PQerror(f"sending query failed: {error_message(self)}") + raise e.OperationalError(f"sending query failed: {error_message(self)}") def exec_params( self, @@ -252,7 +252,7 @@ cdef class PGconn: cvalues, clengths, cformats, result_format) _clear_query_params(ctypes, cvalues, clengths, cformats) if not rv: - raise PQerror( + raise e.OperationalError( f"sending query and params failed: {error_message(self)}" ) @@ -279,7 +279,7 @@ cdef class PGconn: ) PyMem_Free(atypes) if not rv: - raise PQerror( + raise e.OperationalError( f"sending query and params failed: {error_message(self)}" ) @@ -307,7 +307,7 @@ cdef class PGconn: clengths, cformats, result_format) _clear_query_params(ctypes, cvalues, clengths, cformats) if not rv: - raise PQerror( + raise e.OperationalError( f"sending prepared query failed: {error_message(self)}" ) @@ -376,7 +376,7 @@ cdef class PGconn: _ensure_pgconn(self) cdef int rv = libpq.PQsendDescribePrepared(self.pgconn_ptr, name) if not rv: - raise PQerror( + raise e.OperationalError( f"sending describe prepared failed: {error_message(self)}" ) @@ -391,7 +391,7 @@ cdef class PGconn: _ensure_pgconn(self) cdef int rv = libpq.PQsendDescribePortal(self.pgconn_ptr, name) if not rv: - raise PQerror( + raise e.OperationalError( f"sending describe prepared failed: {error_message(self)}" ) @@ -403,7 +403,7 @@ cdef class PGconn: def consume_input(self) -> None: if 1 != libpq.PQconsumeInput(self.pgconn_ptr): - raise PQerror(f"consuming input failed: {error_message(self)}") + raise e.OperationalError(f"consuming input failed: {error_message(self)}") def is_busy(self) -> int: cdef int rv @@ -418,24 +418,24 @@ cdef class PGconn: @nonblocking.setter def nonblocking(self, int arg) -> None: if 0 > libpq.PQsetnonblocking(self.pgconn_ptr, arg): - raise PQerror(f"setting nonblocking failed: {error_message(self)}") + raise e.OperationalError(f"setting nonblocking failed: {error_message(self)}") def flush(self) -> int: if self.pgconn_ptr == NULL: - raise PQerror(f"flushing failed: the connection is closed") + raise e.OperationalError(f"flushing failed: the connection is closed") cdef int rv = libpq.PQflush(self.pgconn_ptr) if rv < 0: - raise PQerror(f"flushing failed: {error_message(self)}") + raise e.OperationalError(f"flushing failed: {error_message(self)}") return rv def set_single_row_mode(self) -> None: if not libpq.PQsetSingleRowMode(self.pgconn_ptr): - raise PQerror("setting single row mode failed") + raise e.OperationalError("setting single row mode failed") def get_cancel(self) -> PGcancel: cdef libpq.PGcancel *ptr = libpq.PQgetCancel(self.pgconn_ptr) if not ptr: - raise PQerror("couldn't create cancel object") + raise e.OperationalError("couldn't create cancel object") return PGcancel._from_ptr(ptr) cpdef object notifies(self): @@ -457,7 +457,7 @@ cdef class PGconn: _buffer_as_string_and_size(buffer, &cbuffer, &length) rv = libpq.PQputCopyData(self.pgconn_ptr, cbuffer, length) if rv < 0: - raise PQerror(f"sending copy data failed: {error_message(self)}") + raise e.OperationalError(f"sending copy data failed: {error_message(self)}") return rv def put_copy_end(self, error: Optional[bytes] = None) -> int: @@ -467,7 +467,7 @@ cdef class PGconn: cerr = PyBytes_AsString(error) rv = libpq.PQputCopyEnd(self.pgconn_ptr, cerr) if rv < 0: - raise PQerror(f"sending copy end failed: {error_message(self)}") + raise e.OperationalError(f"sending copy end failed: {error_message(self)}") return rv def get_copy_data(self, int async_) -> Tuple[int, memoryview]: @@ -475,7 +475,7 @@ cdef class PGconn: cdef int nbytes nbytes = libpq.PQgetCopyData(self.pgconn_ptr, &buffer_ptr, async_) if nbytes == -2: - raise PQerror(f"receiving copy data failed: {error_message(self)}") + raise e.OperationalError(f"receiving copy data failed: {error_message(self)}") if buffer_ptr is not NULL: data = PyMemoryView_FromObject( PQBuffer._from_buffer(buffer_ptr, nbytes)) @@ -495,7 +495,7 @@ cdef int _ensure_pgconn(PGconn pgconn) except 0: if pgconn.pgconn_ptr is not NULL: return 1 - raise PQerror("the connection is closed") + raise e.OperationalError("the connection is closed") cdef char *_call_bytes(PGconn pgconn, conn_bytes_f func) except NULL: diff --git a/psycopg3_c/psycopg3_c/pq/pgresult.pyx b/psycopg3_c/psycopg3_c/pq/pgresult.pyx index 0bcc86cc0..196b1ba92 100644 --- a/psycopg3_c/psycopg3_c/pq/pgresult.pyx +++ b/psycopg3_c/psycopg3_c/pq/pgresult.pyx @@ -154,4 +154,4 @@ cdef class PGresult: cdef int res = libpq.PQsetResultAttrs(self.pgresult_ptr, num, attrs) PyMem_Free(attrs) if (res == 0): - raise PQerror("PQsetResultAttrs failed") + raise e.OperationalError("PQsetResultAttrs failed") diff --git a/tests/pq/test_conninfo.py b/tests/pq/test_conninfo.py index 729d9ab21..a1933f7bc 100644 --- a/tests/pq/test_conninfo.py +++ b/tests/pq/test_conninfo.py @@ -1,5 +1,6 @@ import pytest +import psycopg3 from psycopg3 import pq @@ -29,6 +30,6 @@ def test_conninfo_parse(): def test_conninfo_parse_bad(): - with pytest.raises(pq.PQerror) as e: + with pytest.raises(psycopg3.OperationalError) as e: pq.Conninfo.parse(b"bad_conninfo=") assert "bad_conninfo" in str(e.value) diff --git a/tests/pq/test_copy.py b/tests/pq/test_copy.py index 41a35f176..aab25afb1 100644 --- a/tests/pq/test_copy.py +++ b/tests/pq/test_copy.py @@ -1,5 +1,6 @@ import pytest +import psycopg3 from psycopg3 import pq sample_values = "values (10::int, 20::int, 'hello'::text), (40, NULL, 'world')" @@ -29,20 +30,20 @@ sample_binary = b"".join(sample_binary_rows) def test_put_data_no_copy(pgconn): - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): pgconn.put_copy_data(b"wat") pgconn.finish() - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): pgconn.put_copy_data(b"wat") def test_put_end_no_copy(pgconn): - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): pgconn.put_copy_end() pgconn.finish() - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): pgconn.put_copy_end() @@ -135,11 +136,11 @@ def test_copy_out_error_end(pgconn): def test_get_data_no_copy(pgconn): - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): pgconn.get_copy_data(0) pgconn.finish() - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): pgconn.get_copy_data(0) diff --git a/tests/pq/test_misc.py b/tests/pq/test_misc.py index 8545cfbac..7aa96d887 100644 --- a/tests/pq/test_misc.py +++ b/tests/pq/test_misc.py @@ -1,5 +1,6 @@ import pytest +import psycopg3 from psycopg3 import pq @@ -78,5 +79,5 @@ def test_result_set_attrs(pgconn): assert res.ftype(1) == 1700 assert res.ftype(2) == 25 - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): res.set_attributes(attrs) diff --git a/tests/pq/test_pgconn.py b/tests/pq/test_pgconn.py index c45fbfcc1..a9ae4845e 100644 --- a/tests/pq/test_pgconn.py +++ b/tests/pq/test_pgconn.py @@ -371,7 +371,7 @@ def test_ssl_in_use(pgconn): def test_set_single_row_mode(pgconn): - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): pgconn.set_single_row_mode() pgconn.send_query(b"select 1") @@ -384,14 +384,14 @@ def test_cancel(pgconn): cancel.cancel() pgconn.finish() cancel.cancel() - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): pgconn.get_cancel() def test_cancel_free(pgconn): cancel = pgconn.get_cancel() cancel.free() - with pytest.raises(pq.PQerror): + with pytest.raises(psycopg3.OperationalError): cancel.cancel() cancel.free()