mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-21 20:20:11 +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:
@@ -46,13 +46,23 @@ async def test_set_brightness_transition(dev, turn_on, mocker):
|
||||
|
||||
@dimmer_iot
|
||||
async def test_set_brightness_invalid(dev):
|
||||
for invalid_brightness in [-1, 101, 0.5]:
|
||||
with pytest.raises(ValueError):
|
||||
for invalid_brightness in [-1, 101]:
|
||||
with pytest.raises(ValueError, match="Invalid brightness"):
|
||||
await dev.set_brightness(invalid_brightness)
|
||||
|
||||
for invalid_transition in [-1, 0.5]:
|
||||
with pytest.raises(ValueError):
|
||||
for invalid_type in [0.5, "foo"]:
|
||||
with pytest.raises(TypeError, match="Brightness must be an integer"):
|
||||
await dev.set_brightness(invalid_type)
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
async def test_set_brightness_invalid_transition(dev):
|
||||
for invalid_transition in [-1]:
|
||||
with pytest.raises(ValueError, match="Transition value .+? is not valid."):
|
||||
await dev.set_brightness(1, transition=invalid_transition)
|
||||
for invalid_type in [0.5, "foo"]:
|
||||
with pytest.raises(TypeError, match="Transition must be integer"):
|
||||
await dev.set_brightness(1, transition=invalid_type)
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
@@ -128,14 +138,24 @@ async def test_set_dimmer_transition_to_off(dev, turn_on, mocker):
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
async def test_set_dimmer_transition_invalid(dev):
|
||||
for invalid_brightness in [-1, 101, 0.5]:
|
||||
with pytest.raises(ValueError):
|
||||
async def test_set_dimmer_transition_invalid_brightness(dev):
|
||||
for invalid_brightness in [-1, 101]:
|
||||
with pytest.raises(ValueError, match="Invalid brightness value: "):
|
||||
await dev.set_dimmer_transition(invalid_brightness, 1000)
|
||||
|
||||
for invalid_transition in [-1, 0.5]:
|
||||
with pytest.raises(ValueError):
|
||||
await dev.set_dimmer_transition(1, invalid_transition)
|
||||
for invalid_type in [0.5, "foo"]:
|
||||
with pytest.raises(TypeError, match="Transition must be integer"):
|
||||
await dev.set_dimmer_transition(1, invalid_type)
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
async def test_set_dimmer_transition_invalid_transition(dev):
|
||||
for invalid_transition in [-1]:
|
||||
with pytest.raises(ValueError, match="Transition value .+? is not valid."):
|
||||
await dev.set_dimmer_transition(1, transition=invalid_transition)
|
||||
for invalid_type in [0.5, "foo"]:
|
||||
with pytest.raises(TypeError, match="Transition must be integer"):
|
||||
await dev.set_dimmer_transition(1, transition=invalid_type)
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
|
||||
Reference in New Issue
Block a user