Skip to content

Commit 24ea8ad

Browse files
committed
mitigate lingering timers
1 parent af45ebe commit 24ea8ad

7 files changed

Lines changed: 31 additions & 12 deletions

File tree

tests/conftest.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from collections.abc import Awaitable, Buffer, Callable, Iterable
44
import logging
55
from typing import Any, Final
6-
from unittest.mock import MagicMock
76
from uuid import UUID
87

98
from aiobmsble import BMSInfo, BMSSample, MatcherPattern
@@ -43,16 +42,6 @@ def auto_enable_custom_integrations(enable_custom_integrations: None) -> None:
4342
return
4443

4544

46-
@pytest.fixture(autouse=True)
47-
def fix_HaScanner_patch(monkeypatch: pytest.MonkeyPatch) -> None:
48-
"""Patch HaScanner to avoid BT discovery.
49-
50-
fixes https://github.com/MatthewFlamm/pytest-homeassistant-custom-component/pull/255
51-
TODO: remove when pytest-homeassistant-custom-component is updated or fixed upstream
52-
"""
53-
monkeypatch.setattr("homeassistant.components.bluetooth.HaScanner", MagicMock())
54-
55-
5645
@pytest.fixture(params=[False, True])
5746
def bool_fixture(request: pytest.FixtureRequest) -> bool:
5847
"""Return False, True for tests."""

tests/test_binary_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
SEN_PREFIX: Final[str] = "binary_sensor.config_test_dummy_bms"
2424

