Home | History | Annotate | Download | only in rename_font
      1 #!/usr/bin/env python
      2 
      3 """Tests build_font.py by renaming a font.
      4 
      5 The test copies Roboto-Regular.ttf to a tmp directory and ask build_font.py to rename it and put in another dir.
      6 We then use ttx to dump the new font to its xml and check if rename was successful
      7 
      8 To test locally, use:
      9 PYTHONPATH="$PYTHONPATH:/path/to/android/checkout/external/fonttools/Lib" ./test.py
     10 """
     11 
     12 import unittest
     13 import build_font
     14 
     15 from fontTools import ttx
     16 import os
     17 import xml.etree.ElementTree as etree
     18 import shutil
     19 import tempfile
     20 
     21 class 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 
     44 if __name__ == '__main__':
     45   unittest.main()
     46