diff --git a/Lib/ufoLib/test/test_GLIF2.py b/Lib/ufoLib/test/test_GLIF2.py
new file mode 100644
index 000000000..07f5a940c
--- /dev/null
+++ b/Lib/ufoLib/test/test_GLIF2.py
@@ -0,0 +1,1904 @@
+import unittest
+from ufoLib.glifLib import GlifLibError, readGlyphFromString, writeGlyphToString
+from ufoLib.test.testSupport import Glyph, stripText
+
+# ----------
+# Test Cases
+# ----------
+
+class TestGLIF1(unittest.TestCase):
+
+ def assertEqual(self, first, second, msg=None):
+ if isinstance(first, basestring):
+ first = stripText(first)
+ if isinstance(second, basestring):
+ second = stripText(second)
+ return super(TestGLIF1, self).assertEqual(first, second, msg=msg)
+
+ def pyToGLIF(self, py):
+ py = stripText(py)
+ glyph = Glyph()
+ exec py in {"glyph" : glyph, "pointPen" : glyph}
+ glif = writeGlyphToString(glyph.name, glyphObject=glyph, drawPointsFunc=glyph.drawPoints, formatVersion=2)
+ glif = "\n".join(glif.splitlines()[1:])
+ return glif
+
+ def glifToPy(self, glif):
+ glif = stripText(glif)
+ glif = "\n" + glif
+ glyph = Glyph()
+ readGlyphFromString(glif, glyphObject=glyph, pointPen=glyph)
+ return glyph.py()
+
+ def testTopElement(self):
+ # not glyph
+ glif = """
+
+
+
+
+ """
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testName(self):
+ # legal
+ glif = """
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # empty
+ glif = """
+
+
+
+
+ """
+ py = """
+ glyph.name = ""
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # not a string
+ py = """
+ glyph.name = 1
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+
+ def testFormat(self):
+ # legal
+ glif = """
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # wrong number
+ glif = """
+
+
+
+
+ """
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # not an int
+ glif = """
+
+
+
+
+ """
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testBogusGlyphStructure(self):
+ # unknown element
+ glif = """
+
+
+
+ """
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # content
+ glif = """
+
+ Hello World.
+
+ """
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testAdvance(self):
+ # legal: width and height
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.width = 100
+ glyph.height = 200
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: width and height floats
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.width = 100.1
+ glyph.height = 200.1
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: width
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.width = 100
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: height
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.height = 200
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # illegal: not a number
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.width = "a"
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.height = "a"
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testUnicodes(self):
+ # legal
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.unicodes = [97]
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ glif = """
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.unicodes = [98, 99, 97]
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # illegal
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "zzzzzz"
+ glyph.unicodes = ["1.1"]
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testNote(self):
+ glif = """
+
+
+ hello
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.note = "hello"
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+
+ def testLib(self):
+ glif = """
+
+
+
+
+
+ dict
+
+ hello
+ world
+
+ float
+ 2.5
+ int
+ 1
+ list
+
+ a
+ b
+ 1
+ 2.5
+
+ string
+ a
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.lib = {"dict" : {"hello" : "world"}, "float" : 2.5, "int" : 1, "list" : ["a", "b", 1, 2.5], "string" : "a"}
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+
+ def testGuidelines(self):
+ # legal
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"x" : 1}, {"y" : 1}, {"angle" : 0, "x" : 1, "y" : 1}, {"angle" : 360, "x" : 1, "y" : 1}, {"angle" : 45.5, "x" : 1.1, "y" : 1.1}, {"name" : "a", "x" : 1}, {"color" : "1,1,1,1", "x" : 1}]
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # x not an int or float
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"angle" : 45, "x" : "a", "y" : 1}]
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # y not an int or float
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"angle" : 45, "x" : 1, "y" : "a"}]
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # angle not an int or float
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"angle" : "a", "x" : 1, "y" : 1}]
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # x missing
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"angle" : 45, "y" : 1}]
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # y missing
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"angle" : 45, "x" : 1}]
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # angle missing
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"x" : 1, "y" : 1}]
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # angle out of range
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"angle" : -1, "x" : "1", "y" : 1}]
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"angle" : 361, "x" : "1", "y" : 1}]
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testImage(self):
+ # legal
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"color" : "1,1,1,1", "fileName" : "test.png", "xOffset" : 1, "xScale" : 2, "xyScale" : 3, "yOffset" : 4, "yScale" : 5, "yxScale" : 6}
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: no color or transformation
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"fileName" : "test.png"}
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # no file name
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"color" : "1,1,1,1", "xOffset" : 1, "xScale" : 2, "xyScale" : 3, "yOffset" : 4, "yScale" : 5, "yxScale" : 6}
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # bogus transformation
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"fileName" : "test.png", "xOffset" : 1, "xScale" : "a", "xyScale" : 3, "yOffset" : 4, "yScale" : 5, "yxScale" : 6}
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"fileName" : "test.png", "xOffset" : 1, "xScale" : 2, "xyScale" : "a", "yOffset" : 4, "yScale" : 5, "yxScale" : 6}
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"fileName" : "test.png", "xOffset" : 1, "xScale" : 2, "xyScale" : 3, "yOffset" : 4, "yScale" : 5, "yxScale" : "a"}
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"fileName" : "test.png", "xOffset" : 1, "xScale" : 2, "xyScale" : 3, "yOffset" : 4, "yScale" : "a", "yxScale" : 6}
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"fileName" : "test.png", "xOffset" : "a", "xScale" : 2, "xyScale" : 3, "yOffset" : 4, "yScale" : 5, "yxScale" : 6}
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"fileName" : "test.png", "xOffset" : 1, "xScale" : 2, "xyScale" : 3, "yOffset" : "a", "yScale" : 5, "yxScale" : 6}
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # bogus color
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.image = {"color" : "1,1,1,x"}
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testOutline(self):
+ # unknown element
+ glif = """
+
+
+
+
+
+ """
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # content
+ glif = """
+
+
+ hello
+
+
+ """
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testComponent(self):
+ # legal
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.addComponent(*["x", (2, 3, 6, 5, 1, 4)])
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # no base
+ glif = """
+
+
+
+
+
+ """
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # bogus values in transformation
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.addComponent(*["x", ("a", 3, 6, 5, 1, 4)])
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.addComponent(*["x", (2, "a", 6, 5, 1, 4)])
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.addComponent(*["x", (2, 3, "a", 5, 1, 4)])
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.addComponent(*["x", (2, 3, 6, "a", 1, 4)])
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.addComponent(*["x", (2, 3, 6, 5, "a", 4)])
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ glif = """
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.addComponent(*["x", (2, 3, 6, 5, 1, "a")])
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testContour(self):
+ # legal: one contour
+ glif = """
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: two contours
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, 2)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, 2)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(10, 20)], **{"segmentType" : "line", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # unknown element
+ glif = """
+
+
+
+
+
+
+
+ """
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testContourIdentifier(self):
+ glif = """
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath(**{"identifier" : "foo"})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+
+ def testPointCoordinates(self):
+ # legal: int
+ glif = """
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, -2)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: float
+ glif = """
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1.1, -2.2)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: int
+ glif = """
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[("a", 2)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # legal: int
+ glif = """
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, "a")], **{"segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testPointTypeMove(self):
+ # legal
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, -2)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(3, -4)], **{"segmentType" : "line", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # illegal: smooth=True
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, -2)], **{"segmentType" : "move", "smooth" : True})
+ pointPen.addPoint(*[(3, -4)], **{"segmentType" : "line", "smooth" : False})
+ pointPen.endPath()
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # illegal: not at start
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(3, -4)], **{"segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testPointTypeLine(self):
+ # legal
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, -2)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(3, -4)], **{"segmentType" : "line", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: start of contour
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, -2)], **{"segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(3, -4)], **{"segmentType" : "line", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # illegal: smooth=True
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, -2)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(3, -4)], **{"segmentType" : "line", "smooth" : True})
+ pointPen.endPath()
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testPointTypeCurve(self):
+ # legal
+ glif = """
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "curve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: start of contour
+ glif = """
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: smooth=True
+ glif = """
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "curve", "smooth" : True})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: no off-curves
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "curve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: 1 off-curve
+ glif = """
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(50, 100)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "curve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # illegal: 3 off-curves
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(0, 100)], **{"smooth" : False})
+ pointPen.addPoint(*[(35, 125)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "curve", "smooth" : False})
+ pointPen.endPath()
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testPointQCurve(self):
+ # legal
+ glif = """
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: start of contour
+ glif = """
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "qcurve", "smooth" : False})
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: smooth=True
+ glif = """
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "qcurve", "smooth" : True})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: no off-curves
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: 1 off-curve
+ glif = """
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(50, 100)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: 3 off-curves
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(0, 100)], **{"smooth" : False})
+ pointPen.addPoint(*[(35, 125)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+
+ def testPointTypeOffCurve(self):
+ # legal
+ glif = """
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "curve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # legal: start of contour
+ glif = """
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(65, 200)], **{"smooth" : False})
+ pointPen.addPoint(*[(100, 200)], **{"segmentType" : "curve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # before move
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # before line
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : False})
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "line", "smooth" : False})
+ pointPen.endPath()
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # smooth=True
+ glif = """
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(0, 65)], **{"smooth" : True})
+ pointPen.addPoint(*[(0, 0)], **{"segmentType" : "curve", "smooth" : False})
+ pointPen.endPath()
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+ def testPointIdentifier(self):
+ glif = """
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ pointPen.beginPath()
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+
+ def testIdentifierConflict(self):
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ resultGlif = self.pyToGLIF(py)
+ resultPy = self.glifToPy(glif)
+ self.assertEqual(glif, resultGlif)
+ self.assertEqual(py, resultPy)
+ # point - point
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # point - point
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # point - contour
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "contour1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # point - component
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "component1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # point - guideline
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "guideline1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # contour - contour
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # contour - component
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "contour1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # contour - guideline
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "contour1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # component - component
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # component - guideline
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "component1", "x" : 0}, {"identifier" : "guideline2", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+ # guideline - guideline
+ glif = """
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ py = """
+ glyph.name = "a"
+ glyph.guidelines = [{"identifier" : "guideline1", "x" : 0}, {"identifier" : "guideline1", "x" : 0}]
+ pointPen.beginPath(**{"identifier" : "contour1"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point1", "segmentType" : "move", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point2", "segmentType" : "line", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point3", "segmentType" : "curve", "smooth" : False})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point4", "segmentType" : "qcurve", "smooth" : False})
+ pointPen.endPath()
+ pointPen.beginPath(**{"identifier" : "contour2"})
+ pointPen.addPoint(*[(1, -2)], **{"identifier" : "point5", "segmentType" : "move", "smooth" : False})
+ pointPen.endPath()
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component1"})
+ pointPen.addComponent(*["x", (1, 1, 1, 1, 1, 1)], **{"identifier" : "component2"})
+ """
+ self.assertRaises(GlifLibError, self.pyToGLIF, py)
+ self.assertRaises(GlifLibError, self.glifToPy, glif)
+
+
+if __name__ == "__main__":
+ from robofab.test.testSupport import runTests
+ runTests()