|
1 | 1 | import concurrent.futures |
2 | 2 | import importlib |
3 | 3 | import subprocess |
| 4 | +import warnings |
4 | 5 | from pathlib import Path |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def test_importable_all() -> None: |
8 | | - for path in Path("../core/langchain_core/").glob("*"): |
9 | | - module_name = path.stem |
10 | | - if not module_name.startswith(".") and path.suffix != ".typed": |
11 | | - module = importlib.import_module("langchain_core." + module_name) |
12 | | - all_ = getattr(module, "__all__", []) |
13 | | - for cls_ in all_: |
14 | | - getattr(module, cls_) |
| 9 | + with warnings.catch_warnings(): |
| 10 | + # Suppress pydantic_v1 deprecation warnings during import testing |
| 11 | + # These warnings are expected as modules transition from pydantic v1 to v2 |
| 12 | + # and are not relevant to testing importability |
| 13 | + warnings.filterwarnings( |
| 14 | + "ignore", |
| 15 | + message=".*langchain_core.pydantic_v1.*", |
| 16 | + category=DeprecationWarning, |
| 17 | + ) |
| 18 | + for path in Path("../core/langchain_core/").glob("*"): |
| 19 | + module_name = path.stem |
| 20 | + if not module_name.startswith(".") and path.suffix != ".typed": |
| 21 | + module = importlib.import_module("langchain_core." + module_name) |
| 22 | + all_ = getattr(module, "__all__", []) |
| 23 | + for cls_ in all_: |
| 24 | + getattr(module, cls_) |
15 | 25 |
|
16 | 26 |
|
17 | 27 | def try_to_import(module_name: str) -> tuple[int, str]: |
18 | 28 | """Try to import a module via subprocess.""" |
19 | | - module = importlib.import_module("langchain_core." + module_name) |
20 | | - all_ = getattr(module, "__all__", []) |
21 | | - for cls_ in all_: |
22 | | - getattr(module, cls_) |
| 29 | + with warnings.catch_warnings(): |
| 30 | + # Suppress pydantic_v1 deprecation warnings during import testing |
| 31 | + # These warnings are expected as modules transition from pydantic v1 to v2 |
| 32 | + # and are not relevant to testing importability |
| 33 | + warnings.filterwarnings( |
| 34 | + "ignore", |
| 35 | + message=".*langchain_core.pydantic_v1.*", |
| 36 | + category=DeprecationWarning, |
| 37 | + ) |
| 38 | + module = importlib.import_module("langchain_core." + module_name) |
| 39 | + all_ = getattr(module, "__all__", []) |
| 40 | + for cls_ in all_: |
| 41 | + getattr(module, cls_) |
23 | 42 |
|
24 | 43 | result = subprocess.run( |
25 | 44 | ["python", "-c", f"import langchain_core.{module_name}"], check=True |
|
0 commit comments