mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-12 06:13:36 +00:00
langchain[minor]: enhance unit test to test imports recursively (#21122)
This commit is contained in:
parent
e4f51f59a2
commit
bf95414758
@ -1,6 +1,6 @@
|
|||||||
def __getattr__(name: str = "") -> None:
|
def __getattr__(name: str = "") -> None:
|
||||||
"""Raise an error on import since is deprecated."""
|
"""Raise an error on import since is deprecated."""
|
||||||
raise ImportError(
|
raise AttributeError(
|
||||||
"This module has been moved to langchain-experimental. "
|
"This module has been moved to langchain-experimental. "
|
||||||
"For more details: https://github.com/langchain-ai/langchain/discussions/11352."
|
"For more details: https://github.com/langchain-ai/langchain/discussions/11352."
|
||||||
"To access this code, install it with `pip install langchain-experimental`."
|
"To access this code, install it with `pip install langchain-experimental`."
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
def __getattr__(name: str = "") -> None:
|
def __getattr__(name: str = "") -> None:
|
||||||
"""Raise an error on import since is deprecated."""
|
"""Raise an error on import since is deprecated."""
|
||||||
raise ImportError(
|
raise AttributeError(
|
||||||
"This module has been moved to langchain-experimental. "
|
"This module has been moved to langchain-experimental. "
|
||||||
"For more details: https://github.com/langchain-ai/langchain/discussions/11352."
|
"For more details: https://github.com/langchain-ai/langchain/discussions/11352."
|
||||||
"To access this code, install it with `pip install langchain-experimental`."
|
"To access this code, install it with `pip install langchain-experimental`."
|
||||||
|
@ -2,7 +2,7 @@ from typing import Any
|
|||||||
|
|
||||||
|
|
||||||
def __getattr__(name: str = "") -> Any:
|
def __getattr__(name: str = "") -> Any:
|
||||||
raise ImportError(
|
raise AttributeError(
|
||||||
"This tool has been moved to langchain experiment. "
|
"This tool has been moved to langchain experiment. "
|
||||||
"This tool has access to a python REPL. "
|
"This tool has access to a python REPL. "
|
||||||
"For best practices make sure to sandbox this tool. "
|
"For best practices make sure to sandbox this tool. "
|
||||||
|
@ -1,15 +1,27 @@
|
|||||||
import glob
|
|
||||||
import importlib
|
import importlib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Attempt to recursively import all modules in langchain
|
||||||
|
PKG_ROOT = Path(__file__).parent.parent.parent
|
||||||
|
|
||||||
def test_importable_all() -> None:
|
|
||||||
for path in glob.glob("../langchain/langchain/*"):
|
def test_import_all() -> None:
|
||||||
relative_path = Path(path).parts[-1]
|
"""Generate the public API for this package."""
|
||||||
if relative_path.endswith(".typed"):
|
library_code = PKG_ROOT / "langchain"
|
||||||
continue
|
for path in library_code.rglob("*.py"):
|
||||||
module_name = relative_path.split(".")[0]
|
# Calculate the relative path to the module
|
||||||
module = importlib.import_module("langchain." + module_name)
|
module_name = (
|
||||||
all_ = getattr(module, "__all__", [])
|
path.relative_to(PKG_ROOT).with_suffix("").as_posix().replace("/", ".")
|
||||||
for cls_ in all_:
|
)
|
||||||
getattr(module, cls_)
|
if module_name.endswith("__init__"):
|
||||||
|
# Without init
|
||||||
|
module_name = module_name.rsplit(".", 1)[0]
|
||||||
|
|
||||||
|
mod = importlib.import_module(module_name)
|
||||||
|
|
||||||
|
all = getattr(mod, "__all__", [])
|
||||||
|
|
||||||
|
for name in all:
|
||||||
|
# Attempt to import the name from the module
|
||||||
|
obj = getattr(mod, name)
|
||||||
|
assert obj is not None
|
||||||
|
Loading…
Reference in New Issue
Block a user