-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into make-workspace-panels-dockable
- Loading branch information
Showing
32 changed files
with
376 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,5 @@ python-lsp-server[websockets] | |
bidict==0.22.0 | ||
cached_property | ||
psutil | ||
transformers | ||
transformers | ||
tzlocal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
core/amber/src/main/python/core/runnables/test_console_message.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import pytest | ||
from core.models.internal_queue import InternalQueue | ||
from core.util.buffer.timed_buffer import TimedBuffer | ||
from core.util import set_one_of | ||
from proto.edu.uci.ics.amber.engine.common import ( | ||
ActorVirtualIdentity, | ||
ControlInvocationV2, | ||
ControlPayloadV2, | ||
PythonControlMessage, | ||
) | ||
from proto.edu.uci.ics.amber.engine.architecture.worker import ( | ||
PythonConsoleMessageV2, | ||
ConsoleMessage, | ||
ConsoleMessageType, | ||
ControlCommandV2, | ||
) | ||
from core.util.console_message.timestamp import current_time_in_local_timezone | ||
|
||
|
||
class TestConsoleMessage: | ||
@pytest.fixture | ||
def internal_queue(self): | ||
return InternalQueue() | ||
|
||
@pytest.fixture | ||
def timed_buffer(self): | ||
return TimedBuffer() | ||
|
||
@pytest.fixture | ||
def console_message(self): | ||
return PythonConsoleMessageV2( | ||
ConsoleMessage( | ||
worker_id="0", | ||
timestamp=current_time_in_local_timezone(), | ||
# this will produce error if betterproto is set to 2.0.0b7 | ||
# timestamp=datetime.datetime.now(), | ||
msg_type=ConsoleMessageType.PRINT, | ||
source="pytest", | ||
title="Test Message", | ||
message="Test Message", | ||
) | ||
) | ||
|
||
@pytest.fixture | ||
def mock_controller(self): | ||
return ActorVirtualIdentity("CONTROLLER") | ||
|
||
@pytest.mark.timeout(2) | ||
def test_console_message_serialization(self, mock_controller, console_message): | ||
""" | ||
Test the serialization of the console message | ||
:param mock_controller: the mock actor id | ||
:param console_message: the test message | ||
""" | ||
# below statements wrap the console message as the python control message | ||
command = set_one_of(ControlCommandV2, console_message) | ||
payload = set_one_of(ControlPayloadV2, ControlInvocationV2(1, command=command)) | ||
python_control_message = PythonControlMessage( | ||
tag=mock_controller, payload=payload | ||
) | ||
# serialize the python control message to bytes | ||
python_control_message_bytes = bytes(python_control_message) | ||
# deserialize the control message from bytes | ||
parsed_python_control_message = PythonControlMessage().parse( | ||
python_control_message_bytes | ||
) | ||
# deserialized one should equal to the original one | ||
assert python_control_message == parsed_python_control_message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
core/amber/src/main/python/core/util/console_message/timestamp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import datetime | ||
import tzlocal | ||
|
||
|
||
def current_time_in_local_timezone(): | ||
# Get the system's local timezone | ||
local_timezone = tzlocal.get_localzone() | ||
|
||
# Get the current time in the local timezone | ||
local_time = datetime.datetime.now(local_timezone) | ||
|
||
return local_time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.