# Path: tests/mock_eventloop.py
# class MockAsync:
# 
#     def __init__(self):
#         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
#         self.mainloop = GLib.MainLoop()
# 
#     def run(self):
#         main_context = GLib.MainContext.default()
#         while main_context.pending():
#             main_context.iteration(False)
# 
#     def quit(self):
#         self.mainloop.quit()
# 
# def run_pending_events():
#     """
#     Iterate event loop until all pending events are cleared
#     """
#     main_context = GLib.MainContext.default()
#     while main_context.pending():
#         main_context.iteration(False)
# 
# Path: bluezero/adapter.py
# class AdapterError(Exception):
# class Adapter:
# def list_adapters():
#     def available():
#     def __new__(cls, adapter_addr=None, *args, **kwargs):
#     def __init__(self, adapter_addr=None):
#     def address(self):
#     def name(self):
#     def bt_class(self):
#     def alias(self):
#     def alias(self, new_alias):
#     def get_all(self):
#     def powered(self):
#     def powered(self, new_state):
#     def pairable(self):
#     def pairable(self, new_state):
#     def pairabletimeout(self):
#     def pairabletimeout(self, new_timeout):
#     def discoverable(self):
#     def discoverable(self, new_state):
#     def discoverabletimeout(self):
#     def discoverabletimeout(self, new_timeout):
#     def discovering(self):
#     def _discovering_timeout(self):
#     def uuids(self):
#     def nearby_discovery(self, timeout=10):
#     def show_duplicates(self):
#     def hide_duplicates(self):
#     def start_discovery(self):
#     def stop_discovery(self):
#     def remove_device(self, device_path):
#     def run(self):
#     def quit(self):
#     def _properties_changed(self, interface, changed, invalidated, path):
#     def _device_added(self, dbus_mngr, device_address):
#     def _interfaces_removed(self, path, device_info):
# 
# Path: bluezero/adapter.py
# class AdapterError(Exception):
#     """Custom exception for missing Bluetooth adapter"""
#     pass
# 
# Path: bluezero/observer.py
# DEVICE_INTERFACE = 'org.bluez.Device1'
# EDDYSTONE_SRV_UUID = '0000feaa-0000-1000-8000-00805f9b34fb'
# class Scanner:
#     def start_event_loop(cls):
#     def stop_scan(cls):
#     def clean_beacons(cls):
#     def process_eddystone(cls, data, rssi):
#     def process_ibeacon(cls, data, rssi, beacon_type='iBeacon'):
#     def ble_16bit_match(uuid_16, srv_data):
#     def on_device_found(cls, bz_device_obj):
#     def start_beacon_scan(cls,
#                           on_eddystone_url=None,
#                           on_eddystone_uid=None,
#                           on_ibeacon=None,
#                           on_altbeacon=None):
# def scan_eddystone(on_data=None):


import dbus
import dbusmock
import subprocess
from pathlib import Path
from unittest import mock, skip
from tests.mock_eventloop import MockAsync, run_pending_events
from bluezero import adapter
from bluezero.adapter import AdapterError
from bluezero import observer

    def test_one_adapter_available(self):
        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')
        dongles = adapter.Adapter.available()
        for dongle in dongles:
            self.assertEqual('My-Test-Device', dongle.name)
            self.assertEqual('00:01:02:03:04:05', dongle.address)
            self.assertEqual('0x10c', hex(dongle.bt_class))
            self.assertEqual('My-Test-Device', dongle.alias)
            dongle.alias = 'New Alias'
            self.assertEqual('New Alias', dongle.alias)
            self.assertEqual(True, dongle.powered)

    @skip
    def test_on_device_found(self):
        device_address = '11:01:02:03:04:05'

        class ForTest:
            found_address = None

            @classmethod
            def new_dev(cls, device):
                cls.found_address = device.address

        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')
        dongle = adapter.Adapter()
        dongle.on_device_found = ForTest.new_dev
        self.dbusmock_bluez.AddDevice('hci0',
                                      device_address,
                                      'My-Peripheral-Device')

