Skip to content

Commit

Permalink
chore: fix benchmarks in wrong file (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Dec 22, 2024
1 parent 96e70eb commit 9dbf03c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
19 changes: 11 additions & 8 deletions tests/backend/test_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
BluetoothLERawAdvertisement,
BluetoothLERawAdvertisementsResponse,
)
from habluetooth import BaseHaRemoteScanner, HaBluetoothConnector
from pytest_codspeed import BenchmarkFixture
from bluetooth_data_tools import int_to_bluetooth_address
from habluetooth import BaseHaRemoteScanner, HaBluetoothConnector, get_manager

from bleak_esphome.backend.client import ESPHomeClientData
from bleak_esphome.backend.scanner import ESPHomeScanner
Expand All @@ -18,7 +18,7 @@ def test_scanner() -> None:
assert isinstance(scanner, BaseHaRemoteScanner)


def test_scanner_async_on_advertisement(benchmark: BenchmarkFixture) -> None:
def test_scanner_async_on_advertisement() -> None:
connector = HaBluetoothConnector(ESPHomeClientData, ESP_MAC_ADDRESS, lambda: True)
scanner = ESPHomeScanner(ESP_MAC_ADDRESS, ESP_NAME, connector, True)
adv = BluetoothLERawAdvertisementsResponse(
Expand All @@ -37,8 +37,11 @@ def test_scanner_async_on_advertisement(benchmark: BenchmarkFixture) -> None:
),
]
)

@benchmark
def _benchmark():
for _ in range(1000):
scanner.async_on_raw_advertisements(adv)
scanner.async_on_raw_advertisements(adv)
manager = get_manager()
assert manager.async_last_service_info(
int_to_bluetooth_address(261602360644300), True
)
assert manager.async_last_service_info(
int_to_bluetooth_address(246965243285491), True
)
16 changes: 7 additions & 9 deletions tests/backend/test_scanner_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
BluetoothLERawAdvertisementsResponse,
)
from habluetooth import (
BaseHaRemoteScanner,
HaBluetoothConnector,
)
from pytest_codspeed import BenchmarkFixture

from bleak_esphome.backend.client import ESPHomeClientData
from bleak_esphome.backend.scanner import ESPHomeScanner
Expand All @@ -14,13 +14,7 @@
ESP_NAME = "proxy"


def test_scanner() -> None:
connector = HaBluetoothConnector(ESPHomeClientData, ESP_MAC_ADDRESS, lambda: True)
scanner = ESPHomeScanner(ESP_MAC_ADDRESS, ESP_NAME, connector, True)
assert isinstance(scanner, BaseHaRemoteScanner)


def test_scanner_async_on_advertisement() -> None:
def test_scanner_async_on_advertisement(benchmark: BenchmarkFixture) -> None:
connector = HaBluetoothConnector(ESPHomeClientData, ESP_MAC_ADDRESS, lambda: True)
scanner = ESPHomeScanner(ESP_MAC_ADDRESS, ESP_NAME, connector, True)
adv = BluetoothLERawAdvertisementsResponse(
Expand All @@ -39,4 +33,8 @@ def test_scanner_async_on_advertisement() -> None:
),
]
)
scanner.async_on_raw_advertisements(adv)

@benchmark
def _benchmark():
for _ in range(1000):
scanner.async_on_raw_advertisements(adv)

0 comments on commit 9dbf03c

Please sign in to comment.