@@ -443,6 +443,142 @@ def test_with_intersection_two_nested_rules(self):
443443 self .assertTrue (result is gc_rule )
444444
445445
446+ class Test__string_successor (unittest2 .TestCase ):
447+
448+ def _callFUT (self , * args , ** kwargs ):
449+ from gcloud .bigtable .happybase .table import _string_successor
450+ return _string_successor (* args , ** kwargs )
451+
452+ def test_with_alphanumeric (self ):
453+ self .assertEqual (self ._callFUT (b'boa' ), b'bob' )
454+ self .assertEqual (self ._callFUT (b'abc1' ), b'abc2' )
455+
456+ def test_with_last_byte (self ):
457+ self .assertEqual (self ._callFUT (b'boa\xff ' ), b'bob' )
458+
459+ def test_with_empty_string (self ):
460+ self .assertEqual (self ._callFUT (b'' ), b'' )
461+
462+ def test_with_all_last_bytes (self ):
463+ self .assertEqual (self ._callFUT (b'\xff \xff \xff ' ), b'' )
464+
465+ def test_with_unicode_input (self ):
466+ self .assertEqual (self ._callFUT (u'boa' ), b'bob' )
467+
468+
469+ class Test__convert_to_time_range (unittest2 .TestCase ):
470+
471+ def _callFUT (self , timestamp = None ):
472+ from gcloud .bigtable .happybase .table import _convert_to_time_range
473+ return _convert_to_time_range (timestamp = timestamp )
474+
475+ def test_null (self ):
476+ timestamp = None
477+ result = self ._callFUT (timestamp = timestamp )
478+ self .assertEqual (result , None )
479+
480+ def test_invalid_type (self ):
481+ timestamp = object ()
482+ with self .assertRaises (TypeError ):
483+ self ._callFUT (timestamp = timestamp )
484+
485+ def test_success (self ):
486+ from gcloud ._helpers import _datetime_from_microseconds
487+ from gcloud .bigtable .row import TimestampRange
488+
489+ timestamp = 1441928298571
490+ ts_dt = _datetime_from_microseconds (1000 * timestamp )
491+ result = self ._callFUT (timestamp = timestamp )
492+ self .assertTrue (isinstance (result , TimestampRange ))
493+ self .assertEqual (result .start , None )
494+ self .assertEqual (result .end , ts_dt )
495+
496+
497+ class Test__cells_to_pairs (unittest2 .TestCase ):
498+
499+ def _callFUT (self , * args , ** kwargs ):
500+ from gcloud .bigtable .happybase .table import _cells_to_pairs
501+ return _cells_to_pairs (* args , ** kwargs )
502+
503+ def test_without_timestamp (self ):
504+ from gcloud .bigtable .row_data import Cell
505+
506+ value1 = 'foo'
507+ cell1 = Cell (value = value1 , timestamp = None )
508+ value2 = 'bar'
509+ cell2 = Cell (value = value2 , timestamp = None )
510+
511+ result = self ._callFUT ([cell1 , cell2 ])
512+ self .assertEqual (result , [value1 , value2 ])
513+
514+ def test_with_timestamp (self ):
515+ from gcloud ._helpers import _datetime_from_microseconds
516+ from gcloud .bigtable .row_data import Cell
517+
518+ value1 = 'foo'
519+ ts1_millis = 1221934570148
520+ ts1 = _datetime_from_microseconds (ts1_millis * 1000 )
521+ cell1 = Cell (value = value1 , timestamp = ts1 )
522+
523+ value2 = 'bar'
524+ ts2_millis = 1221955575548
525+ ts2 = _datetime_from_microseconds (ts2_millis * 1000 )
526+ cell2 = Cell (value = value2 , timestamp = ts2 )
527+
528+ result = self ._callFUT ([cell1 , cell2 ], include_timestamp = True )
529+ self .assertEqual (result ,
530+ [(value1 , ts1_millis ), (value2 , ts2_millis )])
531+
532+
533+ class Test__partial_row_to_dict (unittest2 .TestCase ):
534+
535+ def _callFUT (self , partial_row_data , include_timestamp = False ):
536+ from gcloud .bigtable .happybase .table import _partial_row_to_dict
537+ return _partial_row_to_dict (partial_row_data ,
538+ include_timestamp = include_timestamp )
539+
540+ def test_without_timestamp (self ):
541+ from gcloud .bigtable .row_data import Cell
542+ from gcloud .bigtable .row_data import PartialRowData
543+
544+ row_data = PartialRowData (b'row-key' )
545+ val1 = b'hi-im-bytes'
546+ val2 = b'bi-im-hytes'
547+ row_data ._cells [u'fam1' ] = {
548+ b'col1' : [Cell (val1 , None )],
549+ b'col2' : [Cell (val2 , None )],
550+ }
551+ result = self ._callFUT (row_data )
552+ expected_result = {
553+ b'fam1:col1' : val1 ,
554+ b'fam1:col2' : val2 ,
555+ }
556+ self .assertEqual (result , expected_result )
557+
558+ def test_with_timestamp (self ):
559+ from gcloud ._helpers import _datetime_from_microseconds
560+ from gcloud .bigtable .row_data import Cell
561+ from gcloud .bigtable .row_data import PartialRowData
562+
563+ row_data = PartialRowData (b'row-key' )
564+ val1 = b'hi-im-bytes'
565+ ts1_millis = 1221934570148
566+ ts1 = _datetime_from_microseconds (ts1_millis * 1000 )
567+ val2 = b'bi-im-hytes'
568+ ts2_millis = 1331934880000
569+ ts2 = _datetime_from_microseconds (ts2_millis * 1000 )
570+ row_data ._cells [u'fam1' ] = {
571+ b'col1' : [Cell (val1 , ts1 )],
572+ b'col2' : [Cell (val2 , ts2 )],
573+ }
574+ result = self ._callFUT (row_data , include_timestamp = True )
575+ expected_result = {
576+ b'fam1:col1' : (val1 , ts1_millis ),
577+ b'fam1:col2' : (val2 , ts2_millis ),
578+ }
579+ self .assertEqual (result , expected_result )
580+
581+
446582class _Connection (object ):
447583
448584 def __init__ (self , cluster ):
0 commit comments