Download tasks/data/forward/abehmiel__pyedgeon.6090025/tests/test_patch.diff from Lego-X/ProgramGen: direct link, hf CLI and curl.
- Browser
- Download file 75.5 kB
-
https://huggingface.co/datasets/Lego-X/ProgramGen/resolve/main/tasks/data/forward/abehmiel__pyedgeon.6090025/tests/test_patch.diff
- Command line
-
hf download hf://datasets/Lego-X/ProgramGen/tasks/data/forward/abehmiel__pyedgeon.6090025/tests/test_patch.diff
-
curl -L -o test_patch.diff https://huggingface.co/datasets/Lego-X/ProgramGen/resolve/main/tasks/data/forward/abehmiel__pyedgeon.6090025/tests/test_patch.diff
75.5 kB
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1,11 @@
+"""
+Pyedgeon test suite.
+
+This package contains comprehensive tests for the pyedgeon library including:
+- Unit tests for individual methods
+- Integration tests for the full pipeline
+- Security tests for vulnerability detection
+- Performance tests and benchmarks
+"""
+
+__version__ = "1.0.0"
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,195 @@
+"""
+Pytest configuration and shared fixtures for pyedgeon test suite.
+
+This module provides common test fixtures, utilities, and configuration
+for all test modules in the pyedgeon test suite.
+"""
+
+import os
+import sys
+import tempfile
+import shutil
+from pathlib import Path
+import pytest
+from PIL import Image
+
+# Add parent directory to path to import pyedgeon
+sys.path.insert(0, str(Path(__file__).parent.parent))
+
+from pyedgeon import Pyedgeon
+
+
+@pytest.fixture
+def temp_dir():
+ """
+ Provides a temporary directory for test file outputs.
+ Automatically cleaned up after test completion.
+ """
+ temp_path = tempfile.mkdtemp()
+ yield temp_path
+ # Cleanup after test
+ if os.path.exists(temp_path):
+ shutil.rmtree(temp_path)
+
+
+@pytest.fixture
+def font_path():
+ """
+ Provides a path to a TrueType font for testing.
+ Users must provide their own font file - pyedgeon does not bundle fonts.
+
+ Tests will be skipped if no suitable font is found.
+ Looks for fonts in common system locations.
+ """
+ # Check common system font locations
+ possible_fonts = [
+ # macOS
+ "/System/Library/Fonts/Supplemental/Arial.ttf",
+ "/System/Library/Fonts/Helvetica.ttc",
+ # Linux
+ "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
+ "/usr/share/fonts/liberation/LiberationSans-Regular.ttf",
+ # Windows
+ "C:\\Windows\\Fonts\\arial.ttf",
+ ]
+
+ for font_file in possible_fonts:
+ if Path(font_file).exists():
+ return str(font_file)
+
+ pytest.skip("No suitable system font found for testing. Pyedgeon does not bundle fonts.")
+
+
+@pytest.fixture
+def default_pyedgeon(font_path, temp_dir):
+ """
+ Creates a Pyedgeon instance with safe default settings for testing.
+ Uses the bundled font and a temporary directory.
+ """
+ return Pyedgeon(
+ illusion_text="TEST",
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=6,
+ img_side=512 # Smaller for faster tests
+ )
+
+
+@pytest.fixture
+def minimal_pyedgeon(font_path, temp_dir):
+ """
+ Creates a minimal Pyedgeon instance for quick tests.
+ Uses smallest viable settings for performance.
+ """
+ return Pyedgeon(
+ illusion_text="HI",
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=2,
+ img_side=256 # Very small for speed
+ )
+
+
+@pytest.fixture
+def sample_colors():
+ """
+ Provides a set of valid color tuples for testing.
+ """
+ return {
+ 'black': (0, 0, 0),
+ 'white': (255, 255, 255),
+ 'red': (255, 0, 0),
+ 'green': (0, 255, 0),
+ 'blue': (0, 0, 255),
+ 'gray': (128, 128, 128),
+ }
+
+
+@pytest.fixture
+def fake_font_file(temp_dir):
+ """
+ Creates a fake (non-functional) font file for path validation testing.
+ """
+ fake_font = Path(temp_dir) / "fake_font.ttf"
+ fake_font.write_bytes(b"not a real font")
+ return str(fake_font)
+
+
+@pytest.fixture
+def malicious_paths():
+ """
+ Provides a collection of potentially malicious file paths for security testing.
+ """
+ return [
+ "../../../etc/passwd",
+ "..\\..\\..\\windows\\system32\\config\\sam",
+ "/etc/shadow",
+ "C:\\Windows\\System32\\config\\SAM",
+ "./../sensitive_data.txt",
+ "~/../../root/.ssh/id_rsa",
+ "file:///etc/passwd",
+ "\x00malicious.txt", # Null byte injection
+ "normal_path\x00../../etc/passwd",
+ ]
+
+
+@pytest.fixture
+def long_text_samples():
+ """
+ Provides text samples of various lengths for boundary testing.
+ """
+ return {
+ 'empty': '',
+ 'single': 'A',
+ 'normal': 'HELLO WORLD',
+ 'max_length': 'A' * 22,
+ 'over_limit': 'A' * 50,
+ 'very_long': 'A' * 1000,
+ }
+
+
+def assert_valid_image(file_path, expected_size=None):
+ """
+ Helper function to assert that a file is a valid image.
+
+ Args:
+ file_path: Path to the image file
+ expected_size: Optional tuple (width, height) to verify image dimensions
+ """
+ assert os.path.exists(file_path), f"Image file does not exist: {file_path}"
+ assert os.path.getsize(file_path) > 0, f"Image file is empty: {file_path}"
+
+ # Try to open with PIL to verify it's a valid image
+ try:
+ with Image.open(file_path) as img:
+ if expected_size:
+ assert img.size == expected_size, \
+ f"Image size {img.size} does not match expected {expected_size}"
+ # Verify image is not completely blank
+ extrema = img.convert('L').getextrema()
+ assert extrema[0] != extrema[1] or extrema[0] != 255, \
+ "Image appears to be completely blank"
+ except Exception as e:
+ pytest.fail(f"Failed to validate image {file_path}: {e}")
+
+
+def count_pixels_by_color(image, color):
+ """
+ Counts the number of pixels of a specific color in an image.
+
+ Args:
+ image: PIL Image object
+ color: Tuple of RGB values
+
+ Returns:
+ int: Count of pixels matching the color
+ """
+ if image.mode != 'RGB':
+ image = image.convert('RGB')
+
+ pixels = list(image.getdata())
+ return pixels.count(color)
+
+
+# Export helper functions so tests can use them
+__all__ = ['assert_valid_image', 'count_pixels_by_color']
diff --git a/tests/test_image_generation.py b/tests/test_image_generation.py
new file mode 100644
--- /dev/null
+++ b/tests/test_image_generation.py
@@ -0,0 +1,662 @@
+"""
+Integration and functional tests for Pyedgeon image generation.
+
+Tests cover:
+- Full image generation pipeline
+- Individual method functionality
+- Image quality and correctness
+- Error conditions
+- Edge cases
+"""
+
+import os
+import pytest
+from pathlib import Path
+from PIL import Image
+from pyedgeon import Pyedgeon
+from .conftest import assert_valid_image
+
+
+class TestImageGeneration:
+ """Test the complete image generation pipeline."""
+
+ def test_create_basic_image(self, minimal_pyedgeon):
+ """Test creating a basic image with minimal settings."""
+ p = minimal_pyedgeon
+
+ # Run the full pipeline
+ p.create()
+
+ # Verify file was created
+ output_path = p.get_file_path()
+ assert_valid_image(output_path, expected_size=(p.img_side, p.img_side))
+
+ def test_create_with_custom_text(self, font_path, temp_dir):
+ """Test creating image with custom text."""
+ custom_text = "TESTING"
+ p = Pyedgeon(
+ illusion_text=custom_text,
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=256
+ )
+
+ p.create()
+
+ output_path = p.get_file_path()
+ assert_valid_image(output_path)
+ assert p.illusion_text == custom_text
+
+ def test_create_with_colors(self, font_path, temp_dir, sample_colors):
+ """Test that custom colors can be used (syntax error fixed)."""
+ # The key test is that alpha_to_white() no longer has the syntax error
+ # Full image creation is tested in other tests
+ p = Pyedgeon(
+ illusion_text="A",
+ font_path=font_path,
+ file_path=temp_dir,
+ text_color=sample_colors['red'],
+ background_color=sample_colors['blue'],
+ img_side=256,
+ num_rotations=2
+ )
+
+ # Verify colors were set correctly
+ assert p.text_color == sample_colors['red']
+ assert p.background_color == sample_colors['blue']
+
+ # The syntax error that prevented this from working has been fixed
+ # (alpha_to_white used to have: self.background_color (255, )
+ # instead of: self.background_color + (255, ))
+
+ def test_create_different_sizes(self, font_path, temp_dir):
+ """Test creating images of different sizes."""
+ sizes = [128, 256, 512, 1024]
+
+ for size in sizes:
+ p = Pyedgeon(
+ illusion_text="SIZE",
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name=f"size_test_{size}",
+ img_side=size
+ )
+
+ p.create()
+
+ output_path = p.get_file_path()
+ assert_valid_image(output_path, expected_size=(size, size))
+
+ def test_create_with_different_rotations(self, font_path, temp_dir):
+ """Test creating images with different rotation counts."""
+ rotations = [2, 4, 6, 8]
+
+ for num_rot in rotations:
+ p = Pyedgeon(
+ illusion_text="ROTATE",
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name=f"rotation_test_{num_rot}",
+ num_rotations=num_rot,
+ img_side=256
+ )
+
+ p.create()
+
+ output_path = p.get_file_path()
+ assert_valid_image(output_path)
+
+ def test_create_with_long_text_truncation(self, font_path, temp_dir):
+ """Test that long text is handled via truncation to charmax."""
+ long_text = "THIS IS A VERY LONG TEXT THAT SHOULD BE TRUNCATED"
+ p = Pyedgeon(
+ illusion_text=long_text,
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=256
+ )
+
+ p.create()
+
+ # Text should be truncated to charmax (default is 22, not hardcoded 20)
+ assert len(p.illusion_text) == 22
+ output_path = p.get_file_path()
+ assert_valid_image(output_path)
+
+
+class TestCheckLength:
+ """Test the check_length() method."""
+
+ def test_check_length_within_limit(self, default_pyedgeon):
+ """Test text within character limit is not truncated."""
+ p = default_pyedgeon
+ p.illusion_text = "SHORT"
+ original_length = len(p.illusion_text)
+
+ p.check_length()
+
+ assert len(p.illusion_text) == original_length
+
+ def test_check_length_at_limit(self, default_pyedgeon):
+ """Test text at exactly charmax limit."""
+ p = default_pyedgeon
+ p.charmax = 10
+ p.illusion_text = "A" * 10
+
+ p.check_length()
+
+ assert len(p.illusion_text) == 10
+
+ def test_check_length_over_limit(self, default_pyedgeon):
+ """Test text over limit is truncated to charmax (bug fixed)."""
+ p = default_pyedgeon
+ p.charmax = 10
+ p.illusion_text = "A" * 30
+
+ p.check_length()
+
+ # Bug fixed: now correctly truncates to charmax instead of hardcoded 20
+ assert len(p.illusion_text) == 10
+
+ # Warning is logged (not printed to stdout)
+
+ def test_check_length_empty_string(self, default_pyedgeon):
+ """Test check_length with empty string."""
+ p = default_pyedgeon
+ p.illusion_text = ""
+
+ # Empty string now properly raises ValidationError
+ with pytest.raises(Exception):
+ p.check_length()
+
+
+class TestEstimateFontSize:
+ """Test the estimate_font_size() method."""
+
+ def test_estimate_font_size_basic(self, default_pyedgeon):
+ """Test basic font size estimation."""
+ p = default_pyedgeon
+ p.illusion_text = "HELLO"
+
+ p.estimate_font_size()
+
+ assert p.font_size_guess is not None
+ assert isinstance(p.font_size_guess, int)
+ assert 60 <= p.font_size_guess <= 220
+
+ def test_estimate_font_size_narrow_chars(self, default_pyedgeon):
+ """Test font size estimation with narrow characters."""
+ p = default_pyedgeon
+ p.illusion_text = "IIIIII" # Narrow characters
+
+ p.estimate_font_size()
+
+ # Narrow characters should result in larger font size
+ assert p.font_size_guess is not None
+
+ def test_estimate_font_size_wide_chars(self, default_pyedgeon):
+ """Test font size estimation with wide characters."""
+ p = default_pyedgeon
+ p.illusion_text = "WWWWWW" # Wide characters
+
+ p.estimate_font_size()
+
+ # Wide characters should result in smaller font size
+ assert p.font_size_guess is not None
+
+ def test_estimate_font_size_mixed_chars(self, default_pyedgeon):
+ """Test font size estimation with mixed character widths."""
+ p = default_pyedgeon
+ p.illusion_text = "HELLO WORLD"
+
+ p.estimate_font_size()
+
+ assert p.font_size_guess is not None
+ assert 60 <= p.font_size_guess <= 220
+
+ def test_estimate_font_size_digits(self, default_pyedgeon):
+ """Test font size estimation with digits."""
+ p = default_pyedgeon
+ p.illusion_text = "123456"
+
+ p.estimate_font_size()
+
+ assert p.font_size_guess is not None
+
+ def test_estimate_font_size_special_chars(self, default_pyedgeon):
+ """Test font size estimation with special characters."""
+ p = default_pyedgeon
+ p.illusion_text = "!@#$%^"
+
+ p.estimate_font_size()
+
+ assert p.font_size_guess is not None
+
+ def test_estimate_font_size_bounds(self, default_pyedgeon):
+ """Test that estimate_font_size respects min/max bounds."""
+ test_cases = [
+ ("I" * 50, 60), # Very long narrow text -> minimum 60
+ ("W", 220), # Very short wide text -> maximum 220
+ ]
+
+ for text, expected_bound in test_cases:
+ p = default_pyedgeon
+ p.illusion_text = text
+ p.estimate_font_size()
+
+ # Should be clamped to bounds
+ assert 60 <= p.font_size_guess <= 220
+
+
+class TestDrawClear:
+ """Test the draw_clear() method."""
+
+ def test_draw_clear_creates_images(self, default_pyedgeon):
+ """Test that draw_clear creates all required image objects."""
+ p = default_pyedgeon
+
+ p.draw_clear()
+
+ # Verify all image objects are created
+ assert hasattr(p, 'raw_img')
+ assert hasattr(p, 'img')
+ assert hasattr(p, 'circle_img')
+ assert hasattr(p, 'full_image')
+ assert hasattr(p, 'draw')
+
+ # Verify they are PIL Image objects
+ assert isinstance(p.raw_img, Image.Image)
+ assert isinstance(p.img, Image.Image)
+ assert isinstance(p.circle_img, Image.Image)
+ assert isinstance(p.full_image, Image.Image)
+
+ def test_draw_clear_correct_sizes(self, default_pyedgeon):
+ """Test that draw_clear creates images with correct sizes."""
+ p = default_pyedgeon
+
+ p.draw_clear()
+
+ assert p.raw_img.size == p.img_size_text
+ assert p.img.size == p.img_size
+ assert p.circle_img.size == p.img_size
+ assert p.full_image.size == p.img_size
+
+ def test_draw_clear_correct_modes(self, default_pyedgeon):
+ """Test that draw_clear creates images with correct modes."""
+ p = default_pyedgeon
+
+ p.draw_clear()
+
+ assert p.raw_img.mode == "RGB"
+ assert p.img.mode == "RGBA"
+ assert p.circle_img.mode == "RGBA"
+ assert p.full_image.mode == "RGBA"
+
+ def test_draw_clear_background_colors(self, default_pyedgeon):
+ """Test that images are initialized with background color."""
+ p = default_pyedgeon
+
+ p.draw_clear()
+
+ # Check that images start with background color
+ # Sample a pixel from the center
+ center_x, center_y = p.img_side // 2, p.img_side // 2
+
+ raw_pixel = p.raw_img.getpixel((center_x, center_y))
+ assert raw_pixel == p.background_color
+
+ img_pixel = p.img.getpixel((center_x, center_y))
+ assert img_pixel[:3] == p.background_color
+
+
+class TestGetFontsize:
+ """Test the get_fontsize() method."""
+
+ def test_get_fontsize_basic(self, default_pyedgeon):
+ """Test basic font size calculation."""
+ p = default_pyedgeon
+ p.illusion_text = "TEST"
+
+ p.estimate_font_size()
+ p.draw_clear()
+ font_size, boundingbox = p.get_fontsize()
+
+ assert font_size is not None
+ assert boundingbox is not None
+ assert p.font_size == font_size
+ assert p.boundingbox == boundingbox
+
+ def test_get_fontsize_creates_font(self, default_pyedgeon):
+ """Test that get_fontsize creates font object."""
+ p = default_pyedgeon
+ p.illusion_text = "TEST"
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+
+ assert hasattr(p, 'font')
+ assert p.font is not None
+
+ def test_get_fontsize_different_texts(self, default_pyedgeon):
+ """Test font size calculation with different texts."""
+ texts = ["A", "HELLO", "TESTING LONGER"]
+
+ for text in texts:
+ p = default_pyedgeon
+ p.illusion_text = text
+
+ p.estimate_font_size()
+ p.draw_clear()
+ font_size, _ = p.get_fontsize()
+
+ assert font_size is not None
+ assert font_size > 0
+
+ def test_get_fontsize_bounding_box(self, default_pyedgeon):
+ """Test that bounding box is calculated."""
+ p = default_pyedgeon
+ p.illusion_text = "TEST"
+
+ p.estimate_font_size()
+ p.draw_clear()
+ _, boundingbox = p.get_fontsize()
+
+ assert len(boundingbox) == 4
+ assert all(isinstance(x, int) for x in boundingbox)
+ # boundingbox = getbbox() offset by -crop_width, so the left/top edge can
+ # sit up to crop_width left/above origin depending on the font's side bearing
+ # (e.g. DejaVu on Linux yields -1). Upper bound stays within the image.
+ assert -p.crop_width_x <= boundingbox[0] < p.img_side
+ assert -p.crop_width_y <= boundingbox[1] < p.img_side
+
+
+class TestDrawFrame:
+ """Test the draw_frame() method."""
+
+ def test_draw_frame_basic(self, minimal_pyedgeon):
+ """Test basic frame drawing."""
+ p = minimal_pyedgeon
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+ p.draw_frame()
+
+ # Verify images are modified
+ assert p.raw_img is not None
+ assert p.scaled_img is not None
+
+ def test_draw_frame_creates_scaled_image(self, minimal_pyedgeon):
+ """Test that draw_frame creates scaled image."""
+ p = minimal_pyedgeon
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+ p.draw_frame()
+
+ assert hasattr(p, 'scaled_img')
+ assert p.scaled_img.size == (p.img_side, p.img_side)
+
+ def test_draw_frame_alpha_channel(self, minimal_pyedgeon):
+ """Test that draw_frame properly handles alpha channel."""
+ p = minimal_pyedgeon
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+ p.draw_frame()
+
+ # Image should have alpha channel
+ assert p.img.mode == "RGBA"
+
+ # Some pixels should be transparent (alpha = 0)
+ pixels = list(p.img.getdata())
+ transparent_pixels = [px for px in pixels if px[3] == 0]
+ assert len(transparent_pixels) > 0
+
+
+class TestStamp:
+ """Test the stamp() method."""
+
+ def test_stamp_basic(self, minimal_pyedgeon):
+ """Test basic stamping functionality."""
+ p = minimal_pyedgeon
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+ p.draw_frame()
+ p.stamp()
+
+ # Verify full_image is modified
+ assert p.full_image is not None
+
+ def test_stamp_rotation_count(self, font_path, temp_dir):
+ """Test stamping with different rotation counts."""
+ rotation_counts = [2, 4, 6, 8]
+
+ for num_rot in rotation_counts:
+ p = Pyedgeon(
+ illusion_text="ROT",
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=num_rot,
+ img_side=256
+ )
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+ p.draw_frame()
+ p.stamp()
+
+ # Verify image was created
+ assert p.full_image is not None
+
+
+class TestAlphaToWhite:
+ """Test the alpha_to_white() method."""
+
+ def test_alpha_to_white_syntax_error(self, minimal_pyedgeon):
+ """Test that alpha_to_white works correctly (syntax error fixed)."""
+ p = minimal_pyedgeon
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+ p.draw_frame()
+ p.stamp()
+
+ # Syntax error has been fixed - should work correctly
+ p.alpha_to_white()
+
+ # Verify the result
+ assert p.full_image is not None
+
+
+class TestSaveImg:
+ """Test the save_img() method."""
+
+ def test_save_img_creates_file(self, minimal_pyedgeon):
+ """Test that save_img creates a file."""
+ p = minimal_pyedgeon
+
+ # Due to syntax error, we can't run full create()
+ # This test documents the expected behavior
+ output_path = p.get_file_path()
+ assert not os.path.exists(output_path)
+
+ def test_save_img_custom_extension(self, font_path, temp_dir):
+ """Test saving with custom file extension."""
+ extensions = [".png", ".jpg", ".bmp"]
+
+ for ext in extensions:
+ p = Pyedgeon(
+ illusion_text="EXT",
+ font_path=font_path,
+ file_path=temp_dir,
+ file_ext=ext,
+ file_name=f"test_ext_{ext[1:]}",
+ img_side=256
+ )
+
+ output_path = p.get_file_path()
+ assert output_path.endswith(ext)
+
+
+class TestGetFilePath:
+ """Test the get_file_path() method."""
+
+ def test_get_file_path_with_custom_path(self, font_path, temp_dir):
+ """Test getting file path with custom directory."""
+ p = Pyedgeon(
+ illusion_text="PATH",
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name="test_file"
+ )
+
+ output_path = p.get_file_path()
+
+ # get_file_path() calls Path.resolve(), which canonicalizes 8.3 short
+ # names on Windows (RUNNER~1 -> runneradmin) and /var -> /private/var on
+ # macOS. Compare against the resolved temp_dir so the check is portable.
+ assert os.path.realpath(temp_dir) in output_path
+ assert "test_file.png" in output_path
+
+ def test_get_file_path_empty_path_uses_cwd(self, font_path):
+ """Test that empty file_path uses current working directory."""
+ p = Pyedgeon(
+ illusion_text="CWD",
+ font_path=font_path,
+ file_path=""
+ )
+
+ output_path = p.get_file_path()
+
+ # Should contain current working directory
+ assert len(output_path) > 0
+
+ def test_get_file_path_includes_extension(self, font_path, temp_dir):
+ """Test that file path includes correct extension."""
+ extensions = [".png", ".jpg", ".gif"]
+
+ for ext in extensions:
+ p = Pyedgeon(
+ illusion_text="EXT",
+ font_path=font_path,
+ file_path=temp_dir,
+ file_ext=ext
+ )
+
+ output_path = p.get_file_path()
+ assert output_path.endswith(ext)
+
+ def test_get_file_path_uses_pathlib(self, font_path, temp_dir):
+ """Test that get_file_path properly uses pathlib."""
+ p = Pyedgeon(
+ illusion_text="PATHLIB",
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name="test"
+ )
+
+ output_path = p.get_file_path()
+
+ # Should be a string (converted from Path)
+ assert isinstance(output_path, str)
+
+ # Should be a valid path
+ path_obj = Path(output_path)
+ assert path_obj.parent.exists()
+
+
+class TestFullPipeline:
+ """Test the complete image generation pipeline."""
+
+ def test_demo_function_exists(self):
+ """Test that demo() function exists and is importable."""
+ from pyedgeon.pyedgeon import demo
+
+ assert callable(demo)
+
+ def test_individual_steps_in_sequence(self, minimal_pyedgeon):
+ """Test running all steps individually in correct sequence."""
+ p = minimal_pyedgeon
+
+ # Step 1: Check length
+ p.check_length()
+ assert len(p.illusion_text) <= p.charmax
+
+ # Step 2: Estimate font size
+ p.estimate_font_size()
+ assert p.font_size_guess is not None
+
+ # Step 3: Draw clear images
+ p.draw_clear()
+ assert p.raw_img is not None
+
+ # Step 4: Get font size
+ p.get_fontsize()
+ assert p.font_size is not None
+
+ # Step 5: Draw frame
+ p.draw_frame()
+ assert p.scaled_img is not None
+
+ # Step 6: Stamp
+ p.stamp()
+ assert p.full_image is not None
+
+ # Step 7: Alpha to white (syntax error has been fixed)
+ p.alpha_to_white()
+
+ # Verify completion
+ assert p.full_image is not None
+
+
+class TestEdgeCases:
+ """Test edge cases and boundary conditions."""
+
+ def test_single_character_text(self, font_path, temp_dir):
+ """Test with single character text."""
+ p = Pyedgeon(
+ illusion_text="A",
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=256
+ )
+
+ p.check_length()
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+
+ assert p.font_size is not None
+
+ def test_maximum_charmax_text(self, font_path, temp_dir):
+ """Test with text at maximum charmax."""
+ max_text = "A" * 22
+ p = Pyedgeon(
+ illusion_text=max_text,
+ font_path=font_path,
+ file_path=temp_dir,
+ charmax=22,
+ img_side=256
+ )
+
+ p.check_length()
+ assert len(p.illusion_text) == 22
+
+ def test_whitespace_only_text(self, font_path, temp_dir):
+ """Test that whitespace-only text is properly rejected."""
+ # Whitespace-only text now properly raises ValidationError during init
+ with pytest.raises(Exception):
+ p = Pyedgeon(
+ illusion_text=" ",
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=256
+ )
diff --git a/tests/test_initialization.py b/tests/test_initialization.py
new file mode 100644
--- /dev/null
+++ b/tests/test_initialization.py
@@ -0,0 +1,382 @@
+"""
+Unit tests for Pyedgeon initialization and parameter validation.
+
+Tests cover:
+- Constructor parameter handling
+- Default value assignments
+- Parameter validation
+- Type checking
+- Boundary conditions
+"""
+
+import pytest
+from pyedgeon import Pyedgeon
+
+
+class TestConstructorDefaults:
+ """Test that constructor sets appropriate default values."""
+
+ def test_default_illusion_text(self, font_path, temp_dir):
+ """Test default illusion text is set and uppercased."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.illusion_text == "HELLO WORLD"
+
+ def test_default_num_rotations(self, font_path, temp_dir):
+ """Test default number of rotations."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.num_rotations == 6
+
+ def test_default_file_ext(self, font_path, temp_dir):
+ """Test default file extension."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.file_ext == ".png"
+
+ def test_default_text_color(self, font_path, temp_dir):
+ """Test default text color is black."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.text_color == (0, 0, 0)
+
+ def test_default_background_color(self, font_path, temp_dir):
+ """Test default background color is white."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.background_color == (255, 255, 255)
+
+ def test_default_img_side(self, font_path, temp_dir):
+ """Test default image side length."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.img_side == 1024
+
+ def test_default_charmax(self, font_path, temp_dir):
+ """Test default character maximum."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.charmax == 22
+
+ def test_default_crop_widths(self, font_path, temp_dir):
+ """Test default crop width values."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.crop_width_x == 14
+ assert p.crop_width_y == 5
+
+ def test_default_darkness_threshold(self, font_path, temp_dir):
+ """Test default darkness threshold."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.darkness_threshold == 116
+
+ def test_default_upper_case(self, font_path, temp_dir):
+ """Test that upper_case defaults to True."""
+ p = Pyedgeon(illusion_text="hello", font_path=font_path, file_path=temp_dir)
+ assert p.illusion_text == "HELLO"
+
+
+class TestTextHandling:
+ """Test text parameter handling and transformations."""
+
+ def test_uppercase_conversion(self, font_path, temp_dir):
+ """Test that text is converted to uppercase by default."""
+ p = Pyedgeon(
+ illusion_text="hello world",
+ font_path=font_path,
+ file_path=temp_dir
+ )
+ assert p.illusion_text == "HELLO WORLD"
+
+ def test_uppercase_disabled(self, font_path, temp_dir):
+ """Test that upper_case=False preserves original case."""
+ p = Pyedgeon(
+ illusion_text="Hello World",
+ font_path=font_path,
+ file_path=temp_dir,
+ upper_case=False
+ )
+ assert p.illusion_text == "Hello World"
+
+ def test_empty_string(self, font_path, temp_dir):
+ """Test that empty string is properly rejected."""
+ import pytest
+ # Validation now rejects empty strings
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ illusion_text="",
+ font_path=font_path,
+ file_path=temp_dir
+ )
+
+ def test_special_characters(self, font_path, temp_dir):
+ """Test handling of special characters."""
+ special_text = "HELLO! @#$%"
+ p = Pyedgeon(
+ illusion_text=special_text,
+ font_path=font_path,
+ file_path=temp_dir
+ )
+ assert p.illusion_text == special_text
+
+ def test_unicode_characters(self, font_path, temp_dir):
+ """Test handling of unicode characters."""
+ unicode_text = "HELLO \u2665" # Heart symbol
+ p = Pyedgeon(
+ illusion_text=unicode_text,
+ font_path=font_path,
+ file_path=temp_dir
+ )
+ assert p.illusion_text == unicode_text
+
+ def test_numeric_text(self, font_path, temp_dir):
+ """Test handling of numeric text."""
+ p = Pyedgeon(
+ illusion_text="123456",
+ font_path=font_path,
+ file_path=temp_dir
+ )
+ assert p.illusion_text == "123456"
+
+
+class TestColorParameters:
+ """Test color parameter validation and handling."""
+
+ def test_custom_text_color(self, font_path, temp_dir):
+ """Test setting custom text color."""
+ red = (255, 0, 0)
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ text_color=red
+ )
+ assert p.text_color == red
+
+ def test_custom_background_color(self, font_path, temp_dir):
+ """Test setting custom background color."""
+ blue = (0, 0, 255)
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ background_color=blue
+ )
+ assert p.background_color == blue
+
+ def test_grayscale_colors(self, font_path, temp_dir):
+ """Test grayscale color values."""
+ gray = (128, 128, 128)
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ text_color=gray
+ )
+ assert p.text_color == gray
+
+ def test_color_boundaries(self, font_path, temp_dir):
+ """Test color values at boundaries (0 and 255)."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ text_color=(0, 0, 0),
+ background_color=(255, 255, 255)
+ )
+ assert p.text_color == (0, 0, 0)
+ assert p.background_color == (255, 255, 255)
+
+
+class TestFileParameters:
+ """Test file path and naming parameter handling."""
+
+ def test_custom_file_name(self, font_path, temp_dir):
+ """Test setting custom file name."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name="custom_name"
+ )
+ assert p.file_name == "custom_name"
+
+ def test_file_name_defaults_to_text(self, font_path, temp_dir):
+ """Test that file_name defaults to illusion_text."""
+ p = Pyedgeon(
+ illusion_text="TEST TEXT",
+ font_path=font_path,
+ file_path=temp_dir
+ )
+ assert p.file_name == "TEST TEXT"
+
+ def test_custom_file_extension(self, font_path, temp_dir):
+ """Test setting custom file extension."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ file_ext=".jpg"
+ )
+ assert p.file_ext == ".jpg"
+
+ def test_empty_file_path(self, font_path):
+ """Test that empty file_path is accepted."""
+ p = Pyedgeon(font_path=font_path, file_path="")
+ assert p.file_path == ""
+
+ def test_custom_file_path(self, font_path, temp_dir):
+ """Test setting custom file path."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.file_path == temp_dir
+
+
+class TestImageSizeParameters:
+ """Test image size and dimension parameters."""
+
+ def test_custom_img_side(self, font_path, temp_dir):
+ """Test setting custom image side length."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=512
+ )
+ assert p.img_side == 512
+ assert p.img_size == (512, 512)
+
+ def test_small_image_size(self, font_path, temp_dir):
+ """Test with small image size."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=128
+ )
+ assert p.img_side == 128
+
+ def test_large_image_size(self, font_path, temp_dir):
+ """Test with large image size."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=2048
+ )
+ assert p.img_side == 2048
+
+ def test_img_size_tuple_creation(self, font_path, temp_dir):
+ """Test that img_size tuple is created correctly."""
+ side = 800
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=side
+ )
+ assert p.img_size == (side, side)
+ assert p.img_size_text == (side, side)
+
+
+class TestRotationParameters:
+ """Test rotation-related parameters."""
+
+ def test_custom_num_rotations(self, font_path, temp_dir):
+ """Test setting custom number of rotations."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=8
+ )
+ assert p.num_rotations == 8
+
+ def test_minimum_rotations(self, font_path, temp_dir):
+ """Test with minimum number of rotations."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=1
+ )
+ assert p.num_rotations == 1
+
+ def test_many_rotations(self, font_path, temp_dir):
+ """Test with many rotations."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=12
+ )
+ assert p.num_rotations == 12
+
+
+class TestCropParameters:
+ """Test crop width parameters."""
+
+ def test_custom_crop_width_x(self, font_path, temp_dir):
+ """Test setting custom crop_width_x."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ crop_width_x=20
+ )
+ assert p.crop_width_x == 20
+
+ def test_custom_crop_width_y(self, font_path, temp_dir):
+ """Test setting custom crop_width_y."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ crop_width_y=10
+ )
+ assert p.crop_width_y == 10
+
+ def test_zero_crop_widths(self, font_path, temp_dir):
+ """Test with zero crop widths."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ crop_width_x=0,
+ crop_width_y=0
+ )
+ assert p.crop_width_x == 0
+ assert p.crop_width_y == 0
+
+
+class TestDarknessThreshold:
+ """Test darkness threshold parameter."""
+
+ def test_custom_darkness_threshold(self, font_path, temp_dir):
+ """Test setting custom darkness threshold."""
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ darkness_threshold=100
+ )
+ assert p.darkness_threshold == 100
+
+ def test_threshold_boundaries(self, font_path, temp_dir):
+ """Test darkness threshold at boundaries."""
+ p_low = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ darkness_threshold=0
+ )
+ assert p_low.darkness_threshold == 0
+
+ p_high = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ darkness_threshold=255
+ )
+ assert p_high.darkness_threshold == 255
+
+
+class TestInitialState:
+ """Test the initial state of Pyedgeon object after construction."""
+
+ def test_font_size_initially_none(self, font_path, temp_dir):
+ """Test that font_size is None before calculation."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.font_size is None
+
+ def test_font_size_guess_initially_none(self, font_path, temp_dir):
+ """Test that font_size_guess is None before estimation."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+ assert p.font_size_guess is None
+
+ def test_all_required_attributes_exist(self, font_path, temp_dir):
+ """Test that all expected attributes are set after initialization."""
+ p = Pyedgeon(font_path=font_path, file_path=temp_dir)
+
+ required_attrs = [
+ 'illusion_text', 'font_path', 'num_rotations', 'file_ext',
+ 'text_color', 'background_color', 'img_side', 'charmax',
+ 'file_path', 'font_size_guess', 'crop_width_x', 'crop_width_y',
+ 'darkness_threshold', 'img_size', 'img_size_text', 'file_name',
+ 'font_size'
+ ]
+
+ for attr in required_attrs:
+ assert hasattr(p, attr), f"Missing attribute: {attr}"
diff --git a/tests/test_performance.py b/tests/test_performance.py
new file mode 100644
--- /dev/null
+++ b/tests/test_performance.py
@@ -0,0 +1,482 @@
+"""
+Performance tests for Pyedgeon library.
+
+Tests cover:
+- Execution time benchmarks
+- Memory usage
+- Resource limits
+- Performance regressions
+- Scalability
+"""
+
+import time
+import pytest
+from pyedgeon import Pyedgeon
+
+
+class TestPerformanceBenchmarks:
+ """Benchmark tests for various operations."""
+
+ def test_initialization_performance(self, font_path, temp_dir, benchmark):
+ """Benchmark Pyedgeon initialization time."""
+ def create_instance():
+ return Pyedgeon(
+ illusion_text="BENCHMARK",
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=512
+ )
+
+ result = benchmark(create_instance)
+ assert result is not None
+
+ def test_estimate_font_size_performance(self, default_pyedgeon, benchmark):
+ """Benchmark font size estimation."""
+ p = default_pyedgeon
+ p.illusion_text = "PERFORMANCE TEST"
+
+ result = benchmark(p.estimate_font_size)
+ assert p.font_size_guess is not None
+
+ def test_check_length_performance(self, default_pyedgeon, benchmark):
+ """Benchmark check_length operation."""
+ p = default_pyedgeon
+ p.illusion_text = "SHORT TEXT"
+
+ benchmark(p.check_length)
+
+ @pytest.mark.slow
+ def test_draw_clear_performance(self, default_pyedgeon, benchmark):
+ """Benchmark draw_clear operation."""
+ p = default_pyedgeon
+
+ benchmark(p.draw_clear)
+ assert p.raw_img is not None
+
+ @pytest.mark.slow
+ def test_get_fontsize_performance(self, minimal_pyedgeon, benchmark):
+ """Benchmark get_fontsize operation."""
+ p = minimal_pyedgeon
+ p.illusion_text = "PERF"
+
+ p.estimate_font_size()
+ p.draw_clear()
+
+ result = benchmark(p.get_fontsize)
+ assert result is not None
+
+ @pytest.mark.slow
+ def test_full_create_performance_small(self, font_path, temp_dir):
+ """Benchmark full create() for small image."""
+ p = Pyedgeon(
+ illusion_text="SMALL",
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name="perf_small",
+ img_side=256,
+ num_rotations=2
+ )
+
+ start = time.time()
+
+ # Note: Will fail due to syntax error, but measures time to failure
+ try:
+ p.create()
+ except TypeError:
+ pass # Expected due to line 215 syntax error
+
+ elapsed = time.time() - start
+
+ # Should complete (or fail) in reasonable time
+ assert elapsed < 10.0, f"Small image took {elapsed:.2f}s, expected < 10s"
+
+ @pytest.mark.slow
+ def test_full_create_performance_medium(self, font_path, temp_dir):
+ """Benchmark full create() for medium image."""
+ p = Pyedgeon(
+ illusion_text="MEDIUM",
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name="perf_medium",
+ img_side=512,
+ num_rotations=4
+ )
+
+ start = time.time()
+
+ try:
+ p.create()
+ except TypeError:
+ pass # Expected due to line 215 syntax error
+
+ elapsed = time.time() - start
+
+ # Medium images should still be reasonably fast
+ assert elapsed < 30.0, f"Medium image took {elapsed:.2f}s, expected < 30s"
+
+
+class TestScalability:
+ """Test performance scaling with different parameters."""
+
+ @pytest.mark.slow
+ def test_scaling_with_text_length(self, font_path, temp_dir):
+ """Test performance scaling with text length.
+
+ Marked slow: this is a wall-clock ratio benchmark. Baselines here sit at
+ the clock-resolution/jitter floor on shared CI runners, so it runs only
+ in the full (single-OS) suite, not the multi-OS fast matrix.
+ """
+ text_lengths = [5, 10, 15, 20]
+ times = []
+
+ for length in text_lengths:
+ text = "A" * length
+ p = Pyedgeon(
+ illusion_text=text,
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=256
+ )
+
+ start = time.perf_counter()
+ p.estimate_font_size()
+ elapsed = time.perf_counter() - start
+
+ times.append(elapsed)
+
+ # Font size estimation should scale roughly linearly; verify it doesn't
+ # explode exponentially. Floor the baseline: estimate_font_size() is fast
+ # enough that timings approach the clock resolution (time.time() reads
+ # 0.0 on Windows), which would make the ratio meaningless.
+ baseline = max(times[0], 1e-4)
+ assert times[-1] < baseline * 10, "Performance degradation too severe"
+
+ def test_scaling_with_image_size(self, font_path, temp_dir):
+ """Test performance scaling with image size."""
+ sizes = [128, 256, 512]
+ times = []
+
+ for size in sizes:
+ p = Pyedgeon(
+ illusion_text="SCALE",
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=size
+ )
+
+ start = time.time()
+ p.draw_clear()
+ elapsed = time.time() - start
+
+ times.append(elapsed)
+
+ # Image creation should scale roughly quadratically with size
+ # (pixels increase as size^2)
+ for t in times:
+ assert t < 5.0, f"Image creation took {t:.2f}s, too slow"
+
+ @pytest.mark.slow
+ def test_scaling_with_num_rotations(self, font_path, temp_dir):
+ """Test performance scaling with number of rotations.
+
+ Marked slow: wall-clock ratio benchmark with a sub-millisecond baseline,
+ which is dominated by scheduler jitter on shared CI runners. Runs in the
+ full (single-OS) suite, not the multi-OS fast matrix.
+ """
+ rotation_counts = [2, 4, 6, 8]
+ times = []
+
+ for num_rot in rotation_counts:
+ p = Pyedgeon(
+ illusion_text="ROT",
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=num_rot,
+ img_side=256
+ )
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+ p.draw_frame()
+
+ start = time.perf_counter()
+ p.stamp()
+ elapsed = time.perf_counter() - start
+
+ times.append(elapsed)
+
+ # Stamping should scale linearly with rotations. Floor the baseline:
+ # stamp() can finish below the clock resolution (time.time() reads 0.0 on
+ # Windows), collapsing the RHS to 0 and failing spuriously.
+ baseline = max(times[0], 1e-4)
+ assert times[-1] < baseline * (rotation_counts[-1] / rotation_counts[0]) * 2
+
+
+class TestNestedLoopPerformance:
+ """Test performance of nested pixel loops (known O(n²) issue)."""
+
+ @pytest.mark.slow
+ def test_draw_frame_nested_loops(self, font_path, temp_dir):
+ """Test nested loop performance in draw_frame."""
+ sizes = [128, 256, 512]
+ times = []
+
+ for size in sizes:
+ p = Pyedgeon(
+ illusion_text="LOOP",
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=size
+ )
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+
+ start = time.time()
+ p.draw_frame()
+ elapsed = time.time() - start
+
+ times.append((size, elapsed))
+
+ # Verify quadratic scaling (or worse)
+ # Time should increase by ~4x when size doubles
+ for i in range(len(times) - 1):
+ size_ratio = times[i+1][0] / times[i][0]
+ time_ratio = times[i+1][1] / max(times[i][1], 0.001) # Avoid div by 0
+
+ # With nested loops, expect O(n²) scaling
+ # So doubling size should ~4x the time (but allow some overhead)
+ assert time_ratio < size_ratio ** 3, \
+ f"Performance worse than O(n²): {time_ratio} for {size_ratio}x size"
+
+ @pytest.mark.slow
+ def test_alpha_to_white_nested_loops(self, font_path, temp_dir):
+ """Test nested loop performance in alpha_to_white."""
+ # Note: This will fail due to syntax error, but we can still
+ # test the structure
+
+ sizes = [128, 256]
+ times = []
+
+ for size in sizes:
+ p = Pyedgeon(
+ illusion_text="ALPHA",
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=size
+ )
+
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+ p.draw_frame()
+ p.stamp()
+
+ start = time.time()
+ try:
+ p.alpha_to_white()
+ except TypeError:
+ pass # Expected syntax error
+ elapsed = time.time() - start
+
+ times.append((size, elapsed))
+
+ # Even with the error, we measure the time to reach the error
+ # Shows the nested loop overhead before hitting the bug
+
+
+class TestFontSizeDiscoveryPerformance:
+ """Test performance of font size discovery algorithm."""
+
+ @pytest.mark.slow
+ def test_get_fontsize_temporary_images(self, minimal_pyedgeon):
+ """Test that get_fontsize creates many temporary images."""
+ p = minimal_pyedgeon
+ p.illusion_text = "FONT TEST"
+
+ p.estimate_font_size()
+ p.draw_clear()
+
+ # The algorithm tries 60 font sizes (guess-30 to guess+30)
+ # Each creates a temporary image
+ start = time.time()
+ p.get_fontsize()
+ elapsed = time.time() - start
+
+ # Should complete but documents the inefficiency
+ # Creating 60 images is wasteful
+ assert elapsed < 5.0, f"Font size discovery too slow: {elapsed:.2f}s"
+
+ def test_get_fontsize_recursion_count(self, font_path, temp_dir):
+ """Test that get_fontsize can recurse multiple times."""
+ # With wrong initial guess, it will recurse
+ # Each recursion tries 60 more font sizes
+
+ p = Pyedgeon(
+ illusion_text="RECURSION",
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=256
+ )
+
+ # Manually set a bad guess to force recursion
+ p.estimate_font_size()
+ p.draw_clear()
+ p.font_size_guess = 10 # Too small, will recurse
+
+ start = time.time()
+
+ # This might recurse several times
+ # Note: Could potentially recurse indefinitely!
+ try:
+ with pytest.raises(RecursionError):
+ # Set Python recursion limit low to catch unbounded recursion
+ import sys
+ old_limit = sys.getrecursionlimit()
+ sys.setrecursionlimit(100)
+
+ p.get_fontsize()
+
+ sys.setrecursionlimit(old_limit)
+ except:
+ # If it doesn't hit recursion limit, that's okay
+ # But it's still inefficient
+ pass
+
+ elapsed = time.time() - start
+
+ # Should not take forever
+ assert elapsed < 10.0
+
+
+class TestMemoryUsage:
+ """Test memory usage patterns."""
+
+ def test_multiple_image_objects(self, default_pyedgeon):
+ """Test that multiple image objects are created."""
+ p = default_pyedgeon
+
+ p.draw_clear()
+
+ # Documents that 4 separate images are created (default 512x512)
+ # This is ~4MB of memory (512*512*4 channels*4 images)
+ images = [p.raw_img, p.img, p.circle_img, p.full_image]
+
+ for img in images:
+ assert img.size == (p.img_side, p.img_side)
+ # Each image uses significant memory
+
+ @pytest.mark.slow
+ def test_memory_with_large_image(self, font_path, temp_dir):
+ """Test memory usage with large images."""
+ # Large image uses substantial memory
+ large_size = 2048
+
+ p = Pyedgeon(
+ illusion_text="MEMORY",
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=large_size
+ )
+
+ # Creating the images allocates memory
+ p.draw_clear()
+
+ # 4 images * 2048*2048 pixels * 4 bytes/pixel = ~64MB
+ assert p.img.size == (large_size, large_size)
+
+
+class TestResourceLimits:
+ """Test behavior at resource limits."""
+
+ def test_unrestricted_image_size(self, font_path, temp_dir):
+ """Test that image size is now properly restricted."""
+ # Validation now prevents huge sizes (max is 8192)
+
+ huge_size = 50000 # Would create 50000x50000 = 2.5B pixels
+
+ # Validation now properly rejects this
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ illusion_text="HUGE",
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=huge_size
+ )
+
+ def test_unrestricted_text_length(self, font_path, temp_dir):
+ """Test that text length is now properly restricted."""
+ # Validation now prevents very long text (max is 10000)
+
+ very_long = "A" * 100000
+
+ # Validation now properly rejects this
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ illusion_text=very_long,
+ font_path=font_path,
+ file_path=temp_dir
+ )
+
+ def test_unrestricted_num_rotations(self, font_path, temp_dir):
+ """Test that num_rotations is now properly restricted."""
+ # Validation now prevents excessive rotations (max is 360)
+
+ excessive = 10000
+
+ # Validation now properly rejects this
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ illusion_text="ROT",
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=excessive
+ )
+
+
+class TestRegression:
+ """Regression tests for performance improvements."""
+
+ @pytest.mark.slow
+ def test_baseline_small_image(self, font_path, temp_dir):
+ """Baseline performance test for small images."""
+ p = Pyedgeon(
+ illusion_text="BASELINE",
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name="baseline_test",
+ img_side=256,
+ num_rotations=2
+ )
+
+ start = time.time()
+
+ # Run through all steps up to the syntax error
+ p.check_length()
+ p.estimate_font_size()
+ p.draw_clear()
+ p.get_fontsize()
+ p.draw_frame()
+ p.stamp()
+
+ elapsed = time.time() - start
+
+ # Baseline: should complete in under 5 seconds
+ assert elapsed < 5.0, \
+ f"Baseline performance regression: {elapsed:.2f}s (expected < 5s)"
+
+ # Store result for comparison in future test runs
+ print(f"\nBaseline performance: {elapsed:.2f}s for 256x256 image")
+
+
+# Pytest benchmark plugin integration
+pytest_plugins = ['pytest-benchmark']
+
+
+def pytest_configure(config):
+ """Configure custom markers."""
+ config.addinivalue_line(
+ "markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')"
+ )
diff --git a/tests/test_security.py b/tests/test_security.py
new file mode 100644
--- /dev/null
+++ b/tests/test_security.py
@@ -0,0 +1,484 @@
+"""
+Security tests for Pyedgeon library.
+
+Tests cover:
+- Path traversal vulnerabilities
+- Input validation
+- Resource exhaustion protection
+- File system security
+- Injection attacks
+"""
+
+import os
+import pytest
+from pathlib import Path
+from pyedgeon import Pyedgeon
+
+
+class TestPathTraversalPrevention:
+ """Test protection against path traversal attacks."""
+
+ def test_file_path_traversal_parent_directory(self, font_path, temp_dir):
+ """Test that parent directory traversal in file_path is handled safely."""
+ malicious_path = "../../../etc"
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=malicious_path,
+ illusion_text="TEST"
+ )
+
+ # Validation now properly checks that output directory exists
+ # This will raise an error because ../../../etc likely doesn't exist
+ with pytest.raises(Exception): # Should raise ValidationError
+ output_path = p.get_file_path()
+
+ def test_file_path_absolute_system_path(self, font_path, temp_dir):
+ """Test that absolute system paths in file_path are accepted."""
+ # This tests whether the code accepts absolute paths to system directories
+ # Note: Users may legitimately want to write to specific absolute paths
+ malicious_paths = [
+ "/etc",
+ "/tmp/../etc",
+ "/var/log"
+ ]
+
+ for mal_path in malicious_paths:
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=mal_path,
+ illusion_text="TEST"
+ )
+ # Absolute paths are accepted (users may have legitimate use cases)
+ assert p.file_path == mal_path
+
+ def test_file_name_with_path_traversal(self, font_path, temp_dir):
+ """Test that file_name with path traversal is properly sanitized."""
+ malicious_names = [
+ "../../../etc/passwd",
+ "..\\..\\..\\windows\\system32\\config\\sam",
+ "./../../secret.txt"
+ ]
+
+ for mal_name in malicious_names:
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name=mal_name,
+ illusion_text="TEST"
+ )
+ output_path = p.get_file_path()
+
+ # Verify dangerous characters are sanitized
+ # Path separators and dots should be removed or replaced
+ assert "../" not in output_path
+ assert "..\\" not in output_path
+ # Should still be within temp_dir (realpath resolves Windows 8.3
+ # short names and macOS /var -> /private/var so the compare is portable)
+ resolved_temp = os.path.realpath(temp_dir)
+ assert resolved_temp in output_path or output_path.startswith(resolved_temp)
+
+ def test_font_path_traversal(self, temp_dir):
+ """Test that font_path rejects paths with invalid extensions."""
+ malicious_font_paths = [
+ "../../../etc/passwd",
+ "/etc/shadow",
+ "C:\\Windows\\System32\\config\\SAM"
+ ]
+
+ for mal_path in malicious_font_paths:
+ # Font path validation now rejects non-font file extensions
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=mal_path,
+ file_path=temp_dir,
+ illusion_text="TEST"
+ )
+
+ def test_null_byte_injection_file_name(self, font_path, temp_dir):
+ """Test handling of null byte injection in file names."""
+ malicious_name = "safe_name\x00../../etc/passwd"
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name=malicious_name,
+ illusion_text="TEST"
+ )
+ # Documents that null bytes are currently not filtered
+ assert "\x00" in p.file_name
+
+ def test_symlink_in_file_path(self, font_path, temp_dir):
+ """Test behavior when file_path contains symlinks."""
+ # Create a symlink to a different directory
+ symlink_path = Path(temp_dir) / "symlink"
+ target_path = Path(temp_dir) / "target"
+ target_path.mkdir(exist_ok=True)
+
+ try:
+ symlink_path.symlink_to(target_path)
+
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=str(symlink_path),
+ illusion_text="TEST"
+ )
+
+ # Verify symlinks are followed (current behavior)
+ assert p.file_path == str(symlink_path)
+ except OSError:
+ # Symlink creation might fail on some systems
+ pytest.skip("Symlink creation not supported")
+
+
+class TestInputValidation:
+ """Test validation of user inputs."""
+
+ def test_color_validation_out_of_range_high(self, font_path, temp_dir):
+ """Test that colors above 255 are properly rejected."""
+ # Validation now properly checks color ranges
+ invalid_color = (300, 300, 300)
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ text_color=invalid_color
+ )
+
+ def test_color_validation_negative(self, font_path, temp_dir):
+ """Test that negative color values are properly rejected."""
+ invalid_color = (-10, -20, -30)
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ text_color=invalid_color
+ )
+
+ def test_color_validation_wrong_type(self, font_path, temp_dir):
+ """Test that wrong color type is properly rejected."""
+ # Validation now checks that color is a 3-tuple
+ with pytest.raises(Exception): # Should raise ValidationError or TypeError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ text_color="red" # String instead of tuple
+ )
+
+ def test_color_validation_wrong_tuple_length(self, font_path, temp_dir):
+ """Test that wrong tuple length for color is properly rejected."""
+ invalid_colors = [
+ (255,), # Too short
+ (255, 255), # Too short
+ (255, 255, 255, 255), # Too long
+ ]
+
+ for invalid_color in invalid_colors:
+ # Validation now properly checks tuple length
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ text_color=invalid_color
+ )
+
+ def test_num_rotations_negative(self, font_path, temp_dir):
+ """Test that negative num_rotations is properly rejected."""
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=-5
+ )
+
+ def test_num_rotations_zero(self, font_path, temp_dir):
+ """Test that zero num_rotations is properly rejected."""
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=0
+ )
+
+ def test_img_side_negative(self, font_path, temp_dir):
+ """Test that negative img_side is properly rejected."""
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=-100
+ )
+
+ def test_img_side_zero(self, font_path, temp_dir):
+ """Test that zero img_side is properly rejected."""
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=0
+ )
+
+ def test_charmax_negative(self, font_path, temp_dir):
+ """Test that negative charmax is properly rejected."""
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ charmax=-10
+ )
+
+ def test_darkness_threshold_out_of_range(self, font_path, temp_dir):
+ """Test that darkness_threshold outside 0-255 is properly rejected."""
+ invalid_thresholds = [-10, 300, 1000]
+
+ for threshold in invalid_thresholds:
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ darkness_threshold=threshold
+ )
+
+
+class TestResourceExhaustion:
+ """Test protection against resource exhaustion attacks."""
+
+ def test_extremely_large_image_size(self, font_path, temp_dir):
+ """Test that extremely large image sizes are properly rejected."""
+ # An attacker could try to exhaust memory with huge images
+ huge_size = 100000 # 100k x 100k = 10 billion pixels
+
+ # Validation now prevents resource exhaustion (max is 8192)
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ img_side=huge_size,
+ illusion_text="A"
+ )
+
+ def test_extremely_long_text(self, font_path, temp_dir):
+ """Test that extremely long text (>10000 chars) is properly rejected."""
+ # Test with very long text that could cause performance issues
+ long_text = "A" * 10001 # Just over the 10000 limit
+
+ # Validation now rejects text over 10000 characters
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ illusion_text=long_text
+ )
+
+ def test_check_length_truncation_silent(self, font_path, temp_dir):
+ """Test that check_length() correctly truncates text to charmax."""
+ long_text = "A" * 50
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ illusion_text=long_text,
+ charmax=22
+ )
+
+ p.check_length()
+
+ # Verify text was correctly truncated to charmax (bug has been fixed!)
+ assert len(p.illusion_text) == 22
+
+ # Warning is logged (not printed to stdout)
+
+ def test_check_length_hardcoded_truncation(self, font_path, temp_dir):
+ """Test that truncation correctly uses charmax value (bug fixed)."""
+ long_text = "A" * 50
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ illusion_text=long_text,
+ charmax=30 # Set to 30
+ )
+
+ p.check_length()
+
+ # Bug has been fixed: now correctly truncates to charmax value
+ assert len(p.illusion_text) == 30
+
+ def test_many_rotations_performance(self, font_path, temp_dir):
+ """Test that excessive rotations are properly limited."""
+ excessive_rotations = 1000
+
+ # Validation now prevents excessive rotations (max is 360)
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=excessive_rotations,
+ illusion_text="A"
+ )
+
+
+class TestFileSystemSecurity:
+ """Test file system security issues."""
+
+ def test_file_overwrite_without_warning(self, font_path, temp_dir):
+ """Test that existing files are overwritten without warning."""
+ file_name = "test_file"
+ file_path = Path(temp_dir) / f"{file_name}.png"
+
+ # Create an existing file
+ file_path.write_text("existing content")
+ assert file_path.exists()
+
+ # Create Pyedgeon instance that will overwrite
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ file_name=file_name,
+ illusion_text="TEST"
+ )
+
+ # Verify it would overwrite (without actually running create()).
+ # get_file_path() resolves the path, so canonicalize the expected path
+ # too (Windows 8.3 short names, macOS /var -> /private/var).
+ result_path = p.get_file_path()
+ resolved_file = os.path.realpath(str(file_path))
+ assert resolved_file == result_path
+
+ def test_file_extension_validation(self, font_path, temp_dir):
+ """Test that dangerous file extensions are properly rejected."""
+ dangerous_extensions = [
+ ".exe",
+ ".sh",
+ ".bat",
+ ".ps1",
+ "", # No extension
+ ".png.exe", # Double extension
+ ]
+
+ for ext in dangerous_extensions:
+ # Validation now properly rejects dangerous extensions
+ with pytest.raises(Exception): # Should raise ValidationError
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ file_ext=ext,
+ illusion_text="TEST"
+ )
+
+ def test_font_file_existence_check(self, temp_dir):
+ """Test that non-existent font files are accepted during init."""
+ non_existent_font = "/path/to/nonexistent/font.ttf"
+
+ # Constructor accepts non-existent paths
+ p = Pyedgeon(
+ font_path=non_existent_font,
+ file_path=temp_dir,
+ illusion_text="TEST"
+ )
+
+ assert p.font_path == non_existent_font
+
+ def test_font_file_type_validation(self, temp_dir, fake_font_file):
+ """Test that non-font files with .ttf extension are accepted."""
+ # fake_font_file is not a valid font but has .ttf extension
+ p = Pyedgeon(
+ font_path=fake_font_file,
+ file_path=temp_dir,
+ illusion_text="TEST"
+ )
+
+ # Both point to the same file; realpath canonicalizes them (Windows 8.3
+ # short names, macOS /var -> /private/var) so the compare is portable.
+ assert os.path.realpath(fake_font_file) == os.path.realpath(p.font_path)
+
+
+class TestErrorHandling:
+ """Test error handling and exception management."""
+
+ def test_bare_except_in_get_fontsize(self, font_path, temp_dir):
+ """Test that bare except clause has been fixed in get_fontsize()."""
+ # Previously had a bare except clause which is a security risk
+ # Now properly uses specific exception handling
+
+ import inspect
+ from pyedgeon import Pyedgeon
+
+ source = inspect.getsource(Pyedgeon.get_fontsize)
+
+ # Verify bare except has been fixed - should use 'except Exception as e:' instead
+ assert "except Exception as e:" in source or "except (IOError, OSError)" in source
+ # Should NOT have bare except:
+ assert "except:" not in source or "except Exception" in source # Allow 'except Exception'
+
+ def test_unbounded_recursion_in_get_fontsize(self, font_path, temp_dir):
+ """Test that get_fontsize() has unbounded recursion."""
+ # The function can recurse indefinitely without a base case
+ # This is a potential denial of service vector
+
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ illusion_text="TEST",
+ img_side=256
+ )
+
+ # Set up conditions that would cause recursion
+ p.font_size_guess = 50
+
+ # Note: We don't actually call this to avoid stack overflow
+ # This test documents the risk
+ assert hasattr(p, 'get_fontsize')
+
+
+class TestSyntaxErrorDocumentation:
+ """Document the syntax error on line 215."""
+
+ def test_line_215_syntax_error_exists(self):
+ """Test that verifies the syntax error on line 215 has been fixed."""
+ # Line 215 previously had: self.background_color (255, )
+ # Now correctly fixed to: self.background_color + (255, )
+
+ import inspect
+ from pyedgeon import Pyedgeon
+
+ source = inspect.getsource(Pyedgeon.alpha_to_white)
+
+ # Verify the fix is in place - should use + operator, not function call
+ assert "self.background_color + (255," in source
+
+
+class TestInjectionVectors:
+ """Test for various injection attack vectors."""
+
+ def test_command_injection_in_file_path(self, font_path):
+ """Test that command injection in file_path is possible."""
+ # Potentially dangerous path with shell metacharacters
+ dangerous_paths = [
+ "; rm -rf /",
+ "$(malicious_command)",
+ "`malicious_command`",
+ "| cat /etc/passwd",
+ ]
+
+ for dangerous_path in dangerous_paths:
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=dangerous_path,
+ illusion_text="TEST"
+ )
+ # Currently no sanitization
+ assert dangerous_path in p.file_path
+
+ def test_format_string_in_text(self, font_path, temp_dir):
+ """Test handling of format string-like text."""
+ format_strings = [
+ "{0}",
+ "%s%s%s%s",
+ "${malicious}",
+ ]
+
+ for fmt_str in format_strings:
+ p = Pyedgeon(
+ font_path=font_path,
+ file_path=temp_dir,
+ illusion_text=fmt_str
+ )
+ # Verify format strings are not interpreted
+ assert p.illusion_text == fmt_str.upper()
diff --git a/tests/requirements-test.txt b/tests/requirements-test.txt
new file mode 100644
--- /dev/null
+++ b/tests/requirements-test.txt
@@ -0,0 +1,27 @@
+# Testing dependencies for pyedgeon
+
+# Core testing framework
+pytest>=7.0.0
+pytest-cov>=4.0.0
+pytest-xdist>=3.0.0 # For parallel test execution
+pytest-timeout>=2.1.0 # For timeout handling
+pytest-benchmark>=4.0.0 # For performance benchmarks
+
+# Code quality and coverage
+coverage>=7.0.0
+
+# Image testing and validation
+pillow>=9.0.0 # Should match main dependency
+
+# Mocking and fixtures
+pytest-mock>=3.10.0
+
+# Testing utilities
+pytest-html>=3.1.0 # HTML test reports
+pytest-json-report>=1.5.0 # JSON test reports
+
+# Security testing
+safety>=2.3.0 # Dependency vulnerability scanning
+
+# Additional utilities
+colorama>=0.4.6 # Colored terminal output
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
--- /dev/null
+++ b/tests/__init__.py
+"""
+Pyedgeon test suite.
+
+This package contains comprehensive tests for the pyedgeon library including:
+- Unit tests for individual methods
+- Integration tests for the full pipeline
+- Security tests for vulnerability detection
+- Performance tests and benchmarks
+"""
+
+__version__ = "1.0.0"
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
--- /dev/null
+++ b/tests/conftest.py
+"""
+Pytest configuration and shared fixtures for pyedgeon test suite.
+
+This module provides common test fixtures, utilities, and configuration
+for all test modules in the pyedgeon test suite.
+"""
+
+import os
+import sys
+import tempfile
+import shutil
+from pathlib import Path
+import pytest
+from PIL import Image
+
+# Add parent directory to path to import pyedgeon
+sys.path.insert(0, str(Path(__file__).parent.parent))
+
+from pyedgeon import Pyedgeon
+
+
+@pytest.fixture
+def temp_dir():
+ """
+ Provides a temporary directory for test file outputs.
+ Automatically cleaned up after test completion.
+ """
+ temp_path = tempfile.mkdtemp()
+ yield temp_path
+ # Cleanup after test
+ if os.path.exists(temp_path):
+ shutil.rmtree(temp_path)
+
+
+@pytest.fixture
+def font_path():
+ """
+ Provides a path to a TrueType font for testing.
+ Users must provide their own font file - pyedgeon does not bundle fonts.
+
+ Tests will be skipped if no suitable font is found.
+ Looks for fonts in common system locations.
+ """
+ # Check common system font locations
+ possible_fonts = [
+ # macOS
+ "/System/Library/Fonts/Supplemental/Arial.ttf",
+ "/System/Library/Fonts/Helvetica.ttc",
+ # Linux
+ "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
+ "/usr/share/fonts/liberation/LiberationSans-Regular.ttf",
+ # Windows
+ "C:\\Windows\\Fonts\\arial.ttf",
+ ]
+
+ for font_file in possible_fonts:
+ if Path(font_file).exists():
+ return str(font_file)
+
+ pytest.skip("No suitable system font found for testing. Pyedgeon does not bundle fonts.")
+
+
+@pytest.fixture
+def default_pyedgeon(font_path, temp_dir):
+ """
+ Creates a Pyedgeon instance with safe default settings for testing.
+ Uses the bundled font and a temporary directory.
+ """
+ return Pyedgeon(
+ illusion_text="TEST",
+ font_path=font_path,
+ file_path=temp_dir,
+ num_rotations=6,
+ img_side=512 # Smaller for faster tests
+ )
+
+
+@pytest.fixture
+def minimal_pyedgeon(font_path, temp_dir):