Skip to content

Commit

Permalink
Fix ruff findings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shutgun committed Oct 14, 2024
1 parent 75b8f1e commit 7789ba5
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_data() -> TestData:
return load_test_data()


@pytest.fixture()
@pytest.fixture
def block_communication() -> Generator[None, None, None]:
"""Block external communication."""
adapter = OrderedDict()
Expand All @@ -41,20 +41,20 @@ def block_communication() -> Generator[None, None, None]:
yield


@pytest_asyncio.fixture()
@pytest_asyncio.fixture
async def http_client() -> AsyncGenerator[None, None]:
"""Patch HTTP client."""
with patch("devolo_plc_api.device.AsyncClient", autospec=True):
yield


@pytest.fixture()
@pytest.fixture
def mock_device(test_data: TestData) -> Device:
"""Generate a device from test data."""
return Device(ip=test_data.ip)


@pytest.fixture()
@pytest.fixture
def mock_info_from_service() -> Generator[Mock, None, None]:
"""Patch reading info from mDNS entries."""
with patch("devolo_plc_api.device.Device.info_from_service") as ifs:
Expand All @@ -68,7 +68,7 @@ def patch_sleep() -> Generator[AsyncMock, None, None]:
yield sleep


@pytest.fixture()
@pytest.fixture
def service_browser(device_type: DeviceType) -> Generator[None, None, None]:
"""Patch mDNS service browser."""
service_browser = partial(MockServiceBrowser, device_type=device_type)
Expand All @@ -78,7 +78,7 @@ def service_browser(device_type: DeviceType) -> Generator[None, None, None]:
yield


@pytest.fixture()
@pytest.fixture
def snapshot(snapshot: SnapshotAssertion) -> SnapshotAssertion:
"""Return snapshot assertion fixture with nicer path."""
return snapshot.use_extension(DifferentDirectoryExtension)
2 changes: 1 addition & 1 deletion tests/fixtures/device_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tests import TestData


@pytest_asyncio.fixture()
@pytest_asyncio.fixture
async def device_api(test_data: TestData, feature: str) -> AsyncGenerator[DeviceApi, None]:
"""Yield a prepared DeviceApi object."""
test_data.device_info[SERVICE_TYPE].properties["Features"] = feature
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/plcnet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def plcnet_api(test_data: TestData) -> AsyncGenerator[PlcNetApi, None]:
yield PlcNetApi(test_data.ip, client, test_data.device_info[SERVICE_TYPE])


