# Path: xpaw/eventbus.py
# class EventBus:
#     def __init__(self):
#         self._refs = {}
# 
#     def subscribe(self, receiver, event):
#         if event not in self._refs:
#             self._refs[event] = {}
#         if not hasattr(receiver, '__func__') or not hasattr(receiver, '__self__'):
#             raise ValueError("Failed to subscribe, {} has no attribute '__func__' or '__self__'".format(receiver))
#         i = self._calc_id(receiver)
#         if i in self._refs[event]:
#             f = self._refs[event][i]()
#             if f is not None:
#                 return
#         self._refs[event][i] = weakref.WeakMethod(receiver)
# 
#     def unsubscribe(self, receiver, event):
#         if event in self._refs:
#             i = self._calc_id(receiver)
#             if i in self._refs[event]:
#                 del self._refs[event][i]
# 
#     async def send(self, event, **kwargs):
#         if event not in self._refs:
#             return
#         del_list = []
#         for i in self._refs[event]:
#             f = self._refs[event][i]()
#             if f is None:
#                 del_list.append(i)
#             else:
#                 try:
#                     res = f(**kwargs)
#                     if inspect.iscoroutine(res):
#                         await res
#                 except CancelledError:
#                     raise
#                 except Exception:
#                     log.warning("Failed to send the event", exc_info=True)
#         for i in del_list:
#             del self._refs[event][i]
#         del del_list
# 
#     def _calc_id(self, receiver):
#         return hash((id(receiver.__func__), id(receiver.__self__)))


import pytest
from xpaw.eventbus import EventBus
    eventbus = EventBus()
    obj = FooClass()
    eventbus.subscribe(obj.method1, event1)
    await eventbus.send(event1)
    assert obj.count1 == 1
    eventbus.unsubscribe(obj.method1, event1)
    await eventbus.send(event1)
    assert obj.count1 == 1


@pytest.mark.asyncio
async def test_unsubscribe_multi_times():
    eventbus = EventBus()
    obj = FooClass()
    eventbus.subscribe(obj.method1, event1)
    eventbus.unsubscribe(obj.method1, event1)
    eventbus.unsubscribe(obj.method1, event1)


@pytest.mark.asyncio
async def test_send_with_parameters():
    eventbus = EventBus()
    obj = FooClass()
    eventbus.subscribe(obj.method_set_value, event1)
    await eventbus.send(event1, value=-1)
    assert obj.value == -1


@pytest.mark.asyncio
async def test_send_unknown_event():

# Path: xpaw/eventbus.py
# class EventBus:
#     def __init__(self):
#         self._refs = {}
# 
#     def subscribe(self, receiver, event):
#         if event not in self._refs:
#             self._refs[event] = {}
#         if not hasattr(receiver, '__func__') or not hasattr(receiver, '__self__'):
#             raise ValueError("Failed to subscribe, {} has no attribute '__func__' or '__self__'".format(receiver))
#         i = self._calc_id(receiver)
#         if i in self._refs[event]:
#             f = self._refs[event][i]()
#             if f is not None:
#                 return
#         self._refs[event][i] = weakref.WeakMethod(receiver)
# 
#     def unsubscribe(self, receiver, event):
#         if event in self._refs:
#             i = self._calc_id(receiver)
#             if i in self._refs[event]:
#                 del self._refs[event][i]
# 
#     async def send(self, event, **kwargs):
#         if event not in self._refs:
#             return
#         del_list = []
#         for i in self._refs[event]:
#             f = self._refs[event][i]()
#             if f is None:
#                 del_list.append(i)
#             else:
#                 try:
#                     res = f(**kwargs)
#                     if inspect.iscoroutine(res):
#                         await res
#                 except CancelledError:
#                     raise
#                 except Exception:
#                     log.warning("Failed to send the event", exc_info=True)
#         for i in del_list:
#             del self._refs[event][i]
#         del del_list
# 
#     def _calc_id(self, receiver):
#         return hash((id(receiver.__func__), id(receiver.__self__)))


# Path: tests/test_eventbus.py
import pytest
from xpaw.eventbus import EventBus

    eventbus = EventBus()
    obj = FooClass()
    eventbus.subscribe(obj.method1, event1)
    await eventbus.send(event1)
    assert obj.count1 == 1
    eventbus.unsubscribe(obj.method1, event1)
    await eventbus.send(event1)
    assert obj.count1 == 1


@pytest.mark.asyncio
async def test_unsubscribe_multi_times():
    eventbus = EventBus()
    obj = FooClass()
    eventbus.subscribe(obj.method1, event1)
    eventbus.unsubscribe(obj.method1, event1)
    eventbus.unsubscribe(obj.method1, event1)


@pytest.mark.asyncio
async def test_send_with_parameters():
    eventbus = EventBus()
    obj = FooClass()
    eventbus.subscribe(obj.method_set_value, event1)
    await eventbus.send(event1, value=-1)
    assert obj.value == -1


@pytest.mark.asyncio
async def test_send_unknown_event():

    eventbus = EventBus()