Skip to content

Commit 47d0a5b

Browse files
committed
test: the sync test mirror no longer drops the test after a skipped class
A skip marker above a class sent _without_skipped into its decorator state, so it skipped the class and then the first test after it as well: regenerating lost test__partition_data__drains_default_into_monthly_partitions_in_batches from the sync suite. test_cli.py is left out of the mirror (the CLI runs the aio service on its own loop), and a section whose tests are all skipped loses its heading. Regenerating now brings in only the one assertion the sync suite had missed.
1 parent 80ed3f2 commit 47d0a5b

4 files changed

Lines changed: 34 additions & 18 deletions

File tree

‎scripts/sync_tests_mirror.py‎

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
concurrently, say) is marked in the aio suite with a ``# sync-mirror: skip``
1414
line right above it (above its decorators, if any) and is left out of the sync
1515
suite; its thread-based twin lives in ``tests/integration/sync/test_concurrency.py``,
16-
the one module of the sync suite that is written by hand. A module the aio
17-
suite no longer has is removed from the sync suite, that one excepted.
16+
the one module of the sync suite that is written by hand. ``test_cli.py`` has
17+
no sync twin: the CLI runs the aio service on an event loop of its own, so a
18+
mirror would run the same code again. A module the aio suite no longer has is
19+
removed from the sync suite, the hand-written one excepted.
1820
"""
1921

2022
from __future__ import annotations
@@ -28,9 +30,11 @@
2830
SYNC = ROOT / "tests" / "integration" / "sync"
2931

3032
HANDWRITTEN = frozenset({"test_concurrency.py"})
33+
AIO_ONLY = frozenset({"test_cli.py"})
3134
SKIP_MARKER = "# sync-mirror: skip"
32-
TOP_LEVEL = re.compile(r"^(async def |def |class |@|# ──)")
33-
DEFINITION = re.compile(r"^(async )?def ")
35+
SECTION = "# ──"
36+
TOP_LEVEL = re.compile(rf"^(async def |def |class |@|{SECTION})")
37+
DEFINITION = re.compile(r"^((async )?def |class )")
3438
FOR_LOOP = re.compile(r"^(?P<indent>\s*)for (?P<var>\w+) in (?P<rest>.*)$")
3539

3640
RULES: list[tuple[str, str]] = [
@@ -89,19 +93,18 @@
8993

9094
def transform(text: str) -> str:
9195
"""Turn one aio test module into its sync twin."""
92-
text = "\n".join(_without_skipped(text.split("\n")))
96+
text = "\n".join(_without_empty_sections(_without_skipped(text.split("\n"))))
9397
for pattern, repl in RULES:
9498
text = re.sub(pattern, repl, text)
9599
text = text.replace("import asyncio\n", "")
96100
return "\n".join(_yield_from(text.split("\n")))
97101

98102

99103
def _without_skipped(lines: list[str]) -> list[str]:
100-
"""Leave out every function under a ``# sync-mirror: skip`` line.
104+
"""Leave out every function or class under a ``# sync-mirror: skip`` line.
101105
102-
The marker sits right above the function -- above its decorators when it
103-
has any -- and the function ends at the next top-level definition,
104-
decorator or section heading.
106+
The marker sits right above it -- above its decorators when it has any --
107+
and it ends at the next top-level definition, decorator or section heading.
105108
"""
106109
kept: list[str] = []
107110
state = "keep"
@@ -126,6 +129,25 @@ def _without_skipped(lines: list[str]) -> list[str]:
126129
return kept
127130

128131

132+
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."""
134+
kept: list[str] = []
135+
i = 0
136+
while i < len(lines):
137+
if lines[i].startswith(SECTION):
138+
end = i + 1
139+
while end < len(lines) and (
140+
not lines[end].strip() or (lines[end].startswith("#") and not lines[end].startswith(SECTION))
141+
):
142+
end += 1
143+
if end == len(lines) or lines[end].startswith(SECTION):
144+
i = end
145+
continue
146+
kept.append(lines[i])
147+
i += 1
148+
return kept
149+
150+
129151
def _yield_from(lines: list[str]) -> list[str]:
130152
"""Spell ``for x in gen(...): yield x`` -- what an ``async for`` becomes -- as ``yield from``."""
131153
out: list[str] = []
@@ -160,6 +182,8 @@ def main() -> None:
160182
SYNC.mkdir(parents=True, exist_ok=True)
161183
generated: set[str] = set()
162184
for source in sorted(AIO.glob("*.py")):
185+
if source.name in AIO_ONLY:
186+
continue
163187
target = SYNC / source.name
164188
target.write_text(transform(source.read_text(encoding="utf-8")), encoding="utf-8")
165189
generated.add(target.name)

‎tests/integration/sync/test_lifecycle_policies.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ def test__detach_mode_auto__with_a_default_partition__is_planned_as_the_blocking
418418
detach = result.maintenance_plan.detaches[0]
419419
assert detach.mode is DetachMode.BLOCKING
420420
assert "DEFAULT partition" in detach.detail
421+
assert "ACCESS EXCLUSIVE on the parent" in detach.capabilities.lock
421422

422423

423424
def test__detach_mode_auto__without_a_default_partition__stays_concurrent(sync_db_engine: Engine, table: str) -> None:

‎tests/integration/sync/test_maintainer.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,6 @@ def test__maintainer__run_maintenance_safe__never_raises_and_reports_the_error(
279279
assert result.created_count == 0
280280

281281

282-
# ── Two maintainers on the same table ────────────────────────────────────────────
283-
284-
285-
# ── An interrupted DETACH CONCURRENTLY ──────────────────────────────────────────
286-
287-
288282
# ── A hook must not be able to redirect a detach ────────────────────────────────
289283

290284

‎tests/integration/sync/test_safe_drop.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,3 @@ def test__drop_partition__expected_oid_of_another_relation__refused_and_the_tabl
227227
# The right identity still drops it
228228
repo.drop_partition(name, expected_oid=real_oid)
229229
assert not metadata.partition_exists(name)
230-
231-
232-
# ── retry on lock contention ──────────────────────────────────────────────────────

0 commit comments

Comments
 (0)