mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
4de5477b61
With the introduction and use of pytest, it is simple and easy to execute specific tests in isolation through documented command line arguments. Either by specifying the module path or through the `-k EXPRESSION` argument. There is no longer any need to provide the boilerplate: if __name__ == '__main__': unittest.main() To every test file. It is simply noise. The pattern remains in test files that aren't named with `test_*` as those files are not discovered and executed by pytest by default.
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from .helper import PillowTestCase, hopper
|
|
|
|
from PIL import Image
|
|
from PIL import ImageStat
|
|
|
|
|
|
class TestImageStat(PillowTestCase):
|
|
|
|
def test_sanity(self):
|
|
|
|
im = hopper()
|
|
|
|
st = ImageStat.Stat(im)
|
|
st = ImageStat.Stat(im.histogram())
|
|
st = ImageStat.Stat(im, Image.new("1", im.size, 1))
|
|
|
|
# Check these run. Exceptions will cause failures.
|
|
st.extrema
|
|
st.sum
|
|
st.mean
|
|
st.median
|
|
st.rms
|
|
st.sum2
|
|
st.var
|
|
st.stddev
|
|
|
|
self.assertRaises(AttributeError, lambda: st.spam)
|
|
|
|
self.assertRaises(TypeError, ImageStat.Stat, 1)
|
|
|
|
def test_hopper(self):
|
|
|
|
im = hopper()
|
|
|
|
st = ImageStat.Stat(im)
|
|
|
|
# verify a few values
|
|
self.assertEqual(st.extrema[0], (0, 255))
|
|
self.assertEqual(st.median[0], 72)
|
|
self.assertEqual(st.sum[0], 1470218)
|
|
self.assertEqual(st.sum[1], 1311896)
|
|
self.assertEqual(st.sum[2], 1563008)
|
|
|
|
def test_constant(self):
|
|
|
|
im = Image.new("L", (128, 128), 128)
|
|
|
|
st = ImageStat.Stat(im)
|
|
|
|
self.assertEqual(st.extrema[0], (128, 128))
|
|
self.assertEqual(st.sum[0], 128**3)
|
|
self.assertEqual(st.sum2[0], 128**4)
|
|
self.assertEqual(st.mean[0], 128)
|
|
self.assertEqual(st.median[0], 128)
|
|
self.assertEqual(st.rms[0], 128)
|
|
self.assertEqual(st.var[0], 0)
|
|
self.assertEqual(st.stddev[0], 0)
|