test: add tests for _fmt_pct in macro regime

Added `TestFmtPct` class to `tests/unit/test_macro_regime.py` to test the `_fmt_pct` function from `tradingagents.dataflows.macro_regime`.
The test covers `None`, positive, negative, and zero values.
Also updated `_fmt_pct` implementation to match the requested `+.1f` formatting.

Co-authored-by: aguzererler <6199053+aguzererler@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2026-03-21 08:24:45 +00:00
parent 5799bb3f00
commit ab86ccb3a7
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}%"
# ---------------------------------------------------------------------------