aboutsummaryrefslogtreecommitdiff
path: root/Tests/ufoLib/UFO3_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/ufoLib/UFO3_test.py')
-rw-r--r--Tests/ufoLib/UFO3_test.py59
1 files changed, 43 insertions, 16 deletions
diff --git a/Tests/ufoLib/UFO3_test.py b/Tests/ufoLib/UFO3_test.py
index 3cfd7c8f..c4218023 100644
--- a/Tests/ufoLib/UFO3_test.py
+++ b/Tests/ufoLib/UFO3_test.py
@@ -1,18 +1,15 @@
-# -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals
import os
import shutil
import unittest
import tempfile
from io import open
-from fontTools.misc.py23 import unicode
from fontTools.ufoLib import UFOReader, UFOWriter, UFOLibError
from fontTools.ufoLib.glifLib import GlifLibError
from fontTools.misc import plistlib
from .testSupport import fontInfoVersion3
-class TestInfoObject(object): pass
+class TestInfoObject: pass
# --------------
@@ -3943,6 +3940,26 @@ class UFO3WriteLayersTestCase(unittest.TestCase):
result = list(writer.getGlyphSet("layer 2", defaultLayer=False).keys())
self.assertEqual(expected, result)
+ def testGetGlyphSetNoContents(self):
+ self.makeUFO()
+ os.remove(os.path.join(self.ufoPath, "glyphs.layer 1", "contents.plist"))
+
+ reader = UFOReader(self.ufoPath, validate=True)
+ with self.assertRaises(GlifLibError):
+ reader.getGlyphSet("layer 1")
+
+ writer = UFOWriter(self.ufoPath, validate=True)
+ with self.assertRaises(GlifLibError):
+ writer.getGlyphSet("layer 1", defaultLayer=False, expectContentsFile=True)
+
+ # There's a separate code path for < v3 UFOs.
+ with open(os.path.join(self.ufoPath, "metainfo.plist"), "wb") as f:
+ plistlib.dump(dict(creator="test", formatVersion=2), f)
+ os.remove(os.path.join(self.ufoPath, "glyphs", "contents.plist"))
+ writer = UFOWriter(self.ufoPath, validate=True, formatVersion=2)
+ with self.assertRaises(GlifLibError):
+ writer.getGlyphSet(expectContentsFile=True)
+
# make a new font with two layers
def testNewFontOneLayer(self):
@@ -4108,16 +4125,14 @@ class UFO3WriteLayersTestCase(unittest.TestCase):
self.makeUFO()
writer = UFOWriter(self.ufoPath)
writer.deleteGlyphSet("public.default")
+ writer.writeLayerContents(["layer 1", "layer 2"])
# directories
path = os.path.join(self.ufoPath, "glyphs")
- exists = os.path.exists(path)
- self.assertEqual(False, exists)
+ self.assertEqual(False, os.path.exists(path))
path = os.path.join(self.ufoPath, "glyphs.layer 1")
- exists = os.path.exists(path)
- self.assertEqual(True, exists)
+ self.assertEqual(True, os.path.exists(path))
path = os.path.join(self.ufoPath, "glyphs.layer 2")
- exists = os.path.exists(path)
- self.assertEqual(True, exists)
+ self.assertEqual(True, os.path.exists(path))
# layer contents
path = os.path.join(self.ufoPath, "layercontents.plist")
with open(path, "rb") as f:
@@ -4127,7 +4142,7 @@ class UFO3WriteLayersTestCase(unittest.TestCase):
# remove unknown layer
- def testRemoveDefaultLayer(self):
+ def testRemoveDefaultLayer2(self):
self.makeUFO()
writer = UFOWriter(self.ufoPath)
self.assertRaises(UFOLibError, writer.deleteGlyphSet, "does not exist")
@@ -4141,8 +4156,7 @@ class UFO3WriteLayersTestCase(unittest.TestCase):
]
)
writer = UFOWriter(self.ufoPath)
- # if passed bytes string, it'll be decoded to ASCII unicode string
- writer.writeLayerContents(["public.default", "layer 2", b"layer 1"])
+ writer.writeLayerContents(["public.default", "layer 2", "layer 1"])
path = os.path.join(self.ufoPath, "layercontents.plist")
with open(path, "rb") as f:
result = plistlib.load(f)
@@ -4152,8 +4166,8 @@ class UFO3WriteLayersTestCase(unittest.TestCase):
["layer 1", "glyphs.layer 1"],
]
self.assertEqual(expected, result)
- for layerName, directory in result:
- assert isinstance(layerName, unicode)
+ for layerName, _ in result:
+ assert isinstance(layerName, str)
# -----
# /data
@@ -4198,6 +4212,19 @@ class UFO3ReadDataTestCase(unittest.TestCase):
fileObject = reader.getReadFileForPath("data/org.unifiedfontobject.doesNotExist")
self.assertEqual(fileObject, None)
+ def testUFOReaderKernGroupDuplicatesRemoved(self):
+ # Non-kerning group duplicates are kept
+ # Kerning group duplicates are removed
+ expected_groups = {
+ "group1" : ["A"],
+ "group2" : ["B", "C", "B"],
+ "public.kern1.A" : ["A"],
+ "public.kern2.B" : ["B", "A", "C"],
+ }
+ reader = UFOReader(self.getFontPath())
+ groups = reader.readGroups()
+ self.assertEqual(expected_groups, groups)
+
class UFO3WriteDataTestCase(unittest.TestCase):
@@ -4311,7 +4338,7 @@ class UFO3WriteDataTestCase(unittest.TestCase):
# layerinfo.plist
# ---------------
-class TestLayerInfoObject(object):
+class TestLayerInfoObject:
color = guidelines = lib = None