mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-25 14:02:38 +03:00
- the Yahoo vendor owns get_company_profile and get_closes; agent_utils and the graph no longer import yfinance - a test keeps vendor libraries inside dataflows
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
"""Only the data layer imports vendor libraries.
|
|
|
|
Vendor calls belong in dataflows, where failures are raised as VendorError
|
|
subclasses; a call made elsewhere can report an outage as a fact about the market.
|
|
"""
|
|
|
|
import ast
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
VENDOR_LIBRARIES = {"yfinance"}
|
|
|
|
|
|
def _imports(path: Path) -> set[str]:
|
|
names = set()
|
|
for node in ast.walk(ast.parse(path.read_text(encoding="utf-8"))):
|
|
if isinstance(node, ast.Import):
|
|
names |= {a.name.split(".")[0] for a in node.names}
|
|
elif isinstance(node, ast.ImportFrom) and node.module and not node.level:
|
|
names.add(node.module.split(".")[0])
|
|
return names
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_vendor_libraries_are_imported_only_by_the_data_layer():
|
|
data_layer = ROOT / "tradingagents" / "dataflows"
|
|
offenders = sorted(
|
|
str(path.relative_to(ROOT))
|
|
for package in ("tradingagents", "cli")
|
|
for path in (ROOT / package).rglob("*.py")
|
|
if data_layer not in path.parents and _imports(path) & VENDOR_LIBRARIES
|
|
)
|
|
assert offenders == []
|