mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-25 03:23:41 +03:00
Noise effect: take five pixels, assert not all same
This commit is contained in:
parent
11a2026f12
commit
8adab0ec0d
|
@ -100,7 +100,7 @@ class PillowTestCase(unittest.TestCase):
|
||||||
logger.error("Url for test images: %s" %url)
|
logger.error("Url for test images: %s" %url)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.fail(msg or "got different content")
|
self.fail(msg or "got different content")
|
||||||
|
|
||||||
def assert_image_similar(self, a, b, epsilon, msg=None):
|
def assert_image_similar(self, a, b, epsilon, msg=None):
|
||||||
|
@ -161,6 +161,12 @@ class PillowTestCase(unittest.TestCase):
|
||||||
self.assertTrue(found)
|
self.assertTrue(found)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def assert_all_same(self, items, msg=None):
|
||||||
|
self.assertTrue(items.count(items[0]) == len(items), msg)
|
||||||
|
|
||||||
|
def assert_not_all_same(self, items, msg=None):
|
||||||
|
self.assertFalse(items.count(items[0]) == len(items), msg)
|
||||||
|
|
||||||
def skipKnownBadTest(self, msg=None, platform=None,
|
def skipKnownBadTest(self, msg=None, platform=None,
|
||||||
travis=None, interpreter=None):
|
travis=None, interpreter=None):
|
||||||
# Skip if platform/travis matches, and
|
# Skip if platform/travis matches, and
|
||||||
|
@ -206,7 +212,7 @@ class PillowLeakTestCase(PillowTestCase):
|
||||||
# requires unix/osx
|
# requires unix/osx
|
||||||
iterations = 100 # count
|
iterations = 100 # count
|
||||||
mem_limit = 512 # k
|
mem_limit = 512 # k
|
||||||
|
|
||||||
def _get_mem_usage(self):
|
def _get_mem_usage(self):
|
||||||
"""
|
"""
|
||||||
Gets the RUSAGE memory usage, returns in K. Encapsulates the difference
|
Gets the RUSAGE memory usage, returns in K. Encapsulates the difference
|
||||||
|
@ -214,7 +220,7 @@ class PillowLeakTestCase(PillowTestCase):
|
||||||
|
|
||||||
:returns; memory usage in kilobytes
|
:returns; memory usage in kilobytes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from resource import getpagesize, getrusage, RUSAGE_SELF
|
from resource import getpagesize, getrusage, RUSAGE_SELF
|
||||||
mem = getrusage(RUSAGE_SELF).ru_maxrss
|
mem = getrusage(RUSAGE_SELF).ru_maxrss
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
|
@ -225,7 +231,7 @@ class PillowLeakTestCase(PillowTestCase):
|
||||||
# linux
|
# linux
|
||||||
# man 2 getrusage
|
# man 2 getrusage
|
||||||
# ru_maxrss (since Linux 2.6.32)
|
# ru_maxrss (since Linux 2.6.32)
|
||||||
# This is the maximum resident set size used (in kilobytes).
|
# This is the maximum resident set size used (in kilobytes).
|
||||||
return mem # Kb
|
return mem # Kb
|
||||||
|
|
||||||
def _test_leak(self, core):
|
def _test_leak(self, core):
|
||||||
|
|
|
@ -348,24 +348,19 @@ class TestImage(PillowTestCase):
|
||||||
# Arrange
|
# Arrange
|
||||||
size = (100, 100)
|
size = (100, 100)
|
||||||
sigma = 128
|
sigma = 128
|
||||||
# To reduce chance of randomly having the same value twice
|
|
||||||
attempts = 5
|
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
while attempts > 0:
|
im = Image.effect_noise(size, sigma)
|
||||||
im = Image.effect_noise(size, sigma)
|
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
self.assertEqual(im.size, (100, 100))
|
self.assertEqual(im.size, (100, 100))
|
||||||
self.assertEqual(im.mode, "L")
|
self.assertEqual(im.mode, "L")
|
||||||
p0 = im.getpixel((0, 0))
|
p0 = im.getpixel((0, 0))
|
||||||
p1 = im.getpixel((0, 1))
|
p1 = im.getpixel((0, 1))
|
||||||
if p0 == p1:
|
p2 = im.getpixel((0, 2))
|
||||||
# Let's roll again
|
p3 = im.getpixel((0, 3))
|
||||||
attempts -= 1
|
p4 = im.getpixel((0, 4))
|
||||||
else:
|
self.assert_not_all_same([p0, p1, p2, p3, p4])
|
||||||
break
|
|
||||||
self.assertNotEqual(p0, p1)
|
|
||||||
|
|
||||||
def test_effect_spread(self):
|
def test_effect_spread(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
|
Loading…
Reference in New Issue
Block a user