Skip to content

Commit 321efa6

Browse files
committed
fix(personfit): make ignore guard attribute-order independent
1 parent 1b04ca0 commit 321efa6

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

tests/test_scientific_test_execution_contract.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,52 @@
66
TARGET_TEST = "mc_500_reversed_respondent_flagged_by_u3"
77

88

9-
def _personfit_acceptance_is_ignored(source: str) -> bool:
10-
"""Detect the currently guarded ignored-test spelling."""
11-
return f"#[test]\n#[ignore]\nfn {TARGET_TEST}()" in source
9+
def _personfit_acceptance_attributes(source: str) -> tuple[str, ...]:
10+
"""Return Rust attributes attached to the guarded Monte Carlo test."""
11+
lines = source.splitlines()
12+
target = f"fn {TARGET_TEST}() {{"
13+
try:
14+
target_index = next(
15+
index for index, line in enumerate(lines) if line.strip() == target
16+
)
17+
except StopIteration as exc:
18+
raise AssertionError(
19+
"the deterministic person-fit Monte Carlo acceptance test is missing"
20+
) from exc
21+
22+
attributes: list[str] = []
23+
index = target_index - 1
24+
seen_attribute = False
25+
while index >= 0:
26+
stripped = lines[index].strip()
27+
if stripped.startswith("#[") and stripped.endswith("]"):
28+
attributes.append(stripped)
29+
seen_attribute = True
30+
elif seen_attribute and (not stripped or stripped.startswith("///")):
31+
pass
32+
else:
33+
break
34+
index -= 1
35+
36+
return tuple(reversed(attributes))
1237

1338

1439
def test_personfit_monte_carlo_acceptance_is_not_ignored() -> None:
1540
"""Keep deterministic person-fit Monte Carlo acceptance in the normal Rust suite."""
1641
source = PERSONFIT_TESTS.read_text(encoding="utf-8")
17-
active = f"#[test]\nfn {TARGET_TEST}()"
42+
attributes = _personfit_acceptance_attributes(source)
1843

19-
assert not _personfit_acceptance_is_ignored(source), (
44+
assert "#[test]" in attributes, (
45+
"the deterministic person-fit Monte Carlo acceptance must remain a Rust test"
46+
)
47+
assert "#[ignore]" not in attributes, (
2048
"the deterministic 500-rep person-fit Monte Carlo acceptance is skipped; "
2149
"scientific acceptance must run rather than rely on #[ignore]"
2250
)
23-
assert active in source, (
24-
"the deterministic person-fit Monte Carlo acceptance must remain an active Rust test"
25-
)
2651

2752

2853
def test_ignore_guard_is_attribute_order_independent() -> None:
2954
"""Reject an ignore attribute even when it precedes the test attribute."""
3055
reordered = f"#[ignore]\n#[test]\nfn {TARGET_TEST}() {{}}\n"
3156

32-
assert _personfit_acceptance_is_ignored(reordered)
57+
assert "#[ignore]" in _personfit_acceptance_attributes(reordered)

0 commit comments

Comments
 (0)