Test that DS5 splitting code handles unbounded conditions gracefully
Conditions with unbounded values have a "minimum" or "maximum" value of None. These tests check that: a) The public-facing split functions can receive None values without crashing; and b) That their internal helper functions correctly translate the None values to math.inf and -math.inf to express them. These tests are expected to fail, indicating where a fix is required.
This commit is contained in:
parent
1306a71db3
commit
d1ec8e6979
@ -1,9 +1,16 @@
|
||||
import math
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fontTools.designspaceLib import DesignSpaceDocument
|
||||
from fontTools.designspaceLib.split import splitInterpolable, splitVariableFonts, convert5to4
|
||||
from fontTools.designspaceLib.split import (
|
||||
_conditionSetFrom,
|
||||
convert5to4,
|
||||
splitInterpolable,
|
||||
splitVariableFonts,
|
||||
)
|
||||
from fontTools.designspaceLib.types import ConditionSet, Range
|
||||
|
||||
from .fixtures import datadir
|
||||
|
||||
@ -148,3 +155,47 @@ def test_convert5to4(datadir, tmpdir, test_ds, expected_vfs):
|
||||
assert data_out.read_text(encoding="utf-8") == temp_out.read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
["unbounded_condition"],
|
||||
[
|
||||
({"name": "Weight", "minimum": 500, "maximum": None},),
|
||||
({"name": "Weight", "minimum": None, "maximum": 500},),
|
||||
],
|
||||
)
|
||||
def test_optional_min_max(unbounded_condition):
|
||||
"""Check that split functions can handle conditions that are partially
|
||||
unbounded without tripping over the None values."""
|
||||
doc = DesignSpaceDocument()
|
||||
|
||||
doc.addAxisDescriptor(
|
||||
name="Weight", tag="wght", minimum=400, maximum=1000, default=400
|
||||
)
|
||||
|
||||
doc.addRuleDescriptor(
|
||||
name="unbounded",
|
||||
conditionSets=[[unbounded_condition]],
|
||||
)
|
||||
|
||||
assert len(list(splitInterpolable(doc))) == 1
|
||||
assert len(list(splitVariableFonts(doc))) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
["condition", "expected_set"],
|
||||
[
|
||||
(
|
||||
{"name": "axis", "minimum": 0.5, "maximum": None},
|
||||
{"axis": Range(minimum=0.5, maximum=math.inf)},
|
||||
),
|
||||
(
|
||||
{"name": "axis", "minimum": None, "maximum": 0.5},
|
||||
{"axis": Range(minimum=-math.inf, maximum=0.5)},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_optional_min_max_internal(condition, expected_set: ConditionSet):
|
||||
"""Check that split's internal helper functions produce the correct output
|
||||
for conditions that are partially unbounded."""
|
||||
assert _conditionSetFrom([condition]) == expected_set
|
||||
|
Loading…
x
Reference in New Issue
Block a user