mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-13 06:40:04 +00:00
experimental[patch]: Fix import test (#24672)
Import test was misconfigured, the glob wasn't returning any file paths
This commit is contained in:
parent
69eacaa887
commit
c623ae6661
@ -1,15 +1,46 @@
|
|||||||
import glob
|
|
||||||
import importlib
|
import importlib
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
PKG_ROOT = Path(__file__).parent.parent.parent
|
||||||
|
PKG_CODE = PKG_ROOT / "langchain_experimental"
|
||||||
|
|
||||||
|
|
||||||
def test_importable_all() -> None:
|
def test_importable_all() -> None:
|
||||||
for path in glob.glob("../experimental/langchain_experimental/*"):
|
"""Test that all modules in langchain_experimental are importable."""
|
||||||
relative_path = Path(path).parts[-1]
|
failures = []
|
||||||
|
found_at_least_one = False
|
||||||
|
for path in PKG_CODE.rglob("*.py"):
|
||||||
|
relative_path = str(Path(path).relative_to(PKG_CODE)).replace("/", ".")
|
||||||
if relative_path.endswith(".typed"):
|
if relative_path.endswith(".typed"):
|
||||||
continue
|
continue
|
||||||
module_name = relative_path.split(".")[0]
|
if relative_path.endswith("/__init__.py"):
|
||||||
|
# Then strip __init__.py
|
||||||
|
s = "/__init__.py"
|
||||||
|
module_name = relative_path[: -len(s)]
|
||||||
|
else: # just strip .py
|
||||||
|
module_name = relative_path[:-3]
|
||||||
|
|
||||||
|
if not module_name:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
module = importlib.import_module("langchain_experimental." + module_name)
|
module = importlib.import_module("langchain_experimental." + module_name)
|
||||||
|
except ImportError:
|
||||||
|
failures.append("langchain_experimental." + module_name)
|
||||||
|
continue
|
||||||
|
|
||||||
all_ = getattr(module, "__all__", [])
|
all_ = getattr(module, "__all__", [])
|
||||||
for cls_ in all_:
|
for cls_ in all_:
|
||||||
|
try:
|
||||||
getattr(module, cls_)
|
getattr(module, cls_)
|
||||||
|
except AttributeError:
|
||||||
|
failures.append(f"{module_name}.{cls_}")
|
||||||
|
|
||||||
|
found_at_least_one = True
|
||||||
|
|
||||||
|
if failures:
|
||||||
|
raise AssertionError(
|
||||||
|
"The following modules or classes could not be imported: "
|
||||||
|
+ ", ".join(failures)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert found_at_least_one is True
|
||||||
|
Loading…
Reference in New Issue
Block a user