-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_live.py
More file actions
93 lines (76 loc) · 3.21 KB
/
Copy pathtest_live.py
File metadata and controls
93 lines (76 loc) · 3.21 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
"""Live Socrata smoke test for issues #6 + #7.
Run from repo root after copying the deliverables in:
python .tmp-issue-6-7/test_live.py
Hits real Socrata endpoints; needs network. Prints PASS/FAIL per assertion.
"""
from __future__ import annotations
import asyncio
import sys
from agent.tools import data
async def main() -> int:
failures: list[str] = []
def check(label: str, cond: bool, detail: str = "") -> None:
marker = "PASS" if cond else "FAIL"
print(f"[{marker}] {label}{(' — ' + detail) if detail else ''}")
if not cond:
failures.append(label)
# ---- summarize() ------------------------------------------------------
print("\n--- summarize() ---")
result = await data.summarize(
"3syk-w9eu",
where="original_zip='78701'",
dimensions=["permittype"],
portal="data.austintexas.gov",
)
check("summarize status==completed", result["status"] == "completed",
str(result.get("error")))
rows = (result.get("result") or {}).get("rows") or []
check("summarize rows non-empty", len(rows) > 0, f"got {len(rows)} rows")
url = (result.get("result") or {}).get("url", "")
check("summarize url contains $group", "%24group" in url or "$group" in url, url)
print(f" sample rows[0:3]: {rows[:3]}")
print(f" url: {url}")
# ---- empty summarize --------------------------------------------------
print("\n--- summarize() empty result ---")
empty = await data.summarize(
"3syk-w9eu",
where="original_zip='00000'", # nonexistent zip → 0 rows
dimensions=["permittype"],
portal="data.austintexas.gov",
)
check("empty summarize status==completed", empty["status"] == "completed",
str(empty.get("error")))
check("empty summarize rows==[]",
(empty.get("result") or {}).get("rows") == [],
str((empty.get("result") or {}).get("rows")))
# ---- cite() -----------------------------------------------------------
print("\n--- cite() ---")
c = data.cite("3syk-w9eu")
check("cite portal label", c.portal == "City of Austin", c.portal)
check("cite dataset_id", c.dataset_id == "3syk-w9eu", c.dataset_id)
check("cite api_url host", "data.austintexas.gov" in c.api_url, c.api_url)
check("cite landing url", c.url.startswith("https://"), c.url)
print(f" {c.model_dump()}")
# ---- cite() unknown ---------------------------------------------------
print("\n--- cite() unknown dataset ---")
raised = False
try:
data.cite("does-not-exist")
except KeyError as e:
raised = True
print(f" raised KeyError as expected: {e}")
check("cite unknown raises KeyError", raised)
# ---- cite_with_freshness() -------------------------------------------
print("\n--- cite_with_freshness() ---")
c2 = await data.cite_with_freshness("3syk-w9eu")
check("cite_with_freshness last_refreshed populated",
c2.last_refreshed is not None, str(c2.last_refreshed))
print(f" {c2.model_dump()}")
print()
if failures:
print(f"FAILED: {failures}")
return 1
print("ALL PASS")
return 0
if __name__ == "__main__":
sys.exit(asyncio.run(main()))