aboutsummaryrefslogtreecommitdiff
path: root/Tests/ttLib/tables/T_S_I__1_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/ttLib/tables/T_S_I__1_test.py')
-rw-r--r--Tests/ttLib/tables/T_S_I__1_test.py111
1 files changed, 60 insertions, 51 deletions
diff --git a/Tests/ttLib/tables/T_S_I__1_test.py b/Tests/ttLib/tables/T_S_I__1_test.py
index b792221e..e14f41d2 100644
--- a/Tests/ttLib/tables/T_S_I__1_test.py
+++ b/Tests/ttLib/tables/T_S_I__1_test.py
@@ -14,15 +14,19 @@ TSI1_UTF8_DATA = b"""abcd\xc3\xa9ghijklmnopqrstuvxywz0123456789"""
def indextable():
table = table_T_S_I__0()
table.set(
- [(0, 1, 0), # gid 0, length=1, offset=0, text='a'
- (1, 5, 1), # gid 1, length=5, offset=1, text='bcdef'
- (2, 0, 1), # gid 2, length=0, offset=1, text=''
- (3, 0, 1), # gid 3, length=0, offset=1, text=''
- (4, 8, 6)], # gid 4, length=8, offset=6, text='ghijklmn'
- [(0xFFFA, 2, 14), # 'ppgm', length=2, offset=14, text='op'
- (0xFFFB, 4, 16), # 'cvt', length=4, offset=16, text='qrst'
- (0xFFFC, 6, 20), # 'reserved', length=6, offset=20, text='uvxywz'
- (0xFFFD, 10, 26)] # 'fpgm', length=10, offset=26, text='0123456789'
+ [
+ (0, 1, 0), # gid 0, length=1, offset=0, text='a'
+ (1, 5, 1), # gid 1, length=5, offset=1, text='bcdef'
+ (2, 0, 1), # gid 2, length=0, offset=1, text=''
+ (3, 0, 1), # gid 3, length=0, offset=1, text=''
+ (4, 8, 6),
+ ], # gid 4, length=8, offset=6, text='ghijklmn'
+ [
+ (0xFFFA, 2, 14), # 'ppgm', length=2, offset=14, text='op'
+ (0xFFFB, 4, 16), # 'cvt', length=4, offset=16, text='qrst'
+ (0xFFFC, 6, 20), # 'reserved', length=6, offset=20, text='uvxywz'
+ (0xFFFD, 10, 26),
+ ], # 'fpgm', length=10, offset=26, text='0123456789'
)
return table
@@ -33,8 +37,8 @@ def font(indextable):
# ['a', 'b', 'c', ...]
ch = 0x61
n = len(indextable.indices)
- font.glyphOrder = [chr(i) for i in range(ch, ch+n)]
- font['TSI0'] = indextable
+ font.glyphOrder = [chr(i) for i in range(ch, ch + n)]
+ font["TSI0"] = indextable
return font
@@ -43,11 +47,8 @@ def empty_font():
font = TTFont()
font.glyphOrder = []
indextable = table_T_S_I__0()
- indextable.set([], [(0xFFFA, 0, 0),
- (0xFFFB, 0, 0),
- (0xFFFC, 0, 0),
- (0xFFFD, 0, 0)])
- font['TSI0'] = indextable
+ indextable.set([], [(0xFFFA, 0, 0), (0xFFFB, 0, 0), (0xFFFC, 0, 0), (0xFFFD, 0, 0)])
+ font["TSI0"] = indextable
return font
@@ -56,16 +57,18 @@ def test_decompile(font):
table.decompile(TSI1_DATA, font)
assert table.glyphPrograms == {
- 'a': 'a',
- 'b': 'bcdef',
+ "a": "a",
+ "b": "bcdef",
# 'c': '', # zero-length entries are skipped
# 'd': '',
- 'e': 'ghijklmn'}
+ "e": "ghijklmn",
+ }
assert table.extraPrograms == {
- 'ppgm': 'op',
- 'cvt': 'qrst',
- 'reserved': 'uvxywz',
- 'fpgm': '0123456789'}
+ "ppgm": "op",
+ "cvt": "qrst",
+ "reserved": "uvxywz",
+ "fpgm": "0123456789",
+ }
def test_decompile_utf8(font):
@@ -73,16 +76,18 @@ def test_decompile_utf8(font):
table.decompile(TSI1_UTF8_DATA, font)
assert table.glyphPrograms == {
- 'a': 'a',
- 'b': 'bcd\u00e9',
+ "a": "a",
+ "b": "bcd\u00e9",
# 'c': '', # zero-length entries are skipped
# 'd': '',
- 'e': 'ghijklmn'}
+ "e": "ghijklmn",
+ }
assert table.extraPrograms == {
- 'ppgm': 'op',
- 'cvt': 'qrst',
- 'reserved': 'uvxywz',
- 'fpgm': '0123456789'}
+ "ppgm": "op",
+ "cvt": "qrst",
+ "reserved": "uvxywz",
+ "fpgm": "0123456789",
+ }
def test_decompile_empty(empty_font):
@@ -94,32 +99,32 @@ def test_decompile_empty(empty_font):
def test_decompile_invalid_length(empty_font):
- empty_font.glyphOrder = ['a']
- empty_font['TSI0'].indices = [(0, 0x8000+1, 0)]
+ empty_font.glyphOrder = ["a"]
+ empty_font["TSI0"].indices = [(0, 0x8000 + 1, 0)]
table = table_T_S_I__1()
with pytest.raises(TTLibError) as excinfo:
- table.decompile(b'', empty_font)
+ table.decompile(b"", empty_font)
assert excinfo.match("textLength .* must not be > 32768")
def test_decompile_offset_past_end(empty_font):
- empty_font.glyphOrder = ['foo', 'bar']
- content = 'baz'
+ empty_font.glyphOrder = ["foo", "bar"]
+ content = "baz"
data = tobytes(content)
- empty_font['TSI0'].indices = [(0, len(data), 0), (1, 1, len(data)+1)]
+ empty_font["TSI0"].indices = [(0, len(data), 0), (1, 1, len(data) + 1)]
table = table_T_S_I__1()
with CapturingLogHandler(table.log, "WARNING") as captor:
table.decompile(data, empty_font)
# the 'bar' program is skipped because its offset > len(data)
- assert table.glyphPrograms == {'foo': 'baz'}
+ assert table.glyphPrograms == {"foo": "baz"}
assert any("textOffset > totalLength" in r.msg for r in captor.records)
def test_decompile_magic_length_last_extra(empty_font):
- indextable = empty_font['TSI0']
+ indextable = empty_font["TSI0"]
indextable.extra_indices[-1] = (0xFFFD, 0x8000, 0)
content = "0" * (0x8000 + 1)
data = tobytes(content)
@@ -127,20 +132,22 @@ def test_decompile_magic_length_last_extra(empty_font):
table = table_T_S_I__1()
table.decompile(data, empty_font)
- assert table.extraPrograms['fpgm'] == content
+ assert table.extraPrograms["fpgm"] == content
def test_decompile_magic_length_last_glyph(empty_font):
- empty_font.glyphOrder = ['foo', 'bar']
- indextable = empty_font['TSI0']
+ empty_font.glyphOrder = ["foo", "bar"]
+ indextable = empty_font["TSI0"]
indextable.indices = [
(0, 3, 0),
- (1, 0x8000, 3)] # the actual length of 'bar' program is
+ (1, 0x8000, 3),
+ ] # the actual length of 'bar' program is
indextable.extra_indices = [ # the difference between the first extra's
- (0xFFFA, 0, 0x8004), # offset and 'bar' offset: 0x8004 - 3
+ (0xFFFA, 0, 0x8004), # offset and 'bar' offset: 0x8004 - 3
(0xFFFB, 0, 0x8004),
(0xFFFC, 0, 0x8004),
- (0xFFFD, 0, 0x8004)]
+ (0xFFFD, 0, 0x8004),
+ ]
foo_content = "0" * 3
bar_content = "1" * (0x8000 + 1)
data = tobytes(foo_content + bar_content)
@@ -148,17 +155,18 @@ def test_decompile_magic_length_last_glyph(empty_font):
table = table_T_S_I__1()
table.decompile(data, empty_font)
- assert table.glyphPrograms['foo'] == foo_content
- assert table.glyphPrograms['bar'] == bar_content
+ assert table.glyphPrograms["foo"] == foo_content
+ assert table.glyphPrograms["bar"] == bar_content
def test_decompile_magic_length_non_last(empty_font):
- indextable = empty_font['TSI0']
+ indextable = empty_font["TSI0"]
indextable.extra_indices = [
(0xFFFA, 3, 0),
(0xFFFB, 0x8000, 3), # the actual length of 'cvt' program is:
(0xFFFC, 0, 0x8004), # nextTextOffset - textOffset: 0x8004 - 3
- (0xFFFD, 0, 0x8004)]
+ (0xFFFD, 0, 0x8004),
+ ]
ppgm_content = "0" * 3
cvt_content = "1" * (0x8000 + 1)
data = tobytes(ppgm_content + cvt_content)
@@ -166,16 +174,17 @@ def test_decompile_magic_length_non_last(empty_font):
table = table_T_S_I__1()
table.decompile(data, empty_font)
- assert table.extraPrograms['ppgm'] == ppgm_content
- assert table.extraPrograms['cvt'] == cvt_content
+ assert table.extraPrograms["ppgm"] == ppgm_content
+ assert table.extraPrograms["cvt"] == cvt_content
table = table_T_S_I__1()
with CapturingLogHandler(table.log, "WARNING") as captor:
table.decompile(data[:-1], empty_font) # last entry is truncated
captor.assertRegex("nextTextOffset > totalLength")
- assert table.extraPrograms['cvt'] == cvt_content[:-1]
+ assert table.extraPrograms["cvt"] == cvt_content[:-1]
if __name__ == "__main__":
import sys
+
sys.exit(pytest.main(sys.argv))