def test_base_func_init(fig, colorbar, buttons): # We need to create figures within the test function rather than in parametrize() if callable(fig): fig = fig() data = np.random.random((3, 10, 10)) func0 = partial(update_plotval, data=data) func1 = partial(update_plotval, data=data * 10) funcs = [func0, func1] ranges = [(0, 3), (0, 3)] tfa = FuncAnimatorTest(data, funcs, ranges, fig=fig, colorbar=colorbar, button_func=buttons[0], button_labels=buttons[1]) tfa.label_slider(0, "hello") assert tfa.sliders[0]._slider.label.get_text() == "hello" tfa._set_active_slider(1) assert tfa.active_slider == 1 fig = plt.figure() event = mback.KeyEvent(name='key_press_event', canvas=fig.canvas, key='down') tfa._key_press(event) assert tfa.active_slider == 0 event.key = 'up' tfa._key_press(event) assert tfa.active_slider == 1 tfa.slider_buttons[tfa.active_slider]._button.clicked = False event.key = 'p' tfa._click_slider_button( event=event, button=tfa.slider_buttons[tfa.active_slider]._button, slider=tfa.sliders[tfa.active_slider]._slider) assert tfa.slider_buttons[tfa.active_slider]._button.label._text == "||" tfa._key_press(event) assert tfa.slider_buttons[tfa.active_slider]._button.label._text == ">" event.key = 'left' tfa._key_press(event) assert tfa.sliders[tfa.active_slider]._slider.val == tfa.sliders[ tfa.active_slider]._slider.valmax event.key = 'right' tfa._key_press(event) assert tfa.sliders[tfa.active_slider]._slider.val == tfa.sliders[ tfa.active_slider]._slider.valmin event.key = 'right' tfa._key_press(event) assert tfa.sliders[tfa.active_slider]._slider.val == tfa.sliders[ tfa.active_slider]._slider.valmin + 1 event.key = 'left' tfa._key_press(event) assert tfa.sliders[tfa.active_slider]._slider.val == tfa.sliders[ tfa.active_slider]._slider.valmin tfa._start_play(event, tfa.slider_buttons[tfa.active_slider]._button, tfa.sliders[tfa.active_slider]._slider) assert tfa.timer tfa._stop_play(event) assert tfa.timer is None tfa._slider_changed(val=2, slider=tfa.sliders[tfa.active_slider]._slider) assert np.array(tfa.im.get_array()).all() == data[2].all() event.inaxes = tfa.sliders[0] tfa._mouse_click(event) assert tfa.active_slider == 0 # Close the figure if it is a pyplot figure if fig in [plt.figure(i) for i in plt.get_fignums()]: plt.close(fig)
def test_base_func_init(fig, colorbar, buttons): data = np.random.random((3, 10, 10)) func0 = partial(update_plotval, data=data) func1 = partial(update_plotval, data=data*10) funcs = [func0, func1] ranges = [(0, 3), (0, 3)] tfa = FuncAnimatorTest(data, funcs, ranges, fig=fig, colorbar=colorbar, button_func=buttons[0], button_labels=buttons[1]) tfa.label_slider(0, "hello") assert tfa.sliders[0]._slider.label.get_text() == "hello" tfa._set_active_slider(1) assert tfa.active_slider == 1 fig = tfa.fig event = mback.KeyEvent(name='key_press_event', canvas=fig.canvas, key='down') tfa._key_press(event) assert tfa.active_slider == 0 event.key = 'up' tfa._key_press(event) assert tfa.active_slider == 1 tfa.slider_buttons[tfa.active_slider]._button.clicked = False event.key = 'p' tfa._click_slider_button(event=event, button=tfa.slider_buttons[tfa.active_slider]._button, slider=tfa.sliders[tfa.active_slider]._slider) assert tfa.slider_buttons[tfa.active_slider]._button.label._text == "||" tfa._key_press(event) assert tfa.slider_buttons[tfa.active_slider]._button.label._text == ">" event.key = 'left' tfa._key_press(event) assert tfa.sliders[tfa.active_slider]._slider.val == tfa.sliders[tfa.active_slider]._slider.valmax event.key = 'right' tfa._key_press(event) assert tfa.sliders[tfa.active_slider]._slider.val == tfa.sliders[tfa.active_slider]._slider.valmin event.key = 'right' tfa._key_press(event) assert tfa.sliders[tfa.active_slider]._slider.val == tfa.sliders[tfa.active_slider]._slider.valmin + 1 event.key = 'left' tfa._key_press(event) assert tfa.sliders[tfa.active_slider]._slider.val == tfa.sliders[tfa.active_slider]._slider.valmin tfa._start_play(event, tfa.slider_buttons[tfa.active_slider]._button, tfa.sliders[tfa.active_slider]._slider) assert tfa.timer tfa._stop_play(event) assert tfa.timer is None tfa._slider_changed(val=2, slider=tfa.sliders[tfa.active_slider]._slider) assert np.array(tfa.im.get_array()).all() == data[2].all() event.inaxes = tfa.sliders[0] tfa._mouse_click(event) assert tfa.active_slider == 0