FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Upgrading list_value -> array_value for v1beta3. · googleapis/google-cloud-python@20e69bf · GitHub

Commit 20e69bf

Browse files
committed
Upgrading list_value -> array_value for v1beta3.
1 parent 2b6c9c0 commit 20e69bf

2 files changed

Lines changed: 55 additions & 54 deletions

File tree

‎gcloud/datastore/helpers.py‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,20 @@ def _get_meaning(value_pb, is_list=False):
9595
if is_list:
9696
# An empty list will have no values, hence no shared meaning
9797
# set among them.
98-
if len(value_pb.list_value) == 0:
98+
if len(value_pb.array_value.values) == 0:
9999
return None
100100

101101
# We check among all the meanings, some of which may be None,
102102
# the rest which may be enum/int values.
103103
all_meanings = set(_get_meaning(sub_value_pb)
104-
for sub_value_pb in value_pb.list_value)
104+
for sub_value_pb in value_pb.array_value.values)
105105
meaning = all_meanings.pop()
106106
# The value we popped off should have been unique. If not
107107
# then we can't handle a list with values that have more
108108
# than one meaning.
109109
if all_meanings:
110110
raise ValueError('Different meanings set on values '
111-
'within a list_value')
111+
'within an array_value')
112112
elif value_pb.meaning: # Simple field (int32)
113113
meaning = value_pb.meaning
114114

@@ -178,10 +178,11 @@ def entity_from_protobuf(pb):
178178
# in a list agree.
179179
if is_list:
180180
exclude_values = set(value_pb.exclude_from_indexes
181-
for value_pb in value_pb.list_value)
181+
for value_pb in value_pb.array_value.values)
182182
if len(exclude_values) != 1:
183-
raise ValueError('For a list_value, subvalues must either all '
184-
'be indexed or all excluded from indexes.')
183+
raise ValueError('For an array_value, subvalues must either '
184+
'all be indexed or all excluded from '
185+
'indexes.')
185186

186187
if exclude_values.pop():
187188
exclude_from_indexes.append(prop_name)
@@ -223,7 +224,7 @@ def entity_to_protobuf(entity):
223224
if not value_is_list:
224225
value_pb.exclude_from_indexes = True
225226

226-
for sub_value in value_pb.list_value:
227+
for sub_value in value_pb.array_value.values:
227228
sub_value.exclude_from_indexes = True
228229

229230
# Add meaning information to protobuf.
@@ -234,7 +235,7 @@ def entity_to_protobuf(entity):
234235
if orig_value is value:
235236
# For lists, we set meaning on each sub-element.
236237
if value_is_list:
237-
for sub_value_pb in value_pb.list_value:
238+
for sub_value_pb in value_pb.array_value.values:
238239
sub_value_pb.meaning = meaning
239240
else:
240241
value_pb.meaning = meaning
@@ -325,7 +326,7 @@ def _pb_attr_value(val):
325326
elif isinstance(val, Entity):
326327
name, value = 'entity', val
327328
elif isinstance(val, list):
328-
name, value = 'list', val
329+
name, value = 'array', val
329330
else:
330331
raise ValueError("Unknown protobuf attr type %s" % type(val))
331332

@@ -374,9 +375,9 @@ def _get_value_from_value_pb(value_pb):
374375
elif value_pb.HasField('entity_value'): # Message field (Entity)
375376
result = entity_from_protobuf(value_pb.entity_value)
376377

377-
elif value_pb.list_value:
378+
elif value_pb.array_value.values:
378379
result = [_get_value_from_value_pb(value)
379-
for value in value_pb.list_value]
380+
for value in value_pb.array_value.values]
380381

381382
return result
382383

@@ -408,8 +409,8 @@ def _set_protobuf_value(value_pb, val):
408409
elif attr == 'entity_value':
409410
entity_pb = entity_to_protobuf(val)
410411
value_pb.entity_value.CopyFrom(entity_pb)
411-
elif attr == 'list_value':
412-
l_pb = value_pb.list_value
412+
elif attr == 'array_value':
413+
l_pb = value_pb.array_value.values
413414
for item in val:
414415
i_pb = l_pb.add()
415416
_set_protobuf_value(i_pb, item)

