AlwinXavier19/gaia-benchmark-agent
0
1"""2test_tools.py — Quick smoke tests for all GAIA agent tools.3 4Run:5 python test_tools.py6"""7 8import os9import sys10 11# Force UTF-8 output on Windows so arrow/emoji chars don't crash12if sys.stdout.encoding and sys.stdout.encoding.lower() != "utf-8":13 import io14 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")15 16from dotenv import load_dotenv17 18load_dotenv()19 20# ──────────────────────────────────────────────────────────────────────────────21# Colour helpers (works on Windows too)22# ──────────────────────────────────────────────────────────────────────────────23 24GREEN = "\033[92m"25RED = "\033[91m"26YELLOW = "\033[93m"27RESET = "\033[0m"28 29PASS = f"{GREEN}PASS{RESET}"30FAIL = f"{RED}FAIL{RESET}"31SKIP = f"{YELLOW}SKIP{RESET}"32 33 34def test(name: str, fn, *args, expect_contains: str = "", **kwargs):35 try:36 result = fn(*args, **kwargs)37 result_str = str(result)38 if expect_contains and expect_contains.lower() not in result_str.lower():39 print(f"[{FAIL}] {name}")40 print(f" Expected to contain: '{expect_contains}'")41 print(f" Got: {result_str[:200]}")42 else:43 print(f"[{PASS}] {name}")44 print(f" → {result_str[:120]}")45 except Exception as exc:46 print(f"[{FAIL}] {name}: {exc}")47 48 49# ──────────────────────────────────────────────────────────────────────────────50# Tests51# ──────────────────────────────────────────────────────────────────────────────52 53from tools import (54 reverse_text,55 calculate,56 decode_text,57 web_search,58 wikipedia_search,59 execute_python_code,60)61 62 63def run_tests():64 print("\n" + "=" * 60)65 print(" GAIA Agent Tool Tests")66 print("=" * 60 + "\n")67 68 # ── Pure utility tests (no API needed) ────────────────────────────────69 test("reverse_text basic", reverse_text, ".rewsna eht si siht",70 expect_contains="this is the answer")71 72 test("reverse_text short", reverse_text, "hello",73 expect_contains="olleh")74 75 test("calculate add", calculate, "2 + 2",76 expect_contains="4")77 78 test("calculate complex", calculate, "sqrt(144) + 3**2",79 expect_contains="21")80 81 test("calculate pi", calculate, "round(pi, 4)",82 expect_contains="3.1416")83 84 test("decode_text reverse", decode_text, "!dlrow olleh",85 expect_contains="hello world")86 87 test("execute_python_code simple", execute_python_code,88 "print(2 ** 10)", expect_contains="1024")89 90 test("execute_python_code multiline", execute_python_code,91 "x = [i**2 for i in range(5)]\nprint(sum(x))",92 expect_contains="30")93 94 # ── Network tests (require internet) ──────────────────────────────────95 print(f"\n--- Network Tests ---")96 97 test("web_search python", web_search, "Python programming language",98 expect_contains="python")99 100 test("wikipedia_search france", wikipedia_search, "France",101 expect_contains="france")102 103 test("wikipedia_search albert einstein", wikipedia_search, "Albert Einstein",104 expect_contains="einstein")105 106 print("\n" + "=" * 60)107 print("Tests complete!")108 print("=" * 60 + "\n")109 110 111if __name__ == "__main__":112 run_tests()113 