feat: Enhance CSV cleaning and management functionalities by adding new date normalization rules, improving document type homologation, and implementing robust sanitization for CSV cell values. Update GUI components to support loading indicators and status messages during CSV processing, ensuring a smoother user experience.

This commit is contained in:
erik
2026-05-04 01:54:06 -05:00
parent 37d32a5a96
commit e2536380d4
7 changed files with 864 additions and 72 deletions
+52
View File
@@ -0,0 +1,52 @@
from __future__ import annotations
import tempfile
from pathlib import Path
from application.csv_manager import CSVManager, sanitize_csv_cell_value
def test_sanitize_collapses_newlines() -> None:
assert sanitize_csv_cell_value("a\nb") == "a b"
assert sanitize_csv_cell_value("a\r\nb") == "a b"
assert sanitize_csv_cell_value(" x\v\fy ") == "x y"
def test_sanitize_unicode_line_separators() -> None:
assert sanitize_csv_cell_value("a\u2028b\u2029c") == "a b c"
assert sanitize_csv_cell_value("a\x85b") == "a b"
def test_sanitize_preserves_none_and_scalars() -> None:
assert sanitize_csv_cell_value(None) is None
assert sanitize_csv_cell_value(42) == 42
assert sanitize_csv_cell_value(3.14) == 3.14
assert sanitize_csv_cell_value(False) is False
assert sanitize_csv_cell_value(True) is True
def test_sanitize_plain_string_unchanged_identity() -> None:
s = "sin saltos"
assert sanitize_csv_cell_value(s) is s
def test_append_rows_one_physical_line_per_record() -> None:
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "batch.csv"
mgr = CSVManager()
header = ["radicado", "descripcion"]
rows = [
{
"radicado": "235662283",
"descripcion": (
'"Las retenciones son a nivel informativo.\n'
"Paciente: 1010079549 - HERAZO\n"
'Contrato No. URGENCIAS."'
),
},
{"radicado": "2", "descripcion": "ok"},
]
mgr.append_rows(str(path), rows, header)
text = path.read_text(encoding="utf-8")
physical_lines = text.splitlines()
assert len(physical_lines) == 3