|
18 | 18 | import textwrap |
19 | 19 | import uuid |
20 | 20 | from pathlib import Path |
| 21 | +from types import SimpleNamespace |
| 22 | + |
| 23 | +from sqlalchemy import select |
| 24 | +from typer.testing import CliRunner |
21 | 25 |
|
22 | 26 | from cli.cli import cli |
23 | 27 | from cli.service_adapter import WellInventoryResult |
24 | 28 | from db import FieldActivity, FieldEvent, Observation, Sample |
25 | 29 | from db.engine import session_ctx |
26 | | -from sqlalchemy import select |
27 | | -from typer.testing import CliRunner |
28 | 30 |
|
29 | 31 |
|
30 | 32 | def test_initialize_lexicon_invokes_initializer(monkeypatch): |
@@ -95,6 +97,50 @@ def fake_well_inventory(file_path): |
95 | 97 | assert "[WELL INVENTORY IMPORT] SUCCESS" in result.output |
96 | 98 |
|
97 | 99 |
|
| 100 | +def test_transfer_results_command_writes_summary(monkeypatch, tmp_path): |
| 101 | + captured: dict[str, object] = {} |
| 102 | + |
| 103 | + class FakeBuilder: |
| 104 | + def __init__(self, sample_limit: int = 25): |
| 105 | + captured["sample_limit"] = sample_limit |
| 106 | + |
| 107 | + def build(self): |
| 108 | + captured["built"] = True |
| 109 | + return SimpleNamespace( |
| 110 | + results={"WellData": object(), "WaterLevels": object()} |
| 111 | + ) |
| 112 | + |
| 113 | + @staticmethod |
| 114 | + def write_summary(path, comparison): |
| 115 | + captured["summary_path"] = Path(path) |
| 116 | + captured["result_count"] = len(comparison.results) |
| 117 | + |
| 118 | + monkeypatch.setattr( |
| 119 | + "transfers.transfer_results_builder.TransferResultsBuilder", FakeBuilder |
| 120 | + ) |
| 121 | + |
| 122 | + summary_path = tmp_path / "metrics" / "summary.md" |
| 123 | + runner = CliRunner() |
| 124 | + result = runner.invoke( |
| 125 | + cli, |
| 126 | + [ |
| 127 | + "transfer-results", |
| 128 | + "--summary-path", |
| 129 | + str(summary_path), |
| 130 | + "--sample-limit", |
| 131 | + "11", |
| 132 | + ], |
| 133 | + ) |
| 134 | + |
| 135 | + assert result.exit_code == 0, result.output |
| 136 | + assert captured["sample_limit"] == 11 |
| 137 | + assert captured["built"] is True |
| 138 | + assert captured["summary_path"] == summary_path |
| 139 | + assert captured["result_count"] == 2 |
| 140 | + assert f"Wrote comparison summary: {summary_path}" in result.output |
| 141 | + assert "Transfer comparisons: 2" in result.output |
| 142 | + |
| 143 | + |
98 | 144 | def test_well_inventory_csv_command_reports_validation_errors(monkeypatch, tmp_path): |
99 | 145 | inventory_file = tmp_path / "inventory.csv" |
100 | 146 | inventory_file.write_text("header\nvalue\n") |
@@ -198,10 +244,12 @@ def test_water_levels_cli_persists_observations(tmp_path, water_well_thing): |
198 | 244 | """ |
199 | 245 |
|
200 | 246 | def _write_csv(path: Path, *, well_name: str, notes: str): |
201 | | - csv_text = textwrap.dedent(f"""\ |
| 247 | + csv_text = textwrap.dedent( |
| 248 | + f"""\ |
202 | 249 | field_staff,well_name_point_id,field_event_date_time,measurement_date_time,sampler,sample_method,mp_height,level_status,depth_to_water_ft,data_quality,water_level_notes |
203 | 250 | CLI Tester,{well_name},2025-02-15T08:00:00-07:00,2025-02-15T10:30:00-07:00,Groundwater Team,electric tape,1.5,stable,42.5,approved,{notes} |
204 | | - """) |
| 251 | + """ |
| 252 | + ) |
205 | 253 | path.write_text(csv_text) |
206 | 254 |
|
207 | 255 | unique_notes = f"pytest-{uuid.uuid4()}" |
|
0 commit comments