forked from ChelseaKR/ceqa-preflight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_filing_rules.py
More file actions
120 lines (103 loc) · 3.77 KB
/
Copy pathtest_filing_rules.py
File metadata and controls
120 lines (103 loc) · 3.77 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""Tests for conservative NOD and NOE filing-form rules."""
from __future__ import annotations
from pathlib import Path
import pytest
from ceqa_preflight.models import Confidence, FilingType, Finding
from ceqa_preflight.pdf_inspector import PdfInspection
from ceqa_preflight.rule_catalog import load_rule_catalog
from ceqa_preflight.rule_engine import RuleContext, RuleEngine
from ceqa_preflight.rules.nod import NOD_RULES
from ceqa_preflight.rules.noe import NOE_RULES
def _inspection(**updates: object) -> PdfInspection:
values: dict[str, object] = {
"readable": True,
"extraction_confidence": Confidence.HIGH,
}
values.update(updates)
return PdfInspection.model_validate(values)
def _run(filing_type: FilingType, documents: object) -> dict[str, Finding]:
root = Path(__file__).parents[1]
pack = "nod.yaml" if filing_type is FilingType.NOD else "noe.yaml"
registry = NOD_RULES if filing_type is FilingType.NOD else NOE_RULES
catalog = load_rule_catalog([root / "src/ceqa_preflight/rulepacks" / pack])
result = RuleEngine(catalog, registry).run(
RuleContext(filing_type=filing_type, facts={"documents": documents}),
include_experimental=True,
)
assert result.exit_code == 0
return {finding.rule_id: finding for finding in result.findings}
@pytest.mark.parametrize(
("filing_type", "category", "prefix"),
[
(FilingType.NOD, "Notice of Determination", "NOD"),
(FilingType.NOE, "Notice of Exemption", "NOE"),
],
)
def test_declared_primary_form_passes_and_legal_questions_stay_manual(
filing_type: FilingType, category: str, prefix: str
) -> None:
findings = _run(
filing_type,
[
{
"path": f"{prefix}_form.pdf",
"is_pdf": True,
"primary": True,
"category": category,
"inspection": _inspection(),
}
],
)
assert [findings[f"{prefix}-00{number}"].status.value for number in range(1, 4)] == [
"pass",
"pass",
"pass",
]
assert {findings[f"{prefix}-M00{number}"].status.value for number in range(1, 4)} == {"manual"}
@pytest.mark.parametrize(
("filing_type", "category", "prefix"),
[
(FilingType.NOD, "Notice of Determination", "NOD"),
(FilingType.NOE, "Notice of Exemption", "NOE"),
],
)
def test_missing_multiple_and_unclassified_primary_forms_are_safe(
filing_type: FilingType, category: str, prefix: str
) -> None:
missing = _run(filing_type, [])
multiple = _run(
filing_type,
[
{"path": "one.pdf", "is_pdf": True, "primary": True, "category": category},
{"path": "two.pdf", "is_pdf": True, "primary": True, "category": category},
],
)
unknown = _run(
filing_type,
[{"path": "unknown.pdf", "is_pdf": True, "primary": True}],
)
assert missing[f"{prefix}-001"].status.value == "failure"
assert multiple[f"{prefix}-001"].status.value == "failure"
assert unknown[f"{prefix}-001"].status.value == "manual"
assert unknown[f"{prefix}-002"].status.value == "manual"
@pytest.mark.parametrize(
("filing_type", "category", "prefix"),
[
(FilingType.NOD, "Notice of Determination", "NOD"),
(FilingType.NOE, "Notice of Exemption", "NOE"),
],
)
def test_unreadable_primary_form_fails(filing_type: FilingType, category: str, prefix: str) -> None:
findings = _run(
filing_type,
[
{
"path": "form.pdf",
"is_pdf": True,
"primary": True,
"category": category,
"inspection": _inspection(readable=False, encrypted=True),
}
],
)
assert findings[f"{prefix}-002"].status.value == "failure"