Skip to content

Commit 2a64ba5

Browse files
committed
various improvements, change args of query performing functions
* changed args of psql(), safe_psql(), execute(), poll_query_until() * introduced positional_args_hack() decorator for API functions * replaced inline config names with constants in consts.py * introduced default_dbname(), changed default_username()
1 parent 370c934 commit 2a64ba5

File tree

8 files changed

+279
-120
lines changed

8 files changed

+279
-120
lines changed

Diff for: .gitignore

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
*.pyc
2-
dist
3-
tags
4-
*.egg-info/
52
*.egg
6-
Dockerfile
7-
.coverage
3+
*.egg-info/
4+
dist
5+
86
env/
97
venv/
108
build/
9+
10+
.coverage
1111
coverage.xml
12+
13+
Dockerfile
14+
15+
*~
1216
*.swp
17+
tags

Diff for: testgres/backup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from .consts import \
1010
DATA_DIR as _DATA_DIR, \
11+
PG_CONF_FILE as _PG_CONF_FILE, \
1112
BACKUP_LOG_FILE as _BACKUP_LOG_FILE, \
1213
DEFAULT_XLOG_METHOD as _DEFAULT_XLOG_METHOD
1314

@@ -139,8 +140,8 @@ def spawn_primary(self, name=None, destroy=True, use_logging=False):
139140
# New nodes should always remove dir tree
140141
node._should_rm_dirs = True
141142

142-
node.append_conf("postgresql.conf", "\n")
143-
node.append_conf("postgresql.conf", "port = {}".format(node.port))
143+
node.append_conf(_PG_CONF_FILE, "\n")
144+
node.append_conf(_PG_CONF_FILE, "port = {}".format(node.port))
144145

145146
return node
146147

Diff for: testgres/connection.py

+27-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
from enum import Enum
1313

1414
from .exceptions import QueryException
15-
from .utils import default_username as _default_username
15+
16+
from .utils import \
17+
default_dbname as _default_dbname, \
18+
default_username as _default_username
19+
1620

1721
# export these exceptions
1822
InternalError = pglib.InternalError
@@ -33,25 +37,37 @@ class NodeConnection(object):
3337
"""
3438

3539
def __init__(self,
36-
parent_node,
37-
dbname,
38-
host="127.0.0.1",
40+
node,
41+
dbname=None,
3942
username=None,
4043
password=None):
4144

4245
# Use default user if not specified
46+
dbname = dbname or _default_dbname()
4347
username = username or _default_username()
4448

45-
self.parent_node = parent_node
49+
self._node = node
4650

47-
self.connection = pglib.connect(
51+
self._connection = pglib.connect(
4852
database=dbname,
4953
user=username,
50-
port=parent_node.port,
51-
host=host,
52-
password=password)
54+
password=password,
55+
host=node.host,
56+
port=node.port)
57+
58+
self._cursor = self.connection.cursor()
59+
60+
@property
61+
def node(self):
62+
return self._node
63+
64+
@property
65+
def connection(self):
66+
return self._connection
5367

54-
self.cursor = self.connection.cursor()
68+
@property
69+
def cursor(self):
70+
return self._cursor
5571

5672
def __enter__(self):
5773
return self
@@ -73,7 +89,7 @@ def begin(self, isolation_level=IsolationLevel.ReadCommitted):
7389

7490
# Get index of isolation level
7591
level_idx = isolation_level.value
76-
assert(level_idx in range(4))
92+
assert level_idx in range(4)
7793

7894
# Replace isolation level with its name
7995
isolation_level = levels[level_idx]

Diff for: testgres/consts.py

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
DATA_DIR = "data"
55
LOGS_DIR = "logs"
66

7+
RECOVERY_CONF_FILE = "recovery.conf"
8+
PG_CONF_FILE = "postgresql.conf"
9+
HBA_CONF_FILE = "pg_hba.conf"
10+
711
# names for log files
812
PG_LOG_FILE = "postgresql.log"
913
UTILS_LOG_FILE = "utils.log"

Diff for: testgres/logger.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class TestgresLogger(threading.Thread):
1010
"""
11-
Helper class to implement reading from postgresql.log
11+
Helper class to implement reading from log files.
1212
"""
1313

1414
def __init__(self, node_name, log_file_name):

0 commit comments

Comments
 (0)