<commit_before>"""Tests for the Bluetooth integration."""


from unittest.mock import patch

import bleak
from bleak.backends.device import BLEDevice
import bleak_retry_connector

from homeassistant.components.bluetooth.models import (
    HaBleakClientWrapper,
    HaBleakScannerWrapper,
)
from homeassistant.components.bluetooth.usage import (
    install_multiple_bleak_catcher,
    uninstall_multiple_bleak_catcher,
)

from . import _get_manager

MOCK_BLE_DEVICE = BLEDevice(
    "00:00:00:00:00:00", "any", delegate="", details={"path": "/dev/hci0/device"}
)


async def test_multiple_bleak_scanner_instances(hass):
    """Test creating multiple BleakScanners without an integration."""
    install_multiple_bleak_catcher()

    instance = bleak.BleakScanner()

    assert isinstance(instance, HaBleakScannerWrapper)

    uninstall_multiple_bleak_catcher()

    instance = bleak.BleakScanner()

    assert not isinstance(instance, HaBleakScannerWrapper)


async def test_wrapping_bleak_client(hass, enable_bluetooth):
    """Test we wrap BleakClient."""
    install_multiple_bleak_catcher()

    instance = bleak.BleakClient(MOCK_BLE_DEVICE)

    assert isinstance(instance, HaBleakClientWrapper)

    uninstall_multiple_bleak_catcher()

    instance = bleak.BleakClient(MOCK_BLE_DEVICE)

    assert not isinstance(instance, HaBleakClientWrapper)<commit_msg>Ensure we do not actually create a BleakScanner in the usage test (#81362)<commit_after>"""Tests for the Bluetooth integration."""


from unittest.mock import patch

import bleak
from bleak.backends.device import BLEDevice
import bleak_retry_connector

from homeassistant.components.bluetooth.models import (
    HaBleakClientWrapper,
    HaBleakScannerWrapper,
)
from homeassistant.components.bluetooth.usage import (
    install_multiple_bleak_catcher,
    uninstall_multiple_bleak_catcher,
)

from . import _get_manager

MOCK_BLE_DEVICE = BLEDevice(
    "00:00:00:00:00:00", "any", delegate="", details={"path": "/dev/hci0/device"}
)


async def test_multiple_bleak_scanner_instances(hass):
    """Test creating multiple BleakScanners without an integration."""
    install_multiple_bleak_catcher()

    instance = bleak.BleakScanner()

    assert isinstance(instance, HaBleakScannerWrapper)

    uninstall_multiple_bleak_catcher()

    with patch("bleak.get_platform_scanner_backend_type"):
        instance = bleak.BleakScanner()

    assert not isinstance(instance, HaBleakScannerWrapper)


async def test_wrapping_bleak_client(hass, enable_bluetooth):
    """Test we wrap BleakClient."""
    install_multiple_bleak_catcher()

    instance = bleak.BleakClient(MOCK_BLE_DEVICE)

    assert isinstance(instance, HaBleakClientWrapper)

    uninstall_multiple_bleak_catcher()

    instance = bleak.BleakClient(MOCK_BLE_DEVICE)

    assert not isinstance(instance, HaBleakClientWrapper)
{'fraction_non_alphanumeric': 0.08315789473684211, 'fraction_numerical': 0.01087719298245614, 'mean_word_length': 5.5091324200913245, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6802801', 'n_tokens_mistral': 944, 'n_tokens_neox': 884, 'n_words': 175}