Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky tests #48

Merged
merged 10 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/python/modern_colorthief/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from .modern_colorthief import *

__doc__ = modern_colorthief.__doc__
if hasattr(modern_colorthief, "__all__"):
__all__ = modern_colorthief.__all__
__version__ = modern_colorthief.__version__


def get_palette(
Expand All @@ -14,7 +13,7 @@ def get_palette(
quality: int | None = 10,
) -> list[tuple[int, int, int]]:
if isinstance(image, str):
return _get_palette_given_string(image, color_count, quality)
return _get_palette_given_location(image, color_count, quality)

if isinstance(image, bytes):
return _get_palette_given_bytes(image, color_count, quality)
Expand Down
16 changes: 0 additions & 16 deletions test.py

This file was deleted.

39 changes: 36 additions & 3 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,38 @@

path = os.path.join(BASE_DIR, "test.jpg")

TARGET_PALTTE = [
(31, 169, 167),
(179, 51, 55),
(219, 176, 127),
(248, 233, 225),
(160, 98, 87),
(63, 47, 43),
(132, 162, 107),
(179, 119, 52),
(237, 220, 155),
]
TARGET_COLOR = (201, 160, 118)


def test_path():
dominant_color = modern_colorthief.get_color(path)
dominant_palette = modern_colorthief.get_palette(path)

assert dominant_color == TARGET_COLOR

assert dominant_color == (201, 160, 118)
# If we do not use PILLOW the image output is slightly different
assert dominant_palette == [
(30, 169, 166),
(179, 51, 55),
(219, 176, 127),
(248, 233, 225),
(160, 98, 87),
(63, 47, 42),
(131, 163, 107),
(179, 119, 52),
(237, 220, 155),
]


def test_bytesio():
Expand All @@ -22,7 +49,10 @@ def test_bytesio():
img.save(img_byte_arr, format="PNG")

dominant_color = modern_colorthief.get_color(img_byte_arr)
assert dominant_color == (201, 160, 118)
dominant_palette = modern_colorthief.get_palette(img_byte_arr)

assert dominant_color == TARGET_COLOR
assert dominant_palette == TARGET_PALTTE


def test_bytes():
Expand All @@ -32,4 +62,7 @@ def test_bytes():
img.save(img_byte_arr, format="PNG")

dominant_color = modern_colorthief.get_color(img_byte_arr.getvalue())
assert dominant_color == (201, 160, 118)
dominant_palette = modern_colorthief.get_palette(img_byte_arr.getvalue())

assert dominant_color == TARGET_COLOR
assert dominant_palette == TARGET_PALTTE
7 changes: 7 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import modern_colorthief


def test_version():
version = modern_colorthief.__version__

assert isinstance(version, str)