Skip to content

Commit

Permalink
add support for \ character in pytest temporary path - Closes #982
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelgs committed Jul 18, 2024
1 parent 366744f commit 9681a5a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 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 @@ -214,13 +214,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
8 changes: 7 additions & 1 deletion pytest_postgresql/factories/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with pytest-postgresql. If not, see <http://www.gnu.org/licenses/>.
"""Fixture factory for postgresql process."""

import os.path
import platform
import subprocess
Expand All @@ -32,6 +33,11 @@
from pytest_postgresql.janitor import DatabaseJanitor


def _tmp_dir(tmp_path_factory: TempPathFactory, subdir: str) -> Path:
"""Mock out for testing a specific temporary path."""
return tmp_path_factory.mktemp(subdir)


def postgresql_proc(
executable: Optional[str] = None,
host: Optional[str] = None,
Expand Down Expand Up @@ -107,7 +113,7 @@ def postgresql_proc_fixture(
) from ex
postgresql_ctl = os.path.join(pg_bindir, "pg_ctl")

tmpdir = tmp_path_factory.mktemp(f"pytest-postgresql-{request.fixturename}")
tmpdir = _tmp_dir(tmp_path_factory, f"pytest-postgresql-{request.fixturename}")

pg_port = get_port(port) or get_port(config["port"])
assert pg_port is not None
Expand Down
3 changes: 1 addition & 2 deletions tests/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ def test_postgresql_proc(postgresql_proc: PostgreSQLExecutor) -> None:
assert postgresql_proc.running() is True


@pytest.mark.xfail(reason="issue tracked by #982")
def test_postgresql_proc__bad_tmp(postgresql_proc: PostgreSQLExecutor) -> None:
"""Test different postgresql versions."""
r"""Test a \ character in the pytest temporary path."""

def bad_path(tmp_path_factory: TempPathFactory, subdir: str) -> Path:
return tmp_path_factory.mktemp(rf"bad\path/{subdir}")
Expand Down

0 comments on commit 9681a5a

Please sign in to comment.