|
16 | 16 | import unittest2 |
17 | 17 |
|
18 | 18 |
|
| 19 | +class Test__timedelta_to_duration_pb(unittest2.TestCase): |
| 20 | + |
| 21 | + def _callFUT(self, *args, **kwargs): |
| 22 | + from gcloud.bigtable.column_family import _timedelta_to_duration_pb |
| 23 | + return _timedelta_to_duration_pb(*args, **kwargs) |
| 24 | + |
| 25 | + def test_it(self): |
| 26 | + import datetime |
| 27 | + from gcloud.bigtable._generated import duration_pb2 |
| 28 | + |
| 29 | + seconds = microseconds = 1 |
| 30 | + timedelta_val = datetime.timedelta(seconds=seconds, |
| 31 | + microseconds=microseconds) |
| 32 | + result = self._callFUT(timedelta_val) |
| 33 | + self.assertTrue(isinstance(result, duration_pb2.Duration)) |
| 34 | + self.assertEqual(result.seconds, seconds) |
| 35 | + self.assertEqual(result.nanos, 1000 * microseconds) |
| 36 | + |
| 37 | + def test_with_negative_microseconds(self): |
| 38 | + import datetime |
| 39 | + from gcloud.bigtable._generated import duration_pb2 |
| 40 | + |
| 41 | + seconds = 1 |
| 42 | + microseconds = -5 |
| 43 | + timedelta_val = datetime.timedelta(seconds=seconds, |
| 44 | + microseconds=microseconds) |
| 45 | + result = self._callFUT(timedelta_val) |
| 46 | + self.assertTrue(isinstance(result, duration_pb2.Duration)) |
| 47 | + self.assertEqual(result.seconds, seconds - 1) |
| 48 | + self.assertEqual(result.nanos, 10**9 + 1000 * microseconds) |
| 49 | + |
| 50 | + def test_with_negative_seconds(self): |
| 51 | + import datetime |
| 52 | + from gcloud.bigtable._generated import duration_pb2 |
| 53 | + |
| 54 | + seconds = -1 |
| 55 | + microseconds = 5 |
| 56 | + timedelta_val = datetime.timedelta(seconds=seconds, |
| 57 | + microseconds=microseconds) |
| 58 | + result = self._callFUT(timedelta_val) |
| 59 | + self.assertTrue(isinstance(result, duration_pb2.Duration)) |
| 60 | + self.assertEqual(result.seconds, seconds + 1) |
| 61 | + self.assertEqual(result.nanos, -(10**9 - 1000 * microseconds)) |
| 62 | + |
| 63 | + |
| 64 | +class TestGarbageCollectionRule(unittest2.TestCase): |
| 65 | + |
| 66 | + def _getTargetClass(self): |
| 67 | + from gcloud.bigtable.column_family import GarbageCollectionRule |
| 68 | + return GarbageCollectionRule |
| 69 | + |
| 70 | + def _makeOne(self, *args, **kwargs): |
| 71 | + return self._getTargetClass()(*args, **kwargs) |
| 72 | + |
| 73 | + def test_to_pb_virtual(self): |
| 74 | + gc_rule = self._makeOne() |
| 75 | + self.assertRaises(NotImplementedError, gc_rule.to_pb) |
| 76 | + |
| 77 | + |
| 78 | +class TestMaxVersionsGCRule(unittest2.TestCase): |
| 79 | + |
| 80 | + def _getTargetClass(self): |
| 81 | + from gcloud.bigtable.column_family import MaxVersionsGCRule |
| 82 | + return MaxVersionsGCRule |
| 83 | + |
| 84 | + def _makeOne(self, *args, **kwargs): |
| 85 | + return self._getTargetClass()(*args, **kwargs) |
| 86 | + |
| 87 | + def test___eq__max_num_versions(self): |
| 88 | + gc_rule1 = self._makeOne(2) |
| 89 | + gc_rule2 = self._makeOne(2) |
| 90 | + self.assertEqual(gc_rule1, gc_rule2) |
| 91 | + |
| 92 | + def test___eq__type_differ(self): |
| 93 | + gc_rule1 = self._makeOne(10) |
| 94 | + gc_rule2 = object() |
| 95 | + self.assertNotEqual(gc_rule1, gc_rule2) |
| 96 | + |
| 97 | + def test___ne__same_value(self): |
| 98 | + gc_rule1 = self._makeOne(99) |
| 99 | + gc_rule2 = self._makeOne(99) |
| 100 | + comparison_val = (gc_rule1 != gc_rule2) |
| 101 | + self.assertFalse(comparison_val) |
| 102 | + |
| 103 | + def test_to_pb(self): |
| 104 | + from gcloud.bigtable._generated import ( |
| 105 | + bigtable_table_data_pb2 as data_pb2) |
| 106 | + max_num_versions = 1337 |
| 107 | + gc_rule = self._makeOne(max_num_versions=max_num_versions) |
| 108 | + pb_val = gc_rule.to_pb() |
| 109 | + self.assertEqual(pb_val, |
| 110 | + data_pb2.GcRule(max_num_versions=max_num_versions)) |
| 111 | + |
| 112 | + |
| 113 | +class TestMaxAgeGCRule(unittest2.TestCase): |
| 114 | + |
| 115 | + def _getTargetClass(self): |
| 116 | + from gcloud.bigtable.column_family import MaxAgeGCRule |
| 117 | + return MaxAgeGCRule |
| 118 | + |
| 119 | + def _makeOne(self, *args, **kwargs): |
| 120 | + return self._getTargetClass()(*args, **kwargs) |
| 121 | + |
| 122 | + def test___eq__max_age(self): |
| 123 | + max_age = object() |
| 124 | + gc_rule1 = self._makeOne(max_age=max_age) |
| 125 | + gc_rule2 = self._makeOne(max_age=max_age) |
| 126 | + self.assertEqual(gc_rule1, gc_rule2) |
| 127 | + |
| 128 | + def test___eq__type_differ(self): |
| 129 | + max_age = object() |
| 130 | + gc_rule1 = self._makeOne(max_age=max_age) |
| 131 | + gc_rule2 = object() |
| 132 | + self.assertNotEqual(gc_rule1, gc_rule2) |
| 133 | + |
| 134 | + def test___ne__same_value(self): |
| 135 | + max_age = object() |
| 136 | + gc_rule1 = self._makeOne(max_age=max_age) |
| 137 | + gc_rule2 = self._makeOne(max_age=max_age) |
| 138 | + comparison_val = (gc_rule1 != gc_rule2) |
| 139 | + self.assertFalse(comparison_val) |
| 140 | + |
| 141 | + def test_to_pb(self): |
| 142 | + import datetime |
| 143 | + from gcloud.bigtable._generated import ( |
| 144 | + bigtable_table_data_pb2 as data_pb2) |
| 145 | + from gcloud.bigtable._generated import duration_pb2 |
| 146 | + |
| 147 | + max_age = datetime.timedelta(seconds=1) |
| 148 | + duration = duration_pb2.Duration(seconds=1) |
| 149 | + gc_rule = self._makeOne(max_age=max_age) |
| 150 | + pb_val = gc_rule.to_pb() |
| 151 | + self.assertEqual(pb_val, data_pb2.GcRule(max_age=duration)) |
| 152 | + |
| 153 | + |
19 | 154 | class TestColumnFamily(unittest2.TestCase): |
20 | 155 |
|
21 | 156 | def _getTargetClass(self): |
|
0 commit comments