‎gcloud/datastore/test_helpers.py‎

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ def test_it(self):
8080
unindexed_val_pb.integer_value = 10
8181
unindexed_val_pb.exclude_from_indexes = True
8282

83-
list_val_pb1 = _new_value_pb(entity_pb, 'baz')
84-
list_pb1 = list_val_pb1.list_value
83+
array_val_pb1 = _new_value_pb(entity_pb, 'baz')
84+
array_pb1 = array_val_pb1.array_value.values
8585

86-
unindexed_list_val_pb = list_pb1.add()
87-
unindexed_list_val_pb.integer_value = 11
88-
unindexed_list_val_pb.exclude_from_indexes = True
86+
unindexed_array_val_pb = array_pb1.add()
87+
unindexed_array_val_pb.integer_value = 11
88+
unindexed_array_val_pb.exclude_from_indexes = True
8989

90-
list_val_pb2 = _new_value_pb(entity_pb, 'qux')
91-
list_pb2 = list_val_pb2.list_value
90+
array_val_pb2 = _new_value_pb(entity_pb, 'qux')
91+
array_pb2 = array_val_pb2.array_value.values
9292

93-
indexed_list_val_pb = list_pb2.add()
94-
indexed_list_val_pb.integer_value = 12
93+
indexed_array_val_pb = array_pb2.add()
94+
indexed_array_val_pb.integer_value = 12
9595

9696
entity = self._callFUT(entity_pb)
9797
self.assertEqual(entity.kind, _KIND)
@@ -119,14 +119,14 @@ def test_mismatched_value_indexed(self):
119119
entity_pb.key.partition_id.project_id = _PROJECT
120120
entity_pb.key.path.add(kind=_KIND, id=_ID)
121121

122-
list_val_pb = _new_value_pb(entity_pb, 'baz')
123-
list_pb = list_val_pb.list_value
122+
array_val_pb = _new_value_pb(entity_pb, 'baz')
123+
array_pb = array_val_pb.array_value.values
124124

125-
unindexed_value_pb1 = list_pb.add()
125+
unindexed_value_pb1 = array_pb.add()
126126
unindexed_value_pb1.integer_value = 10
127127
unindexed_value_pb1.exclude_from_indexes = True
128128

129-
unindexed_value_pb2 = list_pb.add()
129+
unindexed_value_pb2 = array_pb.add()
130130
unindexed_value_pb2.integer_value = 11
131131

132132
with self.assertRaises(ValueError):
@@ -305,14 +305,14 @@ def test_inverts_to_protobuf(self):
305305

306306
# Add a list property.
307307
val_pb4 = _new_value_pb(original_pb, 'list-quux')
308-
list_val1 = val_pb4.list_value.add()
309-
list_val1.exclude_from_indexes = True
310-
list_val1.meaning = meaning = 22
311-
list_val1.blob_value = b'\xe2\x98\x83'
312-
list_val2 = val_pb4.list_value.add()
313-
list_val2.exclude_from_indexes = True
314-
list_val2.meaning = meaning
315-
list_val2.blob_value = b'\xe2\x98\x85'
308+
array_val1 = val_pb4.array_value.values.add()
309+
array_val1.exclude_from_indexes = False
310+
array_val1.meaning = meaning = 22
311+
array_val1.blob_value = b'\xe2\x98\x83'
312+
array_val2 = val_pb4.array_value.add()
313+
array_val2.exclude_from_indexes = False
314+
array_val2.meaning = meaning
315+
array_val2.blob_value = b'\xe2\x98\x85'
316316

317317
# Convert to the user-space Entity.
318318
entity = entity_from_protobuf(original_pb)
@@ -489,10 +489,10 @@ def test_entity(self):
489489
self.assertEqual(name, 'entity_value')
490490
self.assertTrue(value is entity)
491491

492-
def test_list(self):
492+
def test_array(self):
493493
values = ['a', 0, 3.14]
494494
name, value = self._callFUT(values)
495-
self.assertEqual(name, 'list_value')
495+
self.assertEqual(name, 'array_value')
496496
self.assertTrue(value is values)
497497

498498
def test_object(self):
@@ -569,14 +569,14 @@ def test_entity(self):
569569
self.assertTrue(isinstance(entity, Entity))
570570
self.assertEqual(entity['foo'], 'Foo')
571571

