Exemple #1
0
def _get_expression_with_any():
  my_any_0 = test_any_pb2.MessageWithAny()
  my_value_0 = test_pb2.AllSimple()
  my_value_0.optional_int32 = 0
  my_any_0.my_any.Pack(my_value_0)
  my_any_1 = test_any_pb2.MessageWithAny()
  my_value_1 = test_pb2.UserInfo()
  my_any_1.my_any.Pack(my_value_1)
  my_any_2 = test_any_pb2.MessageWithAny()
  my_value_2 = test_pb2.AllSimple()
  my_value_2.optional_int32 = 20
  my_any_2.my_any.Pack(my_value_2)
  serialized = [x.SerializeToString() for x in [my_any_0, my_any_1, my_any_2]]
  return proto.create_expression_from_proto(
      serialized, test_any_pb2.MessageWithAny.DESCRIPTOR)
Exemple #2
0
 def test_any_path(self):
   my_any_0 = test_any_pb2.MessageWithAny()
   my_value_0 = test_pb2.AllSimple()
   my_value_0.optional_int32 = 17
   my_any_0.my_any.Pack(my_value_0)
   expr = proto.create_expression_from_proto(
       [my_any_0.SerializeToString()], test_any_pb2.MessageWithAny.DESCRIPTOR)
   new_root = promote.promote(
       expr,
       path.Path(
           ["my_any", "(struct2tensor.test.AllSimple)", "optional_int32"]),
       "new_int32")
   new_field = new_root.get_descendant_or_error(
       path.Path(["my_any", "new_int32"]))
   result = calculate_with_source_paths.calculate_prensors_with_source_paths(
       [new_field])
   prensor_result, proto_summary_result = result
   self.assertLen(prensor_result, 1)
   self.assertLen(proto_summary_result, 1)
   leaf_node = prensor_result[0].node
   self.assertAllEqual(leaf_node.parent_index, [0])
   self.assertAllEqual(leaf_node.values, [17])
   list_of_paths = proto_summary_result[0].paths
   expected = [
       path.Path(
           ["my_any", "(struct2tensor.test.AllSimple)", "optional_int32"])
   ]
   self.equal_ignore_order(list_of_paths, expected)
def _create_any(x):
    """Create an any object from a protobuf."""
    new_any = test_any_pb2.MessageWithAny().my_any
    new_any.Pack(x)
    return new_any