|
38 | 38 | from vertexai.reasoning_engines import _reasoning_engines
|
39 | 39 | from vertexai.reasoning_engines import _utils
|
40 | 40 | from google.protobuf import field_mask_pb2
|
| 41 | +from google.protobuf import struct_pb2 |
41 | 42 |
|
42 | 43 |
|
43 | 44 | class CapitalizeEngine:
|
@@ -1081,3 +1082,50 @@ class TestGenerateSchema(parameterized.TestCase):
|
1081 | 1082 | def test_generate_schemas(self, func, required, expected_operation):
|
1082 | 1083 | result = _utils.generate_schema(func, required=required)
|
1083 | 1084 | self.assertDictEqual(result, expected_operation)
|
| 1085 | + |
| 1086 | + |
| 1087 | +class TestToProto(parameterized.TestCase): |
| 1088 | + @parameterized.named_parameters( |
| 1089 | + dict( |
| 1090 | + testcase_name="empty_dict", |
| 1091 | + obj={}, |
| 1092 | + expected_proto=struct_pb2.Struct(fields={}), |
| 1093 | + ), |
| 1094 | + dict( |
| 1095 | + testcase_name="nonempty_dict", |
| 1096 | + obj={"a": 1, "b": 2}, |
| 1097 | + expected_proto=struct_pb2.Struct( |
| 1098 | + fields={ |
| 1099 | + "a": struct_pb2.Value(number_value=1), |
| 1100 | + "b": struct_pb2.Value(number_value=2), |
| 1101 | + }, |
| 1102 | + ), |
| 1103 | + ), |
| 1104 | + dict( |
| 1105 | + testcase_name="empty_proto_message", |
| 1106 | + obj=struct_pb2.Struct(fields={}), |
| 1107 | + expected_proto=struct_pb2.Struct(fields={}), |
| 1108 | + ), |
| 1109 | + dict( |
| 1110 | + testcase_name="nonempty_proto_message", |
| 1111 | + obj=struct_pb2.Struct( |
| 1112 | + fields={ |
| 1113 | + "a": struct_pb2.Value(number_value=1), |
| 1114 | + "b": struct_pb2.Value(number_value=2), |
| 1115 | + }, |
| 1116 | + ), |
| 1117 | + expected_proto=struct_pb2.Struct( |
| 1118 | + fields={ |
| 1119 | + "a": struct_pb2.Value(number_value=1), |
| 1120 | + "b": struct_pb2.Value(number_value=2), |
| 1121 | + }, |
| 1122 | + ), |
| 1123 | + ), |
| 1124 | + ) |
| 1125 | + def test_to_proto(self, obj, expected_proto): |
| 1126 | + result = _utils.to_proto(obj) |
| 1127 | + self.assertDictEqual(_utils.to_dict(result), _utils.to_dict(expected_proto)) |
| 1128 | + # converting a new object to proto should not modify earlier objects. |
| 1129 | + new_result = _utils.to_proto({}) |
| 1130 | + self.assertDictEqual(_utils.to_dict(result), _utils.to_dict(expected_proto)) |
| 1131 | + self.assertEmpty(new_result) |
0 commit comments