Skip to content

Commit 6972bfc

Browse files
[#244] PostgresNode now uses os_ops only (#245)
This patch implements the proposal #244 - detach PostgresNode from ConnectionParams object. It will use os_ops object only. conn_params is saved but must be None. It will be removed in the future.
1 parent a683c65 commit 6972bfc

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

testgres/node.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@
107107
from .operations.os_ops import ConnectionParams
108108
from .operations.os_ops import OsOperations
109109
from .operations.local_ops import LocalOperations
110-
from .operations.remote_ops import RemoteOperations
111110

112111
InternalError = pglib.InternalError
113112
ProgrammingError = pglib.ProgrammingError
@@ -151,7 +150,7 @@ def __init__(self,
151150
name=None,
152151
base_dir=None,
153152
port: typing.Optional[int] = None,
154-
conn_params: ConnectionParams = ConnectionParams(),
153+
conn_params: ConnectionParams = None,
155154
bin_dir=None,
156155
prefix=None,
157156
os_ops: typing.Optional[OsOperations] = None,
@@ -171,11 +170,15 @@ def __init__(self,
171170
assert os_ops is None or isinstance(os_ops, OsOperations)
172171
assert port_manager is None or isinstance(port_manager, PortManager)
173172

173+
if conn_params is not None:
174+
assert type(conn_params) == ConnectionParams # noqa: E721
175+
176+
raise InvalidOperationException("conn_params is deprecated, please use os_ops parameter instead.")
177+
174178
# private
175179
if os_ops is None:
176-
self._os_ops = __class__._get_os_ops(conn_params)
180+
self._os_ops = __class__._get_os_ops()
177181
else:
178-
assert conn_params is None
179182
assert isinstance(os_ops, OsOperations)
180183
self._os_ops = os_ops
181184
pass
@@ -200,11 +203,14 @@ def __init__(self,
200203
self._should_free_port = False
201204
self._port_manager = None
202205
else:
203-
if port_manager is not None:
206+
if port_manager is None:
207+
self._port_manager = __class__._get_port_manager(self._os_ops)
208+
elif os_ops is None:
209+
raise InvalidOperationException("When port_manager is not None you have to define os_ops, too.")
210+
else:
204211
assert isinstance(port_manager, PortManager)
212+
assert self._os_ops is os_ops
205213
self._port_manager = port_manager
206-
else:
207-
self._port_manager = __class__._get_port_manager(self._os_ops)
208214

209215
assert self._port_manager is not None
210216
assert isinstance(self._port_manager, PortManager)
@@ -255,16 +261,11 @@ def __repr__(self):
255261
)
256262

257263
@staticmethod
258-
def _get_os_ops(conn_params: ConnectionParams) -> OsOperations:
264+
def _get_os_ops() -> OsOperations:
259265
if testgres_config.os_ops:
260266
return testgres_config.os_ops
261267

262-
assert type(conn_params) == ConnectionParams # noqa: E721
263-
264-
if conn_params.ssh_key:
265-
return RemoteOperations(conn_params)
266-
267-
return LocalOperations(conn_params)
268+
return LocalOperations()
268269

269270
@staticmethod
270271
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):
294295
node = PostgresNode(
295296
name=name,
296297
base_dir=base_dir,
297-
conn_params=None,
298298
bin_dir=self._bin_dir,
299299
prefix=self._prefix,
300300
os_ops=self._os_ops,

tests/test_testgres_common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,6 @@ def helper__get_node(
14871487
return PostgresNode(
14881488
name,
14891489
port=port,
1490-
conn_params=None,
14911490
os_ops=node_svc.os_ops,
14921491
port_manager=port_manager if port is None else None
14931492
)

tests/test_testgres_remote.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def helper__get_node(name=None):
173173

174174
return testgres.PostgresNode(
175175
name,
176-
conn_params=None,
177176
os_ops=svc.os_ops,
178177
port_manager=svc.port_manager)
179178

0 commit comments

Comments
 (0)
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