Improved test

This commit is contained in:
Andrew Murray 2022-10-11 23:28:27 +11:00
parent 8979f0ccab
commit e007a0b45d
2 changed files with 6 additions and 11 deletions

View File

@ -21,19 +21,14 @@ def test_sanity():
def test_large_file_is_truncated():
import warnings
original_max_file_size = GimpPaletteFile._max_file_size
try:
original_value = GimpPaletteFile._max_file_size
GimpPaletteFile._max_file_size = 100
with warnings.catch_warnings():
warnings.simplefilter("error")
with pytest.raises(UserWarning):
with open("Tests/images/custom_gimp_palette.gpl", "rb") as fp:
GimpPaletteFile(fp)
with open("Tests/images/custom_gimp_palette.gpl", "rb") as fp:
with pytest.warns(UserWarning):
GimpPaletteFile(fp)
finally:
GimpPaletteFile._max_file_size = original_value
GimpPaletteFile._max_file_size = original_max_file_size
def test_get_palette():

View File

@ -49,7 +49,7 @@ class GimpPaletteFile:
warnings.warn(
f"Palette file truncated at {self._max_file_size - len(s)} bytes"
)
break # pragma: no cover
break
# skip fields and comment lines
if re.match(rb"\w+:|#", s):