| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
"""Unittests to check the functionality of Google Fonts Tools""" |
| 18 |
import os |
| 19 |
import re |
| 20 |
from glob import glob |
| 21 |
import unittest |
| 22 |
import subprocess |
| 23 |
from gftools.scripts import _get_subcommands |
| 24 |
|
| 25 |
CWD = os.path.dirname(__file__) |
| 26 |
TEST_DIR = os.path.join(CWD, "..", "data", "test") |
| 27 |
|
| 28 |
|
| 29 |
class TestGFToolsScripts(unittest.TestCase): |
| 30 |
"""Functional tests to determine whether each script can execute successfully""" |
| 31 |
|
| 32 |
def setUp(self): |
| 33 |
self.example_dir = os.path.join(TEST_DIR, "cabin") |
| 34 |
self.example_font = os.path.join(self.example_dir, "Cabin-Regular.ttf") |
| 35 |
self.example_family = glob(os.path.join(TEST_DIR, "mavenpro", "*.ttf")) |
| 36 |
self.example_vf_font = os.path.join(TEST_DIR, "Lora-Roman-VF.ttf") |
| 37 |
self.example_vf_stat = os.path.join(TEST_DIR, "lora_stat.yaml") |
| 38 |
self.example_glyphs_file = os.path.join(TEST_DIR, "Lora.glyphs") |
| 39 |
self.example_builder_config = os.path.join(TEST_DIR, "builder_test.yaml") |
| 40 |
self.example_builder_config_2_sources = os.path.join( |
| 41 |
TEST_DIR, "Libre-Bodoni", "sources", "config.yaml" |
| 42 |
) |
| 43 |
self.src_vtt_font = os.path.join(TEST_DIR, "Inconsolata[wdth,wght].ttf") |
| 44 |
self.gf_family_dir = os.path.join( |
| 45 |
"data", "test", "mock_googlefonts", "ofl", "abel" |
| 46 |
) |
| 47 |
self.nam_file = os.path.join("data", "test", "arabic_unique-glyphs.nam") |
| 48 |
self.dir_before_tests = os.listdir(self.example_dir) |
| 49 |
|
| 50 |
def tearDown(self): |
| 51 |
"""Clears the example folder of any files created during the unit tests""" |
| 52 |
files_to_delete = set(os.listdir(self.example_dir)) - set(self.dir_before_tests) |
| 53 |
for f in files_to_delete: |
| 54 |
os.remove(os.path.join(self.example_dir, f)) |
| 55 |
|
| 56 |
def test_add_font(self): |
| 57 |
from gftools.scripts.add_font import main |
| 58 |
|
| 59 |
main([self.gf_family_dir]) |
| 60 |
|
| 61 |
def test_build_ofl(self): |
| 62 |
from gftools.scripts.build_ofl import main |
| 63 |
from tempfile import TemporaryDirectory |
| 64 |
|
| 65 |
with TemporaryDirectory() as tmp_dir: |
| 66 |
main([self.example_font, tmp_dir]) |
| 67 |
|
| 68 |
def test_check_bbox(self): |
| 69 |
from gftools.scripts.check_bbox import main |
| 70 |
|
| 71 |
main([self.example_font, "--glyphs", "--extremes"]) |
| 72 |
|
| 73 |
def test_check_copyright_notices(self): |
| 74 |
from gftools.scripts.check_copyright_notices import main |
| 75 |
|
| 76 |
main([self.example_font]) |
| 77 |
|
| 78 |
def test_check_font_version(self): |
| 79 |
from gftools.scripts.check_font_version import main |
| 80 |
|
| 81 |
main(["Cabin"]) |
| 82 |
|
| 83 |
def test_check_name(self): |
| 84 |
from gftools.scripts.check_name import main |
| 85 |
|
| 86 |
main([self.example_font]) |
| 87 |
|
| 88 |
def test_check_vtt_compatibility(self): |
| 89 |
from gftools.scripts.check_vtt_compatibility import main |
| 90 |
|
| 91 |
main([self.example_font, self.example_font]) |
| 92 |
|
| 93 |
def test_compare_font(self): |
| 94 |
from gftools.scripts.compare_font import main |
| 95 |
|
| 96 |
main([self.example_font, self.example_font]) |
| 97 |
|
| 98 |
def test_find_features(self): |
| 99 |
from gftools.scripts.find_features import main |
| 100 |
|
| 101 |
main([self.example_font]) |
| 102 |
|
| 103 |
def test_fix_ascii_fontmetadata(self): |
| 104 |
from gftools.scripts.fix_ascii_fontmetadata import main |
| 105 |
|
| 106 |
main([self.example_font]) |
| 107 |
|
| 108 |
def test_fix_cmap(self): |
| 109 |
from gftools.scripts.fix_cmap import main |
| 110 |
|
| 111 |
main([self.example_font]) |
| 112 |
|
| 113 |
def test_fix_familymetadata(self): |
| 114 |
from gftools.scripts.fix_familymetadata import main |
| 115 |
|
| 116 |
main([self.example_font]) |
| 117 |
|
| 118 |
def test_fix_fsselection(self): |
| 119 |
from gftools.scripts.fix_fsselection import main |
| 120 |
|
| 121 |
main([self.example_font]) |
| 122 |
|
| 123 |
def test_fix_fstype(self): |
| 124 |
from gftools.scripts.fix_fstype import main |
| 125 |
|
| 126 |
main([self.example_font]) |
| 127 |
|
| 128 |
def test_fix_gasp(self): |
| 129 |
from gftools.scripts.fix_gasp import main |
| 130 |
|
| 131 |
main([self.example_font]) |
| 132 |
|
| 133 |
def test_fix_glyph_private_encoding(self): |
| 134 |
from gftools.scripts.fix_glyph_private_encoding import main |
| 135 |
|
| 136 |
main([self.example_font]) |
| 137 |
|
| 138 |
def test_fix_hinting(self): |
| 139 |
from gftools.scripts.fix_hinting import main |
| 140 |
|
| 141 |
main([self.example_font]) |
| 142 |
|
| 143 |
def test_fix_isfixedpitch(self): |
| 144 |
from gftools.scripts.fix_isfixedpitch import main |
| 145 |
|
| 146 |
main(["--fonts", self.example_font]) |
| 147 |
|
| 148 |
def test_fix_nameids(self): |
| 149 |
from gftools.scripts.fix_nameids import main |
| 150 |
|
| 151 |
main([self.example_font]) |
| 152 |
|
| 153 |
def test_fix_nonhinting(self): |
| 154 |
from gftools.scripts.fix_nonhinting import main |
| 155 |
|
| 156 |
main([self.example_font, self.example_font + ".fix"]) |
| 157 |
|
| 158 |
def test_fix_ttfautohint(self): |
| 159 |
from gftools.scripts.fix_ttfautohint import main |
| 160 |
|
| 161 |
main([self.example_font]) |
| 162 |
|
| 163 |
def test_fix_vendorid(self): |
| 164 |
from gftools.scripts.fix_vendorid import main |
| 165 |
|
| 166 |
main([self.example_font]) |
| 167 |
|
| 168 |
def test_fix_vertical_metrics(self): |
| 169 |
from gftools.scripts.fix_vertical_metrics import main |
| 170 |
|
| 171 |
main([self.example_font]) |
| 172 |
|
| 173 |
def test_font_weights_coverage(self): |
| 174 |
from gftools.scripts.font_weights_coverage import main |
| 175 |
|
| 176 |
main([self.example_dir]) |
| 177 |
|
| 178 |
def test_fix_font(self): |
| 179 |
from gftools.scripts.fix_font import main |
| 180 |
|
| 181 |
main([self.example_font]) |
| 182 |
|
| 183 |
def test_fix_family(self): |
| 184 |
from gftools.scripts.fix_family import main |
| 185 |
|
| 186 |
main(self.example_family) |
| 187 |
|
| 188 |
def test_list_italicangle(self): |
| 189 |
from gftools.scripts.list_italicangle import main |
| 190 |
|
| 191 |
main([self.example_font]) |
| 192 |
|
| 193 |
def test_list_panose(self): |
| 194 |
from gftools.scripts.list_panose import main |
| 195 |
|
| 196 |
main([self.example_font]) |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
def test_list_weightclass(self): |
| 202 |
from gftools.scripts.list_weightclass import main |
| 203 |
|
| 204 |
main([self.example_font]) |
| 205 |
|
| 206 |
def test_list_widthclass(self): |
| 207 |
from gftools.scripts.list_widthclass import main |
| 208 |
|
| 209 |
main([self.example_font]) |
| 210 |
|
| 211 |
def test_nametable_from_filename(self): |
| 212 |
from gftools.scripts.nametable_from_filename import main |
| 213 |
|
| 214 |
main([self.example_font]) |
| 215 |
|
| 216 |
def test_ots(self): |
| 217 |
from gftools.scripts.ots import main |
| 218 |
|
| 219 |
main([self.example_dir]) |
| 220 |
|
| 221 |
def test_rangify(self): |
| 222 |
from gftools.scripts.rangify import main |
| 223 |
|
| 224 |
main([self.nam_file]) |
| 225 |
|
| 226 |
def test_ttf2cp(self): |
| 227 |
from gftools.scripts.ttf2cp import main |
| 228 |
|
| 229 |
main([self.example_font]) |
| 230 |
|
| 231 |
def test_unicode_names(self): |
| 232 |
from gftools.scripts.unicode_names import main |
| 233 |
|
| 234 |
main(["--nam_file", self.nam_file]) |
| 235 |
|
| 236 |
def test_update_families(self): |
| 237 |
from gftools.scripts.update_families import main |
| 238 |
|
| 239 |
main([self.example_font]) |
| 240 |
|
| 241 |
def test_update_version(self): |
| 242 |
from gftools.scripts.update_version import main |
| 243 |
|
| 244 |
main(["--old_version", "2.00099", "--new_version", "2.001", self.example_font]) |
| 245 |
|
| 246 |
def test_varfont_info(self): |
| 247 |
from gftools.scripts.varfont_info import main |
| 248 |
|
| 249 |
main([self.example_vf_font]) |
| 250 |
|
| 251 |
def test_what_subsets(self): |
| 252 |
from gftools.scripts.what_subsets import main |
| 253 |
|
| 254 |
main([self.example_font]) |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
if __name__ == "__main__": |
| 289 |
unittest.main() |