Skip to content

Commit

Permalink
WIP fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
belluzj committed Oct 31, 2017
1 parent 607f3be commit bef2814
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 31 deletions.
5 changes: 3 additions & 2 deletions Lib/glyphsLib/builder/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import defcon

from glyphsLib import classes, glyphdata_generated
from .constants import PUBLIC_PREFIX, GLYPHS_PREFIX
from .constants import PUBLIC_PREFIX, GLYPHS_PREFIX, FONT_CUSTOM_PARAM_PREFIX

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -198,7 +198,8 @@ def instance_data(self):
# the 'Variation Font Origin' is a font-wide custom parameter, thus it is
# shared by all the master ufos; here we just get it from the first one
varfont_origin_key = "Variation Font Origin"
varfont_origin = first_ufo.lib.get(GLYPHS_PREFIX + varfont_origin_key)
varfont_origin = first_ufo.lib.get(FONT_CUSTOM_PARAM_PREFIX +
varfont_origin_key)
if varfont_origin:
instance_data[varfont_origin_key] = varfont_origin
return instance_data
Expand Down
3 changes: 3 additions & 0 deletions Lib/glyphsLib/builder/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
ROBOFONT_PREFIX = 'com.typemytype.robofont.'
UFO2FT_FILTERS_KEY = 'com.github.googlei18n.ufo2ft.filters'

MASTER_CUSTOM_PARAM_PREFIX = GLYPHS_PREFIX + 'customParameter.GSFontMaster.'
FONT_CUSTOM_PARAM_PREFIX = GLYPHS_PREFIX + 'customParameter.GSFont.'

