Skip to content

Commit

Permalink
Adding GC Rule to Bigtable Column Family class.
Browse files Browse the repository at this point in the history
Also adding equality check for column family
instances.
  • Loading branch information
dhermes committed Dec 17, 2015
1 parent 0ad0d0d commit 9b296c9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
17 changes: 16 additions & 1 deletion gcloud/bigtable/column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,23 @@ class ColumnFamily(object):
:type table: :class:`Table <gcloud.bigtable.table.Table>`
:param table: The table that owns the column family.
:type gc_rule: :class:`GarbageCollectionRule`
:param gc_rule: (Optional) The garbage collection settings for this
column family.
"""

def __init__(self, column_family_id, table):
def __init__(self, column_family_id, table, gc_rule=None):
self.column_family_id = column_family_id
self._table = table
self.gc_rule = gc_rule

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 and
other.gc_rule == self.gc_rule)

def __ne__(self, other):
return not self.__eq__(other)
35 changes: 34 additions & 1 deletion gcloud/bigtable/test_column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,40 @@ def _makeOne(self, *args, **kwargs):
def test_constructor(self):
column_family_id = u'column-family-id'
table = object()
column_family = self._makeOne(column_family_id, table)
gc_rule = object()
column_family = self._makeOne(column_family_id, table, gc_rule=gc_rule)

self.assertEqual(column_family.column_family_id, column_family_id)
self.assertTrue(column_family._table is table)
self.assertTrue(column_family.gc_rule is gc_rule)

def test___eq__(self):
column_family_id = 'column_family_id'
table = object()
gc_rule = object()
column_family1 = self._makeOne(column_family_id, table,
gc_rule=gc_rule)
column_family2 = self._makeOne(column_family_id, table,
gc_rule=gc_rule)
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()
gc_rule = object()
column_family1 = self._makeOne(column_family_id, table,
gc_rule=gc_rule)
column_family2 = self._makeOne(column_family_id, table,
gc_rule=gc_rule)
comparison_val = (column_family1 != column_family2)
self.assertFalse(comparison_val)

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

0 comments on commit 9b296c9

Please sign in to comment.