mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-11-23 09:39:55 +02:00
refactor(dataflows): name the unavailable-vendor error for what it covers
- VendorRateLimitError is VendorUnavailableError: a vendor that throttled or failed the request
This commit is contained in:
@@ -95,11 +95,11 @@ if __name__ == "__main__":
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_an_unreachable_yahoo_is_not_reported_as_a_symbol_without_insider_data():
|
||||
from tradingagents.dataflows.errors import VendorRateLimitError
|
||||
from tradingagents.dataflows.errors import VendorUnavailableError
|
||||
from tradingagents.dataflows.vendors.yahoo import fundamentals
|
||||
|
||||
ticker = type("T", (), {"insider_transactions": pd.DataFrame()})()
|
||||
with mock.patch.object(fundamentals.yf, "Ticker", return_value=ticker), \
|
||||
mock.patch.object(fundamentals, "vendor_reachable", return_value=False), \
|
||||
pytest.raises(VendorRateLimitError):
|
||||
pytest.raises(VendorUnavailableError):
|
||||
fundamentals.get_insider_transactions("AAPL", as_of_date="2026-09-21")
|
||||
|
||||
@@ -144,13 +144,13 @@ def test_a_throttle_lets_the_next_vendor_try(monkeypatch):
|
||||
"""SEC throttles by refusing the request; the router then tries yfinance."""
|
||||
import requests
|
||||
|
||||
from tradingagents.dataflows.errors import VendorRateLimitError
|
||||
from tradingagents.dataflows.errors import VendorUnavailableError
|
||||
|
||||
def _throttled(*a, **k):
|
||||
raise requests.HTTPError(response=mock.Mock(status_code=429))
|
||||
|
||||
monkeypatch.setattr(sec_edgar.requests, "get", _throttled)
|
||||
with pytest.raises(VendorRateLimitError):
|
||||
with pytest.raises(VendorUnavailableError):
|
||||
_REAL_FETCH("https://data.sec.gov/api/xbrl/companyfacts/CIK0000320193.json")
|
||||
|
||||
|
||||
|
||||
@@ -196,14 +196,14 @@ def test_an_unreachable_vendor_is_not_reported_as_a_missing_symbol(monkeypatch):
|
||||
company has no balance sheet, when the truth is we could not ask."""
|
||||
import pandas as pd
|
||||
|
||||
from tradingagents.dataflows.errors import NoMarketDataError, VendorRateLimitError
|
||||
from tradingagents.dataflows.errors import NoMarketDataError, VendorUnavailableError
|
||||
from tradingagents.dataflows.vendors.yahoo import ohlcv
|
||||
|
||||
empty = mock.Mock(quarterly_balance_sheet=pd.DataFrame(), balance_sheet=pd.DataFrame())
|
||||
monkeypatch.setattr(yahoo_market.yf, "Ticker", lambda s: empty)
|
||||
|
||||
monkeypatch.setattr(ohlcv, "vendor_reachable", lambda url: False)
|
||||
with pytest.raises(VendorRateLimitError, match="unreachable"):
|
||||
with pytest.raises(VendorUnavailableError, match="unreachable"):
|
||||
yahoo_fundamentals.get_balance_sheet("AAPL", "annual", "2026-09-01")
|
||||
|
||||
monkeypatch.setattr(ohlcv, "vendor_reachable", lambda url: True)
|
||||
@@ -216,10 +216,10 @@ def test_every_vendor_unavailable_says_so_rather_than_crashing(monkeypatch):
|
||||
"""A throttled or unreachable chain used to raise RuntimeError('No available
|
||||
vendor'), which ends the run, and never said the vendor was the problem."""
|
||||
from tradingagents.dataflows import router
|
||||
from tradingagents.dataflows.errors import VendorRateLimitError
|
||||
from tradingagents.dataflows.errors import VendorUnavailableError
|
||||
|
||||
def _down(*a, **k):
|
||||
raise VendorRateLimitError("Yahoo Finance is unreachable")
|
||||
raise VendorUnavailableError("Yahoo Finance is unreachable")
|
||||
|
||||
monkeypatch.setitem(router.VENDOR_METHODS["get_balance_sheet"], "yfinance", _down)
|
||||
|
||||
@@ -235,13 +235,13 @@ def test_the_price_path_also_tells_an_outage_from_an_unknown_symbol(monkeypatch)
|
||||
delisted symbol either."""
|
||||
import pandas as pd
|
||||
|
||||
from tradingagents.dataflows.errors import NoMarketDataError, VendorRateLimitError
|
||||
from tradingagents.dataflows.errors import NoMarketDataError, VendorUnavailableError
|
||||
from tradingagents.dataflows.vendors.yahoo import ohlcv
|
||||
|
||||
monkeypatch.setattr(yahoo_market.yf, "Ticker", lambda s: mock.Mock(history=lambda **k: pd.DataFrame()))
|
||||
|
||||
monkeypatch.setattr(ohlcv, "vendor_reachable", lambda url: False)
|
||||
with pytest.raises(VendorRateLimitError, match="unreachable"):
|
||||
with pytest.raises(VendorUnavailableError, match="unreachable"):
|
||||
yahoo_market.get_YFin_data_online("AAPL", "2026-09-01", "2026-09-10")
|
||||
|
||||
monkeypatch.setattr(ohlcv, "vendor_reachable", lambda url: True)
|
||||
|
||||
@@ -16,7 +16,7 @@ from tradingagents.dataflows.errors import (
|
||||
NoMarketDataError,
|
||||
VendorError,
|
||||
VendorNotConfiguredError,
|
||||
VendorRateLimitError,
|
||||
VendorUnavailableError,
|
||||
)
|
||||
from tradingagents.dataflows.vendors.alpha_vantage.common import (
|
||||
AlphaVantageNotConfiguredError,
|
||||
@@ -28,7 +28,7 @@ from tradingagents.dataflows.vendors.fred import FredNotConfiguredError
|
||||
@pytest.mark.unit
|
||||
class HierarchyTests(unittest.TestCase):
|
||||
def test_all_conditions_derive_from_vendor_error(self):
|
||||
for cls in (NoMarketDataError, VendorRateLimitError, VendorNotConfiguredError):
|
||||
for cls in (NoMarketDataError, VendorUnavailableError, VendorNotConfiguredError):
|
||||
self.assertTrue(issubclass(cls, VendorError))
|
||||
|
||||
def test_not_configured_is_still_a_value_error(self):
|
||||
@@ -36,7 +36,7 @@ class HierarchyTests(unittest.TestCase):
|
||||
self.assertTrue(issubclass(VendorNotConfiguredError, ValueError))
|
||||
|
||||
def test_vendor_named_errors_subclass_the_generic_bases(self):
|
||||
self.assertTrue(issubclass(AlphaVantageRateLimitError, VendorRateLimitError))
|
||||
self.assertTrue(issubclass(AlphaVantageRateLimitError, VendorUnavailableError))
|
||||
self.assertTrue(issubclass(AlphaVantageNotConfiguredError, VendorNotConfiguredError))
|
||||
self.assertTrue(issubclass(FredNotConfiguredError, VendorNotConfiguredError))
|
||||
# ... and therefore still ValueErrors
|
||||
|
||||
@@ -21,7 +21,7 @@ from tradingagents.agents.tools import (
|
||||
)
|
||||
from tradingagents.dataflows import router
|
||||
from tradingagents.dataflows.config import set_config
|
||||
from tradingagents.dataflows.errors import VendorRateLimitError
|
||||
from tradingagents.dataflows.errors import VendorUnavailableError
|
||||
from tradingagents.dataflows.vendors.yahoo import fundamentals, ohlcv
|
||||
|
||||
DAY = "2026-09-18"
|
||||
@@ -84,7 +84,7 @@ def test_the_indicator_path_retries_a_rate_limit(yahoo):
|
||||
def test_yfinance_raises_the_rate_limit_from_history(yahoo):
|
||||
yahoo.setattr(YfData, "_make_request", _rate_limited)
|
||||
|
||||
with pytest.raises(VendorRateLimitError, match="rate limited"):
|
||||
with pytest.raises(VendorUnavailableError, match="rate limited"):
|
||||
ohlcv.load_ohlcv("AAPL", DAY)
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ def test_a_price_request_that_raises_is_unavailable_whether_or_not_yahoo_answers
|
||||
yahoo.setattr(yf.Ticker, "history", refused)
|
||||
for reachable in (False, True):
|
||||
yahoo.setattr(ohlcv, "vendor_reachable", lambda url, _r=reachable: _r)
|
||||
with pytest.raises(VendorRateLimitError, match="request failed"):
|
||||
with pytest.raises(VendorUnavailableError, match="request failed"):
|
||||
ohlcv.load_ohlcv("AAPL", DAY)
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ def test_a_price_request_that_fails_is_unavailable_even_when_yahoo_answers(monke
|
||||
monkeypatch.setattr(ohlcv.yf, "Ticker", lambda s: type("T", (), {"history": lambda self, **k: timed_out(**k)})())
|
||||
monkeypatch.setattr(ohlcv, "vendor_reachable", lambda url: True)
|
||||
|
||||
with pytest.raises(VendorRateLimitError):
|
||||
with pytest.raises(VendorUnavailableError):
|
||||
ohlcv.load_ohlcv("NVDA", "2026-09-23")
|
||||
|
||||
|
||||
@@ -174,5 +174,5 @@ def test_a_yahoo_request_that_fails_is_unavailable_not_absent(yahoo, call):
|
||||
yahoo.setattr(yf, "Ticker", _Unreachable)
|
||||
yahoo.setattr(yf, "Search", _Unreachable)
|
||||
|
||||
with pytest.raises(VendorRateLimitError):
|
||||
with pytest.raises(VendorUnavailableError):
|
||||
call()
|
||||
|
||||
Reference in New Issue
Block a user