Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for \ character in pytest temporary path - Closes #982 #985

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading