f/run_tests.sh
Greg Pomerantz c4e7b05f09 Fix non-daily rebalancing (never fired), flat-bench beta div-by-zero, nil-token columns
- portfolio._rebalance_dates: Grouper labels groups with period-END
  timestamps (Sundays, month/quarter/year ends) that never exist in a
  trading-day index, so 1W/1ME/QE/YE silently never rebalanced (only
  1D and buy-and-hold worked). Now takes the first trading day of each
  group.
- metrics.beta_alpha: guard var(bench) == 0 (flat benchmark) instead of
  dividing by zero.
- data._read_csv_clean: the downloader has written Go nil tokens
  ('%!f(<nil>)') into price cells (89 symbols, one bad day each), which
  made pandas infer the whole column as string and crash every
  pct_change on any portfolio containing them. Coerce all columns to
  numeric (nil tokens -> NaN); parquet cache rebuilt (0 string cols).
- new tests/test_portfolio.py (18 checks: rebalance dates land on
  trading days and actually fire, flat-benchmark beta, nil-token
  columns), wired into run_tests.sh (now 5 sections).
- full suite: 30 + 22 + 18 + 38 AppTest + 12 browser e2e, all passing
2026-10-24 18:06:38 -04:00

38 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Full test suite: app-level (Streamlit AppTest) + real-browser e2e (Playwright).
#
# Usage: ./run_tests.sh
# The browser e2e part needs the server running (./run.sh, port 8599);
# it is skipped automatically if the server is down.
set -uo pipefail
cd "$(dirname "$0")"
fail=0
echo "=== 1/5 data cache tests (incremental refresh) ==="
.venv/bin/python tests/test_data.py || fail=1
echo
echo "=== 2/5 after-tax model tests (synthetic) ==="
.venv/bin/python tests/test_tax.py || fail=1
echo
echo "=== 3/5 portfolio/metrics/data-loading tests ==="
.venv/bin/python tests/test_portfolio.py || fail=1
echo
echo "=== 4/5 app tests (AppTest, no browser) ==="
.venv/bin/python tests/test_app.py || fail=1
echo
echo "=== 5/5 browser e2e (Playwright, needs the server) ==="
if curl -s -m 3 -o /dev/null http://localhost:8599/healthz; then
.venv/bin/python tests/test_e2e_browser.py || fail=1
else
echo "server not reachable on :8599 — skipping e2e (start it with ./run.sh)"
fi
echo
[ $fail -eq 0 ] && echo "ALL TESTS PASSED" || echo "TESTS FAILED"
exit $fail