From 24219a78d01a4383a3651ee218ac4b85a42f2ee5 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Tue, 17 Sep 2024 11:37:00 +0100 Subject: [PATCH] Rename MessagingTemplate to StompClient --- src/blueapi/cli/cli.py | 4 ++-- src/blueapi/client/client.py | 4 ++-- src/blueapi/client/event_bus.py | 6 +++--- src/blueapi/service/interface.py | 6 +++--- tests/unit_tests/client/test_event_bus.py | 8 ++++---- tests/unit_tests/service/test_interface.py | 10 +++++----- tests/unit_tests/test_cli.py | 10 +++++----- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/blueapi/cli/cli.py b/src/blueapi/cli/cli.py index 9a86b9a92..c0069214d 100644 --- a/src/blueapi/cli/cli.py +++ b/src/blueapi/cli/cli.py @@ -7,7 +7,7 @@ import click from bluesky.callbacks.best_effort import BestEffortCallback -from bluesky_stomp.messaging import MessageContext, MessagingTemplate +from bluesky_stomp.messaging import MessageContext, StompClient from bluesky_stomp.models import Broker from pydantic import ValidationError from requests.exceptions import ConnectionError @@ -148,7 +148,7 @@ def listen_to_events(obj: dict) -> None: config: ApplicationConfig = obj["config"] if config.stomp is not None: event_bus_client = EventBusClient( - MessagingTemplate.for_broker( + StompClient.for_broker( broker=Broker( host=config.stomp.host, port=config.stomp.port, diff --git a/src/blueapi/client/client.py b/src/blueapi/client/client.py index 97dbf35a5..4468bf10e 100644 --- a/src/blueapi/client/client.py +++ b/src/blueapi/client/client.py @@ -1,7 +1,7 @@ import time from concurrent.futures import Future -from bluesky_stomp.messaging import MessageContext, MessagingTemplate +from bluesky_stomp.messaging import MessageContext, StompClient from bluesky_stomp.models import Broker from blueapi.config import ApplicationConfig @@ -41,7 +41,7 @@ def __init__( def from_config(cls, config: ApplicationConfig) -> "BlueapiClient": rest = BlueapiRestClient(config.api) if config.stomp is not None: - template = MessagingTemplate.for_broker( + template = StompClient.for_broker( broker=Broker( host=config.stomp.host, port=config.stomp.port, diff --git a/src/blueapi/client/event_bus.py b/src/blueapi/client/event_bus.py index 94e374d4b..b9516ee70 100644 --- a/src/blueapi/client/event_bus.py +++ b/src/blueapi/client/event_bus.py @@ -1,6 +1,6 @@ from collections.abc import Callable -from bluesky_stomp.messaging import MessageContext, MessagingTemplate +from bluesky_stomp.messaging import MessageContext, StompClient from bluesky_stomp.models import MessageTopic from blueapi.core import DataEvent @@ -17,9 +17,9 @@ def __init__(self, message: str) -> None: class EventBusClient: - app: MessagingTemplate + app: StompClient - def __init__(self, app: MessagingTemplate) -> None: + def __init__(self, app: StompClient) -> None: self.app = app def __enter__(self) -> None: diff --git a/src/blueapi/service/interface.py b/src/blueapi/service/interface.py index 72d546831..914639c62 100644 --- a/src/blueapi/service/interface.py +++ b/src/blueapi/service/interface.py @@ -3,7 +3,7 @@ from functools import lru_cache from typing import Any -from bluesky_stomp.messaging import MessagingTemplate +from bluesky_stomp.messaging import StompClient from bluesky_stomp.models import Broker, DestinationBase, MessageTopic from blueapi.config import ApplicationConfig @@ -49,10 +49,10 @@ def worker() -> TaskWorker: @lru_cache -def messaging_template() -> MessagingTemplate | None: +def messaging_template() -> StompClient | None: stomp_config = config().stomp if stomp_config is not None: - template = MessagingTemplate.for_broker( + template = StompClient.for_broker( broker=Broker( host=stomp_config.host, port=stomp_config.port, auth=stomp_config.auth ) diff --git a/tests/unit_tests/client/test_event_bus.py b/tests/unit_tests/client/test_event_bus.py index ff5eb3101..34ac41a63 100644 --- a/tests/unit_tests/client/test_event_bus.py +++ b/tests/unit_tests/client/test_event_bus.py @@ -1,18 +1,18 @@ from unittest.mock import ANY, Mock import pytest -from bluesky_stomp.messaging import MessagingTemplate +from bluesky_stomp.messaging import StompClient from blueapi.client.event_bus import BlueskyStreamingError, EventBusClient @pytest.fixture -def mock_template() -> MessagingTemplate: - return Mock(spec=MessagingTemplate) +def mock_template() -> StompClient: + return Mock(spec=StompClient) @pytest.fixture -def events(mock_template: MessagingTemplate) -> EventBusClient: +def events(mock_template: StompClient) -> EventBusClient: return EventBusClient(app=mock_template) diff --git a/tests/unit_tests/service/test_interface.py b/tests/unit_tests/service/test_interface.py index 002d2d308..86dd2e5c1 100644 --- a/tests/unit_tests/service/test_interface.py +++ b/tests/unit_tests/service/test_interface.py @@ -3,7 +3,7 @@ from unittest.mock import MagicMock, Mock, patch import pytest -from bluesky_stomp.messaging import MessagingTemplate +from bluesky_stomp.messaging import StompClient from ophyd.sim import SynAxis from stomp.connect import StompConnection11 as Connection @@ -23,8 +23,8 @@ def mock_connection() -> Mock: @pytest.fixture -def template(mock_connection: Mock) -> MessagingTemplate: - template = MessagingTemplate(conn=mock_connection) +def template(mock_connection: Mock) -> StompClient: + template = StompClient(conn=mock_connection) template.disconnect = MagicMock() return template @@ -283,9 +283,9 @@ def test_get_task_by_id(context_mock: MagicMock): ) -def test_stomp_config(template: MessagingTemplate): +def test_stomp_config(template: StompClient): with patch( - "blueapi.service.interface.MessagingTemplate.for_broker", return_value=template + "blueapi.service.interface.StompClient.for_broker", return_value=template ): interface.set_config(ApplicationConfig(stomp=StompConfig())) assert interface.messaging_template() is not None diff --git a/tests/unit_tests/test_cli.py b/tests/unit_tests/test_cli.py index afc0cdece..370a90e85 100644 --- a/tests/unit_tests/test_cli.py +++ b/tests/unit_tests/test_cli.py @@ -9,7 +9,7 @@ import pytest import responses -from bluesky_stomp.messaging import MessagingTemplate +from bluesky_stomp.messaging import StompClient from click.testing import CliRunner from pydantic import BaseModel, ValidationError from requests.exceptions import ConnectionError @@ -38,8 +38,8 @@ def mock_connection() -> Mock: @pytest.fixture -def template(mock_connection: Mock) -> MessagingTemplate: - return MessagingTemplate(conn=mock_connection) +def template(mock_connection: Mock) -> StompClient: + return StompClient(conn=mock_connection) @pytest.fixture @@ -150,9 +150,9 @@ def test_cannot_run_plans_without_stomp_config(runner: CliRunner): ) -@patch("blueapi.cli.cli.MessagingTemplate") +@patch("blueapi.cli.cli.StompClient") def test_valid_stomp_config_for_listener( - template: MessagingTemplate, + template: StompClient, runner: CliRunner, mock_connection: Mock, ):