Skip to content

Commit

Permalink
Implementing equality check for ColumnFamily.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jul 29, 2015
1 parent 63565f0 commit 4ac354a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gcloud_bigtable/column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,12 @@ def name(self):
:returns: The column family name.
"""
return self.table.name + '/columnFamilies/' + self.column_family_id

def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return (other.column_family_id == self.column_family_id and
other.table == self.table)

def __ne__(self, other):
return not self.__eq__(other)
25 changes: 25 additions & 0 deletions gcloud_bigtable/test_column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,31 @@ def test_name_property(self):
expected_name = table_name + '/columnFamilies/' + COLUMN_FAMILY_ID
self.assertEqual(column_family.name, expected_name)

def test___eq__(self):
column_family_id = 'column_family_id'
table = object()
column_family1 = self._makeOne(column_family_id, table)
column_family2 = self._makeOne(column_family_id, table)
self.assertEqual(column_family1, column_family2)

def test___eq__type_differ(self):
column_family1 = self._makeOne('column_family_id', None)
column_family2 = object()
self.assertNotEqual(column_family1, column_family2)

def test___ne__same_value(self):
column_family_id = 'column_family_id'
table = object()
column_family1 = self._makeOne(column_family_id, table)
column_family2 = self._makeOne(column_family_id, table)
comparison_val = (column_family1 != column_family2)
self.assertFalse(comparison_val)

def test___ne__(self):
column_family1 = self._makeOne('column_family_id1', 'table1')
column_family2 = self._makeOne('column_family_id2', 'table2')
self.assertNotEqual(column_family1, column_family2)


class _Table(object):

Expand Down

0 comments on commit 4ac354a

Please sign in to comment.