Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_examples.py
More file actions
Latest commit
61 lines (47 loc) · 1.96 KB
/
Copy pathtest_examples.py
File metadata and controls
61 lines (47 loc) · 1.96 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
importimportlib.util
importsys
frompathlibimportPath
importpytest
defget_example_files() ->list[str]:
"""Get all example files from the directory"""
examples_dir=Path(__file__).parent
examples= []
forfileinexamples_dir.glob("*.py"):
# Skip __init__.py and test files
iffile.name.startswith("__") orfile.name.startswith("test_"):
continue
examples.append(file.name)
returnexamples
EXAMPLES=get_example_files()
# Map of example files to required optional packages
# Note: All examples now require MCP extra for fetch_tools()
OPTIONAL_DEPENDENCIES= {
"openai_integration.py": ["openai", "mcp"],
"langchain_integration.py": ["langchain_openai", "mcp"],
"crewai_integration.py": ["crewai", "mcp"],
"langgraph_integration.py": ["langgraph", "langchain_openai", "mcp"],
"pydantic_ai_integration.py": ["pydantic_ai", "mcp"],
"search_tools.py": ["mcp"],
"auth_management.py": ["mcp"],
}
deftest_example_files_exist() ->None:
"""Verify that we found example files to test"""
assertlen(EXAMPLES) >0, "No example files found"
print(f"Found {len(EXAMPLES)} examples")
@pytest.mark.parametrize("example_file", EXAMPLES)
deftest_run_example(example_file: str) ->None:
"""Run each example file directly using python"""
# Skip if optional dependencies are not available
ifexample_fileinOPTIONAL_DEPENDENCIES:
formoduleinOPTIONAL_DEPENDENCIES[example_file]:
try:
__import__(module)
exceptImportError:
pytest.skip(f"Skipping {example_file}: {module} not installed")
example_path=Path(__file__).parent/example_file
# Import and run the example module directly
spec=importlib.util.spec_from_file_location("example", example_path)
ifspecandspec.loader:
module=importlib.util.module_from_spec(spec)
sys.modules["example"] =module
spec.loader.exec_module(module)