test: Add unittest for hex to color

This commit is contained in:
sigmanificient 2023-02-09 12:24:40 +01:00 committed by backwardspy (cl)
parent bef684afd4
commit 105905ea44

View File

@ -1,3 +1,5 @@
import pytest
from catppuccin.colour import Colour
@ -7,3 +9,21 @@ def test_colour_to_rgb():
def test_colour_to_hex():
assert Colour(0x12, 0xEB, 0x77).hex == "12eb77"
def test_hex_to_color():
assert Colour.from_hex("12eb77") == Colour(0x12, 0xEB, 0x77)
def test_invalid_hex():
for invalid_value in ("1234567", "12345", "Z00000", "ABCDEG", "0F7CBJ"):
with pytest.raises(ValueError):
assert Colour.from_hex(invalid_value)
def test_equality():
assert Colour.from_hex("12eb77") == Colour.from_hex("12eb77")
assert Colour(0x12, 0xEB, 0x77) == Colour(0x12, 0xEB, 0x77)
with pytest.raises(ValueError):
assert Colour(0x12, 0xEB, 0x77) == 42