Skip to content

Commit

Permalink
Upgrade (dev) dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman committed Oct 5, 2024
1 parent c444d07 commit eb8d949
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 65 deletions.
24 changes: 13 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
- id: trailing-whitespace
exclude: setup.cfg
- repo: https://github.com/psf/black
rev: '24.4.2'
rev: '24.8.0'
hooks:
- id: black
args:
Expand All @@ -29,24 +29,24 @@ repos:
exclude_types: [csv, json]
files: ^(async_upnp_client|tests)/.+\.py$
- repo: https://github.com/PyCQA/flake8
rev: '7.0.0'
rev: '7.1.1'
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings~=1.7.0
- pydocstyle~=6.3.0
files: ^(async_upnp_client|tests)/.+\.py$
- repo: https://github.com/PyCQA/pylint
rev: 'v3.2.2'
rev: 'v3.3.1'
hooks:
- id: pylint
additional_dependencies:
- pytest~=7.4.3
- voluptuous~=0.12.1
- pytest~=8.3.3
- voluptuous~=0.15.2
- aiohttp>3.9.0,<4.0
- python-didl-lite~=1.3.2
- python-didl-lite~=1.4.0
- defusedxml~=0.6.0
- pytest-asyncio~=0.21.1
- pytest-asyncio~=0.24.0
- pytest-aiohttp~=1.0.5
files: ^(async_upnp_client|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
Expand All @@ -57,12 +57,14 @@ repos:
- --profile=black
files: ^(async_upnp_client|tests)/.+\.py$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.10.0'
rev: 'v1.11.2'
hooks:
- id: mypy
args: [--ignore-missing-imports]
additional_dependencies:
- aiohttp~=3.9.1
- pytest~=7.4.3
- pytest-asyncio~=0.21.1
- python-didl-lite~=1.4.0
- pytest~=8.3.3
- aiohttp~=3.10.9
- pytest-asyncio~=0.24.0
- pytest-aiohttp~=1.0.5
files: ^(async_upnp_client|tests)/.+\.py$
2 changes: 1 addition & 1 deletion async_upnp_client/advertisement.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
loop: Optional[AbstractEventLoop] = None,
) -> None:
"""Initialize."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
assert (
async_on_alive
or async_on_byebye
Expand Down
4 changes: 2 additions & 2 deletions async_upnp_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __init__(
] = default_on_post_receive_device_spec,
) -> None:
"""Initialize."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
self.requester = requester
self.device_info = device_info
self.services = {service.service_type: service for service in services}
Expand Down Expand Up @@ -406,7 +406,7 @@ def __init__(
] = default_on_post_call_action,
) -> None:
"""Initialize."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
self.requester = requester
self._service_info = service_info
self.state_variables = {sv.name: sv for sv in state_variables}
Expand Down
2 changes: 1 addition & 1 deletion async_upnp_client/client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
] = default_on_post_call_action,
) -> None:
"""Initialize."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
self.requester = requester
self._non_strict = non_strict
self._on_pre_receive_device_spec = on_pre_receive_device_spec
Expand Down
2 changes: 1 addition & 1 deletion async_upnp_client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__( # pylint: disable=too-many-arguments
)


class UpnpClientResponseError(aiohttp.ClientResponseError, UpnpResponseError):
class UpnpClientResponseError(aiohttp.ClientResponseError, UpnpResponseError): # type: ignore
"""HTTP response error with more details from aiohttp."""


