pytest-postgresql 6.0.0__tar.gz → 6.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/CHANGES.rst +32 -0
  2. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/PKG-INFO +2 -2
  3. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pyproject.toml +3 -3
  4. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/__init__.py +1 -1
  5. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/executor.py +8 -6
  6. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/factories/__init__.py +2 -2
  7. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/factories/process.py +47 -40
  8. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql.egg-info/PKG-INFO +2 -2
  9. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/tests/test_executor.py +54 -29
  10. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/AUTHORS.rst +0 -0
  11. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/CONTRIBUTING.rst +0 -0
  12. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/COPYING +0 -0
  13. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/COPYING.lesser +0 -0
  14. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/MANIFEST.in +0 -0
  15. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/README.rst +0 -0
  16. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/config.py +0 -0
  17. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/exceptions.py +0 -0
  18. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/executor_noop.py +0 -0
  19. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/factories/client.py +0 -0
  20. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/factories/noprocess.py +0 -0
  21. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/janitor.py +0 -0
  22. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/loader.py +0 -0
  23. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/plugin.py +0 -0
  24. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/py.typed +0 -0
  25. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql/retry.py +0 -0
  26. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql.egg-info/SOURCES.txt +0 -0
  27. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql.egg-info/dependency_links.txt +0 -0
  28. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql.egg-info/entry_points.txt +0 -0
  29. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql.egg-info/requires.txt +0 -0
  30. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql.egg-info/top_level.txt +0 -0
  31. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/pytest_postgresql.egg-info/zip-safe +0 -0
  32. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/setup.cfg +0 -0
  33. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/tests/test_janitor.py +0 -0
  34. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/tests/test_loader.py +0 -0
  35. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/tests/test_noopexecutor.py +0 -0
  36. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/tests/test_postgres_options_plugin.py +0 -0
  37. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/tests/test_postgresql.py +0 -0
  38. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/tests/test_template_database.py +0 -0
  39. {pytest-postgresql-6.0.0 → pytest_postgresql-6.1.0}/tests/test_version.py +0 -0
@@ -3,6 +3,38 @@ CHANGELOG
3
3
 
4
4
  .. towncrier release notes start
5
5
 
6
+ 6.1.0 (2024-09-04)
7
+ ==================
8
+
9
+ Features
10
+ --------
11
+
12
+ - add support for \\ character in pytest temporary path (`#982 <https://github.com/ClearcodeHQ/pytest-postgresql/issues/982>`__)
13
+
14
+
15
+ Miscellaneus
16
+ ------------
17
+
18
+ - Add test for `PR #965 <https://github.com/ClearcodeHQ/pytest-postgresql/pull/965>`_
19
+ - refactors test_executor.py to enable Mac
20
+
21
+
22
+ 6.0.1 (2024-08-14)
23
+ ==================
24
+
25
+ Bugfixes
26
+ --------
27
+
28
+ - Fixed a long-standing bug, where calls to pg_ctl weren't getting `LC_*` and `LANG` envvars,
29
+ which caused issues on some systems not recognizing --auth parameter. (`#343 <https://github.com/ClearcodeHQ/pytest-postgresql/issues/343>`__)
30
+
31
+
32
+ Miscellaneus
33
+ ------------
34
+
35
+ - `#945 <https://github.com/ClearcodeHQ/pytest-postgresql/issues/945>`__
36
+
37
+
6
38
  6.0.0 (2024-03-11)
7
39
  ==================
8
40
 
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytest-postgresql
3
- Version: 6.0.0
3
+ Version: 6.1.0
4
4
  Summary: Postgresql fixtures and fixture factories for Pytest.
5
5
  Author-email: Grzegorz Śliwiński <fizyk+pypi@fizyk.dev>
6
6
  Project-URL: Source, https://github.com/ClearcodeHQ/pytest-postgresql
7
7
  Project-URL: Bug Tracker, https://github.com/ClearcodeHQ/pytest-postgresql/issues
8
- Project-URL: Changelog, https://github.com/ClearcodeHQ/pytest-postgresql/blob/v6.0.0/CHANGES.rst
8
+ Project-URL: Changelog, https://github.com/ClearcodeHQ/pytest-postgresql/blob/v6.1.0/CHANGES.rst
9
9
  Keywords: tests,pytest,fixture,postgresql
10
10
  Classifier: Development Status :: 5 - Production/Stable
11
11
  Classifier: Environment :: Web Environment
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pytest-postgresql"
3
- version = "6.0.0"
3
+ version = "6.1.0"
4
4
  description = "Postgresql fixtures and fixture factories for Pytest."
5
5
  readme = "README.rst"
6
6
  keywords = ["tests", "pytest", "fixture", "postgresql"]
@@ -39,7 +39,7 @@ requires-python = ">= 3.8"
39
39
  [project.urls]
40
40
  "Source" = "https://github.com/ClearcodeHQ/pytest-postgresql"
41
41
  "Bug Tracker" = "https://github.com/ClearcodeHQ/pytest-postgresql/issues"
42
- "Changelog" = "https://github.com/ClearcodeHQ/pytest-postgresql/blob/v6.0.0/CHANGES.rst"
42
+ "Changelog" = "https://github.com/ClearcodeHQ/pytest-postgresql/blob/v6.1.0/CHANGES.rst"
43
43
 
44
44
  [project.entry-points."pytest11"]
45
45
  pytest_postgresql = "pytest_postgresql.plugin"
@@ -108,7 +108,7 @@ name = "Miscellaneus"
108
108
  showcontent = false
109
109
 
110
110
  [tool.tbump.version]
111
- current = "6.0.0"
111
+ current = "6.1.0"
112
112
 
113
113
  # Example of a semver regexp.
114
114
  # Make sure this matches current_version before
@@ -18,4 +18,4 @@
18
18
  # along with pytest-postgresql. If not, see <http://www.gnu.org/licenses/>.
19
19
  """Main module for pytest-postgresql."""
20
20
 
