lionagi 0.0.305__py3-none-any.whl → 0.0.307__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lionagi/__init__.py +2 -5
- lionagi/core/__init__.py +7 -4
- lionagi/core/agent/__init__.py +3 -0
- lionagi/core/agent/base_agent.py +46 -0
- lionagi/core/branch/__init__.py +4 -0
- lionagi/core/branch/base/__init__.py +0 -0
- lionagi/core/branch/base_branch.py +100 -78
- lionagi/core/branch/branch.py +22 -34
- lionagi/core/branch/branch_flow_mixin.py +3 -7
- lionagi/core/branch/executable_branch.py +192 -0
- lionagi/core/branch/util.py +77 -162
- lionagi/core/direct/__init__.py +13 -0
- lionagi/core/direct/parallel_predict.py +127 -0
- lionagi/core/direct/parallel_react.py +0 -0
- lionagi/core/direct/parallel_score.py +0 -0
- lionagi/core/direct/parallel_select.py +0 -0
- lionagi/core/direct/parallel_sentiment.py +0 -0
- lionagi/core/direct/predict.py +174 -0
- lionagi/core/direct/react.py +33 -0
- lionagi/core/direct/score.py +163 -0
- lionagi/core/direct/select.py +144 -0
- lionagi/core/direct/sentiment.py +51 -0
- lionagi/core/direct/utils.py +83 -0
- lionagi/core/flow/__init__.py +0 -3
- lionagi/core/flow/monoflow/{mono_react.py → ReAct.py} +52 -9
- lionagi/core/flow/monoflow/__init__.py +9 -0
- lionagi/core/flow/monoflow/{mono_chat.py → chat.py} +11 -11
- lionagi/core/flow/monoflow/{mono_chat_mixin.py → chat_mixin.py} +33 -27
- lionagi/core/flow/monoflow/{mono_followup.py → followup.py} +7 -6
- lionagi/core/flow/polyflow/__init__.py +1 -0
- lionagi/core/flow/polyflow/{polychat.py → chat.py} +15 -3
- lionagi/core/mail/__init__.py +8 -0
- lionagi/core/mail/mail_manager.py +88 -40
- lionagi/core/mail/schema.py +32 -6
- lionagi/core/messages/__init__.py +3 -0
- lionagi/core/messages/schema.py +56 -25
- lionagi/core/prompt/__init__.py +0 -0
- lionagi/core/prompt/prompt_template.py +0 -0
- lionagi/core/schema/__init__.py +7 -5
- lionagi/core/schema/action_node.py +29 -0
- lionagi/core/schema/base_mixin.py +56 -59
- lionagi/core/schema/base_node.py +35 -38
- lionagi/core/schema/condition.py +24 -0
- lionagi/core/schema/data_logger.py +98 -98
- lionagi/core/schema/data_node.py +19 -19
- lionagi/core/schema/prompt_template.py +0 -0
- lionagi/core/schema/structure.py +293 -190
- lionagi/core/session/__init__.py +1 -3
- lionagi/core/session/session.py +196 -214
- lionagi/core/tool/tool_manager.py +95 -103
- lionagi/integrations/__init__.py +1 -3
- lionagi/integrations/bridge/langchain_/documents.py +17 -18
- lionagi/integrations/bridge/langchain_/langchain_bridge.py +14 -14
- lionagi/integrations/bridge/llamaindex_/llama_index_bridge.py +22 -22
- lionagi/integrations/bridge/llamaindex_/node_parser.py +12 -12
- lionagi/integrations/bridge/llamaindex_/reader.py +11 -11
- lionagi/integrations/bridge/llamaindex_/textnode.py +7 -7
- lionagi/integrations/config/openrouter_configs.py +0 -1
- lionagi/integrations/provider/oai.py +26 -26
- lionagi/integrations/provider/services.py +38 -38
- lionagi/libs/__init__.py +34 -1
- lionagi/libs/ln_api.py +211 -221
- lionagi/libs/ln_async.py +53 -60
- lionagi/libs/ln_convert.py +118 -120
- lionagi/libs/ln_dataframe.py +32 -33
- lionagi/libs/ln_func_call.py +334 -342
- lionagi/libs/ln_nested.py +99 -107
- lionagi/libs/ln_parse.py +175 -158
- lionagi/libs/sys_util.py +52 -52
- lionagi/tests/test_core/test_base_branch.py +427 -427
- lionagi/tests/test_core/test_branch.py +292 -292
- lionagi/tests/test_core/test_mail_manager.py +57 -57
- lionagi/tests/test_core/test_session.py +254 -266
- lionagi/tests/test_core/test_session_base_util.py +299 -300
- lionagi/tests/test_core/test_tool_manager.py +70 -74
- lionagi/tests/test_libs/test_nested.py +2 -7
- lionagi/tests/test_libs/test_parse.py +2 -2
- lionagi/version.py +1 -1
- {lionagi-0.0.305.dist-info → lionagi-0.0.307.dist-info}/METADATA +4 -2
- lionagi-0.0.307.dist-info/RECORD +115 -0
- lionagi-0.0.305.dist-info/RECORD +0 -94
- {lionagi-0.0.305.dist-info → lionagi-0.0.307.dist-info}/LICENSE +0 -0
- {lionagi-0.0.305.dist-info → lionagi-0.0.307.dist-info}/WHEEL +0 -0
- {lionagi-0.0.305.dist-info → lionagi-0.0.307.dist-info}/top_level.txt +0 -0
@@ -1,313 +1,312 @@
|
|
1
|
-
from lionagi.core.branch.util import MessageUtil
|
2
|
-
from lionagi.core.messages.schema import System, Instruction, Response
|
3
|
-
|
4
|
-
import unittest
|
5
|
-
import pandas as pd
|
6
|
-
import json
|
7
|
-
from datetime import datetime
|
8
|
-
|
9
|
-
|
10
|
-
class TestCreateMessage(unittest.TestCase):
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
# class TestExtend(unittest.TestCase):
|
196
|
-
|
197
|
-
# def test_extend(self):
|
198
|
-
# """Test extending one DataFrame with another, ensuring no duplicate 'node_id'."""
|
199
|
-
# df1 = pd.DataFrame({
|
200
|
-
# "node_id": ["1"],
|
201
|
-
# "role": ["user"],
|
202
|
-
# "sender": ["test"],
|
203
|
-
# "timestamp": ["2020-01-01T00:00:00"],
|
204
|
-
# "content": ['{"message": "test"}']
|
205
|
-
# })
|
206
|
-
# df2 = pd.DataFrame({
|
207
|
-
# "node_id": ["2"],
|
208
|
-
# "role": ["user"],
|
209
|
-
# "sender": ["test"],
|
210
|
-
# "timestamp": ["2020-01-02T00:00:00"],
|
211
|
-
# "content": ['{"message": "test2"}']
|
212
|
-
# })
|
213
|
-
# combined = MessageUtil.extend(df1, df2)
|
214
|
-
# self.assertEqual(len(combined), 2)
|
215
|
-
|
216
|
-
|
217
|
-
class TestToMarkdownString(unittest.TestCase):
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
# )
|
239
|
-
# filtered
|
240
|
-
#
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
#
|
256
|
-
#
|
257
|
-
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
# self.
|
268
|
-
# self.assertEqual(
|
269
|
-
# self.assertEqual(list(df.columns), ["node_id", "content"])
|
1
|
+
# from lionagi.core.branch.util import MessageUtil
|
2
|
+
# from lionagi.core.messages.schema import System, Instruction, Response
|
3
|
+
|
4
|
+
# import unittest
|
5
|
+
# import pandas as pd
|
6
|
+
# import json
|
7
|
+
# from datetime import datetime
|
8
|
+
|
9
|
+
|
10
|
+
# class TestCreateMessage(unittest.TestCase):
|
11
|
+
|
12
|
+
# def test_create_system_message(self):
|
13
|
+
# """Test creating a System message."""
|
14
|
+
# system_info = {"system_info": "System information"}
|
15
|
+
# message = MessageUtil.create_message(
|
16
|
+
# system=system_info["system_info"]
|
17
|
+
# )
|
18
|
+
# self.assertIsInstance(message, System)
|
19
|
+
# self.assertEqual(message.content, system_info)
|
20
|
+
|
21
|
+
# def test_create_instruction_message(self):
|
22
|
+
# """Test creating an Instruction message with context."""
|
23
|
+
# instruction_info = {"task": "Do something"}
|
24
|
+
# context = {"additional": "context"}
|
25
|
+
# message = MessageUtil.create_message(
|
26
|
+
# instruction=instruction_info, context=context
|
27
|
+
# )
|
28
|
+
# self.assertIsInstance(message, Instruction)
|
29
|
+
# self.assertEqual(message.content["instruction"], instruction_info)
|
30
|
+
# self.assertEqual(message.content["context"], context)
|
31
|
+
|
32
|
+
# def test_create_response_message(self):
|
33
|
+
# """Test creating a Response message."""
|
34
|
+
# response_info = {"message": {"content": "This is a response"}}
|
35
|
+
# message = MessageUtil.create_message(response=response_info)
|
36
|
+
# self.assertIsInstance(message, Response)
|
37
|
+
# self.assertEqual(
|
38
|
+
# message.content["response"], response_info["message"]["content"]
|
39
|
+
# )
|
40
|
+
|
41
|
+
# def test_error_on_multiple_roles(self):
|
42
|
+
# """Test error is raised when multiple roles are provided."""
|
43
|
+
# with self.assertRaises(ValueError):
|
44
|
+
# MessageUtil.create_message(
|
45
|
+
# system={"info": "info"}, instruction={"task": "task"}
|
46
|
+
# )
|
47
|
+
|
48
|
+
# def test_return_existing_base_message_instance(self):
|
49
|
+
# """Test returning an existing BaseMessage instance if provided."""
|
50
|
+
# existing_message = System(system={"info": "Already created"})
|
51
|
+
# message = MessageUtil.create_message(system=existing_message)
|
52
|
+
# self.assertEqual(message.content, existing_message.content)
|
53
|
+
|
54
|
+
|
55
|
+
# class TestValidateMessages(unittest.TestCase):
|
56
|
+
|
57
|
+
# # def test_validate_messages_correct_format(self):
|
58
|
+
# # """Test messages DataFrame with the correct format."""
|
59
|
+
# # messages = pd.DataFrame({
|
60
|
+
# # "node_id": ["1"],
|
61
|
+
# # "role": ["user"],
|
62
|
+
# # "sender": ["test"],
|
63
|
+
# # "timestamp": ["2020-01-01T00:00:00"],
|
64
|
+
# # "content": ['{"message": "test"}']
|
65
|
+
# # })
|
66
|
+
# # self.assertTrue(MessageUtil.validate_messages(messages))
|
67
|
+
|
68
|
+
# def test_validate_messages_incorrect_columns(self):
|
69
|
+
# """Test messages DataFrame with incorrect columns raises ValueError."""
|
70
|
+
# messages = pd.DataFrame(
|
71
|
+
# {
|
72
|
+
# "id": ["1"], "type": ["user"], "source": ["test"],
|
73
|
+
# "time": ["2020-01-01T00:00:00"],
|
74
|
+
# "data": ['{"message": "test"}'],
|
75
|
+
# }
|
76
|
+
# )
|
77
|
+
# with self.assertRaises(ValueError):
|
78
|
+
# MessageUtil.validate_messages(messages)
|
79
|
+
|
80
|
+
# def test_validate_messages_null_values(self):
|
81
|
+
# """Test messages DataFrame with null values raises ValueError."""
|
82
|
+
# messages = pd.DataFrame(
|
83
|
+
# {
|
84
|
+
# "node_id": [None], "role": ["user"], "sender": ["test"],
|
85
|
+
# "timestamp": ["2020-01-01T00:00:00"],
|
86
|
+
# "content": ['{"message": "test"}'],
|
87
|
+
# }
|
88
|
+
# )
|
89
|
+
# with self.assertRaises(ValueError):
|
90
|
+
# MessageUtil.validate_messages(messages)
|
91
|
+
|
92
|
+
|
93
|
+
# class TestSignMessage(unittest.TestCase):
|
94
|
+
|
95
|
+
# def test_sign_message(self):
|
96
|
+
# """Test signing message content with sender."""
|
97
|
+
# messages = pd.DataFrame(
|
98
|
+
# {
|
99
|
+
# "node_id": ["1"], "role": ["user"], "sender": ["test"],
|
100
|
+
# "timestamp": ["2020-01-01T00:00:00"],
|
101
|
+
# "content": ["Original message"],
|
102
|
+
# }
|
103
|
+
# )
|
104
|
+
# sender = "system"
|
105
|
+
# signed_messages = MessageUtil.sign_message(messages, sender)
|
106
|
+
# expected_content = "Sender system: Original message"
|
107
|
+
# self.assertEqual(signed_messages["content"][0], expected_content)
|
108
|
+
|
109
|
+
# def test_sign_message_invalid_sender(self):
|
110
|
+
# """Test signing message with an invalid sender raises ValueError."""
|
111
|
+
# messages = pd.DataFrame(
|
112
|
+
# {
|
113
|
+
# "node_id": ["1"], "role": ["user"], "sender": ["test"],
|
114
|
+
# "timestamp": ["2020-01-01T00:00:00"],
|
115
|
+
# "content": ["Original message"],
|
116
|
+
# }
|
117
|
+
# )
|
118
|
+
# with self.assertRaises(ValueError):
|
119
|
+
# MessageUtil.sign_message(messages, None)
|
120
|
+
|
121
|
+
|
122
|
+
# class TestFilterMessagesBy(unittest.TestCase):
|
123
|
+
|
124
|
+
# def setUp(self):
|
125
|
+
# self.messages = pd.DataFrame(
|
126
|
+
# {
|
127
|
+
# "node_id": ["1", "2"], "role": ["user", "assistant"],
|
128
|
+
# "sender": ["test", "assistant"],
|
129
|
+
# "timestamp": [datetime(2020, 1, 1), datetime(2020, 1, 2)],
|
130
|
+
# "content": ['{"message": "test"}', '{"response": "ok"}'],
|
131
|
+
# }
|
132
|
+
# )
|
133
|
+
|
134
|
+
# def test_filter_by_role(self):
|
135
|
+
# """Test filtering messages by role."""
|
136
|
+
# filtered = MessageUtil.filter_messages_by(
|
137
|
+
# self.messages, role="assistant"
|
138
|
+
# )
|
139
|
+
# self.assertEqual(len(filtered), 1)
|
140
|
+
# self.assertEqual(filtered.iloc[0]["sender"], "assistant")
|
141
|
+
|
142
|
+
# def test_filter_by_sender(self):
|
143
|
+
# """Test filtering messages by sender."""
|
144
|
+
# filtered = MessageUtil.filter_messages_by(
|
145
|
+
# self.messages, sender="test"
|
146
|
+
# )
|
147
|
+
# self.assertEqual(len(filtered), 1)
|
148
|
+
# self.assertEqual(filtered.iloc[0]["sender"], "test")
|
149
|
+
|
150
|
+
# def test_filter_by_time_range(self):
|
151
|
+
# """Test filtering messages by time range."""
|
152
|
+
# start_time = datetime(2020, 1, 1, 12)
|
153
|
+
# end_time = datetime(2020, 1, 2, 12)
|
154
|
+
# filtered = MessageUtil.filter_messages_by(
|
155
|
+
# self.messages, start_time=start_time, end_time=end_time
|
156
|
+
# )
|
157
|
+
# self.assertEqual(len(filtered), 1)
|
158
|
+
# self.assertTrue(
|
159
|
+
# start_time <= filtered.iloc[0]["timestamp"] <= end_time
|
160
|
+
# )
|
161
|
+
|
162
|
+
|
163
|
+
# class TestRemoveMessage(unittest.TestCase):
|
164
|
+
|
165
|
+
# def test_remove_message(self):
|
166
|
+
# """Test removing a message by node_id."""
|
167
|
+
# messages = pd.DataFrame(
|
168
|
+
# {
|
169
|
+
# "node_id": ["1", "2"], "role": ["user", "assistant"],
|
170
|
+
# "content": ["message1", "message2"],
|
171
|
+
# }
|
172
|
+
# )
|
173
|
+
# updated_messages = MessageUtil.remove_message(messages, "1")
|
174
|
+
# self.assertTrue(updated_messages)
|
175
|
+
|
176
|
+
|
177
|
+
# class TestGetMessageRows(unittest.TestCase):
|
178
|
+
|
179
|
+
# def test_get_message_rows(self):
|
180
|
+
# """Test retrieving the last 'n' message rows based on criteria."""
|
181
|
+
# messages = pd.DataFrame(
|
182
|
+
# {
|
183
|
+
# "node_id": ["1", "2", "3"],
|
184
|
+
# "role": ["user", "assistant", "user"],
|
185
|
+
# "sender": ["A", "B", "A"],
|
186
|
+
# "content": ["message1", "message2", "message3"],
|
187
|
+
# }
|
188
|
+
# )
|
189
|
+
# rows = MessageUtil.get_message_rows(
|
190
|
+
# messages, sender="A", role="user", n=2
|
191
|
+
# )
|
192
|
+
# self.assertEqual(len(rows), 2)
|
193
|
+
|
194
|
+
|
195
|
+
# # class TestExtend(unittest.TestCase):
|
196
|
+
|
197
|
+
# # def test_extend(self):
|
198
|
+
# # """Test extending one DataFrame with another, ensuring no duplicate 'node_id'."""
|
199
|
+
# # df1 = pd.DataFrame({
|
200
|
+
# # "node_id": ["1"],
|
201
|
+
# # "role": ["user"],
|
202
|
+
# # "sender": ["test"],
|
203
|
+
# # "timestamp": ["2020-01-01T00:00:00"],
|
204
|
+
# # "content": ['{"message": "test"}']
|
205
|
+
# # })
|
206
|
+
# # df2 = pd.DataFrame({
|
207
|
+
# # "node_id": ["2"],
|
208
|
+
# # "role": ["user"],
|
209
|
+
# # "sender": ["test"],
|
210
|
+
# # "timestamp": ["2020-01-02T00:00:00"],
|
211
|
+
# # "content": ['{"message": "test2"}']
|
212
|
+
# # })
|
213
|
+
# # combined = MessageUtil.extend(df1, df2)
|
214
|
+
# # self.assertEqual(len(combined), 2)
|
215
|
+
|
216
|
+
|
217
|
+
# class TestToMarkdownString(unittest.TestCase):
|
218
|
+
|
219
|
+
# def test_to_markdown_string(self):
|
220
|
+
# """Test converting messages to a Markdown-formatted string."""
|
221
|
+
# messages = pd.DataFrame(
|
222
|
+
# {
|
223
|
+
# "node_id": ["1"], "role": ["user"],
|
224
|
+
# "content": [json.dumps({"instruction": "Hello, World!"})],
|
225
|
+
# }
|
226
|
+
# )
|
227
|
+
# markdown_str = MessageUtil.to_markdown_string(messages)
|
228
|
+
# self.assertIn("Hello, World!", markdown_str)
|
229
|
+
|
230
|
+
|
231
|
+
# # class TestSearchKeywords(unittest.TestCase):
|
232
|
+
|
233
|
+
# # def test_search_keywords(self):
|
234
|
+
# # """Test filtering DataFrame for rows containing specified keywords."""
|
235
|
+
# # messages = pd.DataFrame(
|
236
|
+
# # {"node_id": ["1", "2"], "content": ["Hello world", "Goodbye world"]}
|
237
|
+
# # )
|
238
|
+
# # filtered = MessageUtil.search_keywords(messages, "Hello")
|
239
|
+
# # print(filtered)
|
240
|
+
# # self.assertEqual(len(filtered), 1)
|
241
|
+
|
242
|
+
|
243
|
+
# # class TestReplaceKeyword(unittest.TestCase):
|
244
|
+
|
245
|
+
# # def test_replace_keyword(self):
|
246
|
+
# # """Test replacing a keyword in DataFrame's specified column."""
|
247
|
+
# # messages = pd.DataFrame({"content": ["Hello world", "Goodbye world"]})
|
248
|
+
# # MessageUtil.replace_keyword(messages, "world", "universe")
|
249
|
+
# # self.assertTrue(all(messages["content"].str.contains("universe")))
|
250
|
+
|
251
|
+
|
252
|
+
# # class TestReadCsv(unittest.TestCase):
|
253
|
+
|
254
|
+
# # @patch("pandas.read_csv")
|
255
|
+
# # def test_read_csv(self, mock_read_csv):
|
256
|
+
# # """Test reading a CSV file into a DataFrame."""
|
257
|
+
# # mock_df = pd.DataFrame(
|
258
|
+
# # {"node_id": ["1", "2"], "content": ["Hello, World!", "Goodbye, World!"]}
|
259
|
+
# # )
|
260
|
+
# # mock_read_csv.return_value = mock_df
|
261
|
+
|
262
|
+
# # df = MessageUtil.read_csv("path/to/nonexistent/file.csv")
|
263
|
+
|
264
|
+
# # mock_read_csv.assert_called_once_with("path/to/nonexistent/file.csv")
|
265
|
+
|
266
|
+
# # self.assertTrue(isinstance(df, pd.DataFrame))
|
267
|
+
# # self.assertEqual(len(df), 2)
|
268
|
+
# # self.assertEqual(list(df.columns), ["node_id", "content"])
|
270
269
|
|
271
270
|
|
272
|
-
# class TestReadJson(unittest.TestCase):
|
271
|
+
# # class TestReadJson(unittest.TestCase):
|
273
272
|
|
274
|
-
# @patch("pandas.read_json")
|
275
|
-
# def test_read_json(self, mock_read_json):
|
276
|
-
# """Test reading a JSON file into a DataFrame."""
|
277
|
-
# mock_df = pd.DataFrame(
|
278
|
-
# {"node_id": ["1", "2"], "content": ["JSON Message 1", "JSON Message 2"]}
|
279
|
-
# )
|
280
|
-
# mock_read_json.return_value = mock_df
|
281
|
-
|
282
|
-
# df = MessageUtil.read_json("path/to/nonexistent/file.json")
|
273
|
+
# # @patch("pandas.read_json")
|
274
|
+
# # def test_read_json(self, mock_read_json):
|
275
|
+
# # """Test reading a JSON file into a DataFrame."""
|
276
|
+
# # mock_df = pd.DataFrame(
|
277
|
+
# # {"node_id": ["1", "2"], "content": ["JSON Message 1", "JSON Message 2"]}
|
278
|
+
# # )
|
279
|
+
# # mock_read_json.return_value = mock_df
|
280
|
+
|
281
|
+
# # df = MessageUtil.read_json("path/to/nonexistent/file.json")
|
283
282
|
|
284
|
-
# mock_read_json.assert_called_once_with("path/to/nonexistent/file.json")
|
283
|
+
# # mock_read_json.assert_called_once_with("path/to/nonexistent/file.json")
|
285
284
|
|
286
|
-
# self.assertTrue(isinstance(df, pd.DataFrame))
|
287
|
-
# self.assertEqual(len(df), 2)
|
288
|
-
# self.assertEqual(list(df.columns), ["node_id", "content"])
|
285
|
+
# # self.assertTrue(isinstance(df, pd.DataFrame))
|
286
|
+
# # self.assertEqual(len(df), 2)
|
287
|
+
# # self.assertEqual(list(df.columns), ["node_id", "content"])
|
289
288
|
|
290
289
|
|
291
|
-
# class TestRemoveLastNRows(unittest.TestCase):
|
290
|
+
# # class TestRemoveLastNRows(unittest.TestCase):
|
292
291
|
|
293
|
-
# def test_remove_last_n_rows(self):
|
294
|
-
# """Test removing the last 'n' rows from a DataFrame."""
|
295
|
-
# messages = pd.DataFrame({"content": ["message1", "message2", "message3"]})
|
296
|
-
# updated = MessageUtil.remove_last_n_rows(messages, 2)
|
297
|
-
# self.assertEqual(len(updated), 1)
|
292
|
+
# # def test_remove_last_n_rows(self):
|
293
|
+
# # """Test removing the last 'n' rows from a DataFrame."""
|
294
|
+
# # messages = pd.DataFrame({"content": ["message1", "message2", "message3"]})
|
295
|
+
# # updated = MessageUtil.remove_last_n_rows(messages, 2)
|
296
|
+
# # self.assertEqual(len(updated), 1)
|
298
297
|
|
299
298
|
|
300
|
-
# class TestUpdateRow(unittest.TestCase):
|
299
|
+
# # class TestUpdateRow(unittest.TestCase):
|
301
300
|
|
302
|
-
# def test_update_row(self):
|
303
|
-
# """Test updating a row's value for a specified column."""
|
304
|
-
# messages = pd.DataFrame(
|
305
|
-
# {"node_id": ["1", "2"], "content": ["message1", "message2"]}
|
306
|
-
# )
|
307
|
-
# success = MessageUtil.update_row(messages, 0, "node_id", "3")
|
308
|
-
# self.assertTrue(success)
|
309
|
-
# self.assertTrue("3" in messages["node_id"].values)
|
301
|
+
# # def test_update_row(self):
|
302
|
+
# # """Test updating a row's value for a specified column."""
|
303
|
+
# # messages = pd.DataFrame(
|
304
|
+
# # {"node_id": ["1", "2"], "content": ["message1", "message2"]}
|
305
|
+
# # )
|
306
|
+
# # success = MessageUtil.update_row(messages, 0, "node_id", "3")
|
307
|
+
# # self.assertTrue(success)
|
308
|
+
# # self.assertTrue("3" in messages["node_id"].values)
|
310
309
|
|
311
310
|
|
312
|
-
if __name__ == "__main__":
|
313
|
-
|
311
|
+
# if __name__ == "__main__":
|
312
|
+
# unittest.main()
|