| | """ |
| | Generate test fixtures for file parser tests |
| | Author: @mangubee |
| | """ |
| |
|
| | from pathlib import Path |
| |
|
| | |
| | |
| | |
| | FIXTURES_DIR = Path(__file__).parent |
| |
|
| | |
| | |
| | |
| | def generate_pdf(): |
| | """Generate sample PDF file using fpdf""" |
| | try: |
| | from fpdf import FPDF |
| | except ImportError: |
| | print("Skipping PDF generation (fpdf not installed)") |
| | return |
| |
|
| | pdf = FPDF() |
| | pdf.add_page() |
| | pdf.set_font("Arial", size=12) |
| | pdf.cell(200, 10, txt="Test PDF Document", ln=True) |
| | pdf.cell(200, 10, txt="This is page 1 content.", ln=True) |
| | pdf.add_page() |
| | pdf.cell(200, 10, txt="Page 2", ln=True) |
| | pdf.cell(200, 10, txt="This is page 2 content.", ln=True) |
| |
|
| | pdf_path = FIXTURES_DIR / "sample.pdf" |
| | pdf.output(str(pdf_path)) |
| |
|
| | print(f"Created: {pdf_path}") |
| |
|
| |
|
| | |
| | |
| | |
| | def generate_excel(): |
| | """Generate sample Excel file""" |
| | from openpyxl import Workbook |
| |
|
| | wb = Workbook() |
| |
|
| | |
| | ws1 = wb.active |
| | ws1.title = "Data" |
| | ws1.append(["Product", "Price", "Quantity"]) |
| | ws1.append(["Apple", 1.50, 100]) |
| | ws1.append(["Banana", 0.75, 150]) |
| | ws1.append(["Orange", 2.00, 80]) |
| |
|
| | |
| | ws2 = wb.create_sheet("Summary") |
| | ws2.append(["Total Products", 3]) |
| | ws2.append(["Total Quantity", 330]) |
| |
|
| | excel_path = FIXTURES_DIR / "sample.xlsx" |
| | wb.save(excel_path) |
| |
|
| | print(f"Created: {excel_path}") |
| |
|
| |
|
| | |
| | |
| | |
| | def generate_word(): |
| | """Generate sample Word document""" |
| | from docx import Document |
| |
|
| | doc = Document() |
| | doc.add_heading("Test Word Document", 0) |
| | doc.add_paragraph("This is the first paragraph.") |
| | doc.add_paragraph("This is the second paragraph with some content.") |
| | doc.add_heading("Section 2", level=1) |
| | doc.add_paragraph("Content in section 2.") |
| |
|
| | word_path = FIXTURES_DIR / "sample.docx" |
| | doc.save(word_path) |
| |
|
| | print(f"Created: {word_path}") |
| |
|
| |
|
| | |
| | |
| | |
| | if __name__ == "__main__": |
| | print("Generating test fixtures...") |
| | generate_pdf() |
| | generate_excel() |
| | generate_word() |
| | print("All fixtures generated successfully!") |
| |
|