GLYPHS_COLORS = (
'0.85,0.26,0.06,1',
'0.99,0.62,0.11,1',
Expand Down
1 change: 0 additions & 1 deletion Lib/glyphsLib/builder/custom_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def register(handler):
# enforce that winAscent/Descent are positive, according to UFO spec
for glyphs_name in ('winAscent', 'winDescent'):
ufo_name = 'openTypeOS2W' + glyphs_name[1:]
# FIXME: (jany) family or master?
register(ParamHandler(
glyphs_name, ufo_name, glyphs_long_name=ufo_name,
value_to_ufo=lambda value: -abs(value),
Expand Down
2 changes: 1 addition & 1 deletion Lib/glyphsLib/builder/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def to_ufo_font_attributes(self, family_name):

master_id = master.id
ufo.lib[GLYPHS_PREFIX + 'fontMasterID'] = master_id
# FIXME: (jany) in the future, yield this UFO (for memory, laze iter)
# FIXME: (jany) in the future, yield this UFO (for memory, lazy iter)
self._ufos[master_id] = ufo


Expand Down
4 changes: 3 additions & 1 deletion Lib/glyphsLib/builder/guidelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def to_ufo_guidelines(self, ufo_obj, glyphs_obj):
name = guideline.name
if guideline.locked:
name += LOCKED_NAME_SUFFIX
new_guideline = {'x': x, 'y': y, 'angle': angle, 'name': name}
new_guideline = {'x': x, 'y': y, 'angle': angle}
if name:
new_guideline['name'] = name
new_guidelines.append(new_guideline)
ufo_obj.guidelines = new_guidelines

Expand Down
2 changes: 0 additions & 2 deletions Lib/glyphsLib/builder/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# FIXME: (jany) This file should be part of the builder?

from __future__ import (print_function, division, absolute_import,
unicode_literals)

Expand Down
2 changes: 1 addition & 1 deletion Lib/glyphsLib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def reverse_cast_to_number_or_bool(input):
if input is True:
return 'true' # FIXME: (jany) dubious, glyphs handbook says should be 1
if input is False:
return 'true' # FIXME: (jany) dubious, glyphs handbook says should be 0
return 'false' # FIXME: (jany) dubious, glyphs handbook says should be 0
return str(input)


Expand Down
63 changes: 40 additions & 23 deletions tests/builder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
_set_default_params)
from glyphsLib.builder.names import build_stylemap_names, build_style_name
from glyphsLib.builder.filters import parse_glyphs_filter
from glyphsLib.builder.constants import (GLYPHS_PREFIX, PUBLIC_PREFIX,
GLYPHLIB_PREFIX)
from glyphsLib.builder.constants import (
GLYPHS_PREFIX, PUBLIC_PREFIX, GLYPHLIB_PREFIX, FONT_CUSTOM_PARAM_PREFIX,
MASTER_CUSTOM_PARAM_PREFIX)

from classes_test import (generate_minimal_font, generate_instance_from_dict,
add_glyph, add_anchor, add_component)
Expand Down Expand Up @@ -290,8 +291,8 @@ def test_normalizes_curved_quotes_in_names(self):
GSCustomParameter(name='“also bad”', value=2),
]
self.set_custom_params()
self.assertIn(GLYPHS_PREFIX + "'bad'", self.ufo.lib)
self.assertIn(GLYPHS_PREFIX + '"also bad"', self.ufo.lib)
self.assertIn(MASTER_CUSTOM_PARAM_PREFIX + "'bad'", self.ufo.lib)
self.assertIn(MASTER_CUSTOM_PARAM_PREFIX + '"also bad"', self.ufo.lib)

def test_set_glyphOrder(self):
self.master.customParameters['glyphOrder'] = ['A', 'B']
Expand Down Expand Up @@ -400,13 +401,14 @@ def test_gasp_table(self):
def test_set_disables_nice_names(self):
self.font.disablesNiceNames = False
self.set_custom_params()
self.assertEqual(True, self.ufo.lib[GLYPHS_PREFIX + 'useNiceNames'])
self.assertEqual(True, self.ufo.lib[FONT_CUSTOM_PARAM_PREFIX +
'useNiceNames'])

def test_set_disable_last_change(self):
self.font.customParameters['Disable Last Change'] = True
self.set_custom_params()
self.assertEqual(True,
self.ufo.lib[GLYPHS_PREFIX + 'disablesLastChange'])
self.assertEqual(True, self.ufo.lib[FONT_CUSTOM_PARAM_PREFIX +
'disablesLastChange'])


class ParseGlyphsFilterTest(unittest.TestCase):
Expand Down Expand Up @@ -799,8 +801,8 @@ def test_variation_font_origin(self):

ufos, instances = to_ufos(font, include_instances=True)

key = FONT_CUSTOM_PARAM_PREFIX + name
for ufo in ufos:
key = GLYPHS_PREFIX + name
self.assertIn(key, ufo.lib)
self.assertEqual(ufo.lib[key], value)
self.assertIn(name, instances)
Expand Down Expand Up @@ -935,19 +937,21 @@ def test_lib_width(self):
def test_lib_no_custom(self):
font = generate_minimal_font()
ufo = to_ufos(font)[0]
self.assertFalse(GLYPHS_PREFIX + 'customName' in ufo.lib)
self.assertFalse(MASTER_CUSTOM_PARAM_PREFIX + 'customName' in ufo.lib)

def test_lib_custom(self):
font = generate_minimal_font()
font.masters[0].customName = 'FooBar'
ufo = to_ufos(font)[0]
self.assertEqual(ufo.lib[GLYPHS_PREFIX + 'customName'], 'FooBar')
self.assertEqual(
ufo.lib[MASTER_CUSTOM_PARAM_PREFIX + 'customName'], 'FooBar')

def test_coerce_to_bool(self):
font = generate_minimal_font()
font.customParameters['Disable Last Change'] = 'Truthy'
ufo = to_ufos(font)[0]
self.assertEqual(True, ufo.lib[GLYPHS_PREFIX + 'disablesLastChange'])
self.assertEqual(True, ufo.lib[FONT_CUSTOM_PARAM_PREFIX +
'disablesLastChange'])

def _run_guideline_test(self, data_in, expected):
font = generate_minimal_font()
Expand Down Expand Up @@ -1024,15 +1028,28 @@ def addComponent(self, *args, **kwargs):
pass


class _Glyph(object):
def __init__(self):
self.pen = _PointDataPen()

def getPointPen(self):
return self.pen


class _UFOBuilder(object):
def to_ufo_node_user_data(self, *args):
pass


class DrawPathsTest(unittest.TestCase):

def test_to_ufo_draw_paths_empty_nodes(self):
contours = [GSPath()]

pen = _PointDataPen()
to_ufo_draw_paths(None, pen, contours)
glyph = _Glyph()
to_ufo_draw_paths(_UFOBuilder(), glyph, contours)

self.assertEqual(pen.contours, [])
self.assertEqual(glyph.pen.contours, [])

def test_to_ufo_draw_paths_open(self):
path = GSPath()
Expand All @@ -1043,10 +1060,10 @@ def test_to_ufo_draw_paths_open(self):
GSNode(position=(3, 3), nodetype='curve', smooth=True),
]
path.closed = False
pen = _PointDataPen()
to_ufo_draw_paths(None, pen, [path])
glyph = _Glyph()
to_ufo_draw_paths(_UFOBuilder(), glyph, [path])

self.assertEqual(pen.contours, [[
self.assertEqual(glyph.pen.contours, [[
(0, 0, 'move', False),
(1, 1, None, False),
(2, 2, None, False),
Expand All @@ -1065,10 +1082,10 @@ def test_to_ufo_draw_paths_closed(self):
]
path.closed = True

pen = _PointDataPen()
to_ufo_draw_paths(None, pen, [path])
glyph = _Glyph()
to_ufo_draw_paths(_UFOBuilder(), glyph, [path])

points = pen.contours[0]
points = glyph.pen.contours[0]

first_x, first_y = points[0][:2]
self.assertEqual((first_x, first_y), (5, 5))
Expand All @@ -1087,10 +1104,10 @@ def test_to_ufo_draw_paths_qcurve(self):
]
path.closed = True

pen = _PointDataPen()
to_ufo_draw_paths(None, pen, [path])
glyph = _Glyph()
to_ufo_draw_paths(_UFOBuilder(), glyph, [path])

points = pen.contours[0]
points = glyph.pen.contours[0]

first_x, first_y = points[0][:2]
self.assertEqual((first_x, first_y), (223, 334))
Expand Down

0 comments on commit bef2814

Please sign in to comment.