def test_parse_message_level(self): action = test_pb2.Action() action.doc_id = "3" action.number_of_views = 3 tensor_of_protos = tf.constant([action.SerializeToString()]) [field_tuple] = struct2tensor_ops.parse_message_level( tensor_of_protos, test_pb2.Action().DESCRIPTOR, ["number_of_views"]) values = field_tuple.value indices = field_tuple.index self.assertAllEqual(indices, [0]) self.assertAllEqual(values, [3])
def test_parse_full_message_level_action(self): action = test_pb2.Action() action.doc_id = "3" action.number_of_views = 3 result = _get_full_message_level_runnable([action]) self.assertAllEqual(result["doc_id"][INDEX], [0]) self.assertAllEqual(result["doc_id"][VALUE], [b"3"]) self.assertAllEqual(result["number_of_views"][INDEX], [0]) self.assertAllEqual(result["number_of_views"][VALUE], [3])