BrandSmith / tests /test_tools.py
raznis's picture
Upload folder using huggingface_hub
cbef06e verified
import sys
import os
import pytest
import numpy as np
from PIL import Image
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src')))
import tools
from models import ColorPalette, ColorItem
class DummyColorItem:
def __init__(self, R, G, B, count):
self.R = R
self.G = G
self.B = B
self.count = count
class DummyColorPalette:
def __init__(self, colors):
self.colors = colors
def test_extract_color_palette_basic():
img = Image.new('RGBA', (10, 10), (255, 0, 0, 255))
palette = tools.extract_color_palette(img, 1)
assert hasattr(palette, 'colors')
assert len(palette.colors) == 1
assert palette.colors[0].R == 255
assert palette.colors[0].G == 0
assert palette.colors[0].B == 0
def test_create_color_palette_square_grid():
colors = [ColorItem(R=255, G=0, B=0, count=50), ColorItem(R=0, G=255, B=0, count=50)]
palette = ColorPalette(colors=colors)
img = tools.create_color_palette_square_grid(palette, total_pixels=100)
assert isinstance(img, Image.Image)
assert img.size[0] == img.size[1] # Should be square
def test_create_palette_image():
colors = [ColorItem(R=255, G=0, B=0, count=50), ColorItem(R=0, G=255, B=0, count=50)]
palette = ColorPalette(colors=colors)
img = tools.create_palette_image(palette)
assert isinstance(img, Image.Image)