Skip to content

Commit da2c493

Browse files
OsOperation::db_connect is removed (#237)
* OsOperation::db_connect is removed OsOperation does not work with databases. It provides an only OS functional. TODO: CI must explicitly test pg8000 and psycopg2.
1 parent 307ef5f commit da2c493

File tree

4 files changed

+8
-49
lines changed

4 files changed

+8
-49
lines changed

testgres/connection.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ def __init__(self,
4242

4343
self._node = node
4444

45-
self._connection = node.os_ops.db_connect(dbname=dbname,
46-
user=username,
47-
password=password,
48-
host=node.host,
49-
port=node.port)
45+
self._connection = pglib.connect(
46+
database=dbname,
47+
user=username,
48+
password=password,
49+
host=node.host,
50+
port=node.port
51+
)
5052

5153
self._connection.autocommit = autocommit
5254
self._cursor = self.connection.cursor()

testgres/operations/local_ops.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from ..exceptions import ExecUtilException
1414
from ..exceptions import InvalidOperationException
15-
from .os_ops import ConnectionParams, OsOperations, pglib, get_default_encoding
15+
from .os_ops import ConnectionParams, OsOperations, get_default_encoding
1616
from .raise_error import RaiseError
1717
from .helpers import Helpers
1818

@@ -446,14 +446,3 @@ def is_port_free(self, number: int) -> bool:
446446
return True
447447
except OSError:
448448
return False
449-
450-
# Database control
451-
def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
452-
conn = pglib.connect(
453-
host=host,
454-
port=port,
455-
database=dbname,
456-
user=user,
457-
password=password,
458-
)
459-
return conn

testgres/operations/os_ops.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import getpass
22
import locale
33

4-
try:
5-
import psycopg2 as pglib # noqa: F401
6-
except ImportError:
7-
try:
8-
import pg8000 as pglib # noqa: F401
9-
except ImportError:
10-
raise ImportError("You must have psycopg2 or pg8000 modules installed")
11-
124

135
class ConnectionParams:
146
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):
130122
def is_port_free(self, number: int):
131123
assert type(number) == int # noqa: E721
132124
raise NotImplementedError()
133-
134-
# Database control
135-
def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
136-
raise NotImplementedError()

testgres/operations/remote_ops.py

-20
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@
66
import io
77
import logging
88

9-
# we support both pg8000 and psycopg2
10-
try:
11-
import psycopg2 as pglib
12-
except ImportError:
13-
try:
14-
import pg8000 as pglib
15-
except ImportError:
16-
raise ImportError("You must have psycopg2 or pg8000 modules installed")
17-
189
from ..exceptions import ExecUtilException
1910
from ..exceptions import InvalidOperationException
2011
from .os_ops import OsOperations, ConnectionParams, get_default_encoding
@@ -677,17 +668,6 @@ def _is_port_free__process_1(error: str) -> bool:
677668
#
678669
return True
679670

680-
# Database control
681-
def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
682-
conn = pglib.connect(
683-
host=host,
684-
port=port,
685-
database=dbname,
686-
user=user,
687-
password=password,
688-
)
689-
return conn
690-
691671
@staticmethod
692672
def _make_exec_env_list() -> list[str]:
693673
result = list[str]()

0 commit comments

Comments
 (0)