From 8adab0ec0dd46813335b857e4e92b08c53b65cc1 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 19 Dec 2017 17:12:58 +0200 Subject: [PATCH] Noise effect: take five pixels, assert not all same --- Tests/helper.py | 14 ++++++++++---- Tests/test_image.py | 25 ++++++++++--------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index 117c5da54..e5e08e15d 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -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): diff --git a/Tests/test_image.py b/Tests/test_image.py index 875e925a8..6f6d1983e 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -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