Merge pull request #54 from aguzererler/test-macro-regime-fmt-pct-18208719821293052000

🧪 Add tests for `_fmt_pct` in macro regime
This commit is contained in:
ahmet guzererler 2026-03-21 17:36:20 +01:00 committed by GitHub
commit 2ec8a17216
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -23,6 +23,28 @@ def _trending_series(start: float, end: float, n: int = 100) -> pd.Series:
return _make_series(list(np.linspace(start, end, n)))
# ---------------------------------------------------------------------------
# Helpers tests
# ---------------------------------------------------------------------------
class TestFmtPct:
def setup_method(self):
from tradingagents.dataflows.macro_regime import _fmt_pct
self.fn = _fmt_pct
@pytest.mark.parametrize(
("val", "expected"),
[
(None, "N/A"),
(1.234, "+1.2%"),
(-1.234, "-1.2%"),
(0.0, "+0.0%"),
],
)
def test_fmt_pct(self, val, expected):
assert self.fn(val) == expected
# ---------------------------------------------------------------------------
# Individual signal tests
# ---------------------------------------------------------------------------

View File

@ -71,8 +71,7 @@ def _pct_change_n(series: pd.Series, n: int) -> Optional[float]:
def _fmt_pct(val: Optional[float]) -> str:
if val is None:
return "N/A"
sign = "+" if val >= 0 else ""
return f"{sign}{val:.2f}%"
return f"{val:+.1f}%"
# ---------------------------------------------------------------------------