Expand Down
8 changes: 4 additions & 4 deletions async_upnp_client/profiles/dlna.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ async def construct_play_media_metadata(
The base metadata is updated with key:values from meta_data, e.g.
`meta_data = {"artist": "Singer X"}`
"""
# pylint: disable=too-many-arguments, too-many-locals, too-many-branches
# pylint: disable=too-many-arguments, too-many-positional-arguments, too-many-locals, too-many-branches
mime_type = override_mime_type or ""
upnp_class = override_upnp_class or ""
dlna_features = override_dlna_features or "*"
Expand Down Expand Up @@ -1428,7 +1428,7 @@ async def async_browse(
sort_criteria: Union[Iterable[str], str] = DEFAULT_SORT_CRITERIA,
) -> BrowseResult:
"""Retrieve an object's metadata or its children."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
action = self._action("CD", "Browse")
if not action:
raise UpnpError("Missing action CD/Browse")
Expand Down Expand Up @@ -1481,7 +1481,7 @@ async def async_browse_direct_children(
sort_criteria: Union[Iterable[str], str] = DEFAULT_SORT_CRITERIA,
) -> BrowseResult:
"""Get the direct children of an object."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
_LOGGER.debug("browse_direct_children(%r, %r)", object_id, metadata_filter)
result = await self.async_browse(
object_id,
Expand Down Expand Up @@ -1513,7 +1513,7 @@ async def async_search_directory(
NOTE: This is not UpnpProfileDevice.async_search, which searches for
matching UPnP devices.
"""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
_LOGGER.debug(
"search_directory(%r, %r, %r)",
container_id,
Expand Down
4 changes: 2 additions & 2 deletions async_upnp_client/profiles/igd.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ async def async_add_port_mapping(
:param lease_duration Lease duration
:param services List of service names to try to get action from, defaults to [WANIPC,WANPPP]
"""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
services = services or ["WANIPC", "WANPPP"]
action = self._any_action(services, "AddPortMapping")
if not action:
Expand Down Expand Up @@ -579,7 +579,7 @@ async def async_add_pinhole(
lease_time: timedelta,
) -> Optional[int]:
"""Add a pinhole."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
action = self._action("WANIP6FC", "AddPinhole")
if not action:
return None
Expand Down
7 changes: 5 additions & 2 deletions async_upnp_client/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
_LOGGER = logging.getLogger(__name__)


class SsdpSearchListener: # pylint: disable=too-many-arguments,too-many-instance-attributes
class SsdpSearchListener:
"""SSDP Search (response) listener."""

# pylint: disable=too-many-instance-attributes

def __init__(
self,
async_callback: Optional[
Expand All @@ -48,6 +50,7 @@ def __init__(
connect_callback: Optional[Callable[[], None]] = None,
) -> None:
"""Init the ssdp listener class."""
# pylint: disable=too-many-arguments,too-many-positional-arguments
assert (
callback is not None or async_callback is not None
), "Provide at least one callback"
Expand Down Expand Up @@ -168,7 +171,7 @@ async def async_search(
loop: Optional[AbstractEventLoop] = None,
) -> None:
"""Discover devices via SSDP."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
loop_: AbstractEventLoop = loop or asyncio.get_event_loop()
listener: Optional[SsdpSearchListener] = None

Expand Down
4 changes: 2 additions & 2 deletions async_upnp_client/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def __init__(
loop: Optional[asyncio.AbstractEventLoop] = None,
) -> None:
"""Init the ssdp search responder class."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
self.device = device
self.source, self.target = determine_source_target(source, target)
self.options = options or {}
Expand Down Expand Up @@ -1302,7 +1302,7 @@ def __init__(
options: Optional[Dict[str, Any]] = None,
) -> None:
"""Initialize."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
self.server_device = server_device
self.source, self.target = determine_source_target(source, target)
self.http_port = http_port
Expand Down
2 changes: 1 addition & 1 deletion async_upnp_client/ssdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def __init__(
on_data: Optional[Callable[[str, CaseInsensitiveDict], None]] = None,
) -> None:
"""Initialize."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
self.loop = loop
self.async_on_connect = async_on_connect
self.on_connect = on_connect
Expand Down
2 changes: 1 addition & 1 deletion async_upnp_client/ssdp_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def __init__(
device_tracker: Optional[SsdpDeviceTracker] = None,
) -> None:
"""Initialize."""
# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
assert callback or async_callback, "Provide at least one callback"

self.async_callback = async_callback
Expand Down
14 changes: 9 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ keywords =
[options]
python_requires = >=3.8
install_requires =
voluptuous >= 0.12.1
voluptuous >= 0.15.2
aiohttp >3.9.0, <4.0
async-timeout >=3.0, <5.0
python-didl-lite ~= 1.4.0
defusedxml >= 0.6.0
tests_require =
pytest ~= 7.4.3
pytest-asyncio ~= 0.21.1
pytest ~= 8.3.3
pytest-asyncio ~= 0.24.0
pytest-aiohttp ~= 1.0.5
pytest-cov ~= 4.1.0
coverage ~= 7.3.2
pytest-cov ~= 5.0.0
coverage ~= 7.6.1
asyncmock ~= 0.4.2
packages =
async_upnp_client
Expand Down Expand Up @@ -82,6 +82,10 @@ ignore =
W504
noqa-require-code = True

[tool:pytest]
asyncio_mode = auto
asyncio_default_fixture_loop_scope = function

[mypy]
check_untyped_defs = true
disallow_untyped_calls = true
Expand Down
1 change: 1 addition & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for search."""

# pylint: disable=protected-access

from unittest.mock import AsyncMock
Expand Down
35 changes: 24 additions & 11 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import socket
import xml.etree.ElementTree as ET
from collections import namedtuple
from contextlib import asynccontextmanager, suppress
from typing import (
Any,
Expand All @@ -12,13 +11,16 @@
Awaitable,
Callable,
Dict,
NamedTuple,
Optional,
Tuple,
cast,
)

import aiohttp
import pytest
import pytest_asyncio
from pytest_aiohttp.plugin import AiohttpClient

import async_upnp_client.aiohttp
import async_upnp_client.client
Expand Down Expand Up @@ -171,6 +173,15 @@ async def ClientSession(self) -> AsyncIterator: # pylint: disable=invalid-name
yield self.session


class UpnpServerTuple(NamedTuple):
"""Upnp server tuple."""

http_client: AiohttpClient
ssdp_sockets: list[socket.socket]
callback: Callback
server: UpnpServer


@pytest_asyncio.fixture
async def upnp_server(monkeypatch: Any, aiohttp_client: Any) -> AsyncGenerator:
"""Fixture to initialize device."""
Expand Down Expand Up @@ -198,7 +209,7 @@ def __init__(
async def start(self) -> Any:
"""Create HTTP server."""
nonlocal http_client
http_client = await aiohttp_client(self.app)
http_client = cast(AiohttpClient, await aiohttp_client(self.app))
return http_client

callback = Callback()
Expand All @@ -215,16 +226,16 @@ async def start(self) -> Any:
)
await server.async_start()

assert aiohttp_client
await callback.start(aiohttp_client)
upnpserver = namedtuple("upnpserver", "http_client ssdp_sockets callback server")
yield upnpserver(http_client, ssdp_sockets, callback, server)
yield UpnpServerTuple(http_client, ssdp_sockets, callback, server)
# await server.async_stop()
for sock in ssdp_sockets:
sock.close()


@pytest.mark.asyncio
async def test_init(upnp_server: Any) -> None:
async def test_init(upnp_server: UpnpServerTuple) -> None:
"""Test device query."""
# pylint: disable=redefined-outer-name
http_client = upnp_server.http_client
Expand All @@ -235,7 +246,7 @@ async def test_init(upnp_server: Any) -> None:


@pytest.mark.asyncio
async def test_action(upnp_server: Any) -> None:
async def test_action(upnp_server: UpnpServerTuple) -> None:
"""Test action execution."""
# pylint: disable=redefined-outer-name
http_client = upnp_server.http_client
Expand All @@ -254,7 +265,7 @@ async def test_action(upnp_server: Any) -> None:


@pytest.mark.asyncio
async def test_subscribe(upnp_server: Any) -> None:
async def test_subscribe(upnp_server: UpnpServerTuple) -> None:
"""Test subscription to server event."""
# pylint: disable=redefined-outer-name
event = asyncio.Event()
Expand All @@ -273,10 +284,12 @@ async def on_callback(request: aiohttp.web.Request) -> aiohttp.web.Response:

http_client = upnp_server.http_client
callback = upnp_server.callback
service: ServerServiceTest = (
upnp_server.server._device.service( # pylint: disable=protected-access
"urn:schemas-upnp-org:service:TestServerService:1"
)
server = upnp_server.server
server_device = server._device # pylint: disable=protected-access
assert server_device
service = cast(
ServerServiceTest,
server_device.service("urn:schemas-upnp-org:service:TestServerService:1"),
)
callback.set_callback(on_callback)
response = await http_client.request(
Expand Down
1 change: 1 addition & 0 deletions tests/test_ssdp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for ssdp."""

import asyncio
from unittest.mock import ANY, AsyncMock, MagicMock

Expand Down
6 changes: 3 additions & 3 deletions tests/test_ssdp_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,9 @@ async def test_see_search_invalid_usn() -> None:

# See device for the first time through alive-advertisement.
headers = CaseInsensitiveDict(SEARCH_HEADERS_DEFAULT)
headers[
"ST"
] = "urn:Microsoft Windows Peer Name Resolution Protocol: V4:IPV6:LinkLocal"
headers["ST"] = (
"urn:Microsoft Windows Peer Name Resolution Protocol: V4:IPV6:LinkLocal"
)
headers["USN"] = "[fe80::aaaa:bbbb:cccc:dddd]:3540"
del headers["_udn"]
advertisement_listener._on_data(SEARCH_REQUEST_LINE, headers)
Expand Down
Loading

0 comments on commit eb8d949

Please sign in to comment.