From a79bb0fa011f7269b835904c60106c76cce0e0fc Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 17 Jan 2017 13:13:37 +0000 Subject: [PATCH] [Tests] convert varLib/models.py doctests into models_test.py --- Tests/varLib/models_test.py | 77 +++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Tests/varLib/models_test.py diff --git a/Tests/varLib/models_test.py b/Tests/varLib/models_test.py new file mode 100644 index 000000000..c0d2000b4 --- /dev/null +++ b/Tests/varLib/models_test.py @@ -0,0 +1,77 @@ +from __future__ import print_function, division, absolute_import +from fontTools.misc.py23 import * +from fontTools.varLib.models import ( + normalizeLocation, supportScalar, VariationModel) + + +def test_normalizeLocation(): + axes = {"wght": (100, 400, 900)} + assert normalizeLocation({"wght": 400}, axes) == {'wght': 0} + assert normalizeLocation({"wght": 100}, axes) == {'wght': -1.0} + assert normalizeLocation({"wght": 900}, axes) == {'wght': 1.0} + assert normalizeLocation({"wght": 650}, axes) == {'wght': 0.5} + assert normalizeLocation({"wght": 1000}, axes) == {'wght': 1.0} + assert normalizeLocation({"wght": 0}, axes) == {'wght': -1.0} + + axes = {"wght": (0, 0, 1000)} + assert normalizeLocation({"wght": 0}, axes) == {'wght': 0} + assert normalizeLocation({"wght": -1}, axes) == {'wght': 0} + assert normalizeLocation({"wght": 1000}, axes) == {'wght': 1.0} + assert normalizeLocation({"wght": 500}, axes) == {'wght': 0.5} + assert normalizeLocation({"wght": 1001}, axes) == {'wght': 1.0} + + axes = {"wght": (0, 1000, 1000)} + assert normalizeLocation({"wght": 0}, axes) == {'wght': -1.0} + assert normalizeLocation({"wght": -1}, axes) == {'wght': -1.0} + assert normalizeLocation({"wght": 500}, axes) == {'wght': -0.5} + assert normalizeLocation({"wght": 1000}, axes) == {'wght': 0} + assert normalizeLocation({"wght": 1001}, axes) == {'wght': 0} + + +def test_supportScalar(): + assert supportScalar({}, {}) == 1.0 + assert supportScalar({'wght':.2}, {}) == 1.0 + assert supportScalar({'wght':.2}, {'wght':(0,2,3)}) == 0.1 + 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']) + + 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}] + + 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.25}, + {0: 1.0, + 3: 0.75, + 4: 0.25, + 5: 0.6666666666666667, + 6: 0.16666666666666669, + 7: 0.6666666666666667}]