"""Unit tests for pure Python helpers. Run:
    cd unified-portal/cecl-app/scripts && pytest tests/test_helpers.py -v
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from cecl_db import dedup_descriptions, batched


def test_dedup_case_insensitive():
    result = dedup_descriptions([
        "CRE concentration risk",
        "cre concentration risk",
        "  CRE  concentration   risk  ",
        "Inflation / supply chain",
    ])
    assert len(result) == 2
    # First occurrence wins
    assert result[0] == "CRE concentration risk"
    assert result[1] == "Inflation / supply chain"


def test_dedup_strips_empty():
    result = dedup_descriptions(["", "   ", "foo"])
    assert result == ["foo"]


def test_batched_exact_multiple():
    batches = list(batched(range(6), 3))
    assert batches == [[0, 1, 2], [3, 4, 5]]


def test_batched_remainder():
    batches = list(batched(range(7), 3))
    assert batches == [[0, 1, 2], [3, 4, 5], [6]]


def test_batched_empty():
    batches = list(batched([], 3))
    assert batches == []