21
- __version__ = "6.0.0"
21
+ __version__ = "6.1.0"
@@ -49,11 +49,11 @@ class PostgreSQLExecutor(TCPExecutor):
49
49
  """
50
50
 
51
51
  BASE_PROC_START_COMMAND = (
52
- "{executable} start -D {datadir} "
52
+ '{executable} start -D "{datadir}" '
53
53
  "-o \"-F -p {port} -c log_destination='stderr' "
54
54
  "-c logging_collector=off "
55
55
  "-c unix_socket_directories='{unixsocketdir}' {postgres_options}\" "
56
- "-l {logfile} {startparams}"
56
+ '-l "{logfile}" {startparams}'
57
57
  )
58
58
 
59
59
  VERSION_RE = re.compile(r".* (?P<version>\d+(?:\.\d+)?)")
@@ -177,11 +177,13 @@ class PostgreSQLExecutor(TCPExecutor):
177
177
  password_file.write(password)
178
178
  password_file.flush()
179
179
  init_directory += ["-o", " ".join(options)]
180
- subprocess.check_output(init_directory)
180
+ # Passing envvars to command to avoid weird MacOs error.
181
+ subprocess.check_output(init_directory, env=self._envvars)
181
182
  else:
182
183
  options += ["--auth=trust"]
183
184
  init_directory += ["-o", " ".join(options)]
184
- subprocess.check_output(init_directory)
185
+ # Passing envvars to command to avoid weird MacOs error.
186
+ subprocess.check_output(init_directory, env=self._envvars)
185
187
 
186
188
  self._directory_initialised = True
187
189
 
@@ -214,13 +216,13 @@ class PostgreSQLExecutor(TCPExecutor):
214
216
  """Check if server is running."""
215
217
  if not os.path.exists(self.datadir):
216
218
  return False
217
- status_code = subprocess.getstatusoutput(f"{self.executable} status -D {self.datadir}")[0]
219
+ status_code = subprocess.getstatusoutput(f'{self.executable} status -D "{self.datadir}"')[0]
218
220
  return status_code == 0
219
221
 
220
222
  def stop(self: T, sig: Optional[int] = None, exp_sig: Optional[int] = None) -> T:
221
223
  """Issue a stop request to executable."""
222
224
  subprocess.check_output(
223
- f"{self.executable} stop -D {self.datadir} -m f",
225
+ f'{self.executable} stop -D "{self.datadir}" -m f',
224
226
  shell=True,
225
227
  )
226
228
  try:
@@ -19,6 +19,6 @@
19
19
 
20
20
  from pytest_postgresql.factories.client import postgresql
21
21
  from pytest_postgresql.factories.noprocess import postgresql_noproc
22
- from pytest_postgresql.factories.process import postgresql_proc
22
+ from pytest_postgresql.factories.process import PortType, postgresql_proc
23
23
 
24
- __all__ = ("postgresql_proc", "postgresql_noproc", "postgresql")
24
+ __all__ = ("postgresql_proc", "postgresql_noproc", "postgresql", "PortType")
@@ -16,38 +16,67 @@
16
16
  # You should have received a copy of the GNU Lesser General Public License
17
17
  # along with pytest-postgresql. If not, see <http://www.gnu.org/licenses/>.
18
18
  """Fixture factory for postgresql process."""
19
+
19
20
  import os.path
20
21
  import platform
21
22
  import subprocess
22
23
  from pathlib import Path
23
- from typing import Callable, Iterator, List, Optional, Set, Tuple, Union
24
+ from typing import Callable, Iterator, List, Optional, Tuple, Union
24
25
 
26
+ import port_for
25
27
  import pytest
26
28
  from port_for import get_port
27
29
  from pytest import FixtureRequest, TempPathFactory
28
30
 
29
- from pytest_postgresql.config import get_config
31
+ from pytest_postgresql.config import PostgresqlConfigDict, get_config
30
32
  from pytest_postgresql.exceptions import ExecutableMissingException
31
33
  from pytest_postgresql.executor import PostgreSQLExecutor
32
34
  from pytest_postgresql.janitor import DatabaseJanitor
33
35
 
36
+ PortType = port_for.PortType # mypy requires explicit export
37
+
38
+
39
+ def _pg_exe(executable: Optional[str], config: PostgresqlConfigDict) -> str:
40
+ """If executable is set, use it. Otherwise best effort to find the executable."""
41
+ postgresql_ctl = executable or config["exec"]
42
+ # check if that executable exists, as it's no on system PATH
43
+ # only replace if executable isn't passed manually
44
+ if not os.path.exists(postgresql_ctl) and executable is None:
45
+ try:
46
+ pg_bindir = subprocess.check_output(
47
+ ["pg_config", "--bindir"], universal_newlines=True
48
+ ).strip()
49
+ except FileNotFoundError as ex:
50
+ raise ExecutableMissingException(
51
+ "Could not found pg_config executable. Is it in systenm $PATH?"
52
+ ) from ex
53
+ postgresql_ctl = os.path.join(pg_bindir, "pg_ctl")
54
+ return postgresql_ctl
55
+
56
+
57
+ def _pg_port(port: Optional[PortType], config: PostgresqlConfigDict) -> int:
58
+ """User specified port, otherwise find an unused port from config."""
59
+ pg_port = get_port(port) or get_port(config["port"])
60
+ assert pg_port is not None
61
+ return pg_port
62
+
63
+
64
+ def _prepare_dir(tmpdir: Path, pg_port: PortType) -> Tuple[Path, Path]:
65
+ """Prepare directory for the executor."""
66
+ datadir = tmpdir / f"data-{pg_port}"
67
+ datadir.mkdir()
68
+ logfile_path = tmpdir / f"postgresql.{pg_port}.log"
69
+
70
+ if platform.system() == "FreeBSD":
71
+ with (datadir / "pg_hba.conf").open(mode="a") as conf_file:
72
+ conf_file.write("host all all 0.0.0.0/0 trust\n")
73
+ return datadir, logfile_path
74
+
34
75
 
35
76
  def postgresql_proc(
36
77
  executable: Optional[str] = None,
37
78
  host: Optional[str] = None,
38
- port: Union[
39
- None,
40
- str,
41
- int,
42
- Tuple[int, int],
43
- Set[int],
44
- List[str],
45
- List[int],
46
- List[Tuple[int, int]],
47
- List[Set[int]],
48
- List[Union[Set[int], Tuple[int, int]]],
49
- List[Union[str, int, Tuple[int, int], Set[int]]],
50
- ] = -1,
79
+ port: Optional[PortType] = -1,
51
80
  user: Optional[str] = None,
52
81
  password: Optional[str] = None,
53
82
  dbname: Optional[str] = None,
@@ -90,34 +119,12 @@ def postgresql_proc(
90
119
  :returns: tcp executor
91
120
  """
