test.py revision ad3f2883112102c5ca4f0ce5d8f9e9df62a62f57
1#!/usr/bin/env python 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 17from lxml import 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 [f_name, f_version] = build_font.get_font_info(name_tag) 37 shutil.rmtree(srcdir) 38 shutil.rmtree(destdir) 39 self.assertEqual(f_name, "Roboto-Regular1200310") 40 41 42 43if __name__ == '__main__': 44 unittest.main() 45