Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Bigtable Cell class. #1473

Merged
merged 2 commits into from
Feb 16, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Adding test for Bigtable row data and excluding module from docs.
  • Loading branch information
dhermes committed Feb 16, 2016
commit 45bda195ea6d53a995b982ebad08e2a92cf76e72
91 changes: 91 additions & 0 deletions gcloud/bigtable/test_row_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import unittest2


class TestCell(unittest2.TestCase):

def _getTargetClass(self):
from gcloud.bigtable.row_data import Cell
return Cell

def _makeOne(self, *args, **kwargs):
return self._getTargetClass()(*args, **kwargs)

def _from_pb_test_helper(self, labels=None):
import datetime
from gcloud._helpers import _EPOCH
from gcloud.bigtable._generated import bigtable_data_pb2 as data_pb2

timestamp_micros = 18738724000 # Make sure millis granularity
timestamp = _EPOCH + datetime.timedelta(microseconds=timestamp_micros)
value = b'value-bytes'

if labels is None:
cell_pb = data_pb2.Cell(value=value,
timestamp_micros=timestamp_micros)
cell_expected = self._makeOne(value, timestamp)
else:
cell_pb = data_pb2.Cell(value=value,
timestamp_micros=timestamp_micros,
labels=labels)
cell_expected = self._makeOne(value, timestamp, labels=labels)

klass = self._getTargetClass()
result = klass.from_pb(cell_pb)
self.assertEqual(result, cell_expected)

def test_from_pb(self):
self._from_pb_test_helper()

def test_from_pb_with_labels(self):
labels = [u'label1', u'label2']
self._from_pb_test_helper(labels)

def test_constructor(self):
value = object()
timestamp = object()
cell = self._makeOne(value, timestamp)
self.assertEqual(cell.value, value)
self.assertEqual(cell.timestamp, timestamp)

def test___eq__(self):
value = object()
timestamp = object()
cell1 = self._makeOne(value, timestamp)
cell2 = self._makeOne(value, timestamp)
self.assertEqual(cell1, cell2)

def test___eq__type_differ(self):
cell1 = self._makeOne(None, None)
cell2 = object()
self.assertNotEqual(cell1, cell2)

def test___ne__same_value(self):
value = object()
timestamp = object()
cell1 = self._makeOne(value, timestamp)
cell2 = self._makeOne(value, timestamp)
comparison_val = (cell1 != cell2)
self.assertFalse(comparison_val)

def test___ne__(self):
value1 = 'value1'
value2 = 'value2'
timestamp = object()
cell1 = self._makeOne(value1, timestamp)
cell2 = self._makeOne(value2, timestamp)
self.assertNotEqual(cell1, cell2)
1 change: 1 addition & 0 deletions scripts/verify_included_modules.py
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
'gcloud.bigtable.column_family',
'gcloud.bigtable.happybase.connection',
'gcloud.bigtable.row',
'gcloud.bigtable.row_data',
'gcloud.bigtable.table',
'gcloud.datastore.demo.demo',
'gcloud.demo',