File: test_freeze.py

package info (click to toggle)
fonttools-opentype-feature-freezer 1.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 380 kB
  • sloc: python: 1,028; sh: 241; makefile: 2
file content (83 lines) | stat: -rwxr-xr-x 2,401 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import logging
import tempfile

import fontTools.ttLib

import opentype_feature_freezer.cli


def test_freeze(tmp_path, shared_datadir):
    font = fontTools.ttLib.TTFont()
    font.importXML(shared_datadir / "OpenSans-Bold.subset.ttx")
    font_path = tmp_path / "Test.ttf"
    font.save(font_path)

    opentype_feature_freezer.cli.main(
        ["-v", "-f", "c2sc,onum,smcp", "-S", "-U", "SC", "--names", str(font_path)]
    )

    font_processed = fontTools.ttLib.TTFont(
        tmp_path / (font_path.name + ".featfreeze.otf")
    )
    cmap = font_processed.getBestCmap()
    assert cmap[0x30] == "zero.os"
    assert cmap[0x31] == "one.os"
    assert cmap[0x32] == "two.os"
    assert cmap[0x33] == "three.os"
    assert cmap[0x34] == "four.os"
    assert cmap[0x35] == "five.os"
    assert cmap[0x36] == "six.os"
    assert cmap[0x37] == "seven.os"
    assert cmap[0x38] == "eight.os"
    assert cmap[0x39] == "nine.os"


def test_report(tmp_path, shared_datadir, capsys):
    font = fontTools.ttLib.TTFont()
    font.importXML(shared_datadir / "OpenSans-Bold.subset.ttx")
    font_path = tmp_path / "Test.ttf"
    font.save(font_path)

    opentype_feature_freezer.cli.main(
        ["-v", "-f", "c2sc,onum,smcp", "-S", "-U", "SC", "--report", str(font_path)]
    )

    captured = capsys.readouterr()
    assert (
        captured.out
        == """# Scripts and languages:
-s 'latn'
# Features:
-f lnum,onum,pnum,tnum
"""
    )


def test_cant_open():
    with tempfile.NamedTemporaryFile() as f:
        assert (
            opentype_feature_freezer.cli.main(
                ["-v", "-f", "c2sc,onum,smcp", "-S", "-U", "SC", f.name]
            )
            == 1
        )


def test_warn_substituting_glyphs_without_unicode(tmp_path, shared_datadir, caplog):
    font = fontTools.ttLib.TTFont()
    font.importXML(shared_datadir / "SubGlyphsWithoutUnicode.ttx")
    font_path = tmp_path / "Test.ttf"
    font.save(font_path)

    opentype_feature_freezer.cli.main(["-v", "-f", "ss01", "--names", str(font_path)])
    assert any(
        record.levelno == logging.WARNING
        and "neither has a Unicode value" in record.message
        for record in caplog.records
    )

    font_processed = fontTools.ttLib.TTFont(
        tmp_path / (font_path.name + ".featfreeze.otf")
    )
    cmap = font_processed.getBestCmap()
    assert cmap == {0x61: "a.alt1"}  # Takes the first alternate