From 8859d8669d03c9d67eee3a5adc06feece91b4868 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Tue, 21 Mar 2023 17:24:20 +0000 Subject: [PATCH] ttFont_test: add tests for unseekable input file with lazy=True --- Tests/ttLib/ttFont_test.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Tests/ttLib/ttFont_test.py b/Tests/ttLib/ttFont_test.py index f726ad45c..2203b4d9c 100644 --- a/Tests/ttLib/ttFont_test.py +++ b/Tests/ttLib/ttFont_test.py @@ -286,3 +286,35 @@ def test_spooled_tempfile_may_not_have_attribute_seekable(): font.save(tmp) # this should not fail _ = 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)