Spaces:
Sleeping
Sleeping
Download tests/unit/test_utils.py from neurostack-in/talk2map-test: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/neurostack-in/talk2map-test/resolve/main/tests/unit/test_utils.py
- Command line
-
hf download hf://spaces/neurostack-in/talk2map-test/tests/unit/test_utils.py
-
curl -L -o test_utils.py https://huggingface.co/spaces/neurostack-in/talk2map-test/resolve/main/tests/unit/test_utils.py
1.3 kB
| import pytest | |
| from api.app import _sanitize_text, _looks_like_tool_json, _tool_json_to_places, _fmt_places_md | |
| from agent.models import Place, BoundingBox, LatLon | |
| def test_sanitize_text_removes_headers(): | |
| raw = "Hello <|header_start|>SECRET<|header_end|> World" | |
| cleaned = _sanitize_text(raw) | |
| assert "SECRET" not in cleaned | |
| assert cleaned.startswith("Hello") | |
| def test_sanitize_text_handles_none(): | |
| assert _sanitize_text(None) == "" | |
| def test_looks_like_tool_json_valid(): | |
| s = '[{"name":"Test","lat":1.23,"lng":4.56}]' | |
| assert _looks_like_tool_json(s) is True | |
| def test_looks_like_tool_json_invalid(): | |
| assert _looks_like_tool_json("not json") is False | |
| assert _looks_like_tool_json(123) is False | |
| def test_tool_json_to_places_and_fmt(): | |
| raw = '[{"name":"Cafe","address":"123 St","lat":1.0,"lng":2.0,"viewport":{"low":{"latitude":0,"longitude":0},"high":{"latitude":2,"longitude":2}}}]' | |
| places = _tool_json_to_places(raw) | |
| assert len(places) == 1 | |
| p = places[0] | |
| assert isinstance(p, Place) | |
| assert p.name == "Cafe" | |
| md = _fmt_places_md(places) | |
| assert "Cafe" in md | |
| assert "lat,lng" in md | |
| def test_tool_json_to_places_invalid_returns_empty(): | |
| assert _tool_json_to_places("not json") == [] | |
| assert _tool_json_to_places("{}") == [] | |