ttFont_test: add tests for unseekable input file with lazy=True

This commit is contained in:
Cosimo Lupo 2023-03-21 17:24:20 +00:00
parent 4543910367
commit 8859d8669d
No known key found for this signature in database
GPG Key ID: DF65A8A5A119C9A8

View File

@ -286,3 +286,35 @@ def test_spooled_tempfile_may_not_have_attribute_seekable():
font.save(tmp) font.save(tmp)
# this should not fail # this should not fail
_ = TTFont(tmp) _ = TTFont(tmp)
def test_unseekable_file_lazy_loading_fails():
class NonSeekableFile:
def __init__(self):
self.file = io.BytesIO()
def read(self, size):
return self.file.read(size)
def seekable(self):
return False
f = NonSeekableFile()
with pytest.raises(TTLibError, match="Input file must be seekable when lazy=True"):
TTFont(f, lazy=True)
def test_unsupported_seek_operation_lazy_loading_fails():
class UnsupportedSeekFile:
def __init__(self):
self.file = io.BytesIO()
def read(self, size):
return self.file.read(size)
def seek(self, offset):
raise io.UnsupportedOperation("Unsupported seek operation")
f = UnsupportedSeekFile()
with pytest.raises(TTLibError, match="Input file must be seekable when lazy=True"):
TTFont(f, lazy=True)