Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add more tests #149

Merged
merged 1 commit into from
Nov 5, 2022
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
3 changes: 2 additions & 1 deletion asyncio_mqtt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
from .client import Client, ProtocolVersion, TLSParameters, Will
from .client import Client, ProtocolVersion, ProxySettings, TLSParameters, Will
from .error import MqttCodeError, MqttError
from .version import __version__

Expand All @@ -8,6 +8,7 @@
"MqttCodeError",
"Client",
"Will",
"ProxySettings",
"ProtocolVersion",
"TLSParameters",
"__version__",
Expand Down
21 changes: 12 additions & 9 deletions asyncio_mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Generator,
Iterable,
Iterator,
List,
Tuple,
Union,
cast,
Expand All @@ -45,8 +46,8 @@
_PahoSocket = Union[socket.socket, ssl.SSLSocket, mqtt.WebsocketWrapper, Any]

WebSocketHeaders = Union[
Dict[str, Any],
Callable[[Dict[str, Any]], Dict[str, Any]],
Dict[str, str],
Callable[[Dict[str, str]], Dict[str, str]],
]


Expand Down Expand Up @@ -107,6 +108,13 @@ def __init__(
Tuple[int, int, None, int],
]

SubscribeTopic = Union[
str,
Tuple[str, mqtt.SubscribeOptions],
List[Tuple[str, mqtt.SubscribeOptions]],
List[Tuple[str, int]],
]

P = ParamSpec("P")

# TODO: Simplify the logic that surrounds `self._outgoing_calls_sem` with
Expand Down Expand Up @@ -238,7 +246,7 @@ def __init__(
self._client.message_retry_set(message_retry_set)
if socket_options is None:
socket_options = ()
self._socket_options: tuple[SocketOption, ...] = tuple(socket_options)
self._socket_options = tuple(socket_options)

@property
def id(self) -> str:
Expand Down Expand Up @@ -300,12 +308,7 @@ async def force_disconnect(self) -> None:
@_outgoing_call
async def subscribe(
self,
topic: (
str
| tuple[str, mqtt.SubscribeOptions]
| list[tuple[str, mqtt.SubscribeOptions]]
| list[tuple[str, int]]
),
topic: SubscribeTopic,
qos: int = 0,
options: mqtt.SubscribeOptions | None = None,
properties: Properties | None = None,
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ profile = "black"
strict = true
show_error_codes = true
no_strict_concatenate = true # TODO: remove when dropping python 3.7

[tool.pytest.ini_options]
filterwarnings = [
"error",
"ignore:ssl.PROTOCOL_TLS is deprecated:DeprecationWarning",
]

[tool.coverage.run]
branch = true
11 changes: 4 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
from __future__ import annotations

import sys
from typing import Any, Dict, Tuple
from typing import Any

import pytest


@pytest.fixture
def os_and_version() -> str:
return sys.platform + "_" + ".".join(map(str, sys.version_info[:2]))


@pytest.fixture
def anyio_backend() -> Tuple[str, Dict[str, Any]]:
def anyio_backend() -> tuple[str, dict[str, Any]]:
if sys.platform == "win32":
from asyncio.windows_events import WindowsSelectorEventLoopPolicy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should do something similar to this in the regular lib as well. We get a lot of issues from Windows users due to this.


Expand Down
24 changes: 24 additions & 0 deletions tests/mosquitto.org.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIIEAzCCAuugAwIBAgIUBY1hlCGvdj4NhBXkZ/uLUZNILAwwDQYJKoZIhvcNAQEL
BQAwgZAxCzAJBgNVBAYTAkdCMRcwFQYDVQQIDA5Vbml0ZWQgS2luZ2RvbTEOMAwG
A1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1vc3F1aXR0bzELMAkGA1UECwwCQ0ExFjAU
Bg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