[ttx_test] Test for split tables (-s) option

#1188
This commit is contained in:
Miguel Sousa 2018-02-22 05:30:51 -08:00
parent e299650f9f
commit bf6852a7f6

View File

@ -1,5 +1,6 @@
from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.misc.testTools import parseXML
from fontTools import ttx
import getopt
import os
@ -40,6 +41,11 @@ class TTXTest(unittest.TestCase):
shutil.copy2(font_path, temppath)
return temppath
@staticmethod
def read_file(file_path):
with open(file_path, "r", encoding="utf-8") as f:
return f.readlines()
# -----
# Tests
# -----
@ -123,6 +129,31 @@ class TTXTest(unittest.TestCase):
(os.path.join(self.tempdir, file_names[i]),
os.path.join(self.tempdir, file_names[i].split('.')[0] + extensions[i])))
def test_parseOptions_split_tables(self):
file_name = 'TestTTF.ttf'
font_path = self.getpath(file_name)
temp_path = self.temp_font(font_path, file_name)
args = ['-s', temp_path]
jobs, options = ttx.parseOptions(args)
ttx_file_path = jobs[0][2]
temp_folder = os.path.dirname(ttx_file_path)
self.assertTrue(options.splitTables)
self.assertTrue(os.path.exists(ttx_file_path))
ttx.process(jobs, options)
# Read the TTX file but strip the first two and the last lines:
# <?xml version="1.0" encoding="UTF-8"?>
# <ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="3.22">
# ...
# </ttFont>
parsed_xml = parseXML(self.read_file(ttx_file_path)[2:-1])
for item in parsed_xml:
if isinstance(item, tuple):
# the tuple looks like this:
# (u'head', {u'src': u'TestTTF._h_e_a_d.ttx'}, [])
table_file_name = item[1].get('src')
table_file_path = os.path.join(temp_folder, table_file_name)
self.assertTrue(os.path.exists(table_file_path))
def test_guessFileType_ttf(self):
file_name = 'TestTTF.ttf'
font_path = self.getpath(file_name)