Skip to content

Commit 1d6ceb4

Browse files
authored
Merge pull request #17 from yugangw-msft/equal
fix a bug in model class equality
2 parents d8c6be6 + 0b44a29 commit 1d6ceb4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

msrest/serialization.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__(self, *args, **kwargs):
9393
def __eq__(self, other):
9494
"""Compare objects by comparing all attributes."""
9595
if isinstance(other, self.__class__):
96-
return self.__class__.__dict__ == other.__class__.__dict__
96+
return self.__dict__ == other.__dict__
9797
return False
9898

9999
def __ne__(self, other):

test/unittest_serialization.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ def __init__(self, name=None, likes_mice=None, dislikes = None, color=None):
716716

717717
self.s.dependencies = old_dependencies
718718

719-
720719
class TestRuntimeDeserialized(unittest.TestCase):
721720

722721
class TestObj(Model):
@@ -1311,6 +1310,24 @@ def __init__(self, name=None, likes_dog_food=None):
13111310
self.assertIsInstance(animal, Dog)
13121311
self.assertTrue(animal.likes_dog_food)
13131312

1313+
class TestModelInstanceEquality(unittest.TestCase):
1314+
1315+
def test_model_instance_equality(self):
1316+
1317+
class Animal(Model):
1318+
1319+
_attribute_map = {
1320+
"name":{"key":"Name", "type":"str"},
1321+
}
1322+
1323+
def __init__(self, name=None):
1324+
self.name = name
1325+
1326+
animal1 = Animal('a1')
1327+
animal2 = Animal('a2')
1328+
animal3 = Animal('a1')
1329+
self.assertTrue(animal1!=animal2)
1330+
self.assertTrue(animal1==animal3)
13141331

13151332
if __name__ == '__main__':
13161333
unittest.main()

0 commit comments

Comments
 (0)