1#!/usr/bin/env python3 2 3"""Tests build_font.py by renaming a font. 4 5The test copies Roboto-Regular.ttf to a tmp directory and ask build_font.py to rename it and put in another dir. 6We then use ttx to dump the new font to its xml and check if rename was successful 7 8To test locally, use: 9PYTHONPATH="$PYTHONPATH:/path/to/android/checkout/external/fonttools/Lib" ./test.py 10""" 11 12import unittest 13import build_font 14 15from fontTools import ttx 16import os 17import xml.etree.ElementTree as etree 18import shutil 19import tempfile 20 21class MyTest(unittest.TestCase): 22 def test(self): 23 font_name = "Roboto-Regular.ttf" 24 srcdir = tempfile.mkdtemp() 25 print("srcdir: " + srcdir) 26 shutil.copy(font_name, srcdir) 27 destdir = tempfile.mkdtemp() 28 print("destdir: " + destdir) 29 self.assertTrue(build_font.main([srcdir, destdir]) is None) 30 out_path = os.path.join(destdir, font_name) 31 ttx.main([out_path]) 32 ttx_path = out_path[:-1] + "x" 33 tree = etree.parse(ttx_path) 34 root = tree.getroot() 35 name_tag = root.find('name') 36 fonts = build_font.get_font_info(name_tag) 37 shutil.rmtree(srcdir) 38 shutil.rmtree(destdir) 39 self.assertEqual(fonts[0].family, "Roboto1200310") 40 self.assertEqual(fonts[0].fullname, "Roboto1200310 Regular") 41 42 43 44if __name__ == '__main__': 45 unittest.main() 46