feat: issue/0020 — generacion de PDFs en Python y Go
Añade 3 tipos Python (PDFDoc, PDFPage, PDFStyle) y 10 funciones Python para construir PDFs con fpdf2 (builder fluent), fusionar PDFs con pypdf y convertir HTML/Markdown a PDF via weasyprint (stub si no disponible). Añade pdf_simple_report en Go como stub hasta que go-pdf/fpdf se integre. - python/types/infra/: pdf_doc, pdf_page, pdf_style - python/functions/infra/: pdf_create, pdf_add_page, pdf_add_text, pdf_add_table, pdf_add_image, pdf_add_header_footer, pdf_from_html, pdf_from_markdown, pdf_merge, pdf_save - functions/infra/pdf_simple_report.go: stub Go con ReportSection/ReportTable - 17 tests Python pasando (pytest) - fpdf2 y pypdf añadidos via uv al venv Python Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Tests para pdf_add_text."""
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "python", "types", "infra"))
|
||||
|
||||
from pdf_create import pdf_create
|
||||
from pdf_add_page import pdf_add_page
|
||||
from pdf_add_text import pdf_add_text
|
||||
from pdf_save import pdf_save
|
||||
from pdf_doc import PDFDoc
|
||||
from pdf_style import PDFStyle
|
||||
|
||||
|
||||
def test_texto_simple_con_estilo_defecto():
|
||||
doc = pdf_create(title="Test")
|
||||
doc = pdf_add_page(doc)
|
||||
doc = pdf_add_text(doc, "Hola mundo")
|
||||
assert isinstance(doc, PDFDoc)
|
||||
# El PDF debe ser valido
|
||||
pdf_bytes = pdf_save(doc)
|
||||
assert pdf_bytes[:4] == b"%PDF"
|
||||
|
||||
|
||||
def test_texto_con_estilo_personalizado_bold_centrado():
|
||||
doc = pdf_create()
|
||||
doc = pdf_add_page(doc)
|
||||
style = PDFStyle(font_family="Helvetica-Bold", font_size=18.0, alignment="center", color="#FF0000")
|
||||
doc = pdf_add_text(doc, "Titulo en Rojo", style=style)
|
||||
pdf_bytes = pdf_save(doc)
|
||||
assert pdf_bytes[:4] == b"%PDF"
|
||||
|
||||
|
||||
def test_texto_multilinea_con_saltos():
|
||||
doc = pdf_create()
|
||||
doc = pdf_add_page(doc)
|
||||
doc = pdf_add_text(doc, "Linea 1\nLinea 2\nLinea 3")
|
||||
pdf_bytes = pdf_save(doc)
|
||||
assert pdf_bytes[:4] == b"%PDF"
|
||||
assert len(pdf_bytes) > 100
|
||||
Reference in New Issue
Block a user