Skip to content

Commit

Permalink
Adding Bigtable Cluster.__eq__.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Nov 20, 2015
1 parent 21101e0 commit 0614fb3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gcloud/bigtable/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,18 @@ def from_pb(cls, cluster_pb, client):
result = cls(match.group('zone'), match.group('cluster_id'), client)
result._update_from_pb(cluster_pb)
return result

def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
# NOTE: This does not compare the configuration values, such as
# the serve_nodes or display_name. This is intentional, since
# the same cluster can be in different states if not
# synchronized. This suggests we should use `project`
# instead of `client` for the third comparison.
return (other.zone == self.zone and
other.cluster_id == self.cluster_id and
other._client == self._client)

def __ne__(self, other):
return not self.__eq__(other)
27 changes: 27 additions & 0 deletions gcloud/bigtable/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,33 @@ def test_from_pb_project_mistmatch(self):
with self.assertRaises(ValueError):
klass.from_pb(cluster_pb, client)

def test___eq__(self):
zone = 'zone'
cluster_id = 'cluster_id'
client = object()
cluster1 = self._makeOne(zone, cluster_id, client)
cluster2 = self._makeOne(zone, cluster_id, client)
self.assertEqual(cluster1, cluster2)

def test___eq__type_differ(self):
cluster1 = self._makeOne('zone', 'cluster_id', 'client')
cluster2 = object()
self.assertNotEqual(cluster1, cluster2)

def test___ne__same_value(self):
zone = 'zone'
cluster_id = 'cluster_id'
client = object()
cluster1 = self._makeOne(zone, cluster_id, client)
cluster2 = self._makeOne(zone, cluster_id, client)
comparison_val = (cluster1 != cluster2)
self.assertFalse(comparison_val)

def test___ne__(self):
cluster1 = self._makeOne('zone1', 'cluster_id1', 'client1')
cluster2 = self._makeOne('zone2', 'cluster_id2', 'client2')
self.assertNotEqual(cluster1, cluster2)


class Test__get_pb_property_value(unittest2.TestCase):

Expand Down

0 comments on commit 0614fb3

Please sign in to comment.