Skip to content

Commit 60e78cd

Browse files
committed
test: pin what the sync test mirror leaves out and keeps
1 parent 47d0a5b commit 60e78cd

4 files changed

Lines changed: 130 additions & 2 deletions

File tree

‎.agents/project.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
- `CHANGELOG.md`: release-please writes the `## [x.y.z](…)` sections; never edit them. A user-visible change adds a hand-written section `## x.y.z — <one-line headline>` at the top of the entries, in the same pull request, with `x.y.z` the version it will ship in (#87, #89, #94). release-please then puts its own section above it. CONTRIBUTING.md and the pull request template say the same; the file has not used an `[Unreleased]` heading since 1.3.0.
3333
- The version lives in `pg_partsmith/__version__.py`, on the line marked `# x-release-please-version`, and in `.release-please-manifest.json`; release-please bumps both. Never change them by hand. To force a version, add a `Release-As: x.y.z` footer to a commit.
34-
- `pg_partsmith/sync/` is generated from `pg_partsmith/aio/` by `scripts/sync_mirror.py`. The exceptions are maintained by hand: the lock managers, `maintainer.py`, `command_hooks.py`, `python_hooks.py` and `repositories/{resolver,fk_manager,timeouts,pin}.py`. `tests/integration/sync/` is generated from `tests/integration/aio/` by `scripts/sync_tests_mirror.py`, except `test_concurrency.py`. Edit the aio side, regenerate, run `ruff check --fix` and `ruff format` on the output, then review the diff (CONTRIBUTING.md, "Keeping aio and sync in sync"). CI does not check the mirror.
34+
- `pg_partsmith/sync/` is generated from `pg_partsmith/aio/` by `scripts/sync_mirror.py`. The exceptions are maintained by hand: the lock managers, `maintainer.py`, `command_hooks.py`, `python_hooks.py` and `repositories/{resolver,fk_manager,timeouts,pin}.py`. `tests/integration/sync/` is generated from `tests/integration/aio/` by `scripts/sync_tests_mirror.py`, except `test_concurrency.py`, and `test_cli.py` has no sync twin (the CLI runs the aio service itself). Edit the aio side, regenerate, run `ruff check --fix` and `ruff format` on the output, then review the diff (CONTRIBUTING.md, "Keeping aio and sync in sync"). CI does not check the mirror.
3535
- `docs/agents.md` is part of the public API: it changes in the same pull request as the API (CONTRIBUTING.md, "The agents page").
3636
- `docs/changelog.md` is a copy of `CHANGELOG.md` made by the docs build, and git ignores it.
3737
- Files from the engineering-assets hub (`AGENTS.md` explains how it works): the copy-page files (`docs/assets/javascripts/copy-page.js`, `docs/assets/stylesheets/copy-page.css`, `overrides/main.html`, `scripts/emit_markdown.py`), `.github/workflows/docs.yml`, `.github/workflows/release-please.yml`, `.editorconfig` and `CODE_OF_CONDUCT.md`. Change them in the hub; a change here makes the file this repository's own. `.github/dependabot.yml` already belongs to this repository: it adds the `docker` ecosystem for the Dockerfile's base images.

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ uv run ruff check --fix tests/integration/sync && uv run ruff format tests/integ
170170
A test that drives two coroutines at once cannot be mirrored mechanically: put a
171171
`# sync-mirror: skip` line right above it and write its thread-based twin in
172172
`tests/integration/sync/test_concurrency.py`, the one hand-written module of that suite.
173+
`tests/integration/aio/test_cli.py` has no sync twin: the CLI runs the aio service itself.
173174
`tests/unit/sync/` mirrors `tests/unit/` by hand — only the modules touching the aio package
174175
have a sync twin.
175176

‎scripts/sync_tests_mirror.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _without_skipped(lines: list[str]) -> list[str]:
130130

131131

132132
def _without_empty_sections(lines: list[str]) -> list[str]:
133-
"""Drop a section heading, with the comment under it, when every test of its section was skipped."""
133+
"""Drop a section heading, and the comments under it, when no code is left in its section."""
134134
kept: list[str] = []
135135
i = 0
136136
while i < len(lines):
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
"""The generator of the sync integration suite: what it leaves out and what it must keep.
2+
3+
CI does not compare the sync suite with the aio one, so a test the generator
4+
drops by mistake just stops running, with nothing to say so.
5+
"""
6+
7+
from __future__ import annotations
8+
9+
from typing import TYPE_CHECKING
10+
11+
import pytest
12+
13+
from scripts import sync_tests_mirror
14+
from scripts.sync_tests_mirror import transform
15+
16+
if TYPE_CHECKING:
17+
from pathlib import Path
18+
19+
pytestmark = pytest.mark.unit
20+
21+
22+
def test__transform__a_skipped_class__keeps_the_heading_and_the_test_after_it() -> None:
23+
# Arrange
24+
source = """\
25+
# sync-mirror: skip
26+
class _Writer:
27+
async def write(self) -> None:
28+
await self.conn.execute(self.sql)
29+
30+
31+
# ── partition_data ──────────────────────────────────────────────────────────────
32+
33+
34+
async def test__drains(db_engine: AsyncEngine) -> None:
35+
assert await count(db_engine) == 0
36+
"""
37+
38+
expected = """\
39+
# ── partition_data ──────────────────────────────────────────────────────────────
40+
41+
42+
def test__drains(sync_db_engine: Engine) -> None:
43+
assert count(sync_db_engine) == 0
44+
"""
45+
46+
# Act
47+
mirrored = transform(source)
48+
49+
# Assert
50+
assert mirrored == expected
51+
52+
53+
def test__transform__a_skipped_decorated_test__keeps_the_test_after_it() -> None:
54+
# Arrange
55+
source = """\
56+
# sync-mirror: skip
57+
@pytest.mark.parametrize("n", [1, 2])
58+
async def test__races(db_engine: AsyncEngine, n: int) -> None:
59+
await asyncio.gather(work(db_engine), work(db_engine))
60+
61+
62+
async def test__plain(db_engine: AsyncEngine) -> None:
63+
assert await count(db_engine) == 0
64+
"""
65+
66+
expected = """\
67+
def test__plain(sync_db_engine: Engine) -> None:
68+
assert count(sync_db_engine) == 0
69+
"""
70+
71+
# Act
72+
mirrored = transform(source)
73+
74+
# Assert
75+
assert mirrored == expected
76+
77+
78+
def test__transform__a_section_whose_tests_are_all_skipped__loses_its_heading_and_comment() -> None:
79+
# Arrange
80+
source = """\
81+
# ── under a live writer ─────────────────────────────────────────────────────────
82+
#
83+
# Why these tests need two coroutines at once.
84+
85+
86+
# sync-mirror: skip
87+
async def test__races(db_engine: AsyncEngine) -> None:
88+
await asyncio.gather(work(db_engine), work(db_engine))
89+
90+
91+
# ── retry ───────────────────────────────────────────────────────────────────────
92+
93+
94+
async def test__retries(db_engine: AsyncEngine) -> None:
95+
assert await count(db_engine) == 0
96+
"""
97+
98+
expected = """\
99+
# ── retry ───────────────────────────────────────────────────────────────────────
100+
101+
102+
def test__retries(sync_db_engine: Engine) -> None:
103+
assert count(sync_db_engine) == 0
104+
"""
105+
106+
# Act
107+
mirrored = transform(source)
108+
109+
# Assert
110+
assert mirrored == expected
111+
112+
113+
def test__main__the_cli_module__gets_no_sync_twin(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
114+
# Arrange
115+
aio, sync = tmp_path / "aio", tmp_path / "sync"
116+
aio.mkdir()
117+
(aio / "test_cli.py").write_text("async def test__cli() -> None:\n pass\n", encoding="utf-8")
118+
(aio / "test_plan.py").write_text("async def test__plan() -> None:\n pass\n", encoding="utf-8")
119+
monkeypatch.setattr(sync_tests_mirror, "ROOT", tmp_path)
120+
monkeypatch.setattr(sync_tests_mirror, "AIO", aio)
121+
monkeypatch.setattr(sync_tests_mirror, "SYNC", sync)
122+
123+
# Act
124+
sync_tests_mirror.main()
125+
126+
# Assert
127+
assert sorted(path.name for path in sync.iterdir()) == ["test_plan.py"]

0 commit comments

Comments
 (0)