mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +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:
@@ -118,7 +118,9 @@ class IotDimmer(IotPlug):
|
||||
)
|
||||
|
||||
if not 0 <= brightness <= 100:
|
||||
raise ValueError("Brightness value %s is not valid." % brightness)
|
||||
raise ValueError(
|
||||
f"Invalid brightness value: {brightness} (valid range: 0-100%)"
|
||||
)
|
||||
|
||||
# Dimmers do not support a brightness of 0, but bulbs do.
|
||||
# Coerce 0 to 1 to maintain the same interface between dimmers and bulbs.
|
||||
@@ -161,20 +163,18 @@ class IotDimmer(IotPlug):
|
||||
A brightness value of 0 will turn off the dimmer.
|
||||
"""
|
||||
if not isinstance(brightness, int):
|
||||
raise ValueError(
|
||||
"Brightness must be integer, " "not of %s.", type(brightness)
|
||||
)
|
||||
raise TypeError(f"Brightness must be an integer, not {type(brightness)}.")
|
||||
|
||||
if not 0 <= brightness <= 100:
|
||||
raise ValueError("Brightness value %s is not valid." % brightness)
|
||||
raise ValueError(
|
||||
f"Invalid brightness value: {brightness} (valid range: 0-100%)"
|
||||
)
|
||||
|
||||
# If zero set to 1 millisecond
|
||||
if transition == 0:
|
||||
transition = 1
|
||||
if not isinstance(transition, int):
|
||||
raise ValueError(
|
||||
"Transition must be integer, " "not of %s.", type(transition)
|
||||
)
|
||||
raise TypeError(f"Transition must be integer, not of {type(transition)}.")
|
||||
if transition <= 0:
|
||||
raise ValueError("Transition value %s is not valid." % transition)
|
||||
|
||||
|
Reference in New Issue
Block a user