se reorganiza tests/ y se agrega suite pytest
Los scripts manuales pasan a tools/ y los correos de ejemplo a tests/fixtures/. Suite de 95 pruebas: caracterización de la extracción sobre los 46 correos (resultados esperados en tests/golden/, fuera de la carpeta que descargar_correos_prueba borra), unitarias de draft_sap, notificaciones, documentos, adjuntos y config_validator, y flujo completo de _procesar_un_correo con SAP/HANA/Outlook simulados. pytest como dependencia dev y configuración en pyproject.toml. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b1b6f70983
commit
1d6d869111
261 files changed
+7876
-7
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import os
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
from sunat_schema import NAMESPACES, _find_text
|
||||
|
||||
ns = NAMESPACES
|
||||
ns["cbc"] = "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
|
||||
|
||||
CARPETA_BASE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "tests", "fixtures", "correos_prueba")
|
||||
|
||||
|
||||
def explorar_notes(ruta_carpeta):
|
||||
archivos = sorted(
|
||||
os.path.join(ruta_carpeta, f) for f in os.listdir(ruta_carpeta)
|
||||
if f.lower().endswith(".xml") and os.path.isfile(os.path.join(ruta_carpeta, f))
|
||||
)
|
||||
|
||||
for xml_path in archivos:
|
||||
tree = ET.parse(xml_path)
|
||||
root = tree.getroot()
|
||||
|
||||
if "Invoice" not in root.tag:
|
||||
continue
|
||||
|
||||
tipo = _find_text(root, "inv:InvoiceTypeCode", ns) or _find_text(root, "cbc:InvoiceTypeCode", ns) or ""
|
||||
if tipo != "01":
|
||||
continue
|
||||
|
||||
print(f"\n=== {os.path.basename(xml_path)} ===")
|
||||
lineas = root.findall(".//cac:InvoiceLine", ns)
|
||||
for i, linea in enumerate(lineas):
|
||||
notes = linea.findall("cbc:Note", ns)
|
||||
desc = _find_text(linea, "cac:Item/cbc:Description", ns) or ""
|
||||
print(f" Línea {i}: Description={desc[:80]}...")
|
||||
for note in notes:
|
||||
print(f" Note[{note.attrib.get('languageLocaleID', '?')}]: {note.text}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
carpeta = sys.argv[1] if len(sys.argv) > 1 else "001_correo"
|
||||
ruta = os.path.join(CARPETA_BASE, carpeta)
|
||||
if os.path.isdir(ruta):
|
||||
explorar_notes(ruta)
|
||||
else:
|
||||
print(f"❌ Carpeta no encontrada: {ruta}")
|
||||
Reference in new issue
Block a user