Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/test_ankaios.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ def test_get_reponse_by_id():
assert ankaios._get_response_by_id("3344") == response
assert ankaios._responses.empty()

ankaios._responses.put(Response(MESSAGE_BUFFER_COMPLETE_STATE))
with pytest.raises(TimeoutError):
ankaios._responses.put(Response(MESSAGE_BUFFER_COMPLETE_STATE))
ankaios._get_response_by_id("3344", timeout=0.01)

ankaios._responses.put(Response(MESSAGE_BUFFER_CONNECTION_CLOSED))
with pytest.raises(ConnectionClosedException):
ankaios._responses.put(Response(MESSAGE_BUFFER_CONNECTION_CLOSED))
ankaios._get_response_by_id("1122")


Expand Down
33 changes: 16 additions & 17 deletions tests/test_control_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,30 +395,28 @@ def test_handle_response_connection_closed():

# Got connection closed response as initial response
response_callback = MagicMock()
ci = ControlInterface(
add_response_callback=response_callback,
add_log_callback=lambda _: None,
add_event_callback=lambda _: None,
)
ci._state = ControlInterfaceState.INITIALIZED
with pytest.raises(
ConnectionClosedException, match="Connection closed reason"
):
ci = ControlInterface(
add_response_callback=response_callback,
add_log_callback=lambda _: None,
add_event_callback=lambda _: None,
)
ci._state = ControlInterfaceState.INITIALIZED

ci._handle_response(conn_closed_response)

# Got connection closed response while already connected
response_callback = MagicMock()
ci = ControlInterface(
add_response_callback=response_callback,
add_log_callback=lambda _: None,
add_event_callback=lambda _: None,
)
ci._state = ControlInterfaceState.CONNECTED
with pytest.raises(
ConnectionClosedException, match="Connection closed reason"
):
ci = ControlInterface(
add_response_callback=response_callback,
add_log_callback=lambda _: None,
add_event_callback=lambda _: None,
)
ci._state = ControlInterfaceState.CONNECTED

ci._handle_response(conn_closed_response)


Expand Down Expand Up @@ -540,24 +538,25 @@ def test_write_request():
add_log_callback=lambda _: None,
add_event_callback=lambda _: None,
)
test_request = generate_test_request()

ci._state = ControlInterfaceState.TERMINATED
with pytest.raises(
ControlInterfaceException, match="Could not write to pipe"
):
ci.write_request(generate_test_request())
ci.write_request(test_request)

ci._state = ControlInterfaceState.CONNECTED
with patch("ankaios_sdk.ControlInterface._write_to_pipe") as mock_write:
ci.write_request(generate_test_request())
ci.write_request(test_request)
mock_write.assert_called_once()

ci._state = ControlInterfaceState.CONNECTION_CLOSED
with pytest.raises(
ConnectionClosedException,
match="Could not write to pipe, connection closed.",
):
ci.write_request(generate_test_request())
ci.write_request(test_request)


def test_send_initial_hello():
Expand Down
6 changes: 5 additions & 1 deletion tests/workload/test_access_right_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
This module contains unit tests for the AccessRightRule class.
"""

from ankaios_sdk import AccessRightRule
import pytest
from ankaios_sdk import AccessRightRule, WorkloadFieldException
from ankaios_sdk._protos import _ank_base


Expand All @@ -42,6 +43,9 @@ def test_state_rule():
"filterMask": ["mask_1", "mask_2"],
}

with pytest.raises(WorkloadFieldException):
_ = AccessRightRule.state_rule("Invalid", ["mask"])


def test_log_rule():
"""
Expand Down
10 changes: 0 additions & 10 deletions tests/workload/test_workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,6 @@ def test_rules(workload: Workload): # pylint: disable=redefined-outer-name
assert len(allow_rules) == 1
assert len(deny_rules) == 1

with pytest.raises(WorkloadFieldException):
workload.update_allow_rules(
[AccessRightRule.state_rule("Invalid", ["mask"])]
)

with pytest.raises(WorkloadFieldException):
workload.update_deny_rules(
[AccessRightRule.state_rule("Invalid", ["mask"])]
)

allow_rules.append(
AccessRightRule.state_rule(
"Write", [f"{WORKLOADS_PREFIX}.another_workload"]
Expand Down
5 changes: 2 additions & 3 deletions tests/workload_state/test_workload_execution_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_interpret_state_error():
Test the handling of an invalid execution state in the
WorkloadExecutionState class, ensuring it raises a ValueError.
"""
invalid_state = _ank_base.ExecutionState(additionalInfo="No state present")
with pytest.raises(ValueError, match="Invalid state for workload."):
WorkloadExecutionState(
_ank_base.ExecutionState(additionalInfo="No state present")
)
WorkloadExecutionState(invalid_state)
Loading