16from zipfile
import ZipFile
18SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
19SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR,
'..',
'..',
'..'))
20MATERIAL_TTF = os.path.join(SCRIPT_DIR,
'fixtures',
'MaterialIcons-Regular.ttf')
21VARIABLE_MATERIAL_TTF = os.path.join(SCRIPT_DIR,
'fixtures',
'MaterialSymbols-Variable.ttf')
24 (
True,
'1.ttf', MATERIAL_TTF, [
r'57347']),
25 (
True,
'1.ttf', MATERIAL_TTF, [
r'0xE003']),
26 (
True,
'1.ttf', MATERIAL_TTF, [
r'\uE003']),
27 (
False,
'1.ttf', MATERIAL_TTF, [
r'57348']),
28 (
True,
'2.ttf', MATERIAL_TTF, [
r'0xE003',
r'0xE004']),
29 (
True,
'2.ttf', MATERIAL_TTF, [
r'0xE003',
31 (
True,
'2.ttf', MATERIAL_TTF, [
36 (
True,
'2.ttf', MATERIAL_TTF, [
41 (
True,
'3.ttf', MATERIAL_TTF, [
47 (
True,
'1variable.ttf', VARIABLE_MATERIAL_TTF, [
r'57347']),
48 (
True,
'1variable.ttf', VARIABLE_MATERIAL_TTF, [
r'0xE003']),
49 (
True,
'1variable.ttf', VARIABLE_MATERIAL_TTF, [
r'\uE003']),
50 (
False,
'1variable.ttf', VARIABLE_MATERIAL_TTF, [
r'57348'
52 (
True,
'2variable.ttf', VARIABLE_MATERIAL_TTF, [
r'0xE003',
r'0xE004']),
53 (
True,
'2variable.ttf', VARIABLE_MATERIAL_TTF, [
58 (
True,
'3variable.ttf', VARIABLE_MATERIAL_TTF, [
68 ([font_subset,
'output.ttf',
'does-not-exist.ttf'], [
71 ([font_subset,
'output.ttf', MATERIAL_TTF], [
74 ([font_subset,
'output.ttf', MATERIAL_TTF], [
77 ([font_subset,
'output.ttf', MATERIAL_TTF], [
80 ([font_subset,
'output.ttf', MATERIAL_TTF], [
85 ([font_subset,
'non-existent-dir/output.ttf', MATERIAL_TTF], [
88 ([font_subset,
'output.ttf', MATERIAL_TTF], [
91 ([font_subset,
'output.ttf', MATERIAL_TTF], []),
92 ([font_subset,
'output.ttf', MATERIAL_TTF], [
'']),
94 ([font_subset,
'output.ttf', VARIABLE_MATERIAL_TTF], [
97 ([font_subset,
'output.ttf', VARIABLE_MATERIAL_TTF], [
100 ([font_subset,
'output.ttf', VARIABLE_MATERIAL_TTF], [
103 ([font_subset,
'output.ttf', VARIABLE_MATERIAL_TTF], [
108 ([font_subset,
'non-existent-dir/output.ttf', VARIABLE_MATERIAL_TTF], [
111 ([font_subset,
'output.ttf', VARIABLE_MATERIAL_TTF], [
114 ([font_subset,
'output.ttf', VARIABLE_MATERIAL_TTF], []),
115 ([font_subset,
'output.ttf', VARIABLE_MATERIAL_TTF], [
'']),
120 print(
'Running command:')
122 print(
'STDIN: "%s"' %
' '.
join(codepoints))
123 p = subprocess.Popen(
124 cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, cwd=SRC_DIR
126 stdout_data, stderr_data = p.communicate(input=
' '.
join(codepoints).
encode())
127 if p.returncode != 0
and fail ==
False:
128 print(
'FAILURE: %s' % p.returncode)
133 elif p.returncode == 0
and fail ==
True:
134 print(
'FAILURE - test passed but should have failed.')
146 with ZipFile(font_subset_zip,
'r')
as zip:
147 files = zip.namelist()
148 if 'font-subset%s' % exe
not in files:
149 print(
'expected %s to contain font-subset%s' % (files, exe))
160 'cygwin':
'windows-',
168 parser = argparse.ArgumentParser(description=
'Runs font-subset tests.')
169 parser.add_argument(
'--variant', type=str, required=
True)
170 parser.add_argument(
'--target-cpu', type=str, default=
'x64')
171 args = parser.parse_args()
172 variant = args.variant
174 is_windows = sys.platform.startswith((
'cygwin',
'win'))
175 exe =
'.exe' if is_windows
else ''
176 font_subset = os.path.join(SRC_DIR,
'out', variant,
'font-subset' + exe)
177 font_subset_zip = os.path.join(
178 SRC_DIR,
'out', variant,
'zip_archives',
platform_to_path(sys.platform, args.target_cpu),
181 if not os.path.isfile(font_subset):
183 'Could not locate font-subset%s in %s - build before running this script.' % (exe, variant)
186 print(
'Using font subset binary at %s (%s)' % (font_subset, font_subset_zip))
189 failures +=
test_zip(font_subset_zip, exe)
191 for should_pass, golden_font, input_font, codepoints
in COMPARE_TESTS:
192 gen_ttf = os.path.join(SCRIPT_DIR,
'gen', golden_font)
193 golden_ttf = os.path.join(SCRIPT_DIR,
'fixtures', golden_font)
194 cmd = [font_subset, gen_ttf, input_font]
196 cmp = filecmp.cmp(gen_ttf, golden_ttf, shallow=
False)
197 if (should_pass
and not cmp)
or (
not should_pass
and cmp):
198 print(
'Test case %s failed.' % cmd)
201 with open(os.devnull,
'w')
as devnull:
202 for cmd, codepoints
in fail_tests(font_subset):
203 if run_cmd(cmd, codepoints, fail=
True) == 0:
207 print(
'%s test(s) failed.' % failures)
210 print(
'All tests passed')
214if __name__ ==
'__main__':
static void encode(uint8_t output[16], const uint32_t input[4])
def print(*args, **kwargs)
def test_zip(font_subset_zip, exe)
def platform_to_path(os, cpu)
def fail_tests(font_subset)
def run_cmd(cmd, codepoints, fail=False)
static SkString join(const CommandLineFlags::StringArray &)