# Path: flatland/util/signals.py
# ANY = symbol('ANY')
# ANY_ID = 0
#     ANY = ANY
# class Signal(object):
# class NamedSignal(Signal):
# class Namespace(object):
#     def __init__(self, doc=None):
#     def connect(self, receiver, sender=ANY, weak=True):
#     def send(self, sender=None, **kwargs):
#     def has_receivers_for(self, sender):
#     def receivers_for(self, sender):
#     def disconnect(self, receiver, sender=ANY):
#     def _disconnect(self, receiver_id, sender_id):
#     def _cleanup_receiver(self, receiver_ref):
#     def _cleanup_sender(self, sender_ref):
#     def _clear_state(self):
#     def __init__(self, name, doc=None):
#     def __repr__(self):
#     def __init__(self):
#     def signal(self, name, doc=None):
# def _hashable_identity(obj):


from flatland.util.signals import (
    ANY,
    ANY_ID,
    NamedSignal,
    Namespace,
    Signal,
    receiver_connected,
    )
from tests._util import eq_, assert_raises


def test_meta_connect():
    sentinel = []

    def meta_received(**kw):
        sentinel.append(kw)

    assert not receiver_connected.receivers
    receiver_connected.connect(meta_received)
    assert not sentinel

    def receiver(**kw):
        pass
    sig = Signal()
    sig.connect(receiver)

    eq_(sentinel, [dict(sender=sig,
                        receiver_arg=receiver,
                        sender_arg=ANY,
                        weak_arg=True)])

    receiver_connected._clear_state()


def test_meta_connect_failure():

    def meta_received(**kw):
        raise TypeError('boom')


# Path: flatland/util/signals.py
# ANY = symbol('ANY')
# ANY_ID = 0
#     ANY = ANY
# class Signal(object):
# class NamedSignal(Signal):
# class Namespace(object):
#     def __init__(self, doc=None):
#     def connect(self, receiver, sender=ANY, weak=True):
#     def send(self, sender=None, **kwargs):
#     def has_receivers_for(self, sender):
#     def receivers_for(self, sender):
#     def disconnect(self, receiver, sender=ANY):
#     def _disconnect(self, receiver_id, sender_id):
#     def _cleanup_receiver(self, receiver_ref):
#     def _cleanup_sender(self, sender_ref):
#     def _clear_state(self):
#     def __init__(self, name, doc=None):
#     def __repr__(self):
#     def __init__(self):
#     def signal(self, name, doc=None):
# def _hashable_identity(obj):


# Path: tests/test_signals.py
from flatland.util.signals import (
    ANY,
    ANY_ID,
    NamedSignal,
    Namespace,
    Signal,
    receiver_connected,
    )
from tests._util import eq_, assert_raises



def test_meta_connect():
    sentinel = []

    def meta_received(**kw):
        sentinel.append(kw)

    assert not receiver_connected.receivers
    receiver_connected.connect(meta_received)
    assert not sentinel

    def receiver(**kw):
        pass
    sig = Signal()
    sig.connect(receiver)

    eq_(sentinel, [dict(sender=sig,
                        receiver_arg=receiver,
                        sender_arg=ANY,
                        weak_arg=True)])

    receiver_connected._clear_state()


def test_meta_connect_failure():

    def meta_received(**kw):
        raise TypeError('boom')


    assert not receiver_connected.receivers