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

chore: fix benchmarks in wrong file #46

Merged
merged 1 commit into from
Dec 22, 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
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)
Loading