Spaces:
Configuration error
Configuration error
Download tests/unit/test_json.py from flyingdarkdev/README: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/tests/unit/test_json.py
- Command line
-
hf download hf://spaces/flyingdarkdev/README/tests/unit/test_json.py
-
curl -L -o test_json.py https://huggingface.co/spaces/flyingdarkdev/README/resolve/main/tests/unit/test_json.py
1.4 kB
| from datetime import datetime | |
| from openhands.events.action import MessageAction | |
| from openhands.io import json | |
| 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 | |