From ac543fc382aed02514254ccf3a65ca9e03a3d33d Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Thu, 1 May 2025 20:10:47 +0300 Subject: [PATCH 1/2] [#244] PostgresNode now uses os_ops only This patch implements the proposal #244 - detach PostgresNode from ConnectionParams object. It will use os_ops object only. --- testgres/node.py | 30 +++++++++++++++--------------- tests/test_testgres_common.py | 1 - tests/test_testgres_remote.py | 1 - 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/testgres/node.py b/testgres/node.py index 41504e8..9e46e87 100644 --- a/testgres/node.py +++ b/testgres/node.py @@ -107,7 +107,6 @@ from .operations.os_ops import ConnectionParams from .operations.os_ops import OsOperations from .operations.local_ops import LocalOperations -from .operations.remote_ops import RemoteOperations InternalError = pglib.InternalError ProgrammingError = pglib.ProgrammingError @@ -151,7 +150,7 @@ def __init__(self, name=None, base_dir=None, port: typing.Optional[int] = None, - conn_params: ConnectionParams = ConnectionParams(), + conn_params: ConnectionParams = None, bin_dir=None, prefix=None, os_ops: typing.Optional[OsOperations] = None, @@ -171,11 +170,15 @@ def __init__(self, assert os_ops is None or isinstance(os_ops, OsOperations) assert port_manager is None or isinstance(port_manager, PortManager) + if conn_params is not None: + assert type(conn_params) == ConnectionParams + + raise InvalidOperationException("conn_params is deprecated, please use os_ops parameter instead.") + # private if os_ops is None: - self._os_ops = __class__._get_os_ops(conn_params) + self._os_ops = __class__._get_os_ops() else: - assert conn_params is None assert isinstance(os_ops, OsOperations) self._os_ops = os_ops pass @@ -200,11 +203,14 @@ def __init__(self, self._should_free_port = False self._port_manager = None else: - if port_manager is not None: + if port_manager is None: + self._port_manager = __class__._get_port_manager(self._os_ops) + elif os_ops is None: + raise InvalidOperationException("When port_manager is not None you have to define os_ops, too.") + else: assert isinstance(port_manager, PortManager) + assert self._os_ops is os_ops self._port_manager = port_manager - else: - self._port_manager = __class__._get_port_manager(self._os_ops) assert self._port_manager is not None assert isinstance(self._port_manager, PortManager) @@ -255,16 +261,11 @@ def __repr__(self): ) @staticmethod - def _get_os_ops(conn_params: ConnectionParams) -> OsOperations: + def _get_os_ops() -> OsOperations: if testgres_config.os_ops: return testgres_config.os_ops - assert type(conn_params) == ConnectionParams # noqa: E721 - - if conn_params.ssh_key: - return RemoteOperations(conn_params) - - return LocalOperations(conn_params) + return LocalOperations() @staticmethod def _get_port_manager(os_ops: OsOperations) -> PortManager: @@ -294,7 +295,6 @@ def clone_with_new_name_and_base_dir(self, name: str, base_dir: str): node = PostgresNode( name=name, base_dir=base_dir, - conn_params=None, bin_dir=self._bin_dir, prefix=self._prefix, os_ops=self._os_ops, diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index 21fa00d..46d156b 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -1478,7 +1478,6 @@ def helper__get_node( return PostgresNode( name, port=port, - conn_params=None, os_ops=node_svc.os_ops, port_manager=port_manager if port is None else None ) diff --git a/tests/test_testgres_remote.py b/tests/test_testgres_remote.py index 87cc026..6a8d068 100755 --- a/tests/test_testgres_remote.py +++ b/tests/test_testgres_remote.py @@ -173,7 +173,6 @@ def helper__get_node(name=None): return testgres.PostgresNode( name, - conn_params=None, os_ops=svc.os_ops, port_manager=svc.port_manager) From f1d1cd0694a42c3178b4321d89056016df794382 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Thu, 1 May 2025 23:18:46 +0300 Subject: [PATCH 2/2] Code warning is fixed [flake8] --- testgres/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testgres/node.py b/testgres/node.py index 9e46e87..bab989c 100644 --- a/testgres/node.py +++ b/testgres/node.py @@ -171,7 +171,7 @@ def __init__(self, assert port_manager is None or isinstance(port_manager, PortManager) if conn_params is not None: - assert type(conn_params) == ConnectionParams + assert type(conn_params) == ConnectionParams # noqa: E721 raise InvalidOperationException("conn_params is deprecated, please use os_ops parameter instead.") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy