Personal AI, On Personal Devices
Python
style: ruff format the new tests
Robert Tidball3617accc3205
diff --git a/tests/security/test_data_boundary_audit.py b/tests/security/test_data_boundary_audit.pyindex a7b9bf4a..bd91302c 100644--- a/tests/security/test_data_boundary_audit.py+++ b/tests/security/test_data_boundary_audit.py@@ -773,9 +773,7 @@ def test_market_data_tool_produces_outbound_warn(tmp_path):assert "FXMacroData" in finding.potential_data_path-def test_fxmacrodata_api_key_presence_is_reported_without_value(- tmp_path, monkeypatch-):+def test_fxmacrodata_api_key_presence_is_reported_without_value(tmp_path, monkeypatch):config = _low_noise_config()config.tools.enabled = "fx_macro_data"secret = "fxmacrodata-key-that-must-not-leak"diff --git a/tests/tools/test_fx_macro.py b/tests/tools/test_fx_macro.pyindex 837bb7c3..c6764ee3 100644--- a/tests/tools/test_fx_macro.py+++ b/tests/tools/test_fx_macro.py@@ -82,16 +82,23 @@ def test_registered_with_network_capability_and_optional_key():def test_keyless_history_sends_no_key_refuses_redirects_and_keeps_notices():with patch(_GET, return_value=_response(body=_history_payload())) as get:- result = _run(action="indicator_history", currency=" usd ",- indicator="Inflation", start_date="2026-07-01",- end_date="2026-09-30", limit=5)+ result = _run(+ action="indicator_history",+ currency=" usd ",+ indicator="Inflation",+ start_date="2026-07-01",+ end_date="2026-09-30",+ limit=5,+ )assert result.success, result.contentargs, kwargs = get.call_argsassert args[0] == "https://api.fxmacrodata.com/v1/announcements/usd/inflation"assert "X-API-Key" not in kwargs["headers"]assert kwargs["follow_redirects"] is Falseassert kwargs["params"] == {- "start_date": "2026-07-01", "end_date": "2026-09-30", "limit": "5"+ "start_date": "2026-07-01",+ "end_date": "2026-09-30",+ "limit": "5",}data = json.loads(result.content)assert data["releases"][0]["value"] == 3.4@@ -107,8 +114,9 @@ def test_key_from_credentials_is_sent_as_header_and_never_returned(monkeypatch):body = _history_payload()body["data"][0]["source_url"] = f"https://example.test/?k={_KEY}"with patch(_GET, return_value=_response(body=body)) as get:- result = _run(action="indicator_history", currency="EUR",- indicator="policy_rate")+ result = _run(+ action="indicator_history", currency="EUR", indicator="policy_rate"+ )assert get.call_args.kwargs["headers"]["X-API-Key"] == _KEYassert result.successassert _KEY not in result.content@@ -120,8 +128,9 @@ def test_key_from_credentials_is_sent_as_header_and_never_returned(monkeypatch):def test_redirect_is_an_error(status):response = _response(status, text="", headers={"location": "http://evil.test/"})with patch(_GET, return_value=response):- result = _run(FXMacroDataTool(api_key=_KEY), action="release_calendar",- currency="USD")+ result = _run(+ FXMacroDataTool(api_key=_KEY), action="release_calendar", currency="USD"+ )assert not result.successassert "redirect" in result.contentassert _KEY not in result.content@@ -131,8 +140,9 @@ def test_redirect_is_an_error(status):def test_http_errors_are_clean_and_do_not_echo_the_body(status):response = _response(status, body={"detail": f"bad key {_KEY}"})with patch(_GET, return_value=response):- result = _run(FXMacroDataTool(api_key=_KEY), action="fx_rates",- base="EUR", quote="USD")+ result = _run(+ FXMacroDataTool(api_key=_KEY), action="fx_rates", base="EUR", quote="USD"+ )assert not result.successassert f"HTTP {status}" in result.contentassert _KEY not in result.content@@ -141,10 +151,13 @@ def test_http_errors_are_clean_and_do_not_echo_the_body(status):def test_transport_error_text_is_never_interpolated():error = httpx.ConnectError(f"failed for X-API-Key={_KEY}")with patch(_GET, side_effect=error):- result = _run(FXMacroDataTool(api_key=_KEY), action="indicator_catalogue",- currency="USD")+ result = _run(+ FXMacroDataTool(api_key=_KEY), action="indicator_catalogue", currency="USD"+ )assert not result.success- assert result.content == "FXMacroData lookup failed: FXMacroData could not be reached"+ assert (+ result.content == "FXMacroData lookup failed: FXMacroData could not be reached"+ )def test_unexpected_exception_is_generic():@@ -166,8 +179,7 @@ def test_unexpected_exception_is_generic():)def test_bad_200_bodies_are_errors(response):with patch(_GET, return_value=response):- result = _run(action="indicator_history", currency="USD",- indicator="inflation")+ result = _run(action="indicator_history", currency="USD", indicator="inflation")assert not result.successassert result.content.startswith("FXMacroData lookup failed:")@@ -176,21 +188,61 @@ def test_bad_200_bodies_are_errors(response):("params", "message"),[({"action": "nope"}, "action must be one of"),- ({"action": "indicator_history", "currency": "US", "indicator": "cpi"},- "three-letter"),- ({"action": "indicator_history", "currency": "USD", "indicator": "c p i"},- "indicator slug"),+ (+ {"action": "indicator_history", "currency": "US", "indicator": "cpi"},+ "three-letter",+ ),+ (+ {"action": "indicator_history", "currency": "USD", "indicator": "c p i"},+ "indicator slug",+ ),({"action": "indicator_history", "currency": "USD"}, "indicator slug"),- ({"action": "indicator_history", "currency": "USD", "indicator": "cpi",- "start_date": "2026/01/01"}, "YYYY-MM-DD"),- ({"action": "indicator_history", "currency": "USD", "indicator": "cpi",- "start_date": "2026-02-30"}, "real calendar date"),- ({"action": "indicator_history", "currency": "USD", "indicator": "cpi",- "start_date": "2026-05-01", "end_date": "2026-04-01"}, "on or before"),- ({"action": "indicator_history", "currency": "USD", "indicator": "cpi",- "limit": 101}, "between 1 and 100"),- ({"action": "indicator_history", "currency": "USD", "indicator": "cpi",- "limit": True}, "integer"),+ (+ {+ "action": "indicator_history",+ "currency": "USD",+ "indicator": "cpi",+ "start_date": "2026/01/01",+ },+ "YYYY-MM-DD",+ ),+ (+ {+ "action": "indicator_history",+ "currency": "USD",+ "indicator": "cpi",+ "start_date": "2026-02-30",+ },+ "real calendar date",+ ),+ (+ {+ "action": "indicator_history",+ "currency": "USD",+ "indicator": "cpi",+ "start_date": "2026-05-01",+ "end_date": "2026-04-01",+ },+ "on or before",+ ),+ (+ {+ "action": "indicator_history",+ "currency": "USD",+ "indicator": "cpi",+ "limit": 101,+ },+ "between 1 and 100",+ ),+ (+ {+ "action": "indicator_history",+ "currency": "USD",+ "indicator": "cpi",+ "limit": True,+ },+ "integer",+ ),({"action": "fx_rates", "base": "EUR"}, "quote must be"),],)@@ -204,14 +256,22 @@ def test_invalid_input_never_calls_the_api(params, message):def test_calendar_filters_and_truncates_to_limit():rows = [- {"release": f"r{i}", "name": "Payrolls",- "announcement_datetime_utc": "2026-10-09T12:30:00+00:00",- "date": "2026-09-30", "event_importance": "high"}+ {+ "release": f"r{i}",+ "name": "Payrolls",+ "announcement_datetime_utc": "2026-10-09T12:30:00+00:00",+ "date": "2026-09-30",+ "event_importance": "high",+ }for i in range(5)]with patch(_GET, return_value=_response(body={"data": rows})) as get:- result = _run(action="release_calendar", currency="USD",- indicator="non_farm_payrolls", limit=2)+ result = _run(+ action="release_calendar",+ currency="USD",+ indicator="non_farm_payrolls",+ limit=2,+ )assert get.call_args.kwargs["params"] == {"indicator": "non_farm_payrolls"}events = json.loads(result.content)["events"]assert [e["release"] for e in events] == ["r0", "r1"]@@ -219,25 +279,44 @@ def test_calendar_filters_and_truncates_to_limit():def test_catalogue_is_summarised_and_empty_is_an_error():- body = {"inflation": {"name": "Inflation (CPI)", "unit": "%",- "coverage": {"latest_available_date": "2026-08-31",- "requires_api_key": False}}}+ body = {+ "inflation": {+ "name": "Inflation (CPI)",+ "unit": "%",+ "coverage": {+ "latest_available_date": "2026-08-31",+ "requires_api_key": False,+ },+ }+ }with patch(_GET, return_value=_response(body=body)):result = _run(action="indicator_catalogue", currency="usd")- assert json.loads(result.content)["indicators"] == [{- "indicator": "inflation", "name": "Inflation (CPI)", "unit": "%",- "latest_available_date": "2026-08-31", "requires_api_key": False,- }]+ assert json.loads(result.content)["indicators"] == [+ {+ "indicator": "inflation",+ "name": "Inflation (CPI)",+ "unit": "%",+ "latest_available_date": "2026-08-31",+ "requires_api_key": False,+ }+ ]with patch(_GET, return_value=_response(body={})):assert not _run(action="indicator_catalogue", currency="usd").successdef test_fx_rates_map_rows():- body = {"data": [{"date": "2026-10-06", "val": 1.0931}],- "pagination": {"has_more": True, "total_count": 300}}+ body = {+ "data": [{"date": "2026-10-06", "val": 1.0931}],+ "pagination": {"has_more": True, "total_count": 300},+ }with patch(_GET, return_value=_response(body=body)) as get:- result = _run(FXMacroDataTool(api_key=_KEY), action="fx_rates",- base="eur", quote="usd", limit=1)+ result = _run(+ FXMacroDataTool(api_key=_KEY),+ action="fx_rates",+ base="eur",+ quote="usd",+ limit=1,+ )assert get.call_args.args[0].endswith("/forex/eur/usd")data = json.loads(result.content)assert data["pair"] == "EUR/USD"