# Path: tests/mock_eventloop.py
# class MockAsync:
# 
#     def __init__(self):
#         dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
#         self.mainloop = GLib.MainLoop()
# 
#     def run(self):
#         main_context = GLib.MainContext.default()
#         while main_context.pending():
#             main_context.iteration(False)
# 
#     def quit(self):
#         self.mainloop.quit()
# 
# def run_pending_events():
#     """
#     Iterate event loop until all pending events are cleared
#     """
#     main_context = GLib.MainContext.default()
#     while main_context.pending():
#         main_context.iteration(False)
# 
# Path: bluezero/adapter.py
# class AdapterError(Exception):
# class Adapter:
# def list_adapters():
#     def available():
#     def __new__(cls, adapter_addr=None, *args, **kwargs):
#     def __init__(self, adapter_addr=None):
#     def address(self):
#     def name(self):
#     def bt_class(self):
#     def alias(self):
#     def alias(self, new_alias):
#     def get_all(self):
#     def powered(self):
#     def powered(self, new_state):
#     def pairable(self):
#     def pairable(self, new_state):
#     def pairabletimeout(self):
#     def pairabletimeout(self, new_timeout):
#     def discoverable(self):
#     def discoverable(self, new_state):
#     def discoverabletimeout(self):
#     def discoverabletimeout(self, new_timeout):
#     def discovering(self):
#     def _discovering_timeout(self):
#     def uuids(self):
#     def nearby_discovery(self, timeout=10):
#     def show_duplicates(self):
#     def hide_duplicates(self):
#     def start_discovery(self):
#     def stop_discovery(self):
#     def remove_device(self, device_path):
#     def run(self):
#     def quit(self):
#     def _properties_changed(self, interface, changed, invalidated, path):
#     def _device_added(self, dbus_mngr, device_address):
#     def _interfaces_removed(self, path, device_info):
# 
# Path: bluezero/adapter.py
# class AdapterError(Exception):
#     """Custom exception for missing Bluetooth adapter"""
#     pass
# 
# Path: bluezero/observer.py
# DEVICE_INTERFACE = 'org.bluez.Device1'
# EDDYSTONE_SRV_UUID = '0000feaa-0000-1000-8000-00805f9b34fb'
# class Scanner:
#     def start_event_loop(cls):
#     def stop_scan(cls):
#     def clean_beacons(cls):
#     def process_eddystone(cls, data, rssi):
#     def process_ibeacon(cls, data, rssi, beacon_type='iBeacon'):
#     def ble_16bit_match(uuid_16, srv_data):
#     def on_device_found(cls, bz_device_obj):
#     def start_beacon_scan(cls,
#                           on_eddystone_url=None,
#                           on_eddystone_uid=None,
#                           on_ibeacon=None,
#                           on_altbeacon=None):
# def scan_eddystone(on_data=None):


# Path: tests/test_observer.py
import dbus
import dbusmock
import subprocess
from pathlib import Path
from unittest import mock, skip
from tests.mock_eventloop import MockAsync, run_pending_events
from bluezero import adapter
from bluezero.adapter import AdapterError
from bluezero import observer


    def test_one_adapter_available(self):
        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')
        dongles = adapter.Adapter.available()
        for dongle in dongles:
            self.assertEqual('My-Test-Device', dongle.name)
            self.assertEqual('00:01:02:03:04:05', dongle.address)
            self.assertEqual('0x10c', hex(dongle.bt_class))
            self.assertEqual('My-Test-Device', dongle.alias)
            dongle.alias = 'New Alias'
            self.assertEqual('New Alias', dongle.alias)
            self.assertEqual(True, dongle.powered)

    @skip
    def test_on_device_found(self):
        device_address = '11:01:02:03:04:05'

        class ForTest:
            found_address = None

            @classmethod
            def new_dev(cls, device):
                cls.found_address = device.address

        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')
        dongle = adapter.Adapter()
        dongle.on_device_found = ForTest.new_dev
        self.dbusmock_bluez.AddDevice('hci0',
                                      device_address,
                                      'My-Peripheral-Device')

        run_pending_events()