def test_move_multiple_mimics_slice_reorder(): """Test the that move_multiple provides the same result as slice insertion. """ data = list(range(8)) el = EventedList(data) el.events = Mock(wraps=el.events) assert el == data new_order = [1, 5, 3, 4, 6, 7, 2, 0] # this syntax el.move_multiple(new_order, 0) # is the same as this syntax data[:] = [data[i] for i in new_order] assert el == new_order assert el == data el.events.moving.assert_called_with(index=new_order, new_index=0) el.events.moved.assert_called_with( index=new_order, new_index=0, value=new_order, ) el.events.reordered.assert_called_with(value=new_order) # move_multiple also works omitting the insertion index el[:] = list(range(8)) el.move_multiple(new_order) == [el[i] for i in new_order]
def test_child_events(): """Test that evented lists bubble child events.""" # create a random object that emits events e_obj = E() # and two nestable evented lists root = EventedList() observed = [] root.events.connect(lambda e: observed.append(e)) root.append(e_obj) e_obj.events.test(value="hi") obs = [(e.type, e.index, getattr(e, 'value', None)) for e in observed] expected = [ ('inserting', 0, None), # before we inserted b into root ('inserted', 0, e_obj), # after b was inserted into root ('test', 0, 'hi'), # when e_obj emitted an event called "test" ] for o, e in zip(obs, expected): assert o == e
def __init__(self, viewer): self.viewer = viewer self.key_frames: EventedList[KeyFrame] = EventedList() self.frame: int = -1 self.state_interpolation_map = { "camera.angles": Interpolation.SLERP, "camera.zoom": Interpolation.LOG, }
def test_move_multiple(sources, dest, expectation): """Test the that we can move objects with the move method""" el = EventedList(range(8)) el.events = Mock(wraps=el.events) assert el == [0, 1, 2, 3, 4, 5, 6, 7] def _fail(e): raise AssertionError("unexpected event called") el.events.removing.connect(_fail) el.events.removed.connect(_fail) el.events.inserting.connect(_fail) el.events.inserted.connect(_fail) el.move_multiple(sources, dest) assert el == expectation el.events.moving.assert_called_once() el.events.moved.assert_called_once() el.events.reordered.assert_called_with(value=expectation)
def test_move_multiple_mimics_slice_reorder(): """Test the that move_multiple provides the same result as slice insertion.""" data = list(range(8)) el = EventedList(data) el.events = Mock(wraps=el.events) assert el == data new_order = [1, 5, 3, 4, 6, 7, 2, 0] # this syntax el.move_multiple(new_order, 0) # is the same as this syntax data[:] = [data[i] for i in new_order] assert el == new_order assert el == data assert el.events.moving.call_args_list == [ call(index=1, new_index=0), call(index=5, new_index=1), call(index=4, new_index=2), call(index=5, new_index=3), call(index=6, new_index=4), call(index=7, new_index=5), call(index=7, new_index=6), ] assert el.events.moved.call_args_list == [ call(index=1, new_index=0, value=1), call(index=5, new_index=1, value=5), call(index=4, new_index=2, value=3), call(index=5, new_index=3, value=4), call(index=6, new_index=4, value=6), call(index=7, new_index=5, value=7), call(index=7, new_index=6, value=2), ] el.events.reordered.assert_called_with(value=new_order) # move_multiple also works omitting the insertion index el[:] = list(range(8)) el.move_multiple(new_order) == [el[i] for i in new_order]
def test_array_like_setitem(): """Test that EventedList.__setitem__ works for array-like items""" array = np.array((10, 10)) evented_list = EventedList([array]) evented_list[0] = array