Merge pull request #775 from radarhere/master

Added class checking to Image __eq__ function
This commit is contained in:
Hugo 2014-07-07 19:23:06 +03:00
commit 737c7440d7
2 changed files with 13 additions and 0 deletions

View File

@ -573,6 +573,8 @@ class Image:
return file
def __eq__(self, other):
if self.__class__.__name__ != other.__class__.__name__:
return False
a = (self.mode == other.mode)
b = (self.size == other.size)
c = (self.getpalette() == other.getpalette())

View File

@ -44,6 +44,17 @@ class TestImage(PillowTestCase):
file = self.tempfile("temp.ppm")
im._dump(file)
def test_comparison_with_other_type(self):
# Arrange
item = Image.new('RGB', (25, 25), '#000')
num = 12
# Act/Assert
# Shouldn't cause AttributeError (#774)
self.assertFalse(item is None)
self.assertFalse(item == None)
self.assertFalse(item == num)
if __name__ == '__main__':
unittest.main()