# 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_no_double_send():
    sentinel = []

    def received(sender):
        sentinel.append(sender)

    sig = Signal()

    sig.connect(received, 123)
    sig.connect(received)

    assert not sentinel
    sig.send()
    assert sentinel == [None]
    sig.send(123)
    assert sentinel == [None, 123]
    sig.send()
    assert sentinel == [None, 123, None]


def test_has_receivers():
    received = lambda sender: None

    sig = Signal()
    assert not sig.has_receivers_for(None)
    assert not sig.has_receivers_for(ANY)

    sig.connect(received, 'xyz')
    assert not sig.has_receivers_for(None)

# 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_no_double_send():
    sentinel = []

    def received(sender):
        sentinel.append(sender)

    sig = Signal()

    sig.connect(received, 123)
    sig.connect(received)

    assert not sentinel
    sig.send()
    assert sentinel == [None]
    sig.send(123)
    assert sentinel == [None, 123]
    sig.send()
    assert sentinel == [None, 123, None]


def test_has_receivers():
    received = lambda sender: None

    sig = Signal()
    assert not sig.has_receivers_for(None)
    assert not sig.has_receivers_for(ANY)

    sig.connect(received, 'xyz')
    assert not sig.has_receivers_for(None)

    assert not sig.has_receivers_for(ANY)