File: test.py

package info (click to toggle)
android-framework-23 6.0.1%2Br72-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 233,244 kB
  • sloc: java: 1,707,033; xml: 247,323; cpp: 211,819; ansic: 2,748; python: 2,640; sh: 1,517; yacc: 343; javascript: 338; lex: 214; ruby: 183; perl: 88; makefile: 63; sed: 19
file content (45 lines) | stat: -rwxr-xr-x 1,297 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python

"""Tests build_font.py by renaming a font.

The test copies Roboto-Regular.ttf to a tmp directory and ask build_font.py to rename it and put in another dir.
We then use ttx to dump the new font to its xml and check if rename was successful

To test locally, use:
PYTHONPATH="$PYTHONPATH:/path/to/android/checkout/external/fonttools/Lib" ./test.py
"""

import unittest
import build_font

from fontTools import ttx
import os
import xml.etree.ElementTree as etree
import shutil
import tempfile

class MyTest(unittest.TestCase):
  def test(self):
    font_name = "Roboto-Regular.ttf"
    srcdir = tempfile.mkdtemp()
    print "srcdir: " + srcdir
    shutil.copy(font_name, srcdir)
    destdir = tempfile.mkdtemp()
    print "destdir: " + destdir
    self.assertTrue(build_font.main([srcdir, destdir]) is None)
    out_path = os.path.join(destdir, font_name)
    ttx.main([out_path])
    ttx_path = out_path[:-1] + "x"
    tree = etree.parse(ttx_path)
    root = tree.getroot()
    name_tag = root.find('name')
    fonts = build_font.get_font_info(name_tag)
    shutil.rmtree(srcdir)
    shutil.rmtree(destdir)
    self.assertEqual(fonts[0].family, "Roboto1200310")
    self.assertEqual(fonts[0].fullname, "Roboto1200310 Regular")



if __name__ == '__main__':
  unittest.main()