forked from ChelseaKR/ceqa-preflight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
180 lines (145 loc) · 5.3 KB
/
Copy pathtest_cli.py
File metadata and controls
180 lines (145 loc) · 5.3 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
"""CLI smoke tests."""
from pathlib import Path
from pypdf import PdfWriter
from typer.testing import CliRunner
from ceqa_preflight import __version__
from ceqa_preflight.cli import app
runner = CliRunner()
def test_version_option() -> None:
result = runner.invoke(app, ["--version"])
assert result.exit_code == 0
assert result.stdout == f"{__version__}\n"
def test_version_command() -> None:
result = runner.invoke(app, ["version"])
assert result.exit_code == 0
assert result.stdout == f"{__version__}\n"
def test_help_discloses_advisory_scope() -> None:
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "does not provide legal advice" in result.stdout
def test_check_writes_json_report(tmp_path: Path) -> None:
package = tmp_path / "package"
package.mkdir()
document = package / "notice.pdf"
writer = PdfWriter()
writer.add_blank_page(width=612, height=792)
with document.open("wb") as output:
writer.write(output)
output_directory = tmp_path / "reports"
result = runner.invoke(
app,
[
"check",
str(package),
"--filing-type",
"NOE",
"--format",
"json",
"--output",
str(output_directory),
],
)
assert result.exit_code == 0
assert "Wrote advisory report" in result.stdout
assert '"filing_type": "NOE"' in (output_directory / "report.json").read_text(encoding="utf-8")
def test_check_writes_html_report(tmp_path: Path) -> None:
package = tmp_path / "package"
package.mkdir()
writer = PdfWriter()
writer.add_blank_page(width=612, height=792)
with (package / "notice.pdf").open("wb") as output:
writer.write(output)
output_directory = tmp_path / "reports"
result = runner.invoke(
app,
[
"check",
str(package),
"--filing-type",
"NOE",
"--format",
"html",
"--output",
str(output_directory),
],
)
assert result.exit_code == 0
assert '<html lang="en">' in (output_directory / "report.html").read_text(encoding="utf-8")
def test_rules_list_and_show_are_source_cited() -> None:
listed = runner.invoke(app, ["rules", "list", "--filing-type", "NOE"])
shown = runner.invoke(app, ["rules", "show", "noe-001"])
missing = runner.invoke(app, ["rules", "show", "missing-001"])
assert listed.exit_code == 0
assert "NOE-001" in listed.stdout
assert "NOD-001" not in listed.stdout
assert shown.exit_code == 0
assert '"url": "https://lci.ca.gov/sch/faq/"' in shown.stdout
assert missing.exit_code == 2
assert "Unknown rule identifier" in missing.stderr
def test_check_excludes_filing_pilot_rules_unless_explicitly_requested(tmp_path: Path) -> None:
package = tmp_path / "package"
package.mkdir()
writer = PdfWriter()
writer.add_blank_page(width=612, height=792)
with (package / "notice.pdf").open("wb") as output:
writer.write(output)
manifest = tmp_path / "package.yaml"
manifest.write_text(
"filing_type: NOE\nproject:\n title: Example Project\ndocuments:\n - path: notice.pdf\n"
" category: Notice of Exemption\n primary: true\n",
encoding="utf-8",
)
base_arguments = [
"check",
str(package),
"--filing-type",
"NOE",
"--manifest",
str(manifest),
"--format",
"json",
]
default = runner.invoke(app, base_arguments)
experimental = runner.invoke(app, [*base_arguments, "--include-experimental"])
assert default.exit_code == 0
assert '"rule_id": "NOE-001"' not in default.stdout
assert experimental.exit_code == 0
assert '"rule_id": "NOE-001"' in experimental.stdout
def test_init_creates_a_non_overwriting_template(tmp_path: Path) -> None:
directory = tmp_path / "new-package"
created = runner.invoke(app, ["init", str(directory), "--filing-type", "NOD"])
existing = runner.invoke(app, ["init", str(directory), "--filing-type", "NOD"])
assert created.exit_code == 0
assert "Created manifest template" in created.stdout
assert "filing_type: NOD" in (directory / "package.yaml").read_text(encoding="utf-8")
assert existing.exit_code == 2
assert "refusing to overwrite" in existing.stderr
def test_pilot_commands_create_and_summarize_controlled_label_files(tmp_path: Path) -> None:
result = runner.invoke(app, ["pilot", "init", str(tmp_path)])
reviews = tmp_path / "finding-review.csv"
baseline = tmp_path / "manual-baseline.csv"
reviews.write_text(
"package_id,filing_type,rule_id,finding_status,disposition,severity,elapsed_seconds\n"
"PKG_001,NOE,NOE-001,warning,true_positive,medium,60\n",
encoding="utf-8",
)
baseline.write_text(
"package_id,filing_type,severity,was_missed\nPKG_001,NOE,high,false\n",
encoding="utf-8",
)
summary = runner.invoke(
app,
[
"pilot",
"summarize",
"--reviews",
str(reviews),
"--baseline",
str(baseline),
"--format",
"json",
],
)
assert result.exit_code == 0
assert summary.exit_code == 0
assert '"go_no_go": "go"' in summary.stdout