Skip to content

[#244] PostgresNode now uses os_ops only #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 # noqa: E721

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
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tests/test_testgres_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
1 change: 0 additions & 1 deletion tests/test_testgres_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down