572-
def test_list(self):
572+
def test_array(self):
573573
from gcloud.datastore._generated import entity_pb2
574574

575575
pb = entity_pb2.Value()
576-
list_pb = pb.list_value
577-
item_pb = list_pb.add()
576+
array_pb = pb.array_value.values
577+
item_pb = array_pb.add()
578578
item_pb.string_value = 'Foo'
579-
item_pb = list_pb.add()
579+
item_pb = array_pb.add()
580580
item_pb.string_value = 'Bar'
581581
items = self._callFUT(pb)
582582
self.assertEqual(items, ['Foo', 'Bar'])
@@ -717,11 +717,11 @@ def test_entity_w_key(self):
717717
self.assertEqual(list(prop_dict.keys()), [name])
718718
self.assertEqual(prop_dict[name].string_value, value)
719719

720-
def test_list(self):
720+
def test_array(self):
721721
pb = self._makePB()
722722
values = [u'a', 0, 3.14]
723723
self._callFUT(pb, values)
724-
marshalled = pb.list_value
724+
marshalled = pb.array_value.values
725725
self.assertEqual(len(marshalled), len(values))
726726
self.assertEqual(marshalled[0].string_value, values[0])
727727
self.assertEqual(marshalled[1].integer_value, values[1])
@@ -830,23 +830,23 @@ def test_single(self):
830830
result = self._callFUT(value_pb)
831831
self.assertEqual(meaning, result)
832832

833-
def test_empty_list_value(self):
833+
def test_empty_array_value(self):
834834
from gcloud.datastore._generated import entity_pb2
835835

836836
value_pb = entity_pb2.Value()
837-
value_pb.list_value.add()
838-
value_pb.list_value.pop()
837+
value_pb.array_value.values.add()
838+
value_pb.array_value.values.pop()
839839

840840
result = self._callFUT(value_pb, is_list=True)
841841
self.assertEqual(None, result)
842842

843-
def test_list_value(self):
843+
def test_array_value(self):
844844
from gcloud.datastore._generated import entity_pb2
845845

846846
value_pb = entity_pb2.Value()
847847
meaning = 9
848-
sub_value_pb1 = value_pb.list_value.add()
849-
sub_value_pb2 = value_pb.list_value.add()
848+
sub_value_pb1 = value_pb.array_value.values.add()
849+
sub_value_pb2 = value_pb.array_value.values.add()
850850

851851
sub_value_pb1.meaning = sub_value_pb2.meaning = meaning
852852
sub_value_pb1.string_value = u'hi'
@@ -855,14 +855,14 @@ def test_list_value(self):
855855
result = self._callFUT(value_pb, is_list=True)
856856
self.assertEqual(meaning, result)
857857

858-
def test_list_value_disagreeing(self):
858+
def test_array_value_disagreeing(self):
859859
from gcloud.datastore._generated import entity_pb2
860860

861861
value_pb = entity_pb2.Value()
862862
meaning1 = 9
863863
meaning2 = 10
864-
sub_value_pb1 = value_pb.list_value.add()
865-
sub_value_pb2 = value_pb.list_value.add()
864+
sub_value_pb1 = value_pb.array_value.values.add()
865+
sub_value_pb2 = value_pb.array_value.values.add()
866866

867867
sub_value_pb1.meaning = meaning1
868868
sub_value_pb2.meaning = meaning2
@@ -872,13 +872,13 @@ def test_list_value_disagreeing(self):
872872
with self.assertRaises(ValueError):
873873
self._callFUT(value_pb, is_list=True)
874874

875-
def test_list_value_partially_unset(self):
875+
def test_array_value_partially_unset(self):
876876
from gcloud.datastore._generated import entity_pb2
877877

878878
value_pb = entity_pb2.Value()
879879
meaning1 = 9
880-
sub_value_pb1 = value_pb.list_value.add()
881-
sub_value_pb2 = value_pb.list_value.add()
880+
sub_value_pb1 = value_pb.array_value.values.add()
881+
sub_value_pb2 = value_pb.array_value.values.add()
882882

883883
sub_value_pb1.meaning = meaning1
884884
sub_value_pb1.string_value = u'hi'

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL