Spaces:
Running
Running
File size: 1,042 Bytes
cd004e1 |
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 |
import ast
import pathlib
import pytest
def test_examples_no_webtool_imports():
"""No example files should import WebTool or the websearch module."""
examples_dir = pathlib.Path("examples")
for py_file in examples_dir.rglob("*.py"):
content = py_file.read_text()
tree = ast.parse(content)
for node in ast.walk(tree):
if isinstance(node, ast.ImportFrom):
module = node.module or ""
if "websearch" in module:
pytest.fail(f"{py_file} imports websearch (should be removed)")
# Also check for `from src.tools import WebTool`
for alias in node.names:
if alias.name == "WebTool":
pytest.fail(f"{py_file} imports WebTool (should be removed)")
elif isinstance(node, ast.Import):
for alias in node.names:
if "websearch" in alias.name:
pytest.fail(f"{py_file} imports websearch (should be removed)")
|