106 lines
2.4 KiB
Python
106 lines
2.4 KiB
Python
"""
|
|
Pytest configuration and fixtures for pyPhotoAlbum tests
|
|
"""
|
|
|
|
import pytest
|
|
import tempfile
|
|
import os
|
|
from pathlib import Path
|
|
from PIL import Image
|
|
from pyPhotoAlbum.models import ImageData, PlaceholderData, TextBoxData
|
|
from pyPhotoAlbum.page_layout import PageLayout, GridLayout
|
|
from pyPhotoAlbum.project import Project, Page
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_image_file():
|
|
"""Create a temporary test image file"""
|
|
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as f:
|
|
# Create a simple test image
|
|
img = Image.new('RGB', (100, 100), color='red')
|
|
img.save(f.name)
|
|
yield f.name
|
|
# Cleanup
|
|
try:
|
|
os.unlink(f.name)
|
|
except:
|
|
pass
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_dir():
|
|
"""Create a temporary directory for tests"""
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
yield tmpdir
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_image_data(temp_image_file):
|
|
"""Create a sample ImageData instance"""
|
|
return ImageData(
|
|
image_path=temp_image_file,
|
|
x=10.0,
|
|
y=20.0,
|
|
width=100.0,
|
|
height=150.0
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_placeholder_data():
|
|
"""Create a sample PlaceholderData instance"""
|
|
return PlaceholderData(
|
|
placeholder_type="image",
|
|
x=50.0,
|
|
y=60.0,
|
|
width=200.0,
|
|
height=150.0
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_textbox_data():
|
|
"""Create a sample TextBoxData instance"""
|
|
return TextBoxData(
|
|
text_content="Sample Text",
|
|
x=30.0,
|
|
y=40.0,
|
|
width=150.0,
|
|
height=50.0
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_page_layout():
|
|
"""Create a sample PageLayout instance"""
|
|
layout = PageLayout()
|
|
return layout
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_grid_layout():
|
|
"""Create a sample GridLayout instance"""
|
|
return GridLayout(rows=2, columns=2, spacing=10.0)
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_page(sample_page_layout):
|
|
"""Create a sample Page instance"""
|
|
return Page(layout=sample_page_layout, page_number=1)
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_project():
|
|
"""Create a sample Project instance"""
|
|
return Project(name="Test Project")
|
|
|
|
|
|
@pytest.fixture
|
|
def populated_page_layout(sample_image_data, sample_placeholder_data, sample_textbox_data):
|
|
"""Create a page layout populated with various elements"""
|
|
layout = PageLayout()
|
|
layout.add_element(sample_image_data)
|
|
layout.add_element(sample_placeholder_data)
|
|
layout.add_element(sample_textbox_data)
|
|
return layout
|