Download tests/test_tools.py from DriptoBhattacharyya/Agent-Course-Submission: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/DriptoBhattacharyya/Agent-Course-Submission/resolve/main/tests/test_tools.py
- Command line
-
hf download hf://spaces/DriptoBhattacharyya/Agent-Course-Submission/tests/test_tools.py
-
curl -L -o test_tools.py https://huggingface.co/spaces/DriptoBhattacharyya/Agent-Course-Submission/resolve/main/tests/test_tools.py
1.89 kB
| """Unit tests for tools with mocked HTTP / external calls.""" | |
| from unittest.mock import MagicMock, patch | |
| from gaia_agent.tools import ( | |
| classify_file, | |
| python_repl, | |
| read_spreadsheet, | |
| read_text_file, | |
| ) | |
| from gaia_agent.tools.files import fetch_task_file | |
| def test_classify_file(): | |
| assert classify_file("a/b/data.xlsx") == "spreadsheet" | |
| assert classify_file("clip.MP3") == "audio" | |
| assert classify_file("pic.jpeg") == "image" | |
| assert classify_file("script.py") == "code" | |
| assert classify_file("notes.txt") == "text" | |
| assert classify_file("weird.xyz") == "other" | |
| def test_python_repl_arithmetic(): | |
| out = python_repl.invoke({"code": "result = sum(range(1, 11))"}) | |
| assert "55" in out | |
| def test_python_repl_handles_error(): | |
| out = python_repl.invoke({"code": "1/0"}) | |
| assert "Error" in out | |
| def test_read_text_file(tmp_path): | |
| p = tmp_path / "f.txt" | |
| p.write_text("hello gaia", encoding="utf-8") | |
| assert "hello gaia" in read_text_file.invoke({"path": str(p)}) | |
| def test_read_spreadsheet_csv(tmp_path): | |
| p = tmp_path / "t.csv" | |
| p.write_text("a,b\n1,2\n3,4\n", encoding="utf-8") | |
| out = read_spreadsheet.invoke({"path": str(p)}) | |
| assert "2 rows" in out and "['a', 'b']" in out | |
| def test_fetch_task_file_no_file(): | |
| """A non-200 response yields None rather than a path.""" | |
| with patch("gaia_agent.tools.files.requests.get") as mock_get: | |
| mock_get.return_value = MagicMock(status_code=404, content=b"") | |
| assert fetch_task_file("missing") is None | |
| def test_fetch_task_file_writes(tmp_path): | |
| resp = MagicMock(status_code=200, content=b"col\n1\n", | |
| headers={"content-disposition": 'attachment; filename="x.csv"'}) | |
| with patch("gaia_agent.tools.files.requests.get", return_value=resp): | |
| path = fetch_task_file("task1") | |
| assert path is not None and path.endswith("x.csv") | |