forked from All-Hands-AI/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_json.py
46 lines (41 loc) · 1.38 KB
/
test_json.py
1
2
3
4
5
6
7
8
9
10
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
from datetime import datetime
from openhands.core.utils import json
from openhands.events.action import MessageAction
def test_event_serialization_deserialization():
message = MessageAction(content='This is a test.', wait_for_response=False)
message._id = 42
message._timestamp = datetime(2020, 1, 1, 23, 59, 58)
serialized = json.dumps(message)
deserialized = json.loads(serialized)
expected = {
'id': 42,
'timestamp': '2020-01-01T23:59:58',
'action': 'message',
'message': 'This is a test.',
'args': {
'content': 'This is a test.',
'image_urls': None,
'wait_for_response': False,
},
}
assert deserialized == expected
def test_array_serialization_deserialization():
message = MessageAction(content='This is a test.', wait_for_response=False)
message._id = 42
message._timestamp = datetime(2020, 1, 1, 0, 0, 0)
serialized = json.dumps([message])
deserialized = json.loads(serialized)
expected = [
{
'id': 42,
'timestamp': '2020-01-01T00:00:00',
'action': 'message',
'message': 'This is a test.',
'args': {
'content': 'This is a test.',
'image_urls': None,
'wait_for_response': False,
},
}
]
assert deserialized == expected