Make _make_linear_lut public and issue deprecation warnings from old private methods

This commit is contained in:
hugovk 2014-07-20 10:13:26 +03:00
parent 3c39a44f6e
commit 37691bc1e4
2 changed files with 70 additions and 0 deletions

View File

@ -17,6 +17,7 @@
#
import array
import warnings
from PIL import Image, ImageColor
@ -125,6 +126,26 @@ def raw(rawmode, data):
# Factories
def _make_linear_lut(black, white):
warnings.warn(
'_make_linear_lut() is deprecated. '
'Please call make_linear_lut() instead.',
DeprecationWarning,
stacklevel=2
)
return make_linear_lut(black, white)
def _make_gamma_lut(exp):
warnings.warn(
'_make_gamma_lut() is deprecated. '
'Please call make_gamma_lut() instead.',
DeprecationWarning,
stacklevel=2
)
return make_gamma_lut(exp)
def make_linear_lut(black, white):
lut = []
if black == 0:
for i in range(256):

View File

@ -44,6 +44,34 @@ class TestImagePalette(PillowTestCase):
self.assertIsInstance(p, ImagePalette)
self.assertEqual(p.palette, palette.tobytes())
def test_make_linear_lut(self):
# Arrange
from PIL.ImagePalette import make_linear_lut
black = 0
white = 255
# Act
lut = make_linear_lut(black, white)
# Assert
self.assertIsInstance(lut, list)
self.assertEqual(len(lut), 256)
# Check values
for i in range(0, len(lut)):
self.assertEqual(lut[i], i)
def test_make_linear_lut_not_yet_implemented(self):
# Update after FIXME
# Arrange
from PIL.ImagePalette import make_linear_lut
black = 1
white = 255
# Act
self.assertRaises(
NotImplementedError,
lambda: make_linear_lut(black, white))
def test_make_gamma_lut(self):
# Arrange
from PIL.ImagePalette import make_gamma_lut
@ -62,6 +90,27 @@ class TestImagePalette(PillowTestCase):
self.assertEqual(lut[191], 60)
self.assertEqual(lut[255], 255)
def test_private_make_linear_lut_warning(self):
# Arrange
from PIL.ImagePalette import _make_linear_lut
black = 0
white = 255
# Act / Assert
self.assert_warning(
DeprecationWarning,
lambda: _make_linear_lut(black, white))
def test_private_make_gamma_lut_warning(self):
# Arrange
from PIL.ImagePalette import _make_gamma_lut
exp = 5
# Act / Assert
self.assert_warning(
DeprecationWarning,
lambda: _make_gamma_lut(exp))
if __name__ == '__main__':
unittest.main()