@requires_application()
def test_image_vertex_updates():
    'Test image visual coordinates are only built when needed.'
    size = (40, 40)
    with TestingCanvas(size=size, bgcolor='w') as c:
        shape = (size + (3,))
        np.random.seed(0)
        image = Image(cmap='grays', clim=[0, 1], parent=c.scene)
        with mock.patch.object(image, '_build_vertex_data', wraps=image._build_vertex_data) as build_vertex_mock:
            data = np.random.rand(*shape)
            image.set_data(data)
            c.render()
            build_vertex_mock.assert_called_once()
            build_vertex_mock.reset_mock()
            c.render()
            build_vertex_mock.assert_not_called()
            data = np.zeros_like(data)
            image.set_data(data)
            c.render()
            build_vertex_mock.assert_not_called()
            data = data[:(- 5), :(- 5)]
            image.set_data(data)
            c.render()
            build_vertex_mock.assert_called_once()
Test image visual coordinates are only built when needed.
@requires_application()
def test_image_vertex_updates():
    
    size = (40, 40)
    with TestingCanvas(size=size, bgcolor='w') as c:
        shape = (size + (3,))
        np.random.seed(0)
        image = Image(cmap='grays', clim=[0, 1], parent=c.scene)
        with mock.patch.object(image, '_build_vertex_data', wraps=image._build_vertex_data) as build_vertex_mock:
            data = np.random.rand(*shape)
            image.set_data(data)
            c.render()
            build_vertex_mock.assert_called_once()
            build_vertex_mock.reset_mock()
            c.render()
            build_vertex_mock.assert_not_called()
            data = np.zeros_like(data)
            image.set_data(data)
            c.render()
            build_vertex_mock.assert_not_called()
            data = data[:(- 5), :(- 5)]
            image.set_data(data)
            c.render()
            build_vertex_mock.assert_called_once()