Skip to content

Commit

Permalink
Fix flaky tests (#48)
Browse files Browse the repository at this point in the history
* ad

* add

* Update __init__.py

* add

* Update conf.py

* Update __init__.py

* Update __init__.py

* add

* remove placeholders
  • Loading branch information
baseplate-admin authored May 20, 2024
1 parent 55e5f88 commit a48f1d2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
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)

0 comments on commit a48f1d2

Please sign in to comment.