mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +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)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
self.fail(msg or "got different content")
|
||||
|
||||
def assert_image_similar(self, a, b, epsilon, msg=None):
|
||||
|
@ -161,6 +161,12 @@ class PillowTestCase(unittest.TestCase):
|
|||
self.assertTrue(found)
|
||||
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,
|
||||
travis=None, interpreter=None):
|
||||
# Skip if platform/travis matches, and
|
||||
|
@ -206,7 +212,7 @@ class PillowLeakTestCase(PillowTestCase):
|
|||
# requires unix/osx
|
||||
iterations = 100 # count
|
||||
mem_limit = 512 # k
|
||||
|
||||
|
||||
def _get_mem_usage(self):
|
||||
"""
|
||||
Gets the RUSAGE memory usage, returns in K. Encapsulates the difference
|
||||
|
@ -214,7 +220,7 @@ class PillowLeakTestCase(PillowTestCase):
|
|||
|
||||
:returns; memory usage in kilobytes
|
||||
"""
|
||||
|
||||
|
||||
from resource import getpagesize, getrusage, RUSAGE_SELF
|
||||
mem = getrusage(RUSAGE_SELF).ru_maxrss
|
||||
if sys.platform == 'darwin':
|
||||
|
@ -225,7 +231,7 @@ class PillowLeakTestCase(PillowTestCase):
|
|||
# linux
|
||||
# man 2 getrusage
|
||||
# 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
|
||||
|
||||
def _test_leak(self, core):
|
||||
|
|
|
@ -348,24 +348,19 @@ class TestImage(PillowTestCase):
|
|||
# Arrange
|
||||
size = (100, 100)
|
||||
sigma = 128
|
||||
# To reduce chance of randomly having the same value twice
|
||||
attempts = 5
|
||||
|
||||
# Act
|
||||
while attempts > 0:
|
||||
im = Image.effect_noise(size, sigma)
|
||||
im = Image.effect_noise(size, sigma)
|
||||
|
||||
# Assert
|
||||
self.assertEqual(im.size, (100, 100))
|
||||
self.assertEqual(im.mode, "L")
|
||||
p0 = im.getpixel((0, 0))
|
||||
p1 = im.getpixel((0, 1))
|
||||
if p0 == p1:
|
||||
# Let's roll again
|
||||
attempts -= 1
|
||||
else:
|
||||
break
|
||||
self.assertNotEqual(p0, p1)
|
||||
# Assert
|
||||
self.assertEqual(im.size, (100, 100))
|
||||
self.assertEqual(im.mode, "L")
|
||||
p0 = im.getpixel((0, 0))
|
||||
p1 = im.getpixel((0, 1))
|
||||
p2 = im.getpixel((0, 2))
|
||||
p3 = im.getpixel((0, 3))
|
||||
p4 = im.getpixel((0, 4))
|
||||
self.assert_not_all_same([p0, p1, p2, p3, p4])
|
||||
|
||||
def test_effect_spread(self):
|
||||
# Arrange
|
||||
|
|
Loading…
Reference in New Issue
Block a user