def test_disconnect_false_receiver(self): """ this receiver isn't coming from this dispatcher """ # this is REALLY constructed. you may *not* instantiate a Receiver yourself anyway rec = Receiver('test', None, None, None) self.dispatcher.disconnect(rec)
def test_calling_with_clashing_kw(self): rec = Receiver('test', self._callback, (1, 2, 3), {'test': 'a', 'p': 'a'}) self.assertEquals(rec.signal, 'test') rec(p='q') self.assertEquals(self.called, 1) self.assertEquals(self.args, (1, 2, 3)) self.assertEquals(self.kw, {'test': 'a', 'p': 'q'}) rec(other='wise') self.assertEquals(self.called, 2) self.assertEquals(self.args, (1, 2, 3)) self.assertEquals(self.kw, {'test': 'a', 'other': 'wise', 'p': 'a'})
def test_calling_with_clashing_kw_and_args(self): rec = Receiver('test', self._callback, (1, 2, 3), {'test': 'a', 'p': 'a'}) self.assertEquals(rec.signal, 'test') # without rec() self.assertEquals(self.called, 1) self.assertEquals(self.args, (1, 2, 3)) self.assertEquals(self.kw, {'test': 'a', 'p': 'a'}) rec(1, 2, 7, test='True', o='p') self.assertEquals(self.called, 2) self.assertEquals(self.args, (1, 2, 7, 1, 2, 3)) self.assertEquals(self.kw, {'test': 'True', 'o': 'p', 'p': 'a'})
def test_calling_with_args(self): rec = Receiver('test', self._callback, (1, 2, 3), {'test': 'a'}) self.assertEquals(rec.signal, 'test') rec(0) self.assertEquals(self.called, 1) self.assertEquals(self.args, (0, 1, 2, 3)) self.assertEquals(self.kw, {'test': 'a'}) rec(-1) self.assertEquals(self.called, 2) self.assertEquals(self.args, (-1, 1, 2, 3)) self.assertEquals(self.kw, {'test': 'a'}) rec(-2) self.assertEquals(self.called, 3) self.assertEquals(self.args, (-2, 1, 2, 3)) self.assertEquals(self.kw, {'test': 'a'})
def test_simple_calling(self): rec = Receiver('test', self._callback, (), {}) self.assertEquals(rec.signal, 'test') rec() self.assertEquals(self.called, 1) self.assertEquals(self.args, ()) self.assertEquals(self.kw, {}) rec() self.assertEquals(self.called, 2) self.assertEquals(self.args, ()) self.assertEquals(self.kw, {}) rec() self.assertEquals(self.called, 3) self.assertEquals(self.args, ()) self.assertEquals(self.kw, {})
def test_repr(self): rec = Receiver('test', 'callback', (0, 1, 2), {}) self.assertIn('%s' % id(rec), '%r' % rec) self.assertIn('test', '%r' % rec) self.assertIn('callback', '%r' % rec) self.assertIn('0, 1, 2', '%r' % rec)
def test_disconnect_wrong_signal_receiver(self): rec = Receiver('Test', None, None, None) self.assertRaises(UnknownSignal, self.dispatcher.disconnect, rec)