Files
IPSExtractor/services/bot_descarga/tests/test_excel_split.py
T

34 lines
951 B
Python

"""Tests de partición Excel para descarga distribuida."""
from __future__ import annotations
from domain.excel_split import parse_radicado_rows, rows_to_xlsx_bytes, split_rows
def test_split_rows_balanced():
rows = [(str(i), "NIT") for i in range(100)]
chunks = split_rows(rows, 2)
assert len(chunks) == 2
assert len(chunks[0]) == 50
assert len(chunks[1]) == 50
def test_split_rows_uneven():
rows = [(str(i), "N") for i in range(10)]
chunks = split_rows(rows, 3)
assert len(chunks) == 3
assert sum(len(c) for c in chunks) == 10
assert [len(c) for c in chunks] == [4, 3, 3]
def test_roundtrip_xlsx():
rows = [("RAD-1", "900"), ("RAD-2", "901")]
data = rows_to_xlsx_bytes(rows)
parsed = parse_radicado_rows(data, "shard.xlsx")
assert parsed == rows
def test_split_more_workers_than_rows():
rows = [("A", "1"), ("B", "2")]
chunks = split_rows(rows, 5)
assert len(chunks) == 2