1from __future__ import print_function, division, absolute_import 2from fontTools.misc.py23 import * 3from fontTools.pens.recordingPen import RecordingPen, DecomposingRecordingPen 4import pytest 5 6 7class _TestGlyph(object): 8 9 def draw(self, pen): 10 pen.moveTo((0.0, 0.0)) 11 pen.lineTo((0.0, 100.0)) 12 pen.curveTo((50.0, 75.0), (60.0, 50.0), (50.0, 0.0)) 13 pen.closePath() 14 15 16class RecordingPenTest(object): 17 18 def test_addComponent(self): 19 pen = RecordingPen() 20 pen.addComponent("a", (2, 0, 0, 3, -10, 5)) 21 assert pen.value == [("addComponent", ("a", (2, 0, 0, 3, -10, 5)))] 22 23 24class DecomposingRecordingPenTest(object): 25 26 def test_addComponent_decomposed(self): 27 pen = DecomposingRecordingPen({"a": _TestGlyph()}) 28 pen.addComponent("a", (2, 0, 0, 3, -10, 5)) 29 assert pen.value == [ 30 ('moveTo', ((-10.0, 5.0),)), 31 ('lineTo', ((-10.0, 305.0),)), 32 ('curveTo', ((90.0, 230.0), (110.0, 155.0), (90.0, 5.0),)), 33 ('closePath', ())] 34 35 def test_addComponent_missing_raises(self): 36 pen = DecomposingRecordingPen(dict()) 37 with pytest.raises(KeyError) as excinfo: 38 pen.addComponent("a", (1, 0, 0, 1, 0, 0)) 39 assert excinfo.value.args[0] == "a" 40