mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-01 18:33:05 +03:00
Merge pull request #2894 from hugovk/avoid-random-noise-failure
Test: avoid random noise failure
This commit is contained in:
commit
c4a91f05ef
|
@ -20,6 +20,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def convert_to_comparable(a, b):
|
def convert_to_comparable(a, b):
|
||||||
new_a, new_b = a, b
|
new_a, new_b = a, b
|
||||||
if a.mode == 'P':
|
if a.mode == 'P':
|
||||||
|
@ -161,6 +162,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
|
||||||
|
@ -201,6 +208,7 @@ class PillowTestCase(unittest.TestCase):
|
||||||
return Image.open(outfile)
|
return Image.open(outfile)
|
||||||
raise IOError()
|
raise IOError()
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS")
|
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS")
|
||||||
class PillowLeakTestCase(PillowTestCase):
|
class PillowLeakTestCase(PillowTestCase):
|
||||||
# requires unix/osx
|
# requires unix/osx
|
||||||
|
@ -215,7 +223,7 @@ class PillowLeakTestCase(PillowTestCase):
|
||||||
:returns; memory usage in kilobytes
|
:returns; memory usage in kilobytes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from resource import getpagesize, getrusage, RUSAGE_SELF
|
from resource import getrusage, RUSAGE_SELF
|
||||||
mem = getrusage(RUSAGE_SELF).ru_maxrss
|
mem = getrusage(RUSAGE_SELF).ru_maxrss
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
# man 2 getrusage:
|
# man 2 getrusage:
|
||||||
|
@ -309,6 +317,7 @@ def imagemagick_available():
|
||||||
def on_appveyor():
|
def on_appveyor():
|
||||||
return 'APPVEYOR' in os.environ
|
return 'APPVEYOR' in os.environ
|
||||||
|
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
IMCONVERT = os.environ.get('MAGICK_HOME', '')
|
IMCONVERT = os.environ.get('MAGICK_HOME', '')
|
||||||
if IMCONVERT:
|
if IMCONVERT:
|
||||||
|
|
|
@ -22,7 +22,7 @@ class TestImage(PillowTestCase):
|
||||||
'BGR;15', 'BGR;16', 'BGR;24', 'BGR;32'
|
'BGR;15', 'BGR;16', 'BGR;24', 'BGR;32'
|
||||||
]:
|
]:
|
||||||
with self.assertRaises(ValueError) as e:
|
with self.assertRaises(ValueError) as e:
|
||||||
Image.new(mode, (1, 1));
|
Image.new(mode, (1, 1))
|
||||||
self.assertEqual(str(e.exception), 'unrecognized image mode')
|
self.assertEqual(str(e.exception), 'unrecognized image mode')
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
|
@ -277,7 +277,8 @@ class TestImage(PillowTestCase):
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
source.alpha_composite, over, "invalid source")
|
source.alpha_composite, over, "invalid source")
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
source.alpha_composite, over, (0, 0), "invalid destination")
|
source.alpha_composite, over, (0, 0),
|
||||||
|
"invalid destination")
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
source.alpha_composite, over, (0))
|
source.alpha_composite, over, (0))
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
|
@ -354,7 +355,12 @@ class TestImage(PillowTestCase):
|
||||||
# Assert
|
# Assert
|
||||||
self.assertEqual(im.size, (100, 100))
|
self.assertEqual(im.size, (100, 100))
|
||||||
self.assertEqual(im.mode, "L")
|
self.assertEqual(im.mode, "L")
|
||||||
self.assertNotEqual(im.getpixel((0, 0)), im.getpixel((0, 1)))
|
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):
|
def test_effect_spread(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
|
|
Loading…
Reference in New Issue
Block a user