lionagi 0.2.11__py3-none-any.whl → 0.3.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lionagi/core/action/function_calling.py +13 -6
- lionagi/core/action/tool.py +10 -9
- lionagi/core/action/tool_manager.py +18 -9
- lionagi/core/agent/README.md +1 -1
- lionagi/core/agent/base_agent.py +5 -2
- lionagi/core/agent/eval/README.md +1 -1
- lionagi/core/collections/README.md +1 -1
- lionagi/core/collections/_logger.py +16 -6
- lionagi/core/collections/abc/README.md +1 -1
- lionagi/core/collections/abc/component.py +35 -11
- lionagi/core/collections/abc/concepts.py +5 -3
- lionagi/core/collections/abc/exceptions.py +3 -1
- lionagi/core/collections/flow.py +16 -5
- lionagi/core/collections/model.py +34 -8
- lionagi/core/collections/pile.py +65 -28
- lionagi/core/collections/progression.py +1 -2
- lionagi/core/collections/util.py +11 -2
- lionagi/core/director/README.md +1 -1
- lionagi/core/engine/branch_engine.py +35 -10
- lionagi/core/engine/instruction_map_engine.py +14 -5
- lionagi/core/engine/sandbox_.py +3 -1
- lionagi/core/engine/script_engine.py +6 -2
- lionagi/core/executor/base_executor.py +10 -3
- lionagi/core/executor/graph_executor.py +12 -4
- lionagi/core/executor/neo4j_executor.py +18 -6
- lionagi/core/generic/edge.py +7 -2
- lionagi/core/generic/graph.py +23 -7
- lionagi/core/generic/node.py +14 -5
- lionagi/core/generic/tree_node.py +5 -1
- lionagi/core/mail/mail_manager.py +3 -1
- lionagi/core/mail/package.py +3 -1
- lionagi/core/message/action_request.py +9 -2
- lionagi/core/message/action_response.py +9 -3
- lionagi/core/message/instruction.py +8 -2
- lionagi/core/message/util.py +15 -5
- lionagi/core/report/base.py +12 -7
- lionagi/core/report/form.py +7 -4
- lionagi/core/report/report.py +10 -3
- lionagi/core/report/util.py +3 -1
- lionagi/core/rule/action.py +4 -1
- lionagi/core/rule/base.py +17 -6
- lionagi/core/rule/rulebook.py +8 -4
- lionagi/core/rule/string.py +3 -1
- lionagi/core/session/branch.py +15 -4
- lionagi/core/session/session.py +6 -2
- lionagi/core/unit/parallel_unit.py +9 -3
- lionagi/core/unit/template/action.py +1 -1
- lionagi/core/unit/template/predict.py +3 -1
- lionagi/core/unit/template/select.py +5 -3
- lionagi/core/unit/unit.py +4 -2
- lionagi/core/unit/unit_form.py +13 -15
- lionagi/core/unit/unit_mixin.py +45 -27
- lionagi/core/unit/util.py +7 -3
- lionagi/core/validator/validator.py +28 -15
- lionagi/core/work/work_edge.py +7 -3
- lionagi/core/work/work_task.py +11 -5
- lionagi/core/work/worker.py +20 -5
- lionagi/core/work/worker_engine.py +6 -2
- lionagi/core/work/worklog.py +3 -1
- lionagi/experimental/compressor/llm_compressor.py +20 -5
- lionagi/experimental/directive/README.md +1 -1
- lionagi/experimental/directive/parser/base_parser.py +41 -14
- lionagi/experimental/directive/parser/base_syntax.txt +23 -23
- lionagi/experimental/directive/template/base_template.py +14 -6
- lionagi/experimental/directive/tokenizer.py +3 -1
- lionagi/experimental/evaluator/README.md +1 -1
- lionagi/experimental/evaluator/ast_evaluator.py +6 -2
- lionagi/experimental/evaluator/base_evaluator.py +27 -16
- lionagi/integrations/bridge/autogen_/autogen_.py +7 -3
- lionagi/integrations/bridge/langchain_/documents.py +13 -10
- lionagi/integrations/bridge/llamaindex_/llama_pack.py +36 -12
- lionagi/integrations/bridge/llamaindex_/node_parser.py +8 -3
- lionagi/integrations/bridge/llamaindex_/reader.py +3 -1
- lionagi/integrations/bridge/llamaindex_/textnode.py +9 -3
- lionagi/integrations/bridge/pydantic_/pydantic_bridge.py +7 -1
- lionagi/integrations/bridge/transformers_/install_.py +3 -1
- lionagi/integrations/chunker/chunk.py +5 -2
- lionagi/integrations/loader/load.py +7 -3
- lionagi/integrations/loader/load_util.py +35 -16
- lionagi/integrations/provider/oai.py +13 -4
- lionagi/integrations/provider/openrouter.py +13 -4
- lionagi/integrations/provider/services.py +3 -1
- lionagi/integrations/provider/transformers.py +5 -3
- lionagi/integrations/storage/neo4j.py +23 -7
- lionagi/integrations/storage/storage_util.py +23 -7
- lionagi/integrations/storage/structure_excel.py +7 -2
- lionagi/integrations/storage/to_csv.py +8 -2
- lionagi/integrations/storage/to_excel.py +11 -3
- lionagi/libs/ln_api.py +41 -19
- lionagi/libs/ln_context.py +4 -4
- lionagi/libs/ln_convert.py +35 -14
- lionagi/libs/ln_dataframe.py +9 -3
- lionagi/libs/ln_func_call.py +53 -18
- lionagi/libs/ln_image.py +9 -5
- lionagi/libs/ln_knowledge_graph.py +21 -7
- lionagi/libs/ln_nested.py +57 -16
- lionagi/libs/ln_parse.py +45 -15
- lionagi/libs/ln_queue.py +8 -3
- lionagi/libs/ln_tokenize.py +19 -6
- lionagi/libs/ln_validate.py +14 -3
- lionagi/libs/sys_util.py +44 -12
- lionagi/lions/coder/coder.py +24 -8
- lionagi/lions/coder/util.py +6 -2
- lionagi/lions/researcher/data_source/google_.py +12 -4
- lionagi/lions/researcher/data_source/wiki_.py +3 -1
- lionagi/version.py +1 -1
- {lionagi-0.2.11.dist-info → lionagi-0.3.0.dist-info}/METADATA +6 -7
- lionagi-0.3.0.dist-info/RECORD +226 -0
- lionagi/tests/__init__.py +0 -0
- lionagi/tests/api/__init__.py +0 -0
- lionagi/tests/api/aws/__init__.py +0 -0
- lionagi/tests/api/aws/conftest.py +0 -25
- lionagi/tests/api/aws/test_aws_s3.py +0 -6
- lionagi/tests/integrations/__init__.py +0 -0
- lionagi/tests/libs/__init__.py +0 -0
- lionagi/tests/libs/test_api.py +0 -48
- lionagi/tests/libs/test_convert.py +0 -89
- lionagi/tests/libs/test_field_validators.py +0 -354
- lionagi/tests/libs/test_func_call.py +0 -701
- lionagi/tests/libs/test_nested.py +0 -382
- lionagi/tests/libs/test_parse.py +0 -171
- lionagi/tests/libs/test_queue.py +0 -68
- lionagi/tests/libs/test_sys_util.py +0 -222
- lionagi/tests/test_core/__init__.py +0 -0
- lionagi/tests/test_core/collections/__init__.py +0 -0
- lionagi/tests/test_core/collections/test_component.py +0 -208
- lionagi/tests/test_core/collections/test_exchange.py +0 -139
- lionagi/tests/test_core/collections/test_flow.py +0 -146
- lionagi/tests/test_core/collections/test_pile.py +0 -172
- lionagi/tests/test_core/collections/test_progression.py +0 -130
- lionagi/tests/test_core/generic/__init__.py +0 -0
- lionagi/tests/test_core/generic/test_edge.py +0 -69
- lionagi/tests/test_core/generic/test_graph.py +0 -97
- lionagi/tests/test_core/generic/test_node.py +0 -107
- lionagi/tests/test_core/generic/test_structure.py +0 -194
- lionagi/tests/test_core/generic/test_tree_node.py +0 -74
- lionagi/tests/test_core/graph/__init__.py +0 -0
- lionagi/tests/test_core/graph/test_graph.py +0 -71
- lionagi/tests/test_core/graph/test_tree.py +0 -76
- lionagi/tests/test_core/mail/__init__.py +0 -0
- lionagi/tests/test_core/mail/test_mail.py +0 -98
- lionagi/tests/test_core/test_branch.py +0 -116
- lionagi/tests/test_core/test_form.py +0 -47
- lionagi/tests/test_core/test_report.py +0 -106
- lionagi/tests/test_core/test_structure/__init__.py +0 -0
- lionagi/tests/test_core/test_structure/test_base_structure.py +0 -198
- lionagi/tests/test_core/test_structure/test_graph.py +0 -55
- lionagi/tests/test_core/test_structure/test_tree.py +0 -49
- lionagi/tests/test_core/test_validator.py +0 -112
- lionagi-0.2.11.dist-info/RECORD +0 -267
- {lionagi-0.2.11.dist-info → lionagi-0.3.0.dist-info}/LICENSE +0 -0
- {lionagi-0.2.11.dist-info → lionagi-0.3.0.dist-info}/WHEEL +0 -0
@@ -1,354 +0,0 @@
|
|
1
|
-
import unittest
|
2
|
-
from unittest.mock import patch
|
3
|
-
|
4
|
-
from lionagi.libs.ln_validate import (
|
5
|
-
_fix_action_field,
|
6
|
-
_fix_bool_field,
|
7
|
-
_fix_enum_field,
|
8
|
-
_fix_number_field,
|
9
|
-
_fix_str_field,
|
10
|
-
check_action_field,
|
11
|
-
check_bool_field,
|
12
|
-
check_dict_field,
|
13
|
-
check_enum_field,
|
14
|
-
check_number_field,
|
15
|
-
check_str_field,
|
16
|
-
)
|
17
|
-
|
18
|
-
|
19
|
-
class TestValidationFunctions(unittest.TestCase):
|
20
|
-
def test_check_dict_field_valid(self):
|
21
|
-
x = {"key": "value"}
|
22
|
-
keys = ["key"]
|
23
|
-
result = check_dict_field(x, keys)
|
24
|
-
self.assertEqual(result, x)
|
25
|
-
|
26
|
-
def test_fix_action_field_invalid_string(self):
|
27
|
-
x = '[{"invalid_key": "value"}]'
|
28
|
-
try:
|
29
|
-
_fix_action_field(x)
|
30
|
-
except ValueError as e:
|
31
|
-
self.assertEqual(str(e), "Invalid action field: {'invalid_key': 'value'}")
|
32
|
-
|
33
|
-
def test_fix_action_field_invalid_discard_disabled(self):
|
34
|
-
x = '[{"function": "func1", "arguments": {}}, {"invalid_key": "value"}]'
|
35
|
-
try:
|
36
|
-
_fix_action_field(x, discard_=False)
|
37
|
-
except ValueError as e:
|
38
|
-
self.assertEqual(str(e), "Invalid action field: {'invalid_key': 'value'}")
|
39
|
-
|
40
|
-
def test_check_dict_field_invalid_fixable(self):
|
41
|
-
x = '{"key": "value"}'
|
42
|
-
keys = ["key"]
|
43
|
-
result = check_dict_field(x, keys, fix_=True)
|
44
|
-
self.assertEqual(result, {"key": "value"})
|
45
|
-
|
46
|
-
def test_check_dict_field_invalid_not_fixable(self):
|
47
|
-
x = '{"invalid_key": "value"}'
|
48
|
-
keys = ["key"]
|
49
|
-
with self.assertRaises(ValueError) as cm:
|
50
|
-
check_dict_field(x, keys, fix_=False)
|
51
|
-
self.assertEqual(
|
52
|
-
str(cm.exception), "Default value for DICT must be a dict, got str"
|
53
|
-
)
|
54
|
-
|
55
|
-
def test_check_action_field_invalid_not_fixable(self):
|
56
|
-
x = '[{"invalid_key": "value"}]'
|
57
|
-
try:
|
58
|
-
check_action_field(x, fix_=False)
|
59
|
-
except ValueError as e:
|
60
|
-
self.assertEqual(str(e), "Invalid action field type.")
|
61
|
-
|
62
|
-
def test_check_action_field_invalid_fix_disabled(self):
|
63
|
-
x = '[{"function": "func1", "arguments": {}}, {"invalid_key": "value"}]'
|
64
|
-
try:
|
65
|
-
check_action_field(x, fix_=False)
|
66
|
-
except ValueError as e:
|
67
|
-
self.assertEqual(str(e), "Invalid action field type.")
|
68
|
-
|
69
|
-
def test_check_action_field_valid(self):
|
70
|
-
x = [
|
71
|
-
{"function": "func1", "arguments": {}},
|
72
|
-
{"function": "func2", "arguments": {}},
|
73
|
-
]
|
74
|
-
result = check_action_field(x)
|
75
|
-
self.assertEqual(result, x)
|
76
|
-
|
77
|
-
def test_check_action_field_invalid_fixable(self):
|
78
|
-
x = '[{"function": "func1", "arguments": {}}, {"function": "func2", "arguments": {}}]'
|
79
|
-
result = check_action_field(x, fix_=True)
|
80
|
-
self.assertEqual(
|
81
|
-
result,
|
82
|
-
[
|
83
|
-
{"function": "func1", "arguments": {}},
|
84
|
-
{"function": "func2", "arguments": {}},
|
85
|
-
],
|
86
|
-
)
|
87
|
-
|
88
|
-
def test_check_action_field_invalid_fix_disabled(self):
|
89
|
-
x = '[{"function": "func1", "arguments": {}}, {"invalid_key": "value"}]'
|
90
|
-
try:
|
91
|
-
check_action_field(x, fix_=False)
|
92
|
-
except ValueError as e:
|
93
|
-
self.assertEqual(str(e), "Invalid action field type.")
|
94
|
-
|
95
|
-
def test_check_number_field_valid(self):
|
96
|
-
x = 42
|
97
|
-
result = check_number_field(x)
|
98
|
-
self.assertEqual(result, x)
|
99
|
-
|
100
|
-
def test_check_number_field_invalid_fixable(self):
|
101
|
-
x = "42"
|
102
|
-
result = check_number_field(x, fix_=True)
|
103
|
-
self.assertEqual(result, 42)
|
104
|
-
|
105
|
-
def test_check_number_field_invalid_not_fixable(self):
|
106
|
-
x = "not_a_number"
|
107
|
-
with self.assertRaises(ValueError) as cm:
|
108
|
-
check_number_field(x, fix_=True)
|
109
|
-
self.assertEqual(
|
110
|
-
str(cm.exception), "Failed to convert not_a_number into a numeric value"
|
111
|
-
)
|
112
|
-
|
113
|
-
def test_check_number_field_invalid_fix_disabled(self):
|
114
|
-
x = "42"
|
115
|
-
with self.assertRaises(ValueError) as cm:
|
116
|
-
check_number_field(x, fix_=False)
|
117
|
-
self.assertEqual(
|
118
|
-
str(cm.exception),
|
119
|
-
"Default value for NUMERIC must be an int or float, got str",
|
120
|
-
)
|
121
|
-
|
122
|
-
def test_check_bool_field_valid(self):
|
123
|
-
x = True
|
124
|
-
result = check_bool_field(x)
|
125
|
-
self.assertEqual(result, x)
|
126
|
-
|
127
|
-
def test_check_bool_field_invalid_fixable(self):
|
128
|
-
x = "true"
|
129
|
-
result = check_bool_field(x, fix_=True)
|
130
|
-
self.assertTrue(result)
|
131
|
-
|
132
|
-
def test_check_bool_field_invalid_not_fixable(self):
|
133
|
-
x = "not_a_boolean"
|
134
|
-
with self.assertRaises(ValueError) as cm:
|
135
|
-
check_bool_field(x, fix_=True)
|
136
|
-
self.assertEqual(
|
137
|
-
str(cm.exception), "Failed to convert not_a_boolean into a boolean value"
|
138
|
-
)
|
139
|
-
|
140
|
-
def test_check_bool_field_invalid_fix_disabled(self):
|
141
|
-
x = "true"
|
142
|
-
with self.assertRaises(ValueError) as cm:
|
143
|
-
check_bool_field(x, fix_=False)
|
144
|
-
self.assertEqual(
|
145
|
-
str(cm.exception), "Default value for BOOLEAN must be a bool, got str"
|
146
|
-
)
|
147
|
-
|
148
|
-
def test_check_str_field_valid(self):
|
149
|
-
x = "hello"
|
150
|
-
result = check_str_field(x)
|
151
|
-
self.assertEqual(result, x)
|
152
|
-
|
153
|
-
def test_check_str_field_invalid_fixable(self):
|
154
|
-
x = 42
|
155
|
-
result = check_str_field(x, fix_=True)
|
156
|
-
self.assertEqual(result, "42")
|
157
|
-
|
158
|
-
def test_check_str_field_invalid_not_fixable(self):
|
159
|
-
x = object()
|
160
|
-
try:
|
161
|
-
check_str_field(x, fix_=False)
|
162
|
-
except ValueError as e:
|
163
|
-
self.assertEqual(
|
164
|
-
str(e), "Default value for STRING must be a str, got object"
|
165
|
-
)
|
166
|
-
|
167
|
-
def test_check_str_field_invalid_fix_disabled(self):
|
168
|
-
x = 42
|
169
|
-
with self.assertRaises(ValueError) as cm:
|
170
|
-
check_str_field(x, fix_=False)
|
171
|
-
self.assertEqual(
|
172
|
-
str(cm.exception), "Default value for STRING must be a str, got int"
|
173
|
-
)
|
174
|
-
|
175
|
-
def test_check_enum_field_valid(self):
|
176
|
-
x = "option1"
|
177
|
-
choices = ["option1", "option2"]
|
178
|
-
result = check_enum_field(x, choices)
|
179
|
-
self.assertEqual(result, x)
|
180
|
-
|
181
|
-
def test_check_enum_field_invalid_fixable(self):
|
182
|
-
x = "option3"
|
183
|
-
choices = ["option1", "option2"]
|
184
|
-
with patch("lionagi.libs.ln_validate._fix_enum_field", return_value="option1"):
|
185
|
-
result = check_enum_field(x, choices, fix_=True)
|
186
|
-
self.assertEqual(result, "option1")
|
187
|
-
|
188
|
-
def test_check_enum_field_invalid_not_fixable(self):
|
189
|
-
x = "option3"
|
190
|
-
choices = ["option1", "option2"]
|
191
|
-
with self.assertRaises(ValueError) as cm:
|
192
|
-
check_enum_field(x, choices, fix_=False)
|
193
|
-
self.assertEqual(
|
194
|
-
str(cm.exception),
|
195
|
-
"Default value for ENUM must be one of the ['option1', 'option2'], got option3",
|
196
|
-
)
|
197
|
-
|
198
|
-
def test_check_enum_field_invalid_choices(self):
|
199
|
-
x = "option1"
|
200
|
-
choices = ["option1", 42]
|
201
|
-
with self.assertRaises(ValueError) as cm:
|
202
|
-
check_enum_field(x, choices)
|
203
|
-
self.assertEqual(
|
204
|
-
str(cm.exception),
|
205
|
-
"Field type ENUM requires all choices to be of the same type, got ['option1', 42]",
|
206
|
-
)
|
207
|
-
|
208
|
-
def test_check_enum_field_invalid_type(self):
|
209
|
-
x = 42
|
210
|
-
choices = ["option1", "option2"]
|
211
|
-
with self.assertRaises(ValueError) as cm:
|
212
|
-
check_enum_field(x, choices)
|
213
|
-
self.assertEqual(
|
214
|
-
str(cm.exception),
|
215
|
-
"Default value for ENUM must be an instance of the str, got int",
|
216
|
-
)
|
217
|
-
|
218
|
-
def test_fix_action_field_string(self):
|
219
|
-
x = '[{"function": "func1", "arguments": {}}, {"function": "func2", "arguments": {}}]'
|
220
|
-
result = _fix_action_field(x)
|
221
|
-
self.assertEqual(
|
222
|
-
result,
|
223
|
-
[
|
224
|
-
{"function": "func1", "arguments": {}},
|
225
|
-
{"function": "func2", "arguments": {}},
|
226
|
-
],
|
227
|
-
)
|
228
|
-
|
229
|
-
def test_fix_action_field_invalid_string(self):
|
230
|
-
x = '[{"invalid_key": "value"}]'
|
231
|
-
try:
|
232
|
-
_fix_action_field(x)
|
233
|
-
except ValueError as e:
|
234
|
-
self.assertEqual(str(e), "Invalid action field: {'invalid_key': 'value'}")
|
235
|
-
|
236
|
-
def test_fix_action_field_invalid_discard_disabled(self):
|
237
|
-
x = '[{"function": "func1", "arguments": {}}, {"invalid_key": "value"}]'
|
238
|
-
try:
|
239
|
-
_fix_action_field(x, discard_=False)
|
240
|
-
except ValueError as e:
|
241
|
-
self.assertEqual(str(e), "Invalid action field: {'invalid_key': 'value'}")
|
242
|
-
|
243
|
-
def test_fix_number_field_valid(self):
|
244
|
-
x = "42"
|
245
|
-
result = _fix_number_field(x)
|
246
|
-
self.assertEqual(result, 42)
|
247
|
-
|
248
|
-
def test_fix_number_field_invalid(self):
|
249
|
-
x = "not_a_number"
|
250
|
-
with self.assertRaises(ValueError) as cm:
|
251
|
-
_fix_number_field(x)
|
252
|
-
self.assertEqual(
|
253
|
-
str(cm.exception), "Failed to convert not_a_number into a numeric value"
|
254
|
-
)
|
255
|
-
|
256
|
-
def test_fix_bool_field_true(self):
|
257
|
-
x = "true"
|
258
|
-
result = _fix_bool_field(x)
|
259
|
-
self.assertTrue(result)
|
260
|
-
|
261
|
-
def test_fix_bool_field_false(self):
|
262
|
-
x = "false"
|
263
|
-
result = _fix_bool_field(x)
|
264
|
-
self.assertFalse(result)
|
265
|
-
|
266
|
-
def test_fix_bool_field_invalid(self):
|
267
|
-
x = "not_a_boolean"
|
268
|
-
with self.assertRaises(ValueError) as cm:
|
269
|
-
_fix_bool_field(x)
|
270
|
-
self.assertEqual(
|
271
|
-
str(cm.exception), "Failed to convert not_a_boolean into a boolean value"
|
272
|
-
)
|
273
|
-
|
274
|
-
def test_fix_str_field_valid(self):
|
275
|
-
x = 42
|
276
|
-
result = _fix_str_field(x)
|
277
|
-
self.assertEqual(result, "42")
|
278
|
-
|
279
|
-
def test_fix_str_field_invalid(self):
|
280
|
-
x = object()
|
281
|
-
try:
|
282
|
-
_fix_str_field(x)
|
283
|
-
except ValueError as e:
|
284
|
-
self.assertEqual(
|
285
|
-
str(e),
|
286
|
-
"Failed to convert <object object at 0x{:x}> into a string value".format(
|
287
|
-
id(x)
|
288
|
-
),
|
289
|
-
)
|
290
|
-
|
291
|
-
def test_fix_enum_field_valid(self):
|
292
|
-
x = "option3"
|
293
|
-
choices = ["option1", "option2"]
|
294
|
-
with patch(
|
295
|
-
"lionagi.libs.StringMatch.choose_most_similar", return_value="option1"
|
296
|
-
):
|
297
|
-
result = _fix_enum_field(x, choices)
|
298
|
-
self.assertEqual(result, "option1")
|
299
|
-
|
300
|
-
def test_fix_enum_field_invalid(self):
|
301
|
-
x = "option3"
|
302
|
-
choices = ["option1", "option2"]
|
303
|
-
with patch(
|
304
|
-
"lionagi.libs.StringMatch.choose_most_similar",
|
305
|
-
side_effect=ValueError("No match found"),
|
306
|
-
):
|
307
|
-
with self.assertRaises(ValueError) as cm:
|
308
|
-
_fix_enum_field(x, choices)
|
309
|
-
self.assertEqual(
|
310
|
-
str(cm.exception), "Failed to convert option3 into one of the choices"
|
311
|
-
)
|
312
|
-
|
313
|
-
def test_fix_bool_field_false(self):
|
314
|
-
x = "false"
|
315
|
-
result = _fix_bool_field(x)
|
316
|
-
self.assertFalse(result)
|
317
|
-
|
318
|
-
def test_fix_str_field_invalid(self):
|
319
|
-
x = object()
|
320
|
-
try:
|
321
|
-
_fix_str_field(x)
|
322
|
-
except ValueError as e:
|
323
|
-
self.assertEqual(
|
324
|
-
str(e),
|
325
|
-
"Failed to convert <object object at 0x{:x}> into a string value".format(
|
326
|
-
id(x)
|
327
|
-
),
|
328
|
-
)
|
329
|
-
|
330
|
-
def test_fix_enum_field_valid(self):
|
331
|
-
x = "option3"
|
332
|
-
choices = ["option1", "option2"]
|
333
|
-
with patch(
|
334
|
-
"lionagi.libs.StringMatch.choose_most_similar", return_value="option1"
|
335
|
-
):
|
336
|
-
result = _fix_enum_field(x, choices)
|
337
|
-
self.assertEqual(result, "option1")
|
338
|
-
|
339
|
-
def test_fix_enum_field_invalid(self):
|
340
|
-
x = "option3"
|
341
|
-
choices = ["option1", "option2"]
|
342
|
-
with patch(
|
343
|
-
"lionagi.libs.StringMatch.choose_most_similar",
|
344
|
-
side_effect=ValueError("No match found"),
|
345
|
-
):
|
346
|
-
with self.assertRaises(ValueError) as cm:
|
347
|
-
_fix_enum_field(x, choices)
|
348
|
-
self.assertEqual(
|
349
|
-
str(cm.exception), "Failed to convert option3 into one of the choices"
|
350
|
-
)
|
351
|
-
|
352
|
-
|
353
|
-
if __name__ == "__main__":
|
354
|
-
unittest.main()
|