mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-16 21:18:25 +00:00
Add flake8-pytest-style (PT) for ruff (#1105)
This will catch common issues with pytest code. * Use `match` when using `pytest.raises()` for base exception types like `TypeError` or `ValueError` * Use tuples for `parametrize()` * Enforces `pytest.raises()` to contain simple statements, using `noqa` to skip this on some cases for now. * Fixes incorrect exception type (valueerror instead of typeerror) for iotdimmer. * Adds check valid types for `iotbulb.set_hsv` and `color` smart module. * Consolidate exception messages for common interface modules.
This commit is contained in:
@@ -252,7 +252,7 @@ INVALIDS = [
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("msg, data", INVALIDS)
|
||||
@pytest.mark.parametrize(("msg", "data"), INVALIDS)
|
||||
async def test_discover_invalid_info(msg, data, mocker):
|
||||
"""Make sure that invalid discovery information raises an exception."""
|
||||
host = "127.0.0.1"
|
||||
@@ -304,7 +304,7 @@ async def test_discover_datagram_received(mocker, discovery_data):
|
||||
assert dev.host == addr
|
||||
|
||||
|
||||
@pytest.mark.parametrize("msg, data", INVALIDS)
|
||||
@pytest.mark.parametrize(("msg", "data"), INVALIDS)
|
||||
async def test_discover_invalid_responses(msg, data, mocker):
|
||||
"""Verify that we don't crash whole discovery if some devices in the network are sending unexpected data."""
|
||||
proto = _DiscoverProtocol()
|
||||
@@ -349,7 +349,7 @@ async def test_discover_single_authentication(discovery_mock, mocker):
|
||||
side_effect=AuthenticationError("Failed to authenticate"),
|
||||
)
|
||||
|
||||
with pytest.raises(
|
||||
with pytest.raises( # noqa: PT012
|
||||
AuthenticationError,
|
||||
match="Failed to authenticate",
|
||||
):
|
||||
@@ -495,7 +495,7 @@ async def test_do_discover_drop_packets(mocker, port, do_not_reply_count):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"port, will_timeout",
|
||||
("port", "will_timeout"),
|
||||
[(FakeDatagramTransport.GHOST_PORT, True), (20002, False)],
|
||||
ids=["unknownport", "unsupporteddevice"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user