92
121
  config = get_config(request)
93
- postgresql_ctl = executable or config["exec"]
94
122
  pg_dbname = dbname or config["dbname"]
95
123
  pg_load = load or config["load"]
96
-
97
- # check if that executable exists, as it's no on system PATH
98
- # only replace if executable isn't passed manually
99
- if not os.path.exists(postgresql_ctl) and executable is None:
100
- try:
101
- pg_bindir = subprocess.check_output(
102
- ["pg_config", "--bindir"], universal_newlines=True
103
- ).strip()
104
- except FileNotFoundError as ex:
105
- raise ExecutableMissingException(
106
- "Could not found pg_config executable. Is it in systenm $PATH?"
107
- ) from ex
108
- postgresql_ctl = os.path.join(pg_bindir, "pg_ctl")
109
-
124
+ postgresql_ctl = _pg_exe(executable, config)
125
+ pg_port = _pg_port(port, config)
110
126
  tmpdir = tmp_path_factory.mktemp(f"pytest-postgresql-{request.fixturename}")
111
-
112
- pg_port = get_port(port) or get_port(config["port"])
113
- assert pg_port is not None
114
- datadir = tmpdir / f"data-{pg_port}"
115
- datadir.mkdir()
116
- logfile_path = tmpdir / f"postgresql.{pg_port}.log"
117
-
118
- if platform.system() == "FreeBSD":
119
- with (datadir / "pg_hba.conf").open(mode="a") as conf_file:
120
- conf_file.write("host all all 0.0.0.0/0 trust\n")
127
+ datadir, logfile_path = _prepare_dir(tmpdir, str(pg_port))
121
128
 
