diff --git a/testgres/connection.py b/testgres/connection.py index ccedd135..b8dc49a9 100644 --- a/testgres/connection.py +++ b/testgres/connection.py @@ -42,11 +42,13 @@ def __init__(self, self._node = node - self._connection = node.os_ops.db_connect(dbname=dbname, - user=username, - password=password, - host=node.host, - port=node.port) + self._connection = pglib.connect( + database=dbname, + user=username, + password=password, + host=node.host, + port=node.port + ) self._connection.autocommit = autocommit self._cursor = self.connection.cursor() diff --git a/testgres/operations/local_ops.py b/testgres/operations/local_ops.py index 39c81405..9785d462 100644 --- a/testgres/operations/local_ops.py +++ b/testgres/operations/local_ops.py @@ -12,7 +12,7 @@ from ..exceptions import ExecUtilException from ..exceptions import InvalidOperationException -from .os_ops import ConnectionParams, OsOperations, pglib, get_default_encoding +from .os_ops import ConnectionParams, OsOperations, get_default_encoding from .raise_error import RaiseError from .helpers import Helpers @@ -446,14 +446,3 @@ def is_port_free(self, number: int) -> bool: return True except OSError: return False - - # Database control - def db_connect(self, dbname, user, password=None, host="localhost", port=5432): - conn = pglib.connect( - host=host, - port=port, - database=dbname, - user=user, - password=password, - ) - return conn diff --git a/testgres/operations/os_ops.py b/testgres/operations/os_ops.py index 489a7cb2..d25e76bc 100644 --- a/testgres/operations/os_ops.py +++ b/testgres/operations/os_ops.py @@ -1,14 +1,6 @@ import getpass import locale -try: - import psycopg2 as pglib # noqa: F401 -except ImportError: - try: - import pg8000 as pglib # noqa: F401 - except ImportError: - raise ImportError("You must have psycopg2 or pg8000 modules installed") - class ConnectionParams: def __init__(self, host='127.0.0.1', port=None, ssh_key=None, username=None): @@ -130,7 +122,3 @@ def get_process_children(self, pid): def is_port_free(self, number: int): assert type(number) == int # noqa: E721 raise NotImplementedError() - - # Database control - def db_connect(self, dbname, user, password=None, host="localhost", port=5432): - raise NotImplementedError() diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py index ee747e52..25d02f38 100644 --- a/testgres/operations/remote_ops.py +++ b/testgres/operations/remote_ops.py @@ -6,15 +6,6 @@ import io import logging -# we support both pg8000 and psycopg2 -try: - import psycopg2 as pglib -except ImportError: - try: - import pg8000 as pglib - except ImportError: - raise ImportError("You must have psycopg2 or pg8000 modules installed") - from ..exceptions import ExecUtilException from ..exceptions import InvalidOperationException from .os_ops import OsOperations, ConnectionParams, get_default_encoding @@ -677,17 +668,6 @@ def _is_port_free__process_1(error: str) -> bool: # return True - # Database control - def db_connect(self, dbname, user, password=None, host="localhost", port=5432): - conn = pglib.connect( - host=host, - port=port, - database=dbname, - user=user, - password=password, - ) - return conn - @staticmethod def _make_exec_env_list() -> list[str]: result = list[str]()