From aec7a67a58e9da61f5f6620a61ea81990f14d1ca Mon Sep 17 00:00:00 2001 From: Sid <27780930+autinerd@users.noreply.github.com> Date: Fri, 29 Mar 2024 23:58:30 +0100 Subject: [PATCH] Unignore Ruff PLE, PLW in tests (#114406) * Unignore Ruff PLE, PLW in tests * fix tests --- tests/components/google_assistant/test_helpers.py | 5 ++++- tests/components/history/test_init.py | 2 +- tests/components/history/test_init_db_schema_30.py | 2 +- tests/components/recorder/test_history.py | 2 +- .../components/recorder/test_history_db_schema_30.py | 2 +- .../components/recorder/test_history_db_schema_32.py | 2 +- .../components/recorder/test_history_db_schema_42.py | 2 +- tests/components/template/test_config_flow.py | 2 +- tests/components/xiaomi/test_device_tracker.py | 2 +- tests/ruff.toml | 12 ------------ tests/testing_config/custom_components/test/light.py | 2 +- tests/testing_config/custom_components/test/lock.py | 2 +- .../testing_config/custom_components/test/remote.py | 2 +- .../testing_config/custom_components/test/weather.py | 2 +- 14 files changed, 16 insertions(+), 25 deletions(-) diff --git a/tests/components/google_assistant/test_helpers.py b/tests/components/google_assistant/test_helpers.py index 3f7fd91fed2..492f1be1829 100644 --- a/tests/components/google_assistant/test_helpers.py +++ b/tests/components/google_assistant/test_helpers.py @@ -344,7 +344,10 @@ def test_supported_features_string(caplog: pytest.LogCaptureFixture) -> None: State("test.entity_id", "on", {"supported_features": "invalid"}), ) assert entity.is_supported() is False - assert "Entity test.entity_id contains invalid supported_features value invalid" + assert ( + "Entity test.entity_id contains invalid supported_features value invalid" + in caplog.text + ) def test_request_data() -> None: diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py index 13574bb2bb2..5d9cb86f9b6 100644 --- a/tests/components/history/test_init.py +++ b/tests/components/history/test_init.py @@ -87,7 +87,7 @@ def test_get_significant_states_minimal_response(hass_history) -> None: entity_states = states[entity_id] for state_idx in range(1, len(entity_states)): input_state = entity_states[state_idx] - orig_last_changed = orig_last_changed = json.dumps( + orig_last_changed = json.dumps( process_timestamp(input_state.last_changed), cls=JSONEncoder, ).replace('"', "") diff --git a/tests/components/history/test_init_db_schema_30.py b/tests/components/history/test_init_db_schema_30.py index 0bbd913ce2b..ce5c5a4b6c6 100644 --- a/tests/components/history/test_init_db_schema_30.py +++ b/tests/components/history/test_init_db_schema_30.py @@ -96,7 +96,7 @@ def test_get_significant_states_minimal_response(legacy_hass_history) -> None: entity_states = states[entity_id] for state_idx in range(1, len(entity_states)): input_state = entity_states[state_idx] - orig_last_changed = orig_last_changed = json.dumps( + orig_last_changed = json.dumps( process_timestamp(input_state.last_changed), cls=JSONEncoder, ).replace('"', "") diff --git a/tests/components/recorder/test_history.py b/tests/components/recorder/test_history.py index d16a6856399..04204cf84a6 100644 --- a/tests/components/recorder/test_history.py +++ b/tests/components/recorder/test_history.py @@ -554,7 +554,7 @@ def test_get_significant_states_minimal_response( entity_states = states[entity_id] for state_idx in range(1, len(entity_states)): input_state = entity_states[state_idx] - orig_last_changed = orig_last_changed = json.dumps( + orig_last_changed = json.dumps( process_timestamp(input_state.last_changed), cls=JSONEncoder, ).replace('"', "") diff --git a/tests/components/recorder/test_history_db_schema_30.py b/tests/components/recorder/test_history_db_schema_30.py index cbe4c3ac5c8..0aaf1ebb094 100644 --- a/tests/components/recorder/test_history_db_schema_30.py +++ b/tests/components/recorder/test_history_db_schema_30.py @@ -328,7 +328,7 @@ def test_get_significant_states_minimal_response( entity_states = states[entity_id] for state_idx in range(1, len(entity_states)): input_state = entity_states[state_idx] - orig_last_changed = orig_last_changed = json.dumps( + orig_last_changed = json.dumps( process_timestamp(input_state.last_changed), cls=JSONEncoder, ).replace('"', "") diff --git a/tests/components/recorder/test_history_db_schema_32.py b/tests/components/recorder/test_history_db_schema_32.py index b926aa1903b..9bb6d70b125 100644 --- a/tests/components/recorder/test_history_db_schema_32.py +++ b/tests/components/recorder/test_history_db_schema_32.py @@ -327,7 +327,7 @@ def test_get_significant_states_minimal_response( entity_states = states[entity_id] for state_idx in range(1, len(entity_states)): input_state = entity_states[state_idx] - orig_last_changed = orig_last_changed = json.dumps( + orig_last_changed = json.dumps( process_timestamp(input_state.last_changed), cls=JSONEncoder, ).replace('"', "") diff --git a/tests/components/recorder/test_history_db_schema_42.py b/tests/components/recorder/test_history_db_schema_42.py index 98ed6089de6..a72345e71bd 100644 --- a/tests/components/recorder/test_history_db_schema_42.py +++ b/tests/components/recorder/test_history_db_schema_42.py @@ -556,7 +556,7 @@ def test_get_significant_states_minimal_response( entity_states = states[entity_id] for state_idx in range(1, len(entity_states)): input_state = entity_states[state_idx] - orig_last_changed = orig_last_changed = json.dumps( + orig_last_changed = json.dumps( process_timestamp(input_state.last_changed), cls=JSONEncoder, ).replace('"', "") diff --git a/tests/components/template/test_config_flow.py b/tests/components/template/test_config_flow.py index 30d6942750c..0a34dff9776 100644 --- a/tests/components/template/test_config_flow.py +++ b/tests/components/template/test_config_flow.py @@ -754,7 +754,7 @@ async def test_option_flow_preview( """Test the option flow preview.""" client = await hass_ws_client(hass) - input_entities = input_entities = ["one", "two"] + input_entities = ["one", "two"] # Setup the config entry config_entry = MockConfigEntry( diff --git a/tests/components/xiaomi/test_device_tracker.py b/tests/components/xiaomi/test_device_tracker.py index 0a576b70bdf..1b1d898add1 100644 --- a/tests/components/xiaomi/test_device_tracker.py +++ b/tests/components/xiaomi/test_device_tracker.py @@ -48,7 +48,7 @@ def mocked_requests(*args, **kwargs): raise requests.HTTPError(self.status_code) data = kwargs.get("data") - global FIRST_CALL + global FIRST_CALL # noqa: PLW0603 if data and data.get("username", None) == INVALID_USERNAME: # deliver an invalid token diff --git a/tests/ruff.toml b/tests/ruff.toml index 76e4feacdd2..1a8876b9171 100644 --- a/tests/ruff.toml +++ b/tests/ruff.toml @@ -2,22 +2,10 @@ extend = "../pyproject.toml" [lint] -extend-select = [ - "PT001", # Use @pytest.fixture without parentheses - "PT002", # Configuration for fixture specified via positional args, use kwargs - "PT003", # The scope='function' is implied in @pytest.fixture() - "PT006", # Single parameter in parameterize is a string, multiple a tuple - "PT013", # Found incorrect pytest import, use simple import pytest instead - "PT015", # Assertion always fails, replace with pytest.fail() - "PT021", # use yield instead of request.addfinalizer - "PT022", # No teardown in fixture, replace useless yield with return -] extend-ignore = [ "PLC", # pylint - "PLE", # pylint "PLR", # pylint - "PLW", # pylint "B904", # Use raise from to specify exception cause "N815", # Variable {name} in class scope should not be mixedCase ] diff --git a/tests/testing_config/custom_components/test/light.py b/tests/testing_config/custom_components/test/light.py index eed98a8210a..4cd49fec606 100644 --- a/tests/testing_config/custom_components/test/light.py +++ b/tests/testing_config/custom_components/test/light.py @@ -13,7 +13,7 @@ ENTITIES = [] def init(empty=False): """Initialize the platform with entities.""" - global ENTITIES + global ENTITIES # noqa: PLW0603 ENTITIES = ( [] diff --git a/tests/testing_config/custom_components/test/lock.py b/tests/testing_config/custom_components/test/lock.py index ba5a91e2d24..e97d3f8de22 100644 --- a/tests/testing_config/custom_components/test/lock.py +++ b/tests/testing_config/custom_components/test/lock.py @@ -12,7 +12,7 @@ ENTITIES = {} def init(empty=False): """Initialize the platform with entities.""" - global ENTITIES + global ENTITIES # noqa: PLW0603 ENTITIES = ( {} diff --git a/tests/testing_config/custom_components/test/remote.py b/tests/testing_config/custom_components/test/remote.py index 541215f1c47..3226c93310c 100644 --- a/tests/testing_config/custom_components/test/remote.py +++ b/tests/testing_config/custom_components/test/remote.py @@ -13,7 +13,7 @@ ENTITIES = [] def init(empty=False): """Initialize the platform with entities.""" - global ENTITIES + global ENTITIES # noqa: PLW0603 ENTITIES = ( [] diff --git a/tests/testing_config/custom_components/test/weather.py b/tests/testing_config/custom_components/test/weather.py index 0e99ef48680..b051531b9e8 100644 --- a/tests/testing_config/custom_components/test/weather.py +++ b/tests/testing_config/custom_components/test/weather.py @@ -33,7 +33,7 @@ ENTITIES = [] def init(empty=False): """Initialize the platform with entities.""" - global ENTITIES + global ENTITIES # noqa: PLW0603 ENTITIES = [] if empty else [MockWeather()]