# Path: fuocore/dispatch.py
# class Signal(object):
#     """provider signal/slot design pattern
# 
#     similar as pyqt signal/slot
#     """
#     def __init__(self, name='', *sig):
#         self.sig = sig
#         self.receivers = set()
# 
#     def emit(self, *args):
#         for receiver in self.receivers:
#             try:
#                 receiver()(*args)
#             except Exception:
#                 logger.exception('receiver %s run error' % receiver())
# 
#     def _ref(self, receiver):
#         ref = weakref.ref
#         if hasattr(receiver, '__self__') and hasattr(receiver, '__func__'):
#             ref = WeakMethod
#         return ref(receiver)
# 
#     def connect(self, receiver):
#         self.receivers.add(self._ref(receiver))
# 
#     def disconnect(self, receiver):
#         receiver = self._ref(receiver)
#         if receiver in self.receivers:
#             self.receivers.remove(receiver)
#             return True
#         return False
# 
# Path: fuocore/dispatch.py
# def receiver(signal):
#     def _decorator(func):
#         if isinstance(signal, (list, tuple)):
#             for s in signal:
#                 s.connect(func)
#         else:
#             signal.connect(func)
#         return func
#     return _decorator
# 
# Path: tests/helpers.py



from unittest import TestCase
from fuocore.dispatch import Signal
from fuocore.dispatch import receiver
from .helpers import mock
        pass

    def test_ref(self):
        s = Signal()
        self.assertTrue(s._ref(self.a1.f) == s._ref(self.a1.f))
        self.assertFalse(s._ref(self.a1.f) == s._ref(self.a2.f))

    def test_connect1(self):
        with mock.patch.object(A, 'f', return_value=None) as mock_method_f:
            s = Signal()
            # pay attention
            self.assertTrue(self.a1.f == self.a2.f == mock_method_f)
            s.connect(self.a1.f)
            s.emit(1, 'hello')
            mock_method_f.assert_called_once_with(1, 'hello')

    def test_connect2(self):
        s = Signal()
        s.connect(f)
        s.emit(1, 'hello')
        s.emit(1, 'hello')

    def test_disconnect(self):
        s = Signal()
        s.connect(f)
        s.disconnect(f)
        s.emit(1, 'hello')

    @mock.patch.object(Signal, 'connect')
    def test_receiver(self, mock_connect):

# Path: fuocore/dispatch.py
# class Signal(object):
#     """provider signal/slot design pattern
# 
#     similar as pyqt signal/slot
#     """
#     def __init__(self, name='', *sig):
#         self.sig = sig
#         self.receivers = set()
# 
#     def emit(self, *args):
#         for receiver in self.receivers:
#             try:
#                 receiver()(*args)
#             except Exception:
#                 logger.exception('receiver %s run error' % receiver())
# 
#     def _ref(self, receiver):
#         ref = weakref.ref
#         if hasattr(receiver, '__self__') and hasattr(receiver, '__func__'):
#             ref = WeakMethod
#         return ref(receiver)
# 
#     def connect(self, receiver):
#         self.receivers.add(self._ref(receiver))
# 
#     def disconnect(self, receiver):
#         receiver = self._ref(receiver)
#         if receiver in self.receivers:
#             self.receivers.remove(receiver)
#             return True
#         return False
# 
# Path: fuocore/dispatch.py
# def receiver(signal):
#     def _decorator(func):
#         if isinstance(signal, (list, tuple)):
#             for s in signal:
#                 s.connect(func)
#         else:
#             signal.connect(func)
#         return func
#     return _decorator
# 
# Path: tests/helpers.py



# Path: tests/test_signal.py
from unittest import TestCase
from fuocore.dispatch import Signal
from fuocore.dispatch import receiver
from .helpers import mock

        pass

    def test_ref(self):
        s = Signal()
        self.assertTrue(s._ref(self.a1.f) == s._ref(self.a1.f))
        self.assertFalse(s._ref(self.a1.f) == s._ref(self.a2.f))

    def test_connect1(self):
        with mock.patch.object(A, 'f', return_value=None) as mock_method_f:
            s = Signal()
            # pay attention
            self.assertTrue(self.a1.f == self.a2.f == mock_method_f)
            s.connect(self.a1.f)
            s.emit(1, 'hello')
            mock_method_f.assert_called_once_with(1, 'hello')

    def test_connect2(self):
        s = Signal()
        s.connect(f)
        s.emit(1, 'hello')
        s.emit(1, 'hello')

    def test_disconnect(self):
        s = Signal()
        s.connect(f)
        s.disconnect(f)
        s.emit(1, 'hello')

    @mock.patch.object(Signal, 'connect')
    def test_receiver(self, mock_connect):

        s = Signal()