File size: 3,633 Bytes
aad7814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Bulk-fix backend test fixtures for official RICS L3 54-leaf matrix."""
from __future__ import annotations

from pathlib import Path

ROOT = Path(__file__).resolve().parents[1] / "backend" / "tests"

REPLACEMENTS = [
    ('E2 Roof coverings', 'D2 Roof coverings'),
    ('Section D3 - Roof coverings', 'Section D2 - Roof coverings'),
    ('Section E2 Roof coverings', 'Section D2 - Roof coverings'),
    ('paragraph_section_id="E2"', 'paragraph_section_id="D2"'),
    ('paragraph_section_id=schema.paragraph_section_id("E2")', 'paragraph_section_id=schema.paragraph_section_id("D2")'),
    ('section_id="E2"', 'section_id="D2"'),
    ('section_id: str = "E2"', 'section_id: str = "D2"'),
    ('SectionDefinition(id="E2", title="Roof coverings"', 'SectionDefinition(id="D2", title="Roof coverings"'),
    ('"template_id": "E2"', '"template_id": "D2"'),
    ('template_id="E2"', 'template_id="D2"'),
    ('sec = "E2"', 'sec = "D2"'),
    ('section_code: str = "E2"', 'section_code: str = "D2"'),
    ('section_code="E2"', 'section_code="D2"'),
    ('"section_code": "E2"', '"section_code": "D2"'),
    ('section_label="Roof coverings",\n        paragraph_section_id="E2"', 'section_label="Roof coverings",\n        paragraph_section_id="D2"'),
    ('hits[0].section_id == "E2"', 'hits[0].section_id == "D2"'),
    ('reference_sources[0].section_id == "E2"', 'reference_sources[0].section_id == "D2"'),
    ('sources[0].section_id == "E2"', 'sources[0].section_id == "D2"'),
    ('chunks[0].section_id == "E2"', 'chunks[0].section_id == "D2"'),
    ('s.section_id == "D3"', 's.section_id == "D2"'),
    ('result.sections if s.section_id == "D3"', 'result.sections if s.section_id == "D2"'),
    ('next(s for s in result.sections if s.section_id == "E2")', 'next(s for s in result.sections if s.section_id == "D2")'),
    ('next(s for s in result.sections if s.section_id == "D3")', 'next(s for s in result.sections if s.section_id == "D2")'),
    ('assert "E2" in sections', 'assert "D2" in sections'),
    ('sections["E2"]', 'sections["D2"]'),
    ('"E2":', '"D2":'),
    ('aliases["E2"]', 'aliases["D2"]'),
    ('"E2": "Roof Coverings"', '"D2": "Roof Coverings"'),
    ('analyze_docx_photo_layout(ref, {"E2"})', 'analyze_docx_photo_layout(ref, {"D2"})'),
    ('section_photo_paths={"E2":', 'section_photo_paths={"D2":'),
    ('save_tenant_photo_layout(tenant, {"E2":', 'save_tenant_photo_layout(tenant, {"D2":'),
    ('list_section_photos(tenant, draft, "E2"', 'list_section_photos(tenant, draft, "D2"'),
    ('vision_observations_for_section(tenant, draft, "E2"', 'vision_observations_for_section(tenant, draft, "D2"'),
    ('upload_section_photo(\n        tenant, draft, "E2"', 'upload_section_photo(\n        tenant, draft, "D2"'),
    ('set_ai_selection(tenant, draft, "E2"', 'set_ai_selection(tenant, draft, "D2"'),
    ('any(s["code"] == "E2"', 'any(s["code"] == "D2"'),
    ('D3: slate', 'D2: slate'),
    ('only_section_ids=["D3"]', 'only_section_ids=["D2"]'),
]

SKIP = {"test_notes_parser.py", "test_notes_keyword_router.py", "test_rics_canonical_l3.py"}


def main() -> None:
    changed: list[str] = []
    for path in ROOT.rglob("*.py"):
        if path.name in SKIP:
            continue
        text = path.read_text(encoding="utf-8")
        orig = text
        for old, new in REPLACEMENTS:
            text = text.replace(old, new)
        if text != orig:
            path.write_text(text, encoding="utf-8")
            changed.append(str(path.relative_to(ROOT.parent.parent)))
    print("Changed", len(changed), "files")
    for p in sorted(changed):
        print(" ", p)


if __name__ == "__main__":
    main()