- Remove build artifacts from git tracking (build/, dist/, __pycache__/, *.spec) - Updated .gitignore to properly exclude generated files - Added old_code/ documentation folder - Updated sample_data.txt to show new 5-field format - Exclude user-specific conf/app.conf from tracking
160 lines
4.7 KiB
Python
160 lines
4.7 KiB
Python
"""
|
|
Test SVG template functionality
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
# Import the PDF generator
|
|
from print_label_pdf import PDFLabelGenerator
|
|
|
|
def test_svg_template():
|
|
"""Test SVG template with sample data"""
|
|
print("=== Testing SVG Template Functionality ===\n")
|
|
|
|
# Check if template exists
|
|
template_path = os.path.join('conf', 'label_template.svg')
|
|
if not os.path.exists(template_path):
|
|
print(f"❌ Template not found: {template_path}")
|
|
return False
|
|
|
|
print(f"✓ Template found: {template_path}")
|
|
|
|
# Sample data
|
|
test_data = {
|
|
'Article': 'COM-2024-001',
|
|
'NrArt': 'ART-12345',
|
|
'Serial': 'SN-20260212-001'
|
|
}
|
|
|
|
print(f"✓ Test data: {test_data}")
|
|
|
|
# Create generator
|
|
generator = PDFLabelGenerator()
|
|
print("✓ PDF generator initialized")
|
|
|
|
# Test SVG template method
|
|
print("\n--- Testing SVG Template Method ---")
|
|
try:
|
|
pdf_output = 'test_label_svg.pdf'
|
|
result = generator.create_label_from_svg_template(
|
|
template_path,
|
|
test_data,
|
|
filename=pdf_output
|
|
)
|
|
|
|
if result and os.path.exists(pdf_output):
|
|
file_size = os.path.getsize(pdf_output)
|
|
print(f"✓ SVG template PDF created: {pdf_output} ({file_size} bytes)")
|
|
return True
|
|
else:
|
|
print("❌ SVG template PDF creation failed")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def test_programmatic_layout():
|
|
"""Test programmatic layout (fallback)"""
|
|
print("\n--- Testing Programmatic Layout (Fallback) ---")
|
|
|
|
generator = PDFLabelGenerator()
|
|
|
|
try:
|
|
pdf_output = 'test_label_programmatic.pdf'
|
|
result = generator.create_label_pdf(
|
|
comanda='COM-2024-001',
|
|
article='ART-12345',
|
|
serial='SN-20260212-001',
|
|
filename=pdf_output,
|
|
image_path=os.path.join('conf', 'accepted.png')
|
|
)
|
|
|
|
if result and os.path.exists(pdf_output):
|
|
file_size = os.path.getsize(pdf_output)
|
|
print(f"✓ Programmatic layout PDF created: {pdf_output} ({file_size} bytes)")
|
|
return True
|
|
else:
|
|
print("❌ Programmatic layout PDF creation failed")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def test_wrapper_functions():
|
|
"""Test convenience wrapper functions"""
|
|
print("\n--- Testing Wrapper Functions ---")
|
|
|
|
from print_label_pdf import create_label_pdf_simple, create_label_pdf_file
|
|
|
|
# Test data string
|
|
test_string = "COM-2024-001;ART-12345;SN-20260212-001"
|
|
|
|
try:
|
|
# Test create_label_pdf_simple (returns bytes)
|
|
print("Testing create_label_pdf_simple()...")
|
|
pdf_bytes = create_label_pdf_simple(test_string)
|
|
if pdf_bytes:
|
|
print(f"✓ create_label_pdf_simple returned {len(pdf_bytes)} bytes")
|
|
else:
|
|
print("❌ create_label_pdf_simple failed")
|
|
return False
|
|
|
|
# Test create_label_pdf_file (returns filename)
|
|
print("Testing create_label_pdf_file()...")
|
|
pdf_file = create_label_pdf_file(test_string, filename='test_label_wrapper.pdf')
|
|
if pdf_file and os.path.exists(pdf_file):
|
|
file_size = os.path.getsize(pdf_file)
|
|
print(f"✓ create_label_pdf_file created: {pdf_file} ({file_size} bytes)")
|
|
return True
|
|
else:
|
|
print("❌ create_label_pdf_file failed")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
if __name__ == '__main__':
|
|
print("SVG Template Test Suite\n")
|
|
print("=" * 50)
|
|
|
|
results = []
|
|
|
|
# Test 1: SVG template
|
|
results.append(("SVG Template", test_svg_template()))
|
|
|
|
# Test 2: Programmatic layout
|
|
results.append(("Programmatic Layout", test_programmatic_layout()))
|
|
|
|
# Test 3: Wrapper functions
|
|
results.append(("Wrapper Functions", test_wrapper_functions()))
|
|
|
|
# Summary
|
|
print("\n" + "=" * 50)
|
|
print("SUMMARY")
|
|
print("=" * 50)
|
|
|
|
for test_name, passed in results:
|
|
status = "✓ PASS" if passed else "❌ FAIL"
|
|
print(f"{status}: {test_name}")
|
|
|
|
total = len(results)
|
|
passed = sum(1 for _, p in results if p)
|
|
|
|
print(f"\nTotal: {passed}/{total} tests passed")
|
|
|
|
if passed == total:
|
|
print("\n🎉 All tests passed!")
|
|
sys.exit(0)
|
|
else:
|
|
print("\n⚠ Some tests failed")
|
|
sys.exit(1)
|