Skip to content

Commit

Permalink
Merge pull request #985 from bhelgs/bad_tmp_path
Browse files Browse the repository at this point in the history
add support for `\` character in pytest temporary path - Closes #982
  • Loading branch information
fizyk authored Sep 4, 2024
2 parents 4f21e9a + a24d7dc commit fa9432a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions newsfragments/982.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add support for \\ character in pytest temporary path
8 changes: 4 additions & 4 deletions pytest_postgresql/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class PostgreSQLExecutor(TCPExecutor):
"""

BASE_PROC_START_COMMAND = (
"{executable} start -D {datadir} "
'{executable} start -D "{datadir}" '
"-o \"-F -p {port} -c log_destination='stderr' "
"-c logging_collector=off "
"-c unix_socket_directories='{unixsocketdir}' {postgres_options}\" "
"-l {logfile} {startparams}"
'-l "{logfile}" {startparams}'
)

VERSION_RE = re.compile(r".* (?P<version>\d+(?:\.\d+)?)")
Expand Down Expand Up @@ -216,13 +216,13 @@ def running(self) -> bool:
"""Check if server is running."""
if not os.path.exists(self.datadir):
return False
status_code = subprocess.getstatusoutput(f"{self.executable} status -D {self.datadir}")[0]
status_code = subprocess.getstatusoutput(f'{self.executable} status -D "{self.datadir}"')[0]
return status_code == 0

def stop(self: T, sig: Optional[int] = None, exp_sig: Optional[int] = None) -> T:
"""Issue a stop request to executable."""
subprocess.check_output(
f"{self.executable} stop -D {self.datadir} -m f",
f'{self.executable} stop -D "{self.datadir}" -m f',
shell=True,
)
try:
Expand Down
25 changes: 25 additions & 0 deletions tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ def test_executor_init_with_password(
assert_executor_start_stop(executor)


def test_executor_init_bad_tmp_path(
request: FixtureRequest,
tmp_path_factory: pytest.TempPathFactory,
) -> None:
r"""Test init with \ and space chars in the path."""
config = get_config(request)
pg_exe = process._pg_exe(None, config)
port = process._pg_port(-1, config)
tmpdir = tmp_path_factory.mktemp(f"pytest-postgresql-{request.node.name}") / r"a bad\path/"
tmpdir.mkdir(exist_ok=True)
datadir, logfile_path = process._prepare_dir(tmpdir, port)
executor = PostgreSQLExecutor(
executable=pg_exe,
host=config["host"],
port=port,
datadir=str(datadir),
unixsocketdir=config["unixsocketdir"],
logfile=str(logfile_path),
startparams=config["startparams"],
password="some password",
dbname="some database",
)
assert_executor_start_stop(executor)


postgres_with_password = postgresql_proc(password="hunter2")


Expand Down

0 comments on commit fa9432a

Please sign in to comment.