122
129
  postgresql_executor = PostgreSQLExecutor(
123
130
  executable=postgresql_ctl,
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytest-postgresql
3
- Version: 6.0.0
3
+ Version: 6.1.0
4
4
  Summary: Postgresql fixtures and fixture factories for Pytest.
5
5
  Author-email: Grzegorz Śliwiński <fizyk+pypi@fizyk.dev>
6
6
  Project-URL: Source, https://github.com/ClearcodeHQ/pytest-postgresql
7
7
  Project-URL: Bug Tracker, https://github.com/ClearcodeHQ/pytest-postgresql/issues
8
- Project-URL: Changelog, https://github.com/ClearcodeHQ/pytest-postgresql/blob/v6.0.0/CHANGES.rst
8
+ Project-URL: Changelog, https://github.com/ClearcodeHQ/pytest-postgresql/blob/v6.1.0/CHANGES.rst
9
9
  Keywords: tests,pytest,fixture,postgresql
10
10
  Classifier: Development Status :: 5 - Production/Stable
11
11
  Classifier: Environment :: Web Environment
@@ -1,6 +1,5 @@
1
1
  """Test various executor behaviours."""
2
2
 
3
- import sys
4
3
  from typing import Any
5
4
 
6
5
  import psycopg
@@ -10,6 +9,7 @@ from port_for import get_port
10
9
  from psycopg import Connection
11
10
  from pytest import FixtureRequest
12
11
 
12
+ import pytest_postgresql.factories.process as process
13
13
  from pytest_postgresql.config import get_config
14
14
  from pytest_postgresql.exceptions import PostgreSQLUnsupported
15
15
  from pytest_postgresql.executor import PostgreSQLExecutor
@@ -17,6 +17,28 @@ from pytest_postgresql.factories import postgresql, postgresql_proc
17
17
  from pytest_postgresql.retry import retry
18
18
 
19
19
 
20
+ def assert_executor_start_stop(executor: PostgreSQLExecutor) -> None:
21
+ """Check that the executor is working."""
22
+ with executor:
23
+ assert executor.running()
24
+ psycopg.connect(
25
+ dbname=executor.user,
26
+ user=executor.user,
27
+ password=executor.password,
28
+ host=executor.host,
29
+ port=executor.port,
30
+ )
31
+ with pytest.raises(psycopg.OperationalError):
32
+ psycopg.connect(
33
+ dbname=executor.user,
34
+ user=executor.user,
35
+ password="bogus",
36
+ host=executor.host,
37
+ port=executor.port,
38
+ )
39
+ assert not executor.running()
40
+
41
+
20
42
  class PatchedPostgreSQLExecutor(PostgreSQLExecutor):
21
43
  """PostgreSQLExecutor that always says it's 8.9 version."""
22
44
 
@@ -46,10 +68,7 @@ def test_unsupported_version(request: FixtureRequest) -> None:
46
68
  executor.start()
47
69
 
48
70
 
49
- @pytest.mark.skipif(
50
- sys.platform == "darwin", reason="The default pg_ctl path is for linux, not macos"
51
- )
52
- @pytest.mark.parametrize("locale", ("en_US.UTF-8", "de_DE.UTF-8"))
71
+ @pytest.mark.parametrize("locale", ("en_US.UTF-8", "de_DE.UTF-8", "nl_NO.UTF-8"))
53
72
  def test_executor_init_with_password(
54
73
  request: FixtureRequest,
55
74
  monkeypatch: pytest.MonkeyPatch,
@@ -59,14 +78,12 @@ def test_executor_init_with_password(
59
78
  """Test whether the executor initializes properly."""
60
79
  config = get_config(request)
61
80
  monkeypatch.setenv("LC_ALL", locale)
62
- port = get_port(config["port"])
63
- assert port is not None
81
+ pg_exe = process._pg_exe(None, config)
82
+ port = process._pg_port(-1, config)
64
83
  tmpdir = tmp_path_factory.mktemp(f"pytest-postgresql-{request.node.name}")
65
- datadir = tmpdir / f"data-{port}"
66
- datadir.mkdir()
67
- logfile_path = tmpdir / f"postgresql.{port}.log"
84
+ datadir, logfile_path = process._prepare_dir(tmpdir, port)
68
85
  executor = PostgreSQLExecutor(
69
- executable=config["exec"],
86
+ executable=pg_exe,
70
87
  host=config["host"],
71
88
  port=port,
72
89
  datadir=str(datadir),
@@ -76,24 +93,32 @@ def test_executor_init_with_password(
76
93
  password="somepassword",
77
94
  dbname="somedatabase",
78
95
  )
79
- with executor:
80
- assert executor.running()
81
- psycopg.connect(
82
- dbname=executor.user,
83
- user=executor.user,
84
- password=executor.password,
85
- host=executor.host,
86
- port=executor.port,
87
- )
88
- with pytest.raises(psycopg.OperationalError):
89
- psycopg.connect(
90
- dbname=executor.user,
91
- user=executor.user,
92
- password="bogus",
93
- host=executor.host,
94
- port=executor.port,
95
- )
96
- assert not executor.running()
96
+ assert_executor_start_stop(executor)
97
+
98
+
99
+ def test_executor_init_bad_tmp_path(
100
+ request: FixtureRequest,
101
+ tmp_path_factory: pytest.TempPathFactory,
102
+ ) -> None:
103
+ r"""Test init with \ and space chars in the path."""
104
+ config = get_config(request)
105
+ pg_exe = process._pg_exe(None, config)
106
+ port = process._pg_port(-1, config)
107
+ tmpdir = tmp_path_factory.mktemp(f"pytest-postgresql-{request.node.name}") / r"a bad\path/"
108
+ tmpdir.mkdir(exist_ok=True)
109
+ datadir, logfile_path = process._prepare_dir(tmpdir, port)
110
+ executor = PostgreSQLExecutor(
111
+ executable=pg_exe,
112
+ host=config["host"],
113
+ port=port,
114
+ datadir=str(datadir),
115
+ unixsocketdir=config["unixsocketdir"],
116
+ logfile=str(logfile_path),
117
+ startparams=config["startparams"],
118
+ password="some password",
119
+ dbname="some database",
120
+ )
121
+ assert_executor_start_stop(executor)
97
122
 
98
123
 
99
124
  postgres_with_password = postgresql_proc(password="hunter2")