Kaynağa Gözat

Fix ruff issues in tests

CI filters out tests because there were quite a few issues.
Of the 25 issues from ruff check, 20 were automatically fixable, so
the workload to clear them all up was not great.
Jason Rumney 2 yıl önce
ebeveyn
işleme
f77da842cd

+ 1 - 1
tests/devices/test_arlec_fan_light.py

@@ -3,7 +3,7 @@ from homeassistant.components.fan import (
     DIRECTION_REVERSE,
     FanEntityFeature,
 )
-from homeassistant.components.light import ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ColorMode
+from homeassistant.components.light import ColorMode
 
 from ..const import ARLEC_FAN_LIGHT_PAYLOAD
 from ..helpers import assert_device_properties_set

+ 2 - 2
tests/devices/test_beok_tr9b_thermostat.py

@@ -190,12 +190,12 @@ class TestBeokTR9BThermostat(
     async def test_set_target_temperature_fails_outside_valid_range(self):
         with self.assertRaisesRegex(
             ValueError,
-            f"temperature \\(4.5\\) must be between 5.0 and 1000.0",
+            "temperature \\(4.5\\) must be between 5.0 and 1000.0",
         ):
             await self.subject.async_set_target_temperature(4.5)
         with self.assertRaisesRegex(
             ValueError,
-            f"temperature \\(1001\\) must be between 5.0 and 1000.0",
+            "temperature \\(1001\\) must be between 5.0 and 1000.0",
         ):
             await self.subject.async_set_target_temperature(1001)
 

+ 0 - 1
tests/devices/test_inkbird_itc308_thermostat.py

@@ -4,7 +4,6 @@ from homeassistant.components.number.const import NumberDeviceClass
 from homeassistant.const import UnitOfTemperature, UnitOfTime
 
 from ..const import INKBIRD_ITC308_THERMOSTAT_PAYLOAD
-from ..helpers import assert_device_properties_set
 from ..mixins.binary_sensor import MultiBinarySensorTests
 from ..mixins.climate import TargetTemperatureTests
 from ..mixins.number import MultiNumberTests

+ 0 - 1
tests/devices/test_ir_remote_sensors.py

@@ -2,7 +2,6 @@ from homeassistant.components.sensor import SensorDeviceClass
 from homeassistant.const import PERCENTAGE, UnitOfTemperature
 
 from ..const import IR_REMOTE_SENSORS_PAYLOAD
-from ..helpers import assert_device_properties_set
 from ..mixins.sensor import MultiSensorTests
 from .base_device_tests import TuyaDeviceTestCase
 

+ 2 - 3
tests/devices/test_jiahong_et72w_thermostat.py

@@ -4,7 +4,6 @@ from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDevic
 from homeassistant.const import UnitOfEnergy, UnitOfTemperature
 
 from ..const import JIAHONG_ET72W_PAYLOAD
-from ..helpers import assert_device_properties_set
 from ..mixins.climate import TargetTemperatureTests
 from ..mixins.lock import BasicLockTests
 from ..mixins.number import BasicNumberTests
@@ -202,12 +201,12 @@ class TestJiahongEt72wThermostat(
     async def test_set_target_temperature_fails_outside_valid_range(self):
         with self.assertRaisesRegex(
             ValueError,
-            f"temperature \\(4.5\\) must be between 5.0 and 40.0",
+            "temperature \\(4.5\\) must be between 5.0 and 40.0",
         ):
             await self.subject.async_set_target_temperature(4.5)
         with self.assertRaisesRegex(
             ValueError,
-            f"temperature \\(41\\) must be between 5.0 and 40.0",
+            "temperature \\(41\\) must be between 5.0 and 40.0",
         ):
             await self.subject.async_set_target_temperature(41)
 

+ 0 - 1
tests/devices/test_kyvol_e30_vacuum.py

@@ -2,7 +2,6 @@ from homeassistant.components.button import ButtonDeviceClass
 from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass
 from homeassistant.components.vacuum import (
     STATE_CLEANING,
-    STATE_DOCKED,
     STATE_ERROR,
     STATE_IDLE,
     STATE_PAUSED,

+ 0 - 1
tests/devices/test_lefant_m213_vacuum.py

@@ -1,7 +1,6 @@
 from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass
 from homeassistant.components.vacuum import (
     STATE_CLEANING,
-    STATE_DOCKED,
     STATE_ERROR,
     STATE_IDLE,
     STATE_PAUSED,

+ 0 - 1
tests/devices/test_simple_switch_with_timer.py

@@ -1,6 +1,5 @@
 """Tests for a simple switch with timer"""
 
-from homeassistant.components.switch import SwitchDeviceClass
 from homeassistant.const import UnitOfTime
 
 from ..const import TIMED_SOCKET_PAYLOAD

+ 0 - 1
tests/devices/test_simple_switch_with_timerv2.py

@@ -1,6 +1,5 @@
 """Tests for a simple switch with timer"""
 
-from homeassistant.components.switch import SwitchDeviceClass
 from homeassistant.const import UnitOfTime
 
 from ..const import TIMED_SOCKETV2_PAYLOAD

+ 0 - 1
tests/devices/test_tompd63lw_breaker.py

@@ -5,7 +5,6 @@ from homeassistant.const import (
     UnitOfElectricCurrent,
     UnitOfElectricPotential,
     UnitOfPower,
-    UnitOfTime,
 )
 
 from ..const import TOMPD63LW_SOCKET_PAYLOAD

+ 0 - 2
tests/devices/test_zx_g30_alarm.py

@@ -4,8 +4,6 @@ from homeassistant.components.alarm_control_panel import (
     AlarmControlPanelEntityFeature as Feature,
 )
 from homeassistant.const import (
-    STATE_ALARM_ARMED_AWAY,
-    STATE_ALARM_ARMED_HOME,
     STATE_ALARM_DISARMED,
 )
 

+ 4 - 4
tests/mixins/light.py

@@ -76,14 +76,14 @@ class MultiLightTests:
         self.multiLightDps = {}
         self.multiLightOn = {}
         self.multiLightOff = {}
-        for l in lights:
-            name = l["name"]
+        for light in lights:
+            name = light["name"]
             subject = self.entities.get(name)
-            testdata = l.get("testdata", (True, False))
+            testdata = light.get("testdata", (True, False))
             if subject is None:
                 raise AttributeError(f"No light for {name} found.")
             self.multiLight[name] = subject
-            self.multiLightDps[name] = l.get("dps")
+            self.multiLightDps[name] = light.get("dps")
             self.multiLightOn[name] = testdata[0]
             self.multiLightOff[name] = testdata[1]
 

+ 0 - 1
tests/mixins/lock.py

@@ -1,5 +1,4 @@
 # Mixins for testing locks
-from homeassistant.components.lock import STATE_LOCKED, STATE_UNLOCKED
 
 from ..helpers import assert_device_properties_set
 

+ 0 - 2
tests/test_device.py

@@ -6,8 +6,6 @@ from unittest.mock import ANY, AsyncMock, Mock, call, patch
 from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP
 
 from custom_components.tuya_local.device import TuyaLocalDevice
-from custom_components.tuya_local.helpers.device_config import TuyaEntityConfig
-from custom_components.tuya_local.switch import TuyaLocalSwitch
 
 from .const import EUROM_600_HEATER_PAYLOAD
 

+ 4 - 4
tests/test_device_config.py

@@ -285,7 +285,7 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
         self.assertTrue(found)
 
     def dp_match(self, condition, accounted, unaccounted, known, required=False):
-        if type(condition) is str:
+        if isinstance(condition, str):
             known.add(condition)
             if condition in unaccounted:
                 unaccounted.remove(condition)
@@ -340,18 +340,18 @@ class TestDeviceConfig(IsolatedAsyncioTestCase):
 
         if prior_match:
             for c in conditions:
-                if type(c) is str:
+                if isinstance(c, str):
                     accounted.add(c)
                 elif "and" in c:
                     for c2 in c["and"]:
-                        if type(c2) is str:
+                        if isinstance(c2, str):
                             accounted.add(c2)
 
         return prior_match or not required
 
     def rule_broken_msg(self, rule):
         msg = ""
-        if type(rule) is str:
+        if isinstance(rule, str):
             return f"{msg} {rule}"
         elif "and" in rule:
             msg = f"{msg} all of ["