@pytest.fixture()
@pytest.fixture
def network() -> LogicalNetwork:
"""Mock a PLC network."""
return LogicalNetwork(devices=[], data_rates=[])
18 changes: 9 additions & 9 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class TestDevice:
"""Test devolo_plc_api.device.Device class."""

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("service_browser")
async def test_async_connect_plc(self, mock_device: Device, snapshot: SnapshotAssertion):
Expand All @@ -37,7 +37,7 @@ async def test_async_connect_plc(self, mock_device: Device, snapshot: SnapshotAs
assert mock_device == snapshot
await mock_device.async_disconnect()

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.REPEATER])
@pytest.mark.usefixtures("service_browser")
async def test_async_connect_repeater(self, mock_device: Device, snapshot: SnapshotAssertion):
Expand All @@ -49,7 +49,7 @@ async def test_async_connect_repeater(self, mock_device: Device, snapshot: Snaps
assert mock_device == snapshot
await mock_device.async_disconnect()

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_sync_connect_multicast(self, test_data: TestData):
"""Test that devices having trouble with unicast zeroconf are queried twice."""
with patch("devolo_plc_api.device.Device._get_zeroconf_info") as get_zeroconf_info, pytest.raises(DeviceNotFound):
Expand All @@ -58,7 +58,7 @@ async def test_sync_connect_multicast(self, test_data: TestData):
assert device._multicast
assert get_zeroconf_info.call_count == 2

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("service_browser")
async def test_async_connect_not_found(self, mock_device: Device, sleep: AsyncMock):
Expand All @@ -74,7 +74,7 @@ def test_connect(self, mock_device: Device):
mock_device.connect()
assert ac.call_count == 1

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("service_browser")
async def test_set_password(self, mock_device: Device):
Expand All @@ -86,7 +86,7 @@ async def test_set_password(self, mock_device: Device):
assert mock_device.device.password == "super_secret"
assert mock_device.plcnet.password == "super_secret"

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("http_client", "service_browser")
async def test_async_disconnect(self, mock_device: Device):
Expand All @@ -110,7 +110,7 @@ def test_disconnect(self, mock_device: Device, event_loop: AbstractEventLoop):
mock_device.disconnect()
assert ad.call_count == 1

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("service_browser")
async def test_async_context_manager(self, test_data: TestData):
Expand All @@ -127,7 +127,7 @@ def test_context_manager(self, test_data: TestData):
assert device._connected
assert not device._connected

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_state_change_removed(self, mock_device: Device):
"""Test that service information are not processed on state change to removed."""
with patch("devolo_plc_api.device.Device._retry_zeroconf_info"), patch(
Expand All @@ -136,7 +136,7 @@ async def test_state_change_removed(self, mock_device: Device):
mock_device._state_change(Mock(), PLCNETAPI, PLCNETAPI, ServiceStateChange.Removed)
assert gsi.call_count == 0

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.usefixtures("service_browser", "sleep")
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
async def test_get_service_info_alien(self, mock_info_from_service: Mock):
Expand Down
36 changes: 18 additions & 18 deletions tests/test_deviceapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_feature(self, device_api: DeviceApi):
"""Test list of default features."""
assert device_api.features == ["reset", "update", "led", "intmtg"]

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("block_communication", "service_browser")
@pytest.mark.httpx_mock(can_send_already_matched_responses=True)
Expand All @@ -70,7 +70,7 @@ async def test_wrong_password_type(self, httpx_mock: HTTPXMock, mock_device: Dev

await mock_device.async_disconnect()

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["led"])
async def test_async_get_led_setting(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
"""Test getting LED settings asynchronously."""
Expand All @@ -85,7 +85,7 @@ def test_get_led_setting(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
httpx_mock.add_response(content=led_setting_get.SerializeToString())
assert device_api.get_led_setting()

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["led"])
async def test_async_set_led_setting(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
"""Test setting LED settings asynchronously."""
Expand All @@ -100,7 +100,7 @@ def test_set_led_setting(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
httpx_mock.add_response(content=led_setting_set.SerializeToString())
assert device_api.set_led_setting(enable=True)

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["multiap"])
async def test_async_get_wifi_multi_ap(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
"""Test setting LED settings asynchronously."""
Expand All @@ -117,7 +117,7 @@ def test_get_wifi_multi_ap(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
details = device_api.get_wifi_multi_ap()
assert details.enabled

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["repeater0"])
async def test_async_get_wifi_repeated_access_points(
self, device_api: DeviceApi, httpx_mock: HTTPXMock, repeated_ap: RepeatedAPInfo
Expand All @@ -136,7 +136,7 @@ def test_get_wifi_repeated_access_points(self, device_api: DeviceApi, httpx_mock
wifi_repeated_access_points = device_api.get_wifi_repeated_access_points()
assert wifi_repeated_access_points == [repeated_ap]

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["repeater0"])
async def test_async_start_wps_clone(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
"""Test starting WPS clone mode asynchronously."""
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_factory_reset(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
httpx_mock.add_response(content=reset.SerializeToString())
assert device_api.factory_reset()

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["restart"])
async def test_async_restart(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
"""Test restarting a device asynchronously."""
Expand All @@ -180,7 +180,7 @@ def test_restart(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
httpx_mock.add_response(content=restart.SerializeToString())
assert device_api.restart()

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["restart"])
async def test_async_uptime(self, device_api: DeviceApi, httpx_mock: HTTPXMock, runtime: int):
"""Test getting a device's update asynchronously."""
Expand All @@ -195,7 +195,7 @@ def test_uptime(self, device_api: DeviceApi, httpx_mock: HTTPXMock, runtime: int
httpx_mock.add_response(content=uptime.SerializeToString())
assert device_api.uptime() == runtime

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["support"])
async def test_async_get_support_info(self, device_api: DeviceApi, httpx_mock: HTTPXMock, support_item: SupportInfoItem):
"""Test getting a device's support information asynchronously."""
Expand All @@ -210,7 +210,7 @@ def test_get_support_info(self, device_api: DeviceApi, httpx_mock: HTTPXMock, su
httpx_mock.add_response(content=support_info.SerializeToString())
assert device_api.get_support_info() == support_info.info

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["update"])
async def test_async_check_firmware_available(
self, device_api: DeviceApi, httpx_mock: HTTPXMock, firmware_update: UpdateFirmwareCheck
Expand All @@ -229,7 +229,7 @@ def test_check_firmware_available(
firmware = device_api.check_firmware_available()
assert firmware == firmware_update

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["update"])
async def test_async_start_firmware_update(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
"""Test firmware update asynchronously."""
Expand All @@ -244,7 +244,7 @@ def test_start_firmware_update(self, device_api: DeviceApi, httpx_mock: HTTPXMoc
httpx_mock.add_response(content=firmware_update.SerializeToString())
assert device_api.start_firmware_update()

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["wifi1"])
async def test_async_get_wifi_connected_station(
self, device_api: DeviceApi, httpx_mock: HTTPXMock, connected_station: ConnectedStationInfo
Expand All @@ -265,7 +265,7 @@ def test_get_wifi_connected_station(
connected_stations = device_api.get_wifi_connected_station()
assert connected_stations == [connected_station]

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["wifi1"])
async def test_async_get_wifi_guest_access(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
"""Test getting wifi guest access status asynchronously."""
Expand All @@ -282,7 +282,7 @@ def test_get_wifi_guest_access(self, device_api: DeviceApi, httpx_mock: HTTPXMoc
wifi_guest_access = device_api.get_wifi_guest_access()
assert wifi_guest_access == wifi_guest_access_get

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["wifi1"])
async def test_async_set_wifi_guest_access(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
"""Test setting wifi guest access status asynchronously."""
Expand All @@ -297,7 +297,7 @@ def test_set_wifi_guest_access(self, device_api: DeviceApi, httpx_mock: HTTPXMoc
httpx_mock.add_response(content=wifi_guest_access_set.SerializeToString())
assert device_api.set_wifi_guest_access(enable=True)

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["wifi1"])
async def test_async_get_wifi_neighbor_access_points(
self, device_api: DeviceApi, httpx_mock: HTTPXMock, neighbor_ap: NeighborAPInfo
Expand All @@ -316,7 +316,7 @@ def test_get_wifi_neighbor_access_points(self, device_api: DeviceApi, httpx_mock
wifi_neighbor_access_points = device_api.get_wifi_neighbor_access_points()
assert wifi_neighbor_access_points == [neighbor_ap]

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("feature", ["wifi1"])
async def test_async_start_wps(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
"""Test starting WPS asynchronously."""
Expand All @@ -331,7 +331,7 @@ def test_start_wps(self, device_api: DeviceApi, httpx_mock: HTTPXMock):
httpx_mock.add_response(content=wps.SerializeToString())
assert device_api.start_wps()

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("block_communication", "service_browser")
async def test_device_unavailable(self, httpx_mock: HTTPXMock, mock_device: Device):
Expand All @@ -343,7 +343,7 @@ async def test_device_unavailable(self, httpx_mock: HTTPXMock, mock_device: Devi
await mock_device.device.async_get_wifi_connected_station()
await mock_device.async_disconnect()

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("block_communication", "service_browser")
async def test_attribute_error(self, mock_device: Device):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class TestNetwork:
"""Test devolo_plc_api.network functions."""

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_async_discover_network(self, test_data: TestData, mock_info_from_service: Mock):
"""Test discovering the network asynchronously."""
with patch("devolo_plc_api.network.ServiceBrowser", MockServiceBrowser), patch(
Expand Down
16 changes: 8 additions & 8 deletions tests/test_plcnetapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class TestPlcApi:
"""Test devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi class."""

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("block_communication", "service_browser")
@pytest.mark.httpx_mock(can_send_already_matched_responses=True)
Expand All @@ -41,7 +41,7 @@ async def test_wrong_password_type(self, httpx_mock: HTTPXMock, mock_device: Dev

await mock_device.async_disconnect()

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_async_get_network_overview(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMock, network: LogicalNetwork):
"""Test getting the network overview asynchronously."""
network_overview = GetNetworkOverview(network=network)
Expand All @@ -56,7 +56,7 @@ def test_get_network_overview(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMock
overview = plcnet_api.get_network_overview()
assert overview == network

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_async_identify_device_start(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMock):
"""Test starting identifying a device asynchronously."""
identify_device = IdentifyDeviceResponse()
Expand All @@ -69,7 +69,7 @@ def test_identify_device_start(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMoc
httpx_mock.add_response(content=identify_device.SerializeToString())
assert plcnet_api.identify_device_start()

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_async_identify_device_stop(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMock):
"""Test stopping identifying a device asynchronously."""
identify_device = IdentifyDeviceResponse()
Expand All @@ -82,7 +82,7 @@ def test_identify_device_stop(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMock
httpx_mock.add_response(content=identify_device.SerializeToString())
assert plcnet_api.identify_device_stop()

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_async_pair_device(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMock):
"""Test pairing a device asynchronously."""
pair_device = PairDeviceStart()
Expand All @@ -95,7 +95,7 @@ def test_pair_device(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMock):
httpx_mock.add_response(content=pair_device.SerializeToString())
assert plcnet_api.pair_device()

@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_async_set_user_device_name(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMock):
"""Test setting a device name asynchronously."""
user_device_name_set = SetUserDeviceNameResponse()
Expand All @@ -108,7 +108,7 @@ def test_set_user_device_name(self, plcnet_api: PlcNetApi, httpx_mock: HTTPXMock
httpx_mock.add_response(content=user_device_name_set.SerializeToString())
assert plcnet_api.set_user_device_name("Test")

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("block_communication", "service_browser")
async def test_device_unavailable(self, httpx_mock: HTTPXMock, mock_device: Device):
Expand All @@ -120,7 +120,7 @@ async def test_device_unavailable(self, httpx_mock: HTTPXMock, mock_device: Devi
await mock_device.plcnet.async_get_network_overview()
await mock_device.async_disconnect()

@pytest.mark.asyncio()
@pytest.mark.asyncio
@pytest.mark.parametrize("device_type", [DeviceType.PLC])
@pytest.mark.usefixtures("block_communication", "service_browser")
async def test_attribute_error(self, mock_device: Device):
Expand Down

0 comments on commit 7789ba5

Please sign in to comment.