Skip to content

Commit

Permalink
test for \ in tmp path (ClearcodeHQ#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelgs committed Jul 22, 2024
1 parent b87fdc3 commit 1dd8104
Showing 1 changed file with 54 additions and 18 deletions.
72 changes: 54 additions & 18 deletions tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@
from pytest_postgresql.retry import retry


def assert_executor_start_stop(executor):
"""Check that the executor is working."""
with executor:
assert executor.running()
psycopg.connect(
dbname=executor.user,
user=executor.user,
password=executor.password,
host=executor.host,
port=executor.port,
)
with pytest.raises(psycopg.OperationalError):
psycopg.connect(
dbname=executor.user,
user=executor.user,
password="bogus",
host=executor.host,
port=executor.port,
)
assert not executor.running()


class PatchedPostgreSQLExecutor(PostgreSQLExecutor):
"""PostgreSQLExecutor that always says it's 8.9 version."""

Expand Down Expand Up @@ -76,24 +98,38 @@ def test_executor_init_with_password(
password="somepassword",
dbname="somedatabase",
)
with executor:
assert executor.running()
psycopg.connect(
dbname=executor.user,
user=executor.user,
password=executor.password,
host=executor.host,
port=executor.port,
)
with pytest.raises(psycopg.OperationalError):
psycopg.connect(
dbname=executor.user,
user=executor.user,
password="bogus",
host=executor.host,
port=executor.port,
)
assert not executor.running()
assert_executor_start_stop(executor)


@pytest.mark.xfail(reason="issue tracked by #982")
@pytest.mark.skipif(
sys.platform == "darwin", reason="The default pg_ctl path is for linux, not macos"
)
def test_executor_init_bad_tmp_path(
request: FixtureRequest,
tmp_path_factory: pytest.TempPathFactory,
) -> None:
r"""Test init when \ char is in tmp path."""
config = get_config(request)
port = get_port(config["port"])
assert port is not None
tmpdir = tmp_path_factory.mktemp(f"pytest-postgresql-{request.node.name}") / r"bad\path/"
tmpdir.mkdir()
datadir = tmpdir / f"data-{port}"
datadir.mkdir()
logfile_path = tmpdir / f"postgresql.{port}.log"
executor = PostgreSQLExecutor(
executable=config["exec"],
host=config["host"],
port=port,
datadir=str(datadir),
unixsocketdir=config["unixsocketdir"],
logfile=str(logfile_path),
startparams=config["startparams"],
password="somepassword",
dbname="somedatabase",
)
assert_executor_start_stop(executor)


postgres_with_password = postgresql_proc(password="hunter2")
Expand Down

0 comments on commit 1dd8104

Please sign in to comment.