# Path: tomate/pomodoro/event.py
# class Bus:
#     def __init__(self):
#         self._bus = blinker.NamedSignal("tomate")
# 
#     def connect(self, event: Events, receiver: Receiver, weak: bool = True):
#         self._bus.connect(receiver, sender=event, weak=weak)
# 
#     def is_connect(self, event: Events, receiver: Receiver) -> bool:
#         return receiver in self._bus.receivers_for(event)
# 
#     def send(self, event: Events, payload: Any = None) -> List[Any]:
#         # drop receiver, index 0, from the result
#         return [result[1] for result in self._bus.send(event, payload=payload)]
# 
#     def disconnect(self, event: Events, receiver: Receiver):
#         self._bus.disconnect(receiver, sender=event)
# 
# class Events(enum.Enum):
#     TIMER_START = 0
#     TIMER_UPDATE = 1
#     TIMER_STOP = 2
#     TIMER_END = 3
# 
#     SESSION_READY = 4
#     SESSION_START = 5
#     SESSION_INTERRUPT = 6
#     SESSION_CHANGE = 7
#     SESSION_END = 8
#     SESSION_RESET = 9
# 
#     WINDOW_SHOW = 10
#     WINDOW_HIDE = 11
# 
#     CONFIG_CHANGE = 12
# 
# class Subscriber:
#     def connect(self, bus: Bus) -> None:
#         for method, events in self.__methods_with_events():
#             for event in events:
#                 logger.debug(
#                     "action=connect event=%s method=%s.%s",
#                     event,
#                     self.__class__.__name__,
#                     method.__name__,
#                 )
#                 bus.connect(event, method)
# 
#     def disconnect(self, bus: Bus):
#         for method, events in self.__methods_with_events():
#             for event in events:
#                 logger.debug(
#                     "action=disconnect event=%s method=%s.%s",
#                     event,
#                     self.__class__.__name__,
#                     method.__name__,
#                 )
#                 bus.disconnect(event, method)
# 
#     def __methods_with_events(self) -> List[Tuple[Any, List[Events]]]:
#         return [
#             (getattr(self, attr), getattr(getattr(self, attr), "_events"))
#             for attr in dir(self)
#             if hasattr(getattr(self, attr), "_events")
#         ]
# 
# def on(*events: Events):
#     def wrapper(method):
#         method._events = events
# 
#         @functools.wraps(method)
#         def wrapped(*args, **kwargs):
#             return method(*(arg for arg in args if not isinstance(arg, Events)), **kwargs)
# 
#         return wrapped
# 
#     return wrapper


from wiring.scanning import scan_to_graph
from tomate.pomodoro import Bus, Events, Subscriber, on



class TestBus:
    def test_connect_receiver(self, bus, mocker):
        def side_effect(*_, payload):
            return payload

        receiver = mocker.Mock(side_effect=side_effect)
        bus.connect(Events.SESSION_START, receiver, weak=False)

        assert bus.send(Events.SESSION_START, payload="payload") == ["payload"]

    def test_disconnect_receiver(self, bus, mocker):
        receiver = mocker.Mock()

# Path: tomate/pomodoro/event.py
# class Bus:
#     def __init__(self):
#         self._bus = blinker.NamedSignal("tomate")
# 
#     def connect(self, event: Events, receiver: Receiver, weak: bool = True):
#         self._bus.connect(receiver, sender=event, weak=weak)
# 
#     def is_connect(self, event: Events, receiver: Receiver) -> bool:
#         return receiver in self._bus.receivers_for(event)
# 
#     def send(self, event: Events, payload: Any = None) -> List[Any]:
#         # drop receiver, index 0, from the result
#         return [result[1] for result in self._bus.send(event, payload=payload)]
# 
#     def disconnect(self, event: Events, receiver: Receiver):
#         self._bus.disconnect(receiver, sender=event)
# 
# class Events(enum.Enum):
#     TIMER_START = 0
#     TIMER_UPDATE = 1
#     TIMER_STOP = 2
#     TIMER_END = 3
# 
#     SESSION_READY = 4
#     SESSION_START = 5
#     SESSION_INTERRUPT = 6
#     SESSION_CHANGE = 7
#     SESSION_END = 8
#     SESSION_RESET = 9
# 
#     WINDOW_SHOW = 10
#     WINDOW_HIDE = 11
# 
#     CONFIG_CHANGE = 12
# 
# class Subscriber:
#     def connect(self, bus: Bus) -> None:
#         for method, events in self.__methods_with_events():
#             for event in events:
#                 logger.debug(
#                     "action=connect event=%s method=%s.%s",
#                     event,
#                     self.__class__.__name__,
#                     method.__name__,
#                 )
#                 bus.connect(event, method)
# 
#     def disconnect(self, bus: Bus):
#         for method, events in self.__methods_with_events():
#             for event in events:
#                 logger.debug(
#                     "action=disconnect event=%s method=%s.%s",
#                     event,
#                     self.__class__.__name__,
#                     method.__name__,
#                 )
#                 bus.disconnect(event, method)
# 
#     def __methods_with_events(self) -> List[Tuple[Any, List[Events]]]:
#         return [
#             (getattr(self, attr), getattr(getattr(self, attr), "_events"))
#             for attr in dir(self)
#             if hasattr(getattr(self, attr), "_events")
#         ]
# 
# def on(*events: Events):
#     def wrapper(method):
#         method._events = events
# 
#         @functools.wraps(method)
#         def wrapped(*args, **kwargs):
#             return method(*(arg for arg in args if not isinstance(arg, Events)), **kwargs)
# 
#         return wrapped
# 
#     return wrapper


# Path: tests/pomodoro/test_event.py
from wiring.scanning import scan_to_graph
from tomate.pomodoro import Bus, Events, Subscriber, on




class TestBus:
    def test_connect_receiver(self, bus, mocker):
        def side_effect(*_, payload):
            return payload

        receiver = mocker.Mock(side_effect=side_effect)
        bus.connect(Events.SESSION_START, receiver, weak=False)

        assert bus.send(Events.SESSION_START, payload="payload") == ["payload"]

    def test_disconnect_receiver(self, bus, mocker):
        receiver = mocker.Mock()

        bus.connect(Events.SESSION_START, receiver, weak=False)