Enable Ruff B017 (#115335)

This commit is contained in:
Sid 2024-04-15 22:25:09 +02:00 committed by GitHub
parent c7e6f3696f
commit 5f055a64bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 16 additions and 11 deletions

View File

@ -668,6 +668,7 @@ select = [
"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.
"B017", # pytest.raises(BaseException) should be considered evil
"B018", # Found useless attribute access. Either assign it to a variable or remove it.
"B023", # Function definition does not bind loop variable {name}
"B026", # Star-arg unpacking after a keyword argument is strongly discouraged

View File

@ -107,7 +107,7 @@ class FakeBleakClientRaisesOnConnect(BaseFakeBleakClient):
async def connect(self, *args, **kwargs):
"""Connect."""
raise Exception("Test exception")
raise ConnectionError("Test exception")
def _generate_ble_device_and_adv_data(
@ -304,8 +304,9 @@ async def test_release_slot_on_connect_exception(
):
ble_device = hci0_device_advs["00:00:00:00:00:01"][0]
client = bleak.BleakClient(ble_device)
with pytest.raises(Exception):
assert await client.connect() is False
with pytest.raises(ConnectionError) as exc_info:
await client.connect()
assert str(exc_info.value) == "Test exception"
assert allocate_slot_mock.call_count == 1
assert release_slot_mock.call_count == 1

View File

@ -15,9 +15,10 @@ async def test_await_or_reraise(hass: HomeAssistant) -> None:
async_noop = async_returns(None)
await await_or_reraise(async_noop())
with pytest.raises(Exception):
async_ex = async_raises(Exception)
with pytest.raises(Exception) as exc_info:
async_ex = async_raises(Exception("Test exception"))
await await_or_reraise(async_ex())
assert str(exc_info.value) == "Test exception"
with pytest.raises(HomeAssistantError):
async_ex = async_raises(AqualinkServiceException)

View File

@ -2,6 +2,7 @@
from unittest.mock import AsyncMock, Mock
from awesomeversion.exceptions import AwesomeVersionStrategyException
from freezegun.api import FrozenDateTimeFactory
import pytest
@ -145,7 +146,7 @@ async def test_create_issue_invalid_version(
"translation_placeholders": {"abc": "123"},
}
with pytest.raises(Exception):
with pytest.raises(AwesomeVersionStrategyException):
async_create_issue(
hass,
issue["domain"],

View File

@ -370,9 +370,9 @@ async def test_remove_entry_installedapp_unknown_error(
) -> None:
"""Test raises exceptions removing the installed app."""
# Arrange
smartthings_mock.delete_installed_app.side_effect = Exception
smartthings_mock.delete_installed_app.side_effect = ValueError
# Act
with pytest.raises(Exception):
with pytest.raises(ValueError):
await smartthings.async_remove_entry(hass, config_entry)
# Assert
assert smartthings_mock.delete_installed_app.call_count == 1
@ -403,9 +403,9 @@ async def test_remove_entry_app_unknown_error(
) -> None:
"""Test raises exceptions removing the app."""
# Arrange
smartthings_mock.delete_app.side_effect = Exception
smartthings_mock.delete_app.side_effect = ValueError
# Act
with pytest.raises(Exception):
with pytest.raises(ValueError):
await smartthings.async_remove_entry(hass, config_entry)
# Assert
assert smartthings_mock.delete_installed_app.call_count == 1

View File

@ -346,8 +346,9 @@ async def test_component_base_exception_setup(hass: HomeAssistant) -> None:
mock_integration(hass, MockModule("comp", setup=exception_setup))
with pytest.raises(BaseException):
with pytest.raises(BaseException) as exc_info:
await setup.async_setup_component(hass, "comp", {})
assert str(exc_info.value) == "fail!"
assert "comp" not in hass.config.components