diff --git a/pyproject.toml b/pyproject.toml index b5f230a..fa7c5ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ description = "Add your description here" requires-python = ">=3.11" dependencies = [ "imagehash>=4.3.2", + "mcp>=1.22.0,<2.0", "mcp-agent[openai]>=0.2.5", "openai>=1.30.0", "pillow>=12.0.0", diff --git a/tests/test_dataset_smith_multiclass.py b/tests/test_dataset_smith_multiclass.py index 97e5262..7f9502f 100644 --- a/tests/test_dataset_smith_multiclass.py +++ b/tests/test_dataset_smith_multiclass.py @@ -1,14 +1,31 @@ import asyncio import logging +import sys +from pathlib import Path -from obp.agents.dataset_smith import dataset_smith -from obp.export import exporter +import pytest + + +ROOT = Path(__file__).resolve().parents[1] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + +_deps_available = True +try: + from obp.agents.dataset_smith import dataset_smith + from obp.export import exporter +except ImportError: + _deps_available = False logging.basicConfig(level=logging.INFO) -async def run_tests() -> None: +@pytest.mark.skipif( + not _deps_available, + reason="Required dependencies (tavily, pymongo, imagehash) are not installed", +) +async def test_build_multiclass_dataset() -> None: scenarios = [ ("Single-class: cats", ["cat"], 20), ( @@ -39,4 +56,4 @@ async def run_tests() -> None: if __name__ == "__main__": - asyncio.run(run_tests()) + asyncio.run(test_build_multiclass_dataset()) diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index bc77f97..9bd2509 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -1,12 +1,32 @@ import logging -from obp.agents.foundational_gatherer import FoundationalGatherer -from obp.downloader import FoundationalDownloader -from obp.db import get_resources_collection +import sys +from pathlib import Path + +import pytest + + +ROOT = Path(__file__).resolve().parents[1] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + +_deps_available = True +try: + from obp.agents.foundational_gatherer import FoundationalGatherer + from obp.downloader import FoundationalDownloader + from obp.db import get_resources_collection +except ImportError: + _deps_available = False + from uuid import uuid4 import time logging.basicConfig(level=logging.INFO) + +@pytest.mark.skipif( + not _deps_available, + reason="Required dependencies (tavily, pymongo) are not installed", +) def test_end_to_end(): request_id = str(uuid4()) query = "Recent advances in quantum computing 2024" diff --git a/tests/test_foundational_agent.py b/tests/test_foundational_agent.py index 3d3af21..b0e27f1 100644 --- a/tests/test_foundational_agent.py +++ b/tests/test_foundational_agent.py @@ -1,12 +1,29 @@ import logging import sys -import json -from obp.agents.foundational_gatherer import FoundationalGatherer +from pathlib import Path + +import pytest + + +ROOT = Path(__file__).resolve().parents[1] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + +_deps_available = True +try: + from obp.agents.foundational_gatherer import FoundationalGatherer +except ImportError: + _deps_available = False # Configure logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') -def run_tests(): + +@pytest.mark.skipif( + not _deps_available, + reason="Required dependencies (tavily, pymongo) are not installed", +) +def test_foundational_agent(): gatherer = FoundationalGatherer() test_cases = [ @@ -76,4 +93,4 @@ def run_tests(): print(f"{'='*60}\n") if __name__ == "__main__": - run_tests() + test_foundational_agent() diff --git a/tests/test_labeled_corpus.py b/tests/test_labeled_corpus.py index 687ea14..27b6af3 100644 --- a/tests/test_labeled_corpus.py +++ b/tests/test_labeled_corpus.py @@ -1,16 +1,34 @@ import csv import logging -from uuid import uuid4 +import sys +from pathlib import Path + +import pytest + -from obp.agents.foundational_gatherer import FoundationalGatherer -from obp.downloader import FoundationalDownloader -from obp.export import exporter +ROOT = Path(__file__).resolve().parents[1] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + +_deps_available = True +try: + from obp.agents.foundational_gatherer import FoundationalGatherer + from obp.downloader import FoundationalDownloader + from obp.export import exporter +except ImportError: + _deps_available = False + +from uuid import uuid4 logging.basicConfig(level=logging.INFO) -def run_labeled_corpus_tests() -> None: +@pytest.mark.skipif( + not _deps_available, + reason="Required dependencies (tavily, pymongo) are not installed", +) +def test_labeled_corpus() -> None: gatherer = FoundationalGatherer() downloader = FoundationalDownloader() @@ -89,4 +107,4 @@ def run_labeled_corpus_tests() -> None: if __name__ == "__main__": - run_labeled_corpus_tests() + test_labeled_corpus() diff --git a/tests/test_mcp_numerical_corpus_tool.py b/tests/test_mcp_numerical_corpus_tool.py index fcfdbd6..295581a 100644 --- a/tests/test_mcp_numerical_corpus_tool.py +++ b/tests/test_mcp_numerical_corpus_tool.py @@ -2,15 +2,25 @@ import sys from pathlib import Path +import pytest + ROOT = Path(__file__).resolve().parents[1] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) -from apps.mcp_agent_main import app, build_labeled_numerical_corpus +_mcp_available = True +try: + from apps.mcp_agent_main import app, build_labeled_numerical_corpus +except ImportError: + _mcp_available = False -async def main() -> None: +@pytest.mark.skipif( + not _mcp_available, + reason="mcp_agent is not installed (mcp.server.fastmcp unavailable)", +) +async def test_build_labeled_numerical_corpus() -> None: async with app.run() as agent_app: result = await build_labeled_numerical_corpus( labels=[ @@ -29,4 +39,4 @@ async def main() -> None: if __name__ == "__main__": - asyncio.run(main()) + asyncio.run(test_build_labeled_numerical_corpus()) diff --git a/tests/test_mcp_text_corpus_tool.py b/tests/test_mcp_text_corpus_tool.py index 7306d1d..86c2278 100644 --- a/tests/test_mcp_text_corpus_tool.py +++ b/tests/test_mcp_text_corpus_tool.py @@ -2,15 +2,25 @@ import sys from pathlib import Path +import pytest + ROOT = Path(__file__).resolve().parents[1] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) -from apps.mcp_agent_main import app, build_labeled_text_corpus +_mcp_available = True +try: + from apps.mcp_agent_main import app, build_labeled_text_corpus +except ImportError: + _mcp_available = False -async def main() -> None: +@pytest.mark.skipif( + not _mcp_available, + reason="mcp_agent is not installed (mcp.server.fastmcp unavailable)", +) +async def test_build_labeled_text_corpus() -> None: async with app.run() as agent_app: result = await build_labeled_text_corpus( labels=[ @@ -33,4 +43,4 @@ async def main() -> None: if __name__ == "__main__": - asyncio.run(main()) + asyncio.run(test_build_labeled_text_corpus()) diff --git a/uv.lock b/uv.lock index 5e47ce2..a63551a 100644 --- a/uv.lock +++ b/uv.lock @@ -568,6 +568,7 @@ dependencies = [ { name = "dagster-webserver" }, { name = "fastapi" }, { name = "imagehash" }, + { name = "mcp" }, { name = "mcp-agent", extra = ["openai"] }, { name = "openai" }, { name = "pillow" }, @@ -585,6 +586,7 @@ requires-dist = [ { name = "dagster-webserver", specifier = ">=1.12.3" }, { name = "fastapi", specifier = ">=0.121.3" }, { name = "imagehash", specifier = ">=4.3.2" }, + { name = "mcp", specifier = ">=1.22.0,<2.0" }, { name = "mcp-agent", extras = ["openai"], specifier = ">=0.2.5" }, { name = "openai", specifier = ">=1.30.0" }, { name = "pillow", specifier = ">=12.0.0" },