Merge pull request #3 from radarhere/gimppalette_test

Improved test
This commit is contained in:
Joao S. O. Bueno 2022-10-12 12:37:03 -03:00 committed by GitHub
commit 6893d1d95a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View File

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

View File

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