diff options
Diffstat (limited to 'Tests/varLib/models_test.py')
-rw-r--r-- | Tests/varLib/models_test.py | 175 |
1 files changed, 116 insertions, 59 deletions
diff --git a/Tests/varLib/models_test.py b/Tests/varLib/models_test.py index c5c2a9a6..ae67e0e9 100644 --- a/Tests/varLib/models_test.py +++ b/Tests/varLib/models_test.py @@ -2,6 +2,7 @@ from __future__ import print_function, division, absolute_import from fontTools.misc.py23 import * from fontTools.varLib.models import ( normalizeLocation, supportScalar, VariationModel) +import pytest def test_normalizeLocation(): @@ -35,65 +36,121 @@ def test_supportScalar(): assert supportScalar({'wght':2.5}, {'wght':(0,2,4)}) == 0.75 -def test_VariationModel(): - locations = [ - {'wght':100}, - {'wght':-100}, - {'wght':-180}, - {'wdth':+.3}, - {'wght':+120,'wdth':.3}, - {'wght':+120,'wdth':.2}, - {}, - {'wght':+180,'wdth':.3}, - {'wght':+180}, - ] - model = VariationModel(locations, axisOrder=['wght']) +class VariationModelTest(object): - assert model.locations == [ - {}, - {'wght': -100}, - {'wght': -180}, - {'wght': 100}, - {'wght': 180}, - {'wdth': 0.3}, - {'wdth': 0.3, 'wght': 180}, - {'wdth': 0.3, 'wght': 120}, - {'wdth': 0.2, 'wght': 120}] + @pytest.mark.parametrize( + "locations, axisOrder, sortedLocs, supports, deltaWeights", + [ + ( + [ + {'wght': 0.55, 'wdth': 0.0}, + {'wght': -0.55, 'wdth': 0.0}, + {'wght': -1.0, 'wdth': 0.0}, + {'wght': 0.0, 'wdth': 1.0}, + {'wght': 0.66, 'wdth': 1.0}, + {'wght': 0.66, 'wdth': 0.66}, + {'wght': 0.0, 'wdth': 0.0}, + {'wght': 1.0, 'wdth': 1.0}, + {'wght': 1.0, 'wdth': 0.0}, + ], + ["wght"], + [ + {}, + {'wght': -0.55}, + {'wght': -1.0}, + {'wght': 0.55}, + {'wght': 1.0}, + {'wdth': 1.0}, + {'wdth': 1.0, 'wght': 1.0}, + {'wdth': 1.0, 'wght': 0.66}, + {'wdth': 0.66, 'wght': 0.66} + ], + [ + {}, + {'wght': (-1.0, -0.55, 0)}, + {'wght': (-1.0, -1.0, -0.55)}, + {'wght': (0, 0.55, 1.0)}, + {'wght': (0.55, 1.0, 1.0)}, + {'wdth': (0, 1.0, 1.0)}, + {'wdth': (0, 1.0, 1.0), 'wght': (0, 1.0, 1.0)}, + {'wdth': (0, 1.0, 1.0), 'wght': (0, 0.66, 1.0)}, + {'wdth': (0, 0.66, 1.0), 'wght': (0, 0.66, 1.0)} + ], + [ + {}, + {0: 1.0}, + {0: 1.0}, + {0: 1.0}, + {0: 1.0}, + {0: 1.0}, + {0: 1.0, + 4: 1.0, + 5: 1.0}, + {0: 1.0, + 3: 0.7555555555555555, + 4: 0.24444444444444444, + 5: 1.0, + 6: 0.66}, + {0: 1.0, + 3: 0.7555555555555555, + 4: 0.24444444444444444, + 5: 0.66, + 6: 0.43560000000000006, + 7: 0.66} + ] + ), + ( + [ + {}, + {'bar': 0.5}, + {'bar': 1.0}, + {'foo': 1.0}, + {'bar': 0.5, 'foo': 1.0}, + {'bar': 1.0, 'foo': 1.0}, + ], + None, + [ + {}, + {'bar': 0.5}, + {'bar': 1.0}, + {'foo': 1.0}, + {'bar': 0.5, 'foo': 1.0}, + {'bar': 1.0, 'foo': 1.0}, + ], + [ + {}, + {'bar': (0, 0.5, 1.0)}, + {'bar': (0.5, 1.0, 1.0)}, + {'foo': (0, 1.0, 1.0)}, + {'bar': (0, 0.5, 1.0), 'foo': (0, 1.0, 1.0)}, + {'bar': (0.5, 1.0, 1.0), 'foo': (0, 1.0, 1.0)}, + ], + [ + {}, + {0: 1.0}, + {0: 1.0}, + {0: 1.0}, + {0: 1.0, 1: 1.0, 3: 1.0}, + {0: 1.0, 2: 1.0, 3: 1.0}, + ], + ) + ] + ) + def test_init( + self, locations, axisOrder, sortedLocs, supports, deltaWeights + ): + model = VariationModel(locations, axisOrder=axisOrder) - assert model.deltaWeights == [ - {}, - {0: 1.0}, - {0: 1.0}, - {0: 1.0}, - {0: 1.0}, - {0: 1.0}, - {0: 1.0, 4: 1.0, 5: 1.0}, - {0: 1.0, 3: 0.75, 4: 0.25, 5: 1.0, 6: 0.6666666666666666}, - {0: 1.0, - 3: 0.75, - 4: 0.25, - 5: 0.6666666666666667, - 6: 0.4444444444444445, - 7: 0.6666666666666667}] + assert model.locations == sortedLocs + assert model.supports == supports + assert model.deltaWeights == deltaWeights -def test_VariationModel(): - locations = [ - {}, - {'bar': 0.5}, - {'bar': 1.0}, - {'foo': 1.0}, - {'bar': 0.5, 'foo': 1.0}, - {'bar': 1.0, 'foo': 1.0}, - ] - model = VariationModel(locations) - - assert model.locations == locations - - assert model.supports == [ - {}, - {'bar': (0, 0.5, 1.0)}, - {'bar': (0.5, 1.0, 1.0)}, - {'foo': (0, 1.0, 1.0)}, - {'bar': (0, 0.5, 1.0), 'foo': (0, 1.0, 1.0)}, - {'bar': (0.5, 1.0, 1.0), 'foo': (0, 1.0, 1.0)}, - ] + def test_init_duplicate_locations(self): + with pytest.raises(ValueError, match="locations must be unique"): + VariationModel( + [ + {"foo": 0.0, "bar": 0.0}, + {"foo": 1.0, "bar": 1.0}, + {"bar": 1.0, "foo": 1.0}, + ] + ) |