Skip to content

Commit b24ff84

Browse files
Fix __eq__ and __ne__. (#3765)
1 parent bebf602 commit b24ff84

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

packages/google-cloud-monitoring/google/cloud/monitoring/label.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ def _to_dict(self):
8787
return info
8888

8989
def __eq__(self, other):
90+
if not isinstance(other, LabelDescriptor):
91+
return NotImplemented
9092
return self.__dict__ == other.__dict__
9193

9294
def __ne__(self, other):
93-
return self.__dict__ != other.__dict__
95+
return not self == other
9496

9597
def __repr__(self):
9698
return (

packages/google-cloud-monitoring/tests/unit/test_label.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import unittest
1616

17+
import mock
18+
1719

1820
class TestLabelValueType(unittest.TestCase):
1921

@@ -108,9 +110,13 @@ def test_equality(self):
108110
KEY = 'response_code'
109111
VALUE_TYPE = 'INT64'
110112
DESCRIPTION = 'HTTP status code for the request.'
111-
descriptor1 = self._make_one(key=KEY, value_type=VALUE_TYPE,
112-
description=DESCRIPTION)
113+
descriptor1a = self._make_one(key=KEY, value_type=VALUE_TYPE,
114+
description=DESCRIPTION)
115+
descriptor1b = self._make_one(key=KEY, value_type=VALUE_TYPE,
116+
description=DESCRIPTION)
113117
descriptor2 = self._make_one(key=KEY, value_type=VALUE_TYPE,
114-
description=DESCRIPTION)
115-
self.assertTrue(descriptor1 == descriptor2)
116-
self.assertFalse(descriptor1 != descriptor2)
118+
description=DESCRIPTION + 'foo')
119+
self.assertEqual(descriptor1a, descriptor1b)
120+
self.assertNotEqual(descriptor1a, descriptor2)
121+
self.assertNotEqual(descriptor1a, object())
122+
self.assertEqual(descriptor1a, mock.ANY)

0 commit comments

Comments
 (0)