Skip to content

Commit

Permalink
increased code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Aug 28, 2024
1 parent 8e0410f commit 3f2b147
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/blueapi/service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,9 @@ def set_state(
and new_state in _ALLOWED_TRANSITIONS[current_state]
):
if new_state == WorkerState.PAUSED:
if state_change_request.defer is not None:
runner.run(interface.pause_worker, state_change_request.defer)
else:
runner.run(interface.pause_worker, False)
if state_change_request.defer is None:
state_change_request.defer = False

Check warning on line 316 in src/blueapi/service/main.py

View check run for this annotation

Codecov / codecov/patch

src/blueapi/service/main.py#L316

Added line #L316 was not covered by tests
runner.run(interface.pause_worker, state_change_request.defer)
elif new_state == WorkerState.RUNNING:
runner.run(interface.resume_worker)
elif new_state in {WorkerState.ABORTING, WorkerState.STOPPING}:
Expand Down
9 changes: 9 additions & 0 deletions tests/service/test_interface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import uuid
from dataclasses import dataclass
from unittest.mock import MagicMock, patch
Expand Down Expand Up @@ -273,3 +274,11 @@ def test_get_task_by_id(context_mock: MagicMock):
def test_stomp_config():
interface.set_config(ApplicationConfig(stomp=StompConfig()))
assert interface.messaging_template() is not None


@pytest.mark.stomp
def test_stomp_connection_failure_with_invalid_config(caplog):
caplog.at_level(logging.exception)
interface.set_config(ApplicationConfig(stomp=StompConfig(host="Not Exists")))
assert interface.messaging_template() is None
assert "Failed to connect to message bus" in caplog.text
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def test_valid_stomp_config_for_listener(runner: CliRunner):
input="\n",
)
assert (
result.output
== 'Subscribing to all bluesky events from localhost:61613\nPress enter to exit{\n "state": "IDLE",\n "task_status": null,\n "errors": [],\n "warnings": []\n}\n'
"Subscribing to all bluesky events from localhost:61613\nPress enter to exit"
in result.output
)
assert result.exit_code == 0

Expand Down

0 comments on commit 3f2b147

Please sign in to comment.