25-
2625
@pytest.mark.usefixtures(
2726
"enable_bluetooth", "patch_default_bleak_client", "patch_entity_enabled_default"
2827
) # enable bluetooth, patch bleak client and enable all sensors
28+
@pytest.mark.parametrize("expected_lingering_timers", [True])
2929
async def test_update(
3030
monkeypatch: pytest.MonkeyPatch,
3131
bt_discovery: BluetoothServiceInfoBleak,

tests/test_config_flow.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def bms_adv(request: pytest.FixtureRequest) -> BluetoothServiceInfoBleak:
7070

7171

7272
@pytest.mark.usefixtures("enable_bluetooth")
73+
@pytest.mark.parametrize("expected_lingering_timers", [True])
7374
async def test_bluetooth_discovery(
7475
monkeypatch: pytest.MonkeyPatch,
7576
hass: HomeAssistant,
@@ -136,6 +137,7 @@ async def test_bluetooth_discovery(
136137
ids=["minimal", "full"],
137138
)
138139
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
140+
@pytest.mark.parametrize("expected_lingering_timers", [True])
139141
async def test_device_setup(
140142
monkeypatch: pytest.MonkeyPatch,
141143
bt_discovery: BluetoothServiceInfoBleak,
@@ -190,6 +192,7 @@ async def test_device_setup(
190192

191193

192194
@pytest.mark.usefixtures("enable_bluetooth")
195+
@pytest.mark.parametrize("expected_lingering_timers", [True])
193196
async def test_device_not_supported(
194197
bt_discovery_notsupported: BluetoothServiceInfoBleak, hass: HomeAssistant
195198
) -> None:
@@ -206,6 +209,7 @@ async def test_device_not_supported(
206209

207210

208211
@pytest.mark.usefixtures("enable_bluetooth")
212+
@pytest.mark.parametrize("expected_lingering_timers", [True])
209213
async def test_user_already_configured(hass: HomeAssistant) -> None:
210214
"""Test that same device cannot be added twice."""
211215

@@ -228,6 +232,7 @@ async def test_user_already_configured(hass: HomeAssistant) -> None:
228232

229233

230234
@pytest.mark.usefixtures("enable_bluetooth")
235+
@pytest.mark.parametrize("expected_lingering_timers", [True])
231236
async def test_bluetooth_already_configured(
232237
hass: HomeAssistant, bt_discovery: BluetoothServiceInfoBleak
233238
) -> None:
@@ -249,6 +254,7 @@ async def test_bluetooth_already_configured(
249254

250255

251256
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
257+
@pytest.mark.parametrize("expected_lingering_timers", [True])
252258
async def test_bluetooth_confirm_entry_added_during_flow(
253259
monkeypatch: pytest.MonkeyPatch,
254260
bt_discovery: BluetoothServiceInfoBleak,
@@ -286,6 +292,7 @@ async def test_bluetooth_confirm_entry_added_during_flow(
286292

287293

288294
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
295+
@pytest.mark.parametrize("expected_lingering_timers", [True])
289296
async def test_async_setup_entry(
290297
monkeypatch: pytest.MonkeyPatch,
291298
bms_fixture: str,
@@ -311,6 +318,7 @@ async def test_async_setup_entry(
311318

312319

313320
@pytest.mark.usefixtures("enable_bluetooth")
321+
@pytest.mark.parametrize("expected_lingering_timers", [True])
314322
async def test_setup_entry_missing_unique_id(
315323
bms_fixture: str, hass: HomeAssistant
316324
) -> None:
@@ -328,6 +336,7 @@ async def test_setup_entry_missing_unique_id(
328336
@pytest.mark.usefixtures(
329337
"enable_bluetooth", "patch_default_bleak_client", "patch_entity_enabled_default"
330338
)
339+
@pytest.mark.parametrize("expected_lingering_timers", [True])
331340
async def test_user_setup(
332341
monkeypatch: pytest.MonkeyPatch,
333342
bt_discovery: BluetoothServiceInfoBleak,
@@ -385,6 +394,7 @@ async def test_user_setup(
385394

386395

387396
@pytest.mark.usefixtures("enable_bluetooth")
397+
@pytest.mark.parametrize("expected_lingering_timers", [True])
388398
async def test_user_setup_invalid(
389399
bt_discovery_notsupported: BluetoothServiceInfoBleak, hass: HomeAssistant
390400
) -> None:
@@ -398,6 +408,7 @@ async def test_user_setup_invalid(
398408

399409

400410
@pytest.mark.usefixtures("enable_bluetooth")
411+
@pytest.mark.parametrize("expected_lingering_timers", [True])
401412
async def test_user_setup_double_configure(
402413
monkeypatch: pytest.MonkeyPatch,
403414
bt_discovery: BluetoothServiceInfoBleak,
@@ -422,6 +433,7 @@ def patch_async_current_ids(_self, include_ignore: bool = True) -> set[str | Non
422433

423434

424435
@pytest.mark.usefixtures("enable_bluetooth")
436+
@pytest.mark.parametrize("expected_lingering_timers", [True])
425437
async def test_options_flow(
426438
monkeypatch: pytest.MonkeyPatch, hass: HomeAssistant
427439
) -> None:
@@ -461,6 +473,7 @@ async def test_options_flow(
461473

462474

463475
@pytest.mark.usefixtures("enable_bluetooth")
476+
@pytest.mark.parametrize("expected_lingering_timers", [True])
464477
async def test_options_flow_no_secret(hass: HomeAssistant) -> None:
465478
"""Test if options flow for BMS without secret."""
466479

@@ -487,6 +500,7 @@ async def test_options_flow_no_secret(hass: HomeAssistant) -> None:
487500

488501
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
489502
@pytest.mark.parametrize("keep_alive", [True, False])
503+
@pytest.mark.parametrize("expected_lingering_timers", [True])
490504
async def test_options_effect(
491505
monkeypatch: pytest.MonkeyPatch,
492506
hass: HomeAssistant,
@@ -551,6 +565,7 @@ def mock_bms_init(
551565

552566

553567
@pytest.mark.usefixtures("enable_bluetooth")
568+
@pytest.mark.parametrize("expected_lingering_timers", [True])
554569
async def test_invalid_options_flow(hass: HomeAssistant) -> None:
555570
"""Test config options flow for unsupported BMS type."""
556571

@@ -569,6 +584,7 @@ async def test_invalid_options_flow(hass: HomeAssistant) -> None:
569584

570585

571586
@pytest.mark.usefixtures("enable_bluetooth")
587+
@pytest.mark.parametrize("expected_lingering_timers", [True])
572588
async def test_no_migration(bms_fixture: str, hass: HomeAssistant) -> None:
573589
"""Test that entries of correct version are kept."""
574590

@@ -586,6 +602,7 @@ async def test_no_migration(bms_fixture: str, hass: HomeAssistant) -> None:
586602

587603

588604
@pytest.mark.usefixtures("enable_bluetooth")
605+
@pytest.mark.parametrize("expected_lingering_timers", [True])
589606
async def test_migrate_entry_future_version(hass: HomeAssistant) -> None:
590607
"""Test migrating entries from future version."""
591608

@@ -601,6 +618,7 @@ async def test_migrate_entry_future_version(hass: HomeAssistant) -> None:
601618

602619

603620
@pytest.mark.usefixtures("enable_bluetooth")
621+
@pytest.mark.parametrize("expected_lingering_timers", [True])
604622
async def test_migrate_invalid_v_0_1(bms_fixture: str, hass: HomeAssistant) -> None:
605623
"""Test migrating an invalid entry in version 0.1."""
606624

@@ -616,6 +634,7 @@ async def test_migrate_invalid_v_0_1(bms_fixture: str, hass: HomeAssistant) -> N
616634

617635

618636
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
637+
@pytest.mark.parametrize("expected_lingering_timers", [True])
619638
async def test_migrate_entry_from_v0_1(
620639
monkeypatch: pytest.MonkeyPatch,
621640
mock_config_v0_1: MockConfigEntry,
@@ -643,6 +662,7 @@ async def test_migrate_entry_from_v0_1(
643662

644663

645664
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
665+
@pytest.mark.parametrize("expected_lingering_timers", [True])
646666
async def test_migrate_entry_from_v1_0(
647667
monkeypatch: pytest.MonkeyPatch,
648668
bt_discovery: BluetoothServiceInfoBleak,
@@ -671,6 +691,7 @@ async def test_migrate_entry_from_v1_0(
671691

672692
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
673693
@pytest.mark.parametrize("bms_fixture", ["dummy_bms", "ective_bms"])
694+
@pytest.mark.parametrize("expected_lingering_timers", [True])
674695
async def test_migrate_entry_from_v2_0(
675696
monkeypatch: pytest.MonkeyPatch,
676697
bt_discovery: BluetoothServiceInfoBleak,
@@ -701,6 +722,7 @@ async def test_migrate_entry_from_v2_0(
701722

702723

703724
@pytest.mark.usefixtures("enable_bluetooth")
725+
@pytest.mark.parametrize("expected_lingering_timers", [True])
704726
@pytest.mark.parametrize(
705727
("unique_id_old", "unique_id_new"),
706728
[

tests/test_coordinator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828

2929
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
30+
@pytest.mark.parametrize("expected_lingering_timers", [True])
3031
async def test_update(
3132
monkeypatch: pytest.MonkeyPatch,
3233
bool_fixture: bool,
@@ -84,6 +85,7 @@ def mock_last_service_info(hass: HomeAssistant, address, connectable) -> None:
8485

8586

8687
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
88+
@pytest.mark.parametrize("expected_lingering_timers", [True])
8789
async def test_nodata(
8890
bt_discovery: BluetoothServiceInfoBleak, hass: HomeAssistant
8991
) -> None:
@@ -110,6 +112,7 @@ async def test_nodata(
110112
@pytest.mark.parametrize(
111113
"mock_coordinator_exception", [TimeoutError, BleakError, EOFError]
112114
)
115+
@pytest.mark.parametrize("expected_lingering_timers", [True])
113116
async def test_update_exception(
114117
bt_discovery: BluetoothServiceInfoBleak,
115118
mock_coordinator_exception: Exception,
@@ -130,6 +133,7 @@ async def test_update_exception(
130133

131134

132135
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
136+
@pytest.mark.parametrize("expected_lingering_timers", [True])
133137
async def test_stale_recovery(
134138
monkeypatch: pytest.MonkeyPatch,
135139
bt_discovery: BluetoothServiceInfoBleak,

tests/test_diagnostics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444

4545
@pytest.mark.usefixtures("enable_bluetooth")
46+
@pytest.mark.parametrize("expected_lingering_timers", [True])
4647
async def test_diagnostics(
4748
monkeypatch: pytest.MonkeyPatch,
4849
bool_fixture: bool,

tests/test_init.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
1717
@pytest.mark.parametrize("swap", [False, True], ids=["devinfo", "update"])
18+
@pytest.mark.parametrize("expected_lingering_timers", [True])
1819
async def test_init_fail(
1920
monkeypatch: pytest.MonkeyPatch,
2021
swap: bool,
@@ -65,6 +66,7 @@ async def mock_coord_shutdown(_self) -> None:
6566

6667

6768
@pytest.mark.usefixtures("enable_bluetooth", "patch_default_bleak_client")
69+
@pytest.mark.parametrize("expected_lingering_timers", [True])
6870
async def test_unload_entry(
6971
monkeypatch: pytest.MonkeyPatch,
7072
bool_fixture: bool,

tests/test_sensor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
@pytest.mark.usefixtures(
4141
"enable_bluetooth", "patch_default_bleak_client", "patch_entity_enabled_default"
4242
) # enable bluetooth, patch bleak client and enable all sensors
43+
@pytest.mark.parametrize("expected_lingering_timers", [True])
4344
async def test_update(
4445
monkeypatch: pytest.MonkeyPatch,
4546
bt_discovery: BluetoothServiceInfoBleak,

0 commit comments

Comments
 (0)