Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ruff B005, B015, B032 and fix occurrences #113543

Merged
merged 8 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/fronius/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def async_step_dhcp(
) -> ConfigFlowResult:
"""Handle a flow initiated by the DHCP client."""
for entry in self._async_current_entries(include_ignore=False):
if entry.data[CONF_HOST].lstrip("http://").rstrip("/").lower() in (
if entry.data[CONF_HOST].removeprefix("http://").rstrip("/").lower() in (
discovery_info.ip,
discovery_info.hostname,
):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/roomba/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def async_step_zeroconf(
) -> ConfigFlowResult:
"""Handle zeroconf discovery."""
return await self._async_step_discovery(
discovery_info.host, discovery_info.hostname.lower().rstrip(".local.")
discovery_info.host, discovery_info.hostname.lower().removesuffix(".local.")
)

async def async_step_dhcp(
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,13 @@ filterwarnings = [
[tool.ruff.lint]
select = [
"B002", # Python does not support the unary prefix increment
"B005", # Using .strip() with multi-character strings is misleading
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
"B015", # Pointless comparison. Did you mean to assign a value? Otherwise, prepend assert or remove it.
"B023", # Function definition does not bind loop variable {name}
"B026", # Star-arg unpacking after a keyword argument is strongly discouraged
"B032", # Possible unintentional type annotation (using :). Did you mean to assign (using =)?
"B904", # Use raise from to specify exception cause
"C", # complexity
"COM818", # Trailing comma on bare tuple prohibited
Expand Down
2 changes: 1 addition & 1 deletion tests/components/alexa/test_state_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ async def test_report_state_number(
}

if unit:
state["unit_of_measurement"]: unit
state["unit_of_measurement"] = unit

hass.states.async_set(
f"{domain}.test_{domain}",
Expand Down
2 changes: 1 addition & 1 deletion tests/components/bluetooth/test_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _allocate_slot_mock(ble_device: BLEDevice):
) as allocate_slot_mock:
ble_device = hci0_device_advs["00:00:00:00:00:03"][0]
client = bleak.BleakClient(ble_device)
await client.connect() is True
assert await client.connect() is True
assert release_slot_mock.call_count == 0

cancel_hci0()
Expand Down
2 changes: 1 addition & 1 deletion tests/components/esphome/bluetooth/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ async def test_client_usage_while_not_connected(client_data: ESPHomeClientData)
with pytest.raises(
BleakError, match=f"{ESP_NAME}.*{ESP_MAC_ADDRESS}.*not connected"
):
await client.write_gatt_char("test", b"test") is False
assert await client.write_gatt_char("test", b"test") is False
12 changes: 6 additions & 6 deletions tests/components/evil_genius_labs/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ async def test_turn_on_color(hass: HomeAssistant, setup_evil_genius_labs) -> Non
)

assert len(mock_set_path_value.mock_calls) == 2
mock_set_path_value.mock_calls[0][1] == ("brightness", 100)
mock_set_path_value.mock_calls[1][1] == ("power", 1)
assert mock_set_path_value.mock_calls[0][1] == ("brightness", 100)
assert mock_set_path_value.mock_calls[1][1] == ("power", 1)

assert len(mock_set_rgb_color.mock_calls) == 1
mock_set_rgb_color.mock_calls[0][1] == (10, 20, 30)
assert mock_set_rgb_color.mock_calls[0][1] == (10, 20, 30)


@pytest.mark.parametrize("platforms", [("light",)])
Expand All @@ -68,8 +68,8 @@ async def test_turn_on_effect(hass: HomeAssistant, setup_evil_genius_labs) -> No
)

assert len(mock_set_path_value.mock_calls) == 2
mock_set_path_value.mock_calls[0][1] == ("pattern", 4)
mock_set_path_value.mock_calls[1][1] == ("power", 1)
assert mock_set_path_value.mock_calls[0][1] == ("pattern", 4)
assert mock_set_path_value.mock_calls[1][1] == ("power", 1)


@pytest.mark.parametrize("platforms", [("light",)])
Expand All @@ -86,4 +86,4 @@ async def test_turn_off(hass: HomeAssistant, setup_evil_genius_labs) -> None:
)

assert len(mock_set_path_value.mock_calls) == 1
mock_set_path_value.mock_calls[0][1] == ("power", 0)
assert mock_set_path_value.mock_calls[0][1] == ("power", 0)
2 changes: 1 addition & 1 deletion tests/components/google/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ async def test_calendar_yaml_update(
assert await component_setup()

mock_calendars_yaml().read.assert_called()
mock_calendars_yaml().write.called is expect_write_calls
assert mock_calendars_yaml().write.called is expect_write_calls

state = hass.states.get(TEST_API_ENTITY)
assert state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1719,9 +1719,12 @@ async def test_multi_pan_addon_using_device_not_running(
"state": "not_running",
}

await silabs_multiprotocol_addon.multi_pan_addon_using_device(
hass, "/dev/ttyAMA1"
) is False
assert (
await silabs_multiprotocol_addon.multi_pan_addon_using_device(
hass, "/dev/ttyAMA1"
)
is False
)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1750,6 +1753,9 @@ async def test_multi_pan_addon_using_device(
"state": "running",
}

await silabs_multiprotocol_addon.multi_pan_addon_using_device(
hass, "/dev/ttyAMA1"
) is expected_result
assert (
await silabs_multiprotocol_addon.multi_pan_addon_using_device(
hass, "/dev/ttyAMA1"
)
is expected_result
)
2 changes: 1 addition & 1 deletion tests/components/media_player/test_browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def test_process_play_media_url(hass: HomeAssistant, mock_sign_path) -> No
)

# Not changing a URL which is not absolute and does not start with /
async_process_play_media_url(hass, "hello") == "hello"
assert async_process_play_media_url(hass, "hello") == "hello"


async def test_process_play_media_url_for_addon(
Expand Down
2 changes: 1 addition & 1 deletion tests/components/recorder/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def test_saving_state_with_commit_interval_zero(
) -> None:
"""Test saving a state with a commit interval of zero."""
hass = hass_recorder({"commit_interval": 0})
get_instance(hass).commit_interval == 0
assert get_instance(hass).commit_interval == 0

entity_id = "test.recorder"
state = "restoring_from_db"
Expand Down
2 changes: 1 addition & 1 deletion tests/components/withings/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ async def test_setup_with_cloud(

for config_entry in hass.config_entries.async_entries("withings"):
await hass.config_entries.async_remove(config_entry.entry_id)
fake_delete_cloudhook.call_count == 2
assert fake_delete_cloudhook.call_count == 2

await hass.async_block_till_done()
assert not hass.config_entries.async_entries(DOMAIN)
Expand Down
2 changes: 1 addition & 1 deletion tests/components/zha/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async def test_gateway_initialize_bellows_thread(
) as mock_new:
await zha_gateway.async_initialize()

mock_new.mock_calls[-1].kwargs["config"]["use_thread"] is thread_state
assert mock_new.mock_calls[-1].kwargs["config"]["use_thread"] is thread_state

await zha_gateway.shutdown()

Expand Down
2 changes: 1 addition & 1 deletion tests/components/zha/test_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ async def test_websocket_change_channel(
assert msg["type"] == const.TYPE_RESULT
assert msg["success"]

change_channel_mock.mock_calls == [call(ANY, new_channel)]
change_channel_mock.assert_has_calls([call(ANY, new_channel)])


@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/test_aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ async def test_sending_named_tuple(
session = client.async_create_clientsession(hass)
resp = await session.post("http://127.0.0.1/rgb", json={"rgb": RGBColor(4, 3, 2)})
assert resp.status == 200
await resp.json() == {"rgb": RGBColor(4, 3, 2)}
aioclient_mock.mock_calls[0][2]["rgb"] == RGBColor(4, 3, 2)
assert await resp.json() == {"rgb": [4, 3, 2]}
assert aioclient_mock.mock_calls[0][2]["rgb"] == RGBColor(4, 3, 2)


async def test_client_session_immutable_headers(hass: HomeAssistant) -> None:
Expand Down