removing cli test cases for verifying will messages, better done through unit test cases in test_client.py

pull/200/head
Andrew Mirsky 2025-06-08 08:57:06 -04:00
rodzic 69f6114830
commit 1756d93ebd
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: A98E67635CDF2C39
3 zmienionych plików z 4 dodań i 38 usunięć

Wyświetl plik

@ -110,8 +110,7 @@ def _version(v:bool) -> None:
def subscribe_main( # pylint: disable=R0914,R0917 # noqa : PLR0913
url: str = typer.Option(None, help="Broker connection URL, *must conform to MQTT or URI scheme: `[mqtt(s)|ws(s)]://<username:password>@HOST:port`*", show_default=False),
config_file: str | None = typer.Option(None, "-c", help="Client configuration file"),
client_id: str | None = typer.Option(None, "-i", help="client identification for mqtt connection. *default: process id and the hostname of the client*"),
max_count: int | None = typer.Option(None, "-n", help="Number of messages to read before ending *default: read indefinitely*"),
client_id: str | None = typer.Option(None, "-i", "--client-id", help="client identification for mqtt connection. *default: process id and the hostname of the client*"), max_count: int | None = typer.Option(None, "-n", help="Number of messages to read before ending *default: read indefinitely*"),
qos: int = typer.Option(0, "--qos", "-q", help="Quality of service (0, 1, or 2)"),
topics: list[str] = typer.Option(..., "-t", help="Topic filter to subscribe, can be used multiple times."), # noqa: B008
keep_alive: int | None = typer.Option(None, "-k", help="Keep alive timeout in seconds"),

Wyświetl plik

@ -185,7 +185,7 @@ timeout = 10
asyncio_default_fixture_loop_scope = "function"
#addopts = ["--tb=short", "--capture=tee-sys"]
#log_cli = true
#log_level = "DEBUG"
log_level = "DEBUG"
# ------------------------------------ MYPY ------------------------------------
[tool.mypy]

Wyświetl plik

@ -4,10 +4,12 @@ import os
import signal
import subprocess
import tempfile
from unittest.mock import patch
import pytest
import yaml
from amqtt.broker import Broker
from amqtt.mqtt.constants import QOS_0
formatter = "[%(asctime)s] %(name)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s"
@ -243,38 +245,3 @@ async def test_pub_client_config(broker, client_config_file):
logger.debug(f"Stderr: {stderr.decode()}")
assert proc.returncode == 0, f"publisher error code: {proc.returncode}"
@pytest.mark.asyncio
async def test_sub_client_config_will(broker, client_config, client_config_file):
# verifying client script functionality of will topic (subscriber)
# https://github.com/Yakifo/amqtt/issues/159
client1 = MQTTClient(client_id="client1")
await client1.connect('mqtt://localhost:1884')
await client1.subscribe([
("test/will/topic", QOS_0)
])
cmd = ["amqtt_sub",
"-t", "test/topic",
"-c", client_config_file,
"-n", "1"]
proc = await asyncio.create_subprocess_shell(
" ".join(cmd), stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
await asyncio.sleep(2)
# force the process to exit
proc.terminate()
await proc.wait()
# validate the 'will' message was received correctly
message = await client1.deliver_message(timeout_duration=3)
assert message.topic == 'test/will/topic'
assert message.data == b'client ABC has disconnected'
await client1.disconnect()