import weakref
import collections
+import types
from .. import exc
self.target = target
self.identifier = identifier
self.fn = fn
+ if isinstance(fn, types.MethodType):
+ self.fn_key = id(fn.__func__), id(fn.__self__)
+ else:
+ self.fn_key = id(fn)
self.fn_wrap = _fn_wrap
self.dispatch_target = dispatch_target
@property
def _key(self):
- return (id(self.target), self.identifier, id(self.fn))
-
+ return (id(self.target), self.identifier, self.fn_key)
def with_wrapper(self, fn_wrap):
if fn_wrap is self._listen_fn:
eq_(m1.mock_calls, [call("x")])
+ def test_instance(self):
+ Target = self._fixture()
+
+ class Foo(object):
+ def __init__(self):
+ self.mock = Mock()
+
+ def evt(self, arg):
+ self.mock(arg)
+
+ f1 = Foo()
+ f2 = Foo()
+
+ event.listen(Target, "event_one", f1.evt)
+ event.listen(Target, "event_one", f2.evt)
+
+ t1 = Target()
+ t1.dispatch.event_one("x")
+
+ event.remove(Target, "event_one", f1.evt)
+
+ t1.dispatch.event_one("y")
+
+ eq_(f1.mock.mock_calls, [call("x")])
+ eq_(f2.mock.mock_calls, [call("x"), call("y")])
+
def test_propagate(self):
Target = self._fixture()