Skip to content

Commit

Permalink
Merge pull request #3 from madjar/master
Browse files Browse the repository at this point in the history
Added signal names and repr.
  • Loading branch information
jpic committed Sep 17, 2014
2 parents 6064c55 + 302510d commit def2652
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion signalslot/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ class Signal(object):
>>> conf_pre_load.is_connected(yourmodule_conf)
False
"""
def __init__(self, args=None):
def __init__(self, args=None, name=None):
self.slots = []
self.args = args or []
self.name = name

def connect(self, slot):
"""
Expand Down Expand Up @@ -117,3 +118,6 @@ def __eq__(self, other):
True
"""
return self.slots == other.slots

def __repr__(self):
return '<signalslot.Signal: %s>' % (self.name or 'NO_NAME')
10 changes: 10 additions & 0 deletions signalslot/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ def test_disconnect_does_not_fail_on_not_connected_slot(self, inspect):
self.signal_a.disconnect(self.slot_b)


def test_anonymous_signal_has_nice_repr():
signal = Signal()
assert repr(signal) == '<signalslot.Signal: NO_NAME>'


def test_named_signal_has_a_nice_repr():
signal = Signal(name='update_stuff')
assert repr(signal) == '<signalslot.Signal: update_stuff>'


class TestSignalConnect(object):
def setup_method(self, method):
self.signal = Signal()
Expand Down

0 comments on commit def2652

Please sign in to comment.