# 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: examples/microbit_poll.py
# def main():


import dbus
import dbusmock
import io
import subprocess
from pathlib import Path
from unittest import mock, skip
from tests.mock_eventloop import MockAsync, run_pending_events
from examples import microbit_poll
        name = dev.Get('org.bluez.Device1', 'Name')
        alias = dev.Get('org.bluez.Device1', 'Alias')
        self.assertIn('micro:bit', name)
        self.assertIn('micro:bit', alias)

    def test_connect_microbit(self):
        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')
        path = self.dbusmock_bluez.AddDevice('hci0', 'E9:06:4D:45:FC:8D', '')
        dev = self.dbus_con.get_object('org.bluez', path)
        self.assertFalse(dev.Get('org.bluez.Device1', 'Connected'))
        self.dbusmock_bluez.ConnectDevice('hci0', 'E9:06:4D:45:FC:8D')
        self.assertTrue(dev.Get('org.bluez.Device1', 'Connected'))

    def test_poll_example(self):
        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')
        path = self.dbusmock_bluez.AddDevice('hci0', 'E9:06:4D:45:FC:8D', '')
        # self.dbusmock_bluez.ConnectMicroBit()
        # path = dbus.ObjectPath('/org/bluez/hci0/dev_E9_06_4D_45_FC_8D/service003c')
        # srvc_props = dbus.Dictionary({'UUID': 'e95d6100-251d-470a-a062-fa1922dfa9a8',
        #                               'Device': '/org/bluez/hci0/dev_E9_06_4D_45_FC_8D',
        #                               'Primary': True}, signature='sv')
        # self.dbusmock_bluez.AddGattService(path, srvc_props)
        # path = dbus.ObjectPath('/org/bluez/hci0/dev_E9_06_4D_45_FC_8D/service003c/char0040')
        # chrc_props = dbus.Dictionary({
        #     'UUID': 'e95d1b25-251d-470a-a062-fa1922dfa9a8',
        #     'Service': '/org/bluez/hci0/dev_E9_06_4D_45_FC_8D/service003c',
        #     'Value': [], 'Flags': ['read', 'write']}, signature='sv')
        # chrc_props['Value'] = dbus.Array(chrc_props['Value'], signature='y')
        # self.dbusmock_bluez.AddGattCharacteristic(path, chrc_props)
        with mock.patch('time.sleep', return_value=None):

# 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: examples/microbit_poll.py
# def main():


# Path: tests/test_microbit_poll_example.py
import dbus
import dbusmock
import io
import subprocess
from pathlib import Path
from unittest import mock, skip
from tests.mock_eventloop import MockAsync, run_pending_events
from examples import microbit_poll

        name = dev.Get('org.bluez.Device1', 'Name')
        alias = dev.Get('org.bluez.Device1', 'Alias')
        self.assertIn('micro:bit', name)
        self.assertIn('micro:bit', alias)

    def test_connect_microbit(self):
        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')
        path = self.dbusmock_bluez.AddDevice('hci0', 'E9:06:4D:45:FC:8D', '')
        dev = self.dbus_con.get_object('org.bluez', path)
        self.assertFalse(dev.Get('org.bluez.Device1', 'Connected'))
        self.dbusmock_bluez.ConnectDevice('hci0', 'E9:06:4D:45:FC:8D')
        self.assertTrue(dev.Get('org.bluez.Device1', 'Connected'))

    def test_poll_example(self):
        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')
        path = self.dbusmock_bluez.AddDevice('hci0', 'E9:06:4D:45:FC:8D', '')
        # self.dbusmock_bluez.ConnectMicroBit()
        # path = dbus.ObjectPath('/org/bluez/hci0/dev_E9_06_4D_45_FC_8D/service003c')
        # srvc_props = dbus.Dictionary({'UUID': 'e95d6100-251d-470a-a062-fa1922dfa9a8',
        #                               'Device': '/org/bluez/hci0/dev_E9_06_4D_45_FC_8D',
        #                               'Primary': True}, signature='sv')
        # self.dbusmock_bluez.AddGattService(path, srvc_props)
        # path = dbus.ObjectPath('/org/bluez/hci0/dev_E9_06_4D_45_FC_8D/service003c/char0040')
        # chrc_props = dbus.Dictionary({
        #     'UUID': 'e95d1b25-251d-470a-a062-fa1922dfa9a8',
        #     'Service': '/org/bluez/hci0/dev_E9_06_4D_45_FC_8D/service003c',
        #     'Value': [], 'Flags': ['read', 'write']}, signature='sv')
        # chrc_props['Value'] = dbus.Array(chrc_props['Value'], signature='y')
        # self.dbusmock_bluez.AddGattCharacteristic(path, chrc_props)
        with mock.patch('time.sleep', return_value=None):

            microbit_poll.main()