|
6 | 6 | TARGET_TEST = "mc_500_reversed_respondent_flagged_by_u3" |
7 | 7 |
|
8 | 8 |
|
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)) |
12 | 37 |
|
13 | 38 |
|
14 | 39 | def test_personfit_monte_carlo_acceptance_is_not_ignored() -> None: |
15 | 40 | """Keep deterministic person-fit Monte Carlo acceptance in the normal Rust suite.""" |
16 | 41 | source = PERSONFIT_TESTS.read_text(encoding="utf-8") |
17 | | - active = f"#[test]\nfn {TARGET_TEST}()" |
| 42 | + attributes = _personfit_acceptance_attributes(source) |
18 | 43 |
|
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, ( |
20 | 48 | "the deterministic 500-rep person-fit Monte Carlo acceptance is skipped; " |
21 | 49 | "scientific acceptance must run rather than rely on #[ignore]" |
22 | 50 | ) |
23 | | - assert active in source, ( |
24 | | - "the deterministic person-fit Monte Carlo acceptance must remain an active Rust test" |
25 | | - ) |
26 | 51 |
|
27 | 52 |
|
28 | 53 | def test_ignore_guard_is_attribute_order_independent() -> None: |
29 | 54 | """Reject an ignore attribute even when it precedes the test attribute.""" |
30 | 55 | reordered = f"#[ignore]\n#[test]\nfn {TARGET_TEST}() {{}}\n" |
31 | 56 |
|
32 | | - assert _personfit_acceptance_is_ignored(reordered) |
| 57 | + assert "#[ignore]" in _personfit_acceptance_attributes(reordered) |
0 commit comments