Exemple #1
0
def test_insertGlyph():
    g = Glyph()
    pen = g.getPen()
    pen.moveTo((0, 0))
    pen.lineTo((1, 1))
    pen.lineTo((0, 1))
    pen.closePath()

    layer = Layer()
    layer.insertGlyph(g, "a")

    assert "a" in layer
    assert layer["a"].name == "a"
    assert layer["a"].contours == g.contours
    assert layer["a"] is not g

    layer.insertGlyph(g, "b")
    assert "b" in layer
    assert layer["b"].name == "b"
    assert layer["b"].contours == layer["a"].contours
    assert layer["b"] is not layer["a"]
    assert layer["b"] is not g

    assert g.name is None

    with pytest.raises(KeyError, match="glyph named 'a' already exists"):
        layer.insertGlyph(g, "a", overwrite=False)

    with pytest.raises(ValueError,
                       match=".*Glyph .* has no name; can't add it"):
        layer.insertGlyph(g)
Exemple #2
0
def test_renameGlyph() -> None:
    g = Glyph()

    layer = Layer(glyphs={"a": g})
    assert g.name == "a"

    layer.renameGlyph("a", "a")  # no-op
    assert g.name == "a"

    layer.renameGlyph("a", "b")
    assert g.name == "b"

    layer.insertGlyph(g, "a")

    with pytest.raises(KeyError, match="target glyph named 'a' already exists"):
        layer.renameGlyph("b", "a")