Skip to content

Commit 6abb4bc

Browse files
committed
Fix build warnings, improve tests, remove some passthru tables
- fix meson warning re buildtype and optimization - remove BASE, DSIG, COLR, CPAL, CFF2 from set of passthru tables - separate test suite into 3 groups and do tighter checks on results; improve reporting - a couple of other minor tweaks
1 parent a499505 commit 6abb4bc

File tree

6 files changed

+66
-28
lines changed

6 files changed

+66
-28
lines changed

.github/workflows/run_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ jobs:
4646
4747
- name: Test with pytest
4848
run: |
49-
pytest tests
49+
pytest -v tests

build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
MESON_CMD = [
3030
TOOLS["meson"],
3131
"--backend=ninja",
32-
"--buildtype=release",
33-
"--strip",
3432
"-Ddebug=true",
33+
"-Doptimization=3",
34+
"--default-library=static",
3535
"--force-fallback-for=libbrotlidec,liblz4",
3636
str(BUILD_DIR),
3737
str(OTS_SRC_DIR),

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ def run(self):
294294
classifiers=classifiers,
295295
description='Python wrapper for ot-sanitizer',
296296
ext_modules=[pyots_mod],
297-
long_description=long_description,
298297
long_description_content_type='text/markdown',
298+
long_description=long_description,
299299
name='pyots',
300300
packages=find_packages('src'),
301301
package_dir={'': 'src'},

src/_pyots/pyots-context.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PyOTSContext: public OTSContext {
1717
public:
1818
explicit PyOTSContext(int level): level_(level) { }
1919
std::stringstream msgs;
20-
bool modified;
20+
bool modified = false;
2121

2222
void Message(int level, const char *format, ...) {
2323
va_list va;
@@ -46,16 +46,8 @@ class PyOTSContext: public OTSContext {
4646

4747
TableAction GetTableAction(uint32_t tag) {
4848
switch (tag) {
49-
// ots seems to drop these silently
50-
case OTS_TAG('B', 'A', 'S', 'E'):
51-
case OTS_TAG('D', 'S', 'I', 'G'):
52-
53-
// from chromium project -- various color tables
5449
case OTS_TAG('C', 'B', 'D', 'T'):
5550
case OTS_TAG('C', 'B', 'L', 'C'):
56-
case OTS_TAG('C', 'O', 'L', 'R'):
57-
case OTS_TAG('C', 'P', 'A', 'L'):
58-
case OTS_TAG('C', 'F', 'F', '2'):
5951
case OTS_TAG('s', 'b', 'i', 'x'):
6052

6153
return TABLE_ACTION_PASSTHRU;

src/pyots/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, raw_tuple):
1616
self.messages = tuple(raw_tuple[2].split("\n"))
1717

1818

19-
def sanitize(input, output=None, quiet=False, font_index=-1) -> tuple:
19+
def sanitize(input, output=None, quiet=False, font_index=-1) -> OTSResult:
2020
"""
2121
Sanitize a file. Options:
2222
output path for output file. If not specified, no output will be

tests/test_ots_suite.py

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,71 @@
1-
import os
1+
from pathlib import Path
22

33
import pyots
44

5-
test_folder = os.path.realpath(os.path.dirname(__file__))
5+
ROOT = Path(__file__).parent.parent.resolve()
6+
test_folder = ROOT / "tests"
67

78

8-
def test_ots_suite():
9+
def test_ots_good():
910

10-
tld = os.path.join(test_folder, "..", "src", "ots", "tests", "fonts")
11-
dirs = ['bad', 'fuzzing', 'good']
11+
tld = ROOT / "src" / "ots" / "tests" / "fonts" / "good"
1212

13-
for d in dirs:
14-
for f in os.listdir(os.path.join(tld, d)):
15-
base, ext = os.path.splitext(f)
16-
if ext.lower() not in ('.ttf', '.woff', '.ttc', '.woff2', '.otf'):
17-
continue
13+
count = 0
14+
for f in tld.iterdir():
15+
ext = f.suffix
16+
if ext.lower() not in ('.ttf', '.woff', '.ttc', '.woff2', '.otf'):
17+
continue
1818

19-
r = pyots.sanitize(os.path.join(tld, d, f))
19+
r = pyots.sanitize(f)
2020

21-
if not r.sanitized and d != "bad":
22-
pp = f"{d}/{f}"
23-
assert f"{pp}" in EXPECT_FAIL, f"{pp} not sanitized and not in expected failures" # noqa: E501
21+
if not r.sanitized:
22+
count += 1
23+
print("[good] unexpected failure on", f, "\n".join(r.messages))
24+
25+
assert not count, f"{count} file{'s' if count != 1 else ''} failed when expected to be sanitized." # noqa: E501
26+
27+
28+
def test_ots_bad():
29+
30+
tld = ROOT / "src" / "ots" / "tests" / "fonts" / "bad"
31+
32+
count = 0
33+
for f in tld.iterdir():
34+
ext = f.suffix
35+
if ext.lower() not in ('.ttf', '.woff', '.ttc', '.woff2', '.otf'):
36+
continue
37+
38+
r = pyots.sanitize(f)
39+
40+
if r.sanitized:
41+
count += 1
42+
print("[bad] unexpected success on", f, "\n".join(r.messages))
43+
44+
assert not count, f"{count} file{'s were' if count != 1 else 'was'} sanitized when expected to be sanitized." # noqa: E501
45+
46+
47+
def test_ots_fuzzing():
48+
49+
tld = ROOT / "src" / "ots" / "tests" / "fonts" / "fuzzing"
50+
51+
count = 0
52+
for f in tld.iterdir():
53+
ext = f.suffix
54+
if ext.lower() not in ('.ttf', '.woff', '.ttc', '.woff2', '.otf'):
55+
continue
56+
57+
r = pyots.sanitize(f)
58+
59+
if str(f.relative_to(ROOT / "src" / "ots" / "tests" / "fonts")) in EXPECT_FAIL: # noqa: E501
60+
if r.sanitized:
61+
count += 1
62+
print("[fuzzing] unexpected success on", f, "\n".join(r.messages)) # noqa: E501
63+
else:
64+
if not r.sanitized:
65+
count += 1
66+
print("[fuzzing] unexpected failure on", f, "\n".join(r.messages)) # noqa: E501
67+
68+
assert not count, f"{count} file{'s' if count != 1 else ''} had an unexpected sanitization result." # noqa: E501
2469

2570

2671
EXPECT_FAIL = {
@@ -63,4 +108,5 @@ def test_ots_suite():
63108
'fuzzing/8240789f6d12d4cfc4b5e8e6f246c3701bcf861f.otf',
64109
'fuzzing/3857535d8c0d2bfeab7ee2cd6ba5e39bcb4abd90.ttf',
65110
'fuzzing/adb242cbc61b3ca428903e397a2c9dcf97fe3042.ttf',
111+
'fuzzing/2a12de12323bfd99b9c4bb33ed20b66b8ff0915f.otf',
66112
}

0 commit comments

Comments
 (0)