# 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()
# 
# Path: examples/adapter_example.py
# def print_dev(device_obj):
# def main():


import dbus
import dbusmock
import io
import subprocess
from pathlib import Path
from unittest import mock
from tests.mock_eventloop import MockAsync
from examples import adapter_example
        cls.start_system_bus()
        cls.dbus_con = cls.get_dbus(True)
        (cls.p_mock, cls.obj_bluez) = cls.spawn_server_template(
            template, {}, stdout=subprocess.PIPE)

    def setUp(self):
        self.obj_bluez.Reset()
        self.dbusmock = dbus.Interface(self.obj_bluez, dbusmock.MOCK_IFACE)
        self.dbusmock_bluez = dbus.Interface(self.obj_bluez, 'org.bluez.Mock')


    @classmethod
    def tearDownClass(cls):
        cls.stop_dbus(cls.system_bus_pid)
        cls.p_mock.terminate()
        cls.p_mock.wait()

    def test_on_device_found(self):

        class ForTest:
            found_address = None

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

        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')

        with mock.patch('bluezero.async_tools.EventLoop', MockAsync):
            with mock.patch('sys.stdout', new=io.StringIO()) as fake_out:

# 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()
# 
# Path: examples/adapter_example.py
# def print_dev(device_obj):
# def main():


# Path: tests/test_adapter_example_db_mock.py
import dbus
import dbusmock
import io
import subprocess
from pathlib import Path
from unittest import mock
from tests.mock_eventloop import MockAsync
from examples import adapter_example

        cls.start_system_bus()
        cls.dbus_con = cls.get_dbus(True)
        (cls.p_mock, cls.obj_bluez) = cls.spawn_server_template(
            template, {}, stdout=subprocess.PIPE)

    def setUp(self):
        self.obj_bluez.Reset()
        self.dbusmock = dbus.Interface(self.obj_bluez, dbusmock.MOCK_IFACE)
        self.dbusmock_bluez = dbus.Interface(self.obj_bluez, 'org.bluez.Mock')


    @classmethod
    def tearDownClass(cls):
        cls.stop_dbus(cls.system_bus_pid)
        cls.p_mock.terminate()
        cls.p_mock.wait()

    def test_on_device_found(self):

        class ForTest:
            found_address = None

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

        self.dbusmock_bluez.AddAdapter('hci0', 'My-Test-Device')

        with mock.patch('bluezero.async_tools.EventLoop', MockAsync):
            with mock.patch('sys.stdout', new=io.StringIO()) as fake_out:

                adapter_example.main()