add tests for buildCORL and buildCPAL
This commit is contained in:
parent
f8b9887f85
commit
acfae6721b
0
Tests/colorLib/__init__.py
Normal file
0
Tests/colorLib/__init__.py
Normal file
56
Tests/colorLib/builder_test.py
Normal file
56
Tests/colorLib/builder_test.py
Normal file
@ -0,0 +1,56 @@
|
||||
from fontTools.colorLib import builder
|
||||
from fontTools.colorLib.errors import ColorLibError
|
||||
import pytest
|
||||
|
||||
|
||||
def test_buildCOLR_v0():
|
||||
color_layer_lists = {
|
||||
"a": [("a.color0", 0), ("a.color1", 1)],
|
||||
"b": [("b.color1", 1), ("b.color0", 0)],
|
||||
}
|
||||
|
||||
colr = builder.buildCOLR(color_layer_lists)
|
||||
|
||||
assert colr.tableTag == "COLR"
|
||||
assert colr.version == 0
|
||||
assert colr.ColorLayers["a"][0].name == "a.color0"
|
||||
assert colr.ColorLayers["a"][0].colorID == 0
|
||||
assert colr.ColorLayers["a"][1].name == "a.color1"
|
||||
assert colr.ColorLayers["a"][1].colorID == 1
|
||||
assert colr.ColorLayers["b"][0].name == "b.color1"
|
||||
assert colr.ColorLayers["b"][0].colorID == 1
|
||||
assert colr.ColorLayers["b"][1].name == "b.color0"
|
||||
assert colr.ColorLayers["b"][1].colorID == 0
|
||||
|
||||
|
||||
def test_buildCPAL_v0():
|
||||
palettes = [
|
||||
[(0.68, 0.20, 0.32, 1.0), (0.45, 0.68, 0.21, 1.0)],
|
||||
[(0.68, 0.20, 0.32, 0.6), (0.45, 0.68, 0.21, 0.6)],
|
||||
[(0.68, 0.20, 0.32, 0.3), (0.45, 0.68, 0.21, 0.3)],
|
||||
]
|
||||
|
||||
cpal = builder.buildCPAL(palettes)
|
||||
|
||||
assert cpal.tableTag == "CPAL"
|
||||
assert cpal.version == 0
|
||||
assert cpal.numPaletteEntries == 2
|
||||
|
||||
assert len(cpal.palettes) == 3
|
||||
assert [tuple(c) for c in cpal.palettes[0]] == [
|
||||
(82, 51, 173, 255),
|
||||
(54, 173, 115, 255),
|
||||
]
|
||||
assert [tuple(c) for c in cpal.palettes[1]] == [
|
||||
(82, 51, 173, 153),
|
||||
(54, 173, 115, 153),
|
||||
]
|
||||
assert [tuple(c) for c in cpal.palettes[2]] == [
|
||||
(82, 51, 173, 76),
|
||||
(54, 173, 115, 76),
|
||||
]
|
||||
|
||||
|
||||
def test_buildCPAL_palettes_different_lengths():
|
||||
with pytest.raises(ColorLibError, match="have different lengths"):
|
||||
builder.buildCPAL([[(1, 1, 1, 1)], [(0, 0, 0, 1), (0.5, 0.5, 0.5, 1)]])
|
Loading…
x
Reference in New Issue
Block a user