Skip to content

Commit 3cb6110

Browse files
authored
Have tests respect PG_CONFIG (#453)
When running tests locally I often switch between different PG installations (@ different versions). In order to do so, I rely on the `PG_CONFIG` environment variable. This PR makes it so that tests are first reading PG's `bindir` from `pg_config` (using explicit path provided with `PG_CONFIG` variable if it exists.
1 parent c3e80d8 commit 3cb6110

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

Diff for: test/pycheck/utils.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,17 @@ def get_pg_major_version():
119119
return int(major_version_string.group(0))
120120

121121

122+
def get_bin_dir():
123+
pg_config_bin = (
124+
os.environ["PG_CONFIG"] if "PG_CONFIG" in os.environ else "pg_config"
125+
)
126+
return capture([pg_config_bin, "--bindir"], silent=True).strip()
127+
128+
122129
PG_MAJOR_VERSION = get_pg_major_version()
123130

131+
PG_BIN_DIR = get_bin_dir()
132+
124133
# this is out of ephemeral port range for many systems hence
125134
# it is a lower change that it will conflict with "in-use" ports
126135
PORT_LOWER_BOUND = 10200
@@ -131,6 +140,10 @@ def get_pg_major_version():
131140
next_port = PORT_LOWER_BOUND
132141

133142

143+
def pg_bin(b):
144+
return os.path.join(PG_BIN_DIR, b)
145+
146+
134147
class NoResultClass:
135148
def __eq__(self, other):
136149
return self is other
@@ -393,7 +406,15 @@ def psql(self, query, **kwargs):
393406
self.set_default_connection_options(kwargs)
394407
connect_options = " ".join([f"{k}={v}" for k, v in kwargs.items()])
395408

396-
run(["psql", f"port={self.port} {connect_options}", "-c", query], shell=False)
409+
run(
410+
[
411+
pg_bin("psql"),
412+
f"port={self.port} {connect_options}",
413+
"-c",
414+
query,
415+
],
416+
shell=False,
417+
)
397418

398419
@contextmanager
399420
def transaction(self, **kwargs):
@@ -541,13 +562,14 @@ def debug(self):
541562
def psql_debug(self, **kwargs):
542563
conninfo = self.make_conninfo(**kwargs)
543564
run(
544-
["psql", conninfo],
565+
[pg_bin("psql"), conninfo],
545566
silent=True,
546567
)
547568

548569
def initdb(self):
570+
initdb = pg_bin("initdb")
549571
run(
550-
f"initdb -A trust --nosync --username postgres --pgdata {self.pgdata}",
572+
f"'{initdb}' -A trust --nosync --username postgres --pgdata {self.pgdata}",
551573
stdout=subprocess.DEVNULL,
552574
)
553575

@@ -595,11 +617,17 @@ def initdb(self):
595617
pgconf.write("duckdb.force_execution = 'true'\n")
596618

597619
def pgctl(self, command, **kwargs):
598-
run(f"pg_ctl -w --pgdata {self.pgdata} {command}", **kwargs)
620+
pg_ctl = pg_bin("pg_ctl")
621+
run(
622+
f"'{pg_ctl}' -w --pgdata {self.pgdata} {command}",
623+
**kwargs,
624+
)
599625

600626
def apgctl(self, command, **kwargs):
627+
pg_ctl = pg_bin("pg_ctl")
601628
return asyncio.create_subprocess_shell(
602-
f"pg_ctl -w --pgdata {self.pgdata} {command}", **kwargs
629+
f"'{pg_ctl}' -w --pgdata {self.pgdata} {command}",
630+
**kwargs,
603631
)
604632

605633
def start(self):

0 commit comments

Comments
 (0)