def test_watch_before_channels(self): """should store registered handler which is executed after Channels is instantiated and a change is made""" self.widget.watch(self.name, self.handler) comm = Mock(spec=Comm) channels = Channels(comm=comm) channels._handle_change_msg(None, self.msg, None) self.assertEqual(self.lst, [1, 2])
def test_watch_bad_name(self): """should not execute a handler registered for a different property""" self.widget.watch("bad name", self.handler) comm = Mock(spec=Comm) channels = Channels(comm=comm) channels._handle_change_msg(None, self.msg, None) self.assertEqual(self.lst, [])
def test_watch(self): """should call watch handler when change is made""" comm = Mock(spec=Comm) channels = Channels(comm=comm) self.widget.watch(self.name, self.handler) channels._handle_change_msg(None, self.msg, None) self.assertEqual(self.lst, [1, 2])
def test_watch_dict_before_channels(self): """should execute a handler given an dict type when watch is registered before Channels instantiated""" self.widget.watch(self.name, self.handler) self.msg['data']['old_val'] = {"a": 1} self.msg['data']['new_val'] = {"b": "c"} comm = Mock(spec=Comm) channels = Channels(comm=comm) channels._handle_change_msg(None, self.msg, None) self.assertEqual(self.lst, [{"a": 1}, {"b": "c"}])
def test_watch_dict(self): """should execute a handler given an dict type""" comm = Mock(spec=Comm) channels = Channels(comm=comm) self.widget.watch(self.name, self.handler) self.msg['data']['old_val'] = {"a": 1} self.msg['data']['new_val'] = {"b": "c"} channels._handle_change_msg(None, self.msg, None) self.assertEqual(self.lst, [{"a": 1}, {"b": "c"}])
def test_watch_array_before_channels(self): """should execute a handler given an array type when watch is registered before Channels instantiated""" self.widget.watch(self.name, self.handler) self.msg['data']['old_val'] = [1, 2] self.msg['data']['new_val'] = [3, 4] comm = Mock(spec=Comm) channels = Channels(comm=comm) channels._handle_change_msg(None, self.msg, None) self.assertEqual(self.lst, [[1, 2], [3, 4]])
def test_watch_array(self): """should execute a handler given an array type""" comm = Mock(spec=Comm) channels = Channels(comm=comm) self.widget.watch(self.name, self.handler) self.msg['data']['old_val'] = [1, 2] self.msg['data']['new_val'] = [3, 4] channels._handle_change_msg(None, self.msg, None) self.assertEqual(self.lst, [[1, 2], [3, 4]])
def test_get_state_flushes_data_cached_by_channels(self): """should return the state of the channels stored before created""" self.widget.set(self.name, 'myvalue') comm = Mock(spec=Comm) channels = Channels(comm=comm) state = channels.get_state() self.assertEqual(state, {"c:{}".format(self.name): 'myvalue'}) self.assertTrue(not widget_channels.channel_data)
def test_get_state_flushes_data_cached_by_channels(self): """should return the state of the channels stored before created""" self.widget.set(self.name, "myvalue") comm = Mock(spec=Comm) channels = Channels(comm=comm) state = channels.get_state() self.assertEqual(state, {"c:{}".format(self.name): "myvalue"}) self.assertTrue(not widget_channels.channel_data)
def test_set_args_before_channels(self): """should call set on the channels model with args when set is called before Channels instantiated""" self.widget.set(self.name, 'myvalue', a = 'vala', b = 'valb') MockSet = Mock() Channels.set = MockSet comm = Mock(spec=Comm) Channels(comm=comm) self.assertEqual(MockSet.call_count, 1) MockSet.assert_called_with(self.name, 'myvalue', 'c', a = 'vala', b = 'valb')
def test_set_args(self): """should call set on the channels model with args""" MockSet = Mock() Channels.set = MockSet comm = Mock(spec=Comm) Channels(comm=comm) self.widget.set(self.name, 'myvalue', a = 'vala', b = 'valb') self.assertEqual(MockSet.call_count, 1) MockSet.assert_called_with(self.name, 'myvalue', 'c', a = 'vala', b = 'valb')