From 0614fb36610a3d225b22ac2cfd33656724e5b98f Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Fri, 20 Nov 2015 14:51:57 -0800 Subject: [PATCH] Adding Bigtable Cluster.__eq__. --- gcloud/bigtable/cluster.py | 15 +++++++++++++++ gcloud/bigtable/test_cluster.py | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/gcloud/bigtable/cluster.py b/gcloud/bigtable/cluster.py index 677ca72c8eb3d..0a5392d8b572c 100644 --- a/gcloud/bigtable/cluster.py +++ b/gcloud/bigtable/cluster.py @@ -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) diff --git a/gcloud/bigtable/test_cluster.py b/gcloud/bigtable/test_cluster.py index 6f19dadad1ff3..44fe91b0edf64 100644 --- a/gcloud/bigtable/test_cluster.py +++ b/gcloud/bigtable/test_cluster.py @@ -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):