Hash :
41906cd5
Author :
Date :
2018-02-11T19:46:06
[subset] Another fixup I broke this in c31fcf4c58d96eb7d9781a986991b1a79ac7be44
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#!/usr/bin/env python
# Runs a subsetting test suite. Compares the results of subsetting via harfbuz
# to subsetting via fonttools.
from __future__ import print_function
import io
import os
import subprocess
import sys
import tempfile
from subset_test_suite import SubsetTestSuite
def cmd(command):
p = subprocess.Popen (
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait ()
print (p.stderr.read (), end="") # file=sys.stderr
return p.stdout.read (), p.returncode
def read_binary(file_path):
with open(file_path, 'rb') as f:
return f.read()
def fail_test(test, cli_args, message):
print ('ERROR: %s' % message)
print ('Test State:')
print (' test.font_path %s' % os.path.abspath(test.font_path))
print (' test.profile_path %s' % os.path.abspath(test.profile_path))
print (' test.unicodes %s' % test.unicodes())
expected_file = os.path.join(test_suite.get_output_directory(),
test.get_font_name())
print (' expected_file %s' % os.path.abspath(expected_file))
return 1
def run_test(test):
out_file = os.path.join(tempfile.mkdtemp(), test.get_font_name() + '-subset.ttf')
cli_args = [hb_subset,
"--font-file=" + test.font_path,
"--output-file=" + out_file,
"--unicodes=%s" % test.unicodes()]
print (' '.join(cli_args))
_, return_code = cmd(cli_args)
if return_code:
return fail_test(test, cli_args, "%s returned %d" % (' '.join(cli_args), return_code))
expected_ttx, return_code = run_ttx(os.path.join(test_suite.get_output_directory(),
test.get_font_name()))
if return_code:
return fail_test(test, cli_args, "ttx (expected) returned %d" % (return_code))
actual_ttx, return_code = run_ttx(out_file)
if return_code:
return fail_test(test, cli_args, "ttx (actual) returned %d" % (return_code))
if not actual_ttx == expected_ttx:
return fail_test(test, cli_args, 'ttx for expected and actual does not match.')
return 0
def run_ttx(file):
cli_args = ["ttx",
"-o-",
file]
return cmd(cli_args)
args = sys.argv[1:]
if not args or sys.argv[1].find('hb-subset') == -1 or not os.path.exists (sys.argv[1]):
print ("First argument does not seem to point to usable hb-subset.")
sys.exit (1)
hb_subset, args = args[0], args[1:]
if not len(args):
print ("No tests supplied.")
sys.exit (1)
_, returncode = cmd(["which", "ttx"])
if returncode:
print("TTX is not present, skipping test.")
sys.exit (77)
fails = 0
for path in args:
with io.open(path, mode="r", encoding="utf-8") as f:
print ("Running tests in " + path)
test_suite = SubsetTestSuite(path, f.read())
for test in test_suite.tests():
fails += run_test(test)
if fails != 0:
print (str (fails) + " test(s) failed.")
sys.exit(1)
else:
print ("All tests passed.")