Add __eq__ to Artist

This commit is contained in:
Thomas Adamcik 2010-04-27 22:47:35 +02:00
parent d64980411d
commit 06d6fd81c7
2 changed files with 36 additions and 0 deletions

View File

@ -32,6 +32,12 @@ class Artist(ImmutableObject):
#: The artist name. Read-only.
name = None
def __eq__(self, other):
return self.__dict__ == other.__dict__
def __ne__(self, other):
return not self.__eq__(other)
class Album(ImmutableObject):
"""

View File

@ -16,6 +16,36 @@ class ArtistTest(unittest.TestCase):
self.assertEqual(artist.name, name)
self.assertRaises(AttributeError, setattr, artist, 'name', None)
def test_eq_name(self):
artist1 = Artist(name=u'name')
artist2 = Artist(name=u'name')
self.assertEqual(artist1, artist2)
def test_eq_uri(self):
artist1 = Artist(uri=u'uri')
artist2 = Artist(uri=u'uri')
self.assertEqual(artist1, artist2)
def test_eq(self):
artist1 = Artist(uri=u'uri', name=u'name')
artist2 = Artist(uri=u'uri', name=u'name')
self.assertEqual(artist1, artist2)
def test_ne_name(self):
artist1 = Artist(name=u'name1')
artist2 = Artist(name=u'name2')
self.assertNotEqual(artist1, artist2)
def test_ne_uri(self):
artist1 = Artist(uri=u'uri1')
artist2 = Artist(uri=u'uri2')
self.assertNotEqual(artist1, artist2)
def test_ne(self):
artist1 = Artist(uri=u'uri1', name=u'name1')
artist2 = Artist(uri=u'uri2', name=u'name2')
self.assertNotEqual(artist1, artist2)
class AlbumTest(unittest.TestCase):
def test_uri(self):