| 1 |
import tempfile |
| 2 |
import pytest |
| 3 |
import shutil |
| 4 |
import os |
| 5 |
import subprocess |
| 6 |
|
| 7 |
from gftools.builder import GFBuilder |
| 8 |
|
| 9 |
|
| 10 |
CWD = os.path.dirname(__file__) |
| 11 |
TEST_DIR = os.path.join(CWD, "..", "data", "test", "builder") |
| 12 |
|
| 13 |
|
| 14 |
@pytest.mark.parametrize( |
| 15 |
"fp,font_paths", |
| 16 |
[ |
| 17 |
|
| 18 |
|
| 19 |
( |
| 20 |
os.path.join(TEST_DIR, "basic_family_glyphs_0"), |
| 21 |
[ |
| 22 |
os.path.join("variable", "TestFamily[wght].ttf"), |
| 23 |
os.path.join("ttf", "TestFamily-Black.ttf"), |
| 24 |
os.path.join("ttf", "TestFamily-Regular.ttf"), |
| 25 |
os.path.join("ttf", "TestFamily-Thin.ttf"), |
| 26 |
os.path.join("otf", "TestFamily-Black.otf"), |
| 27 |
os.path.join("otf", "TestFamily-Regular.otf"), |
| 28 |
os.path.join("otf", "TestFamily-Thin.otf"), |
| 29 |
os.path.join("webfonts", "TestFamily[wght].woff2"), |
| 30 |
os.path.join("webfonts", "TestFamily-Black.woff2"), |
| 31 |
os.path.join("webfonts", "TestFamily-Regular.woff2"), |
| 32 |
os.path.join("webfonts", "TestFamily-Thin.woff2"), |
| 33 |
], |
| 34 |
), |
| 35 |
|
| 36 |
|
| 37 |
( |
| 38 |
os.path.join(TEST_DIR, "check_compatibility_ufo_1"), |
| 39 |
[ |
| 40 |
os.path.join("ttf", "TestFamily-Black.ttf"), |
| 41 |
os.path.join("ttf", "TestFamily-Thin.ttf"), |
| 42 |
os.path.join("otf", "TestFamily-Black.otf"), |
| 43 |
os.path.join("otf", "TestFamily-Thin.otf"), |
| 44 |
os.path.join("webfonts", "TestFamily-Black.woff2"), |
| 45 |
os.path.join("webfonts", "TestFamily-Thin.woff2"), |
| 46 |
], |
| 47 |
), |
| 48 |
|
| 49 |
( |
| 50 |
os.path.join(TEST_DIR, "recipeprovider_noto"), |
| 51 |
[ |
| 52 |
os.path.join("TestFamily", "unhinted", "ttf", "TestFamily-Regular.ttf"), |
| 53 |
os.path.join( |
| 54 |
"TestFamily", "googlefonts", "ttf", "TestFamily-Black.ttf" |
| 55 |
), |
| 56 |
], |
| 57 |
), |
| 58 |
|
| 59 |
( |
| 60 |
os.path.join(TEST_DIR, "split_italic"), |
| 61 |
[ |
| 62 |
os.path.join("variable", "TestFamily[wght].ttf"), |
| 63 |
os.path.join("variable", "TestFamily-Italic[wght].ttf"), |
| 64 |
], |
| 65 |
), |
| 66 |
], |
| 67 |
) |
| 68 |
def test_builder(fp, font_paths): |
| 69 |
with tempfile.TemporaryDirectory() as tmp_dir: |
| 70 |
src_dir = os.path.join(tmp_dir, "sources") |
| 71 |
font_dir = os.path.join(tmp_dir, "fonts") |
| 72 |
shutil.copytree(fp, src_dir) |
| 73 |
build_path = os.path.join(src_dir, "config.yaml") |
| 74 |
subprocess.run(["gftools", "builder", build_path]) |
| 75 |
for font_path in font_paths: |
| 76 |
font_path = os.path.join(font_dir, font_path) |
| 77 |
assert os.path.exists(font_path), f"{font_path} is missing" |
| 78 |
|
| 79 |
|
| 80 |
@pytest.mark.parametrize( |
| 81 |
"fp,font_paths", |
| 82 |
[ |
| 83 |
( |
| 84 |
|
| 85 |
|
| 86 |
os.path.join(TEST_DIR, "basic_family_glyphs_glyphData"), |
| 87 |
[ |
| 88 |
os.path.join("variable", "TestFamily[wght].ttf"), |
| 89 |
os.path.join("ttf", "TestFamily-Black.ttf"), |
| 90 |
os.path.join("ttf", "TestFamily-Regular.ttf"), |
| 91 |
os.path.join("ttf", "TestFamily-Thin.ttf"), |
| 92 |
os.path.join("otf", "TestFamily-Black.otf"), |
| 93 |
os.path.join("otf", "TestFamily-Regular.otf"), |
| 94 |
os.path.join("otf", "TestFamily-Thin.otf"), |
| 95 |
], |
| 96 |
), |
| 97 |
|
| 98 |
( |
| 99 |
os.path.join(TEST_DIR, "recipeprovider_noto_glyphData"), |
| 100 |
[ |
| 101 |
os.path.join( |
| 102 |
"TestFamily", "unhinted", "variable-ttf", "TestFamily[wght].ttf" |
| 103 |
), |
| 104 |
os.path.join("TestFamily", "unhinted", "ttf", "TestFamily-Black.ttf"), |
| 105 |
os.path.join("TestFamily", "unhinted", "ttf", "TestFamily-Regular.ttf"), |
| 106 |
os.path.join("TestFamily", "unhinted", "ttf", "TestFamily-Thin.ttf"), |
| 107 |
os.path.join("TestFamily", "unhinted", "otf", "TestFamily-Black.otf"), |
| 108 |
os.path.join("TestFamily", "unhinted", "otf", "TestFamily-Regular.otf"), |
| 109 |
os.path.join("TestFamily", "unhinted", "otf", "TestFamily-Thin.otf"), |
| 110 |
os.path.join("TestFamily", "hinted", "ttf", "TestFamily-Black.ttf"), |
| 111 |
os.path.join("TestFamily", "hinted", "ttf", "TestFamily-Regular.ttf"), |
| 112 |
os.path.join("TestFamily", "hinted", "ttf", "TestFamily-Thin.ttf"), |
| 113 |
os.path.join( |
| 114 |
"TestFamily", "googlefonts", "variable-ttf", "TestFamily[wght].ttf" |
| 115 |
), |
| 116 |
], |
| 117 |
), |
| 118 |
], |
| 119 |
) |
| 120 |
def test_builder_glyphData(fp, font_paths): |
| 121 |
from fontTools.ttLib import TTFont |
| 122 |
|
| 123 |
with tempfile.TemporaryDirectory() as tmp_dir: |
| 124 |
src_dir = os.path.join(tmp_dir, "sources") |
| 125 |
font_dir = os.path.join(tmp_dir, "fonts") |
| 126 |
shutil.copytree(fp, src_dir) |
| 127 |
build_path = os.path.join(src_dir, "config.yaml") |
| 128 |
subprocess.run(["gftools", "builder", build_path]) |
| 129 |
for font_path in font_paths: |
| 130 |
font_path = os.path.join(font_dir, font_path) |
| 131 |
assert os.path.exists(font_path), f"{font_path} is missing" |
| 132 |
ttFont = TTFont(font_path) |
| 133 |
assert "GDEF" in ttFont |
| 134 |
GDEF = ttFont["GDEF"].table |
| 135 |
assert GDEF.GlyphClassDef |
| 136 |
assert "foo" in GDEF.GlyphClassDef.classDefs |
| 137 |
assert GDEF.GlyphClassDef.classDefs["foo"] == 3 |
| 138 |
|
| 139 |
|
| 140 |
def test_bad_configs(): |
| 141 |
config = {"Sources": ["foo.glyphs"]} |
| 142 |
with pytest.raises(ValueError): |
| 143 |
GFBuilder(config) |