langchain/tests/unit_tests/test_depedencies.py
Eugene Yurtsev e6c8cce050
Add unit-test to catch changes to required deps (#3662)
This adds a unit test that can catch changes to required dependencies
2023-04-27 13:04:17 -04:00

43 lines
1.2 KiB
Python

"""A unit test meant to catch accidental introduction of non-optional dependencies."""
from pathlib import Path
import toml
HERE = Path(__file__).parent
PYPROJECT_TOML = HERE / "../../pyproject.toml"
def test_required_dependencies() -> None:
"""A test that checks if a new non-optional dependency is being introduced.
If this test is triggered, it means that a contributor is trying to introduce a new
required dependency. This should be avoided in most situations.
"""
with open(PYPROJECT_TOML) as f:
pyproject = toml.load(f)
# Get the dependencies from the [tool.poetry.dependencies] section
dependencies = pyproject["tool"]["poetry"]["dependencies"]
required_dependencies = [
package_name
for package_name, requirements in dependencies.items()
if isinstance(requirements, str) or not requirements.get("optional", False)
]
assert sorted(required_dependencies) == [
"PyYAML",
"SQLAlchemy",
"aiohttp",
"async-timeout",
"dataclasses-json",
"numexpr",
"numpy",
"openapi-schema-pydantic",
"pydantic",
"python",
"requests",
"tenacity",
]