def test_appendGuideline(self): glyph = Glyph() glyph.dirty = False guideline = Guideline() glyph.appendGuideline(guideline) self.assertEqual(len(glyph.guidelines), 1) self.assertTrue(glyph.dirty) self.assertEqual(guideline.getParent(), glyph)
def test_identifiers(self): glyph = Glyph() pointPen = glyph.getPointPen() pointPen.beginPath(identifier="contour 1") pointPen.addPoint((0, 0), identifier="point 1") pointPen.addPoint((0, 0), identifier="point 2") pointPen.endPath() pointPen.beginPath(identifier="contour 2") pointPen.endPath() pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 1") pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 2") guideline = Guideline() guideline.identifier = "guideline 1" glyph.appendGuideline(guideline) guideline = Guideline() guideline.identifier = "guideline 2" glyph.appendGuideline(guideline) self.assertEqual([contour.identifier for contour in glyph], ["contour 1", "contour 2"]) self.assertEqual([point.identifier for point in glyph[0]], ["point 1", "point 2"]) self.assertEqual( [component.identifier for component in glyph.components], ["component 1", "component 2"]) with self.assertRaises(AssertionError): pointPen.beginPath(identifier="contour 1") pointPen.endPath() pointPen.beginPath() pointPen.addPoint((0, 0)) with self.assertRaises(AssertionError): pointPen.addPoint((0, 0), identifier="point 1") pointPen.endPath() with self.assertRaises(AssertionError): pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 1") g = Guideline() g.identifier = "guideline 1" with self.assertRaises(AssertionError): glyph.appendGuideline(g) self.assertEqual(sorted(glyph.identifiers), [ "component 1", "component 2", "contour 1", "contour 2", "guideline 1", "guideline 2", "point 1", "point 2" ]) glyph.removeContour(glyph[0]) self.assertEqual(sorted(glyph.identifiers), [ "component 1", "component 2", "contour 2", "guideline 1", "guideline 2" ]) glyph.removeComponent(glyph.components[0]) self.assertEqual( sorted(glyph.identifiers), ["component 2", "contour 2", "guideline 1", "guideline 2"]) glyph.removeGuideline(glyph.guidelines[0]) self.assertEqual(sorted(glyph.identifiers), ["component 2", "contour 2", "guideline 2"])
def test_identifiers(self): glyph = Glyph() pointPen = glyph.getPointPen() pointPen.beginPath(identifier="contour 1") pointPen.addPoint((0, 0), identifier="point 1") pointPen.addPoint((0, 0), identifier="point 2") pointPen.endPath() pointPen.beginPath(identifier="contour 2") pointPen.endPath() pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 1") pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 2") guideline = Guideline() guideline.identifier = "guideline 1" glyph.appendGuideline(guideline) guideline = Guideline() guideline.identifier = "guideline 2" glyph.appendGuideline(guideline) self.assertEqual([contour.identifier for contour in glyph], ["contour 1", "contour 2"]) self.assertEqual([point.identifier for point in glyph[0]], ["point 1", "point 2"]) self.assertEqual( [component.identifier for component in glyph.components], ["component 1", "component 2"]) with self.assertRaises(AssertionError): pointPen.beginPath(identifier="contour 1") pointPen.endPath() pointPen.beginPath() pointPen.addPoint((0, 0)) with self.assertRaises(AssertionError): pointPen.addPoint((0, 0), identifier="point 1") pointPen.endPath() with self.assertRaises(AssertionError): pointPen.addComponent("A", (1, 1, 1, 1, 1, 1), identifier="component 1") g = Guideline() g.identifier = "guideline 1" with self.assertRaises(AssertionError): glyph.appendGuideline(g) self.assertEqual( sorted(glyph.identifiers), ["component 1", "component 2", "contour 1", "contour 2", "guideline 1", "guideline 2", "point 1", "point 2"]) glyph.removeContour(glyph[0]) self.assertEqual( sorted(glyph.identifiers), ["component 1", "component 2", "contour 2", "guideline 1", "guideline 2"]) glyph.removeComponent(glyph.components[0]) self.assertEqual( sorted(glyph.identifiers), ["component 2", "contour 2", "guideline 1", "guideline 2"]) glyph.removeGuideline(glyph.guidelines[0]) self.assertEqual( sorted(glyph.identifiers), ["component 2", "contour 2", "guideline 2"])