Skip to content

Commit

Permalink
Fix __eq__ and __ne__. (#3765)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer authored Aug 8, 2017
1 parent bebf602 commit b24ff84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ def _to_dict(self):
return info

def __eq__(self, other):
if not isinstance(other, LabelDescriptor):
return NotImplemented
return self.__dict__ == other.__dict__

def __ne__(self, other):
return self.__dict__ != other.__dict__
return not self == other

def __repr__(self):
return (
Expand Down
16 changes: 11 additions & 5 deletions packages/google-cloud-monitoring/tests/unit/test_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import unittest

import mock


class TestLabelValueType(unittest.TestCase):

Expand Down Expand Up @@ -108,9 +110,13 @@ def test_equality(self):
KEY = 'response_code'
VALUE_TYPE = 'INT64'
DESCRIPTION = 'HTTP status code for the request.'
descriptor1 = self._make_one(key=KEY, value_type=VALUE_TYPE,
description=DESCRIPTION)
descriptor1a = self._make_one(key=KEY, value_type=VALUE_TYPE,
description=DESCRIPTION)
descriptor1b = self._make_one(key=KEY, value_type=VALUE_TYPE,
description=DESCRIPTION)
descriptor2 = self._make_one(key=KEY, value_type=VALUE_TYPE,
description=DESCRIPTION)
self.assertTrue(descriptor1 == descriptor2)
self.assertFalse(descriptor1 != descriptor2)
description=DESCRIPTION + 'foo')
self.assertEqual(descriptor1a, descriptor1b)
self.assertNotEqual(descriptor1a, descriptor2)
self.assertNotEqual(descriptor1a, object())
self.assertEqual(descriptor1a, mock.ANY)

0 comments on commit b24ff84

Please sign in to comment.