def test_def_callback(self): xs = [] b = Button() @b.def_callback def _(): xs.append(1) b.handle_event(Click(target_id=b.id)) self.assertEqual([1], xs)
def test_set_callback(self): xs = [] b = Button(callback=(lambda: xs.append(1))) b.handle_event({'type': CLICK, 'id': b.id}) self.assertEqual([1], xs) xs = [] b.set_callback(lambda: xs.append(2)) b.handle_event({'type': CLICK, 'id': b.id}) self.assertEqual([2], xs)
def test_callback_is_settable(self): xs = [] b = Button(callback=(lambda: xs.append(1))) b.handle_event(Click(target_id=b.id)) self.assertEqual([1], xs) xs = [] b.callback = (lambda: xs.append(2)) b.handle_event(Click(target_id=b.id)) self.assertEqual([2], xs) xs = [] b.callback = None b.handle_event(Click(target_id=b.id)) self.assertEqual([], xs)