[subset_test] test disabling hb repacker, and capture logging
This commit is contained in:
parent
1bb9607b72
commit
4160f05242
@ -800,14 +800,16 @@ class SubsetTest:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"installed, ok",
|
"installed, enabled, ok",
|
||||||
[
|
[
|
||||||
pytest.param(True, True, id="installed-ok"),
|
pytest.param(True, True, True, id="installed-enabled-ok"),
|
||||||
pytest.param(True, False, id="installed-fail"),
|
pytest.param(True, True, False, id="installed-enabled-fail"),
|
||||||
pytest.param(False, True, id="not_installed"),
|
pytest.param(True, False, True, id="installed-disabled"),
|
||||||
|
pytest.param(False, True, True, id="not_installed-enabled"),
|
||||||
|
pytest.param(False, False, True, id="not_installed-disabled"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_harfbuzz_repacker(self, caplog, monkeypatch, installed, ok):
|
def test_harfbuzz_repacker(self, caplog, monkeypatch, installed, enabled, ok):
|
||||||
# Use a mock to test the pure-python serializer is used when uharfbuzz
|
# Use a mock to test the pure-python serializer is used when uharfbuzz
|
||||||
# returns an error or is not installed
|
# returns an error or is not installed
|
||||||
have_uharfbuzz = fontTools.ttLib.tables.otBase.have_uharfbuzz
|
have_uharfbuzz = fontTools.ttLib.tables.otBase.have_uharfbuzz
|
||||||
@ -831,26 +833,41 @@ class SubsetTest:
|
|||||||
|
|
||||||
fontpath = self.compile_font(self.getpath("harfbuzz_repacker.ttx"), ".otf")
|
fontpath = self.compile_font(self.getpath("harfbuzz_repacker.ttx"), ".otf")
|
||||||
subsetpath = self.temp_path(".otf")
|
subsetpath = self.temp_path(".otf")
|
||||||
with caplog.at_level(logging.ERROR, "fontTools.ttLib.tables.otBase"):
|
args = [
|
||||||
subset.main(
|
fontpath,
|
||||||
[
|
"--unicodes=0x53a9",
|
||||||
fontpath,
|
"--layout-features=*",
|
||||||
"--unicodes=0x53a9",
|
f"--output-file={subsetpath}",
|
||||||
"--layout-features=*",
|
]
|
||||||
f"--output-file={subsetpath}",
|
if not enabled:
|
||||||
]
|
args.append("--no-harfbuzz-repacker")
|
||||||
)
|
|
||||||
|
with caplog.at_level(logging.DEBUG, "fontTools.ttLib.tables.otBase"):
|
||||||
|
subset.main(args)
|
||||||
|
|
||||||
subsetfont = TTFont(subsetpath)
|
subsetfont = TTFont(subsetpath)
|
||||||
# both hb.repack and pure-python serializer compile to the same ttx
|
# both hb.repack and pure-python serializer compile to the same ttx
|
||||||
self.expect_ttx(
|
self.expect_ttx(
|
||||||
subsetfont, self.getpath("expect_harfbuzz_repacker.ttx"), ["GSUB"]
|
subsetfont, self.getpath("expect_harfbuzz_repacker.ttx"), ["GSUB"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if enabled:
|
||||||
|
if installed:
|
||||||
|
assert "serializing 'GSUB' with hb.repack" in caplog.text
|
||||||
|
else:
|
||||||
|
assert (
|
||||||
|
"uharfbuzz not found, compiling 'GSUB' with pure-python serializer"
|
||||||
|
) in caplog.text
|
||||||
|
else:
|
||||||
|
assert (
|
||||||
|
"hb.repack disabled, compiling 'GSUB' with pure-python serializer"
|
||||||
|
) in caplog.text
|
||||||
|
|
||||||
# test we emit a log.error if hb.repack fails (and we don't if successful)
|
# test we emit a log.error if hb.repack fails (and we don't if successful)
|
||||||
assert (
|
assert (
|
||||||
(
|
(
|
||||||
"hb.repack failed, reverting to pure-python serializer; "
|
"hb.repack failed to serialize 'GSUB', reverting to "
|
||||||
"the error message was: mocking"
|
"pure-python serializer; the error message was: mocking"
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
) ^ ok
|
) ^ ok
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user