def test_add_remove_dims(): """ Tests adding and removing dimensions """ dims = Dims(2) assert dims.ndim == 2 dims.ndim = 10 assert dims.ndim == 10 dims.ndim = 5 assert dims.ndim == 5
def test_order_when_changing_ndim(): """ Test order of the dims when changing the number of dimensions. """ dims = Dims(4) dims.set_point(0, 2) dims.ndim = 5 # Test that new dims get appended to the beginning of lists assert dims.point == [0, 2, 0, 0, 0] dims.set_point(2, 3) dims.ndim = 3 # Test that dims get removed from the beginning of lists assert dims.point == [3, 0, 0]
def test_ndim(): """ Test number of dimensions including after adding and removing dimensions. """ dims = Dims() assert dims.ndim == 2 dims = Dims(ndim=4) assert dims.ndim == 4 dims = Dims(ndim=2) assert dims.ndim == 2 dims.ndim = 10 assert dims.ndim == 10 dims.ndim = 5 assert dims.ndim == 5
def test_order_when_changing_ndim(): """ Test order of the dims when changing the number of dimensions. """ dims = Dims(4) dims.set_point(0, 2) dims.ndim = 5 # Test that new dims get appended to the beginning of lists assert dims.point == [0, 2, 0, 0, 0] assert dims.order == [0, 1, 2, 3, 4] assert dims.axis_labels == ['0', '1', '2', '3', '4'] dims.set_point(2, 3) dims.ndim = 3 # Test that dims get removed from the beginning of lists assert dims.point == [3, 0, 0] assert dims.order == [0, 1, 2] assert dims.axis_labels == ['2', '3', '4']
def test_order_when_changing_ndim(): """ Test order of the dims when changing the number of dimensions. """ dims = Dims(ndim=4) dims.set_range(0, (0, 4, 1)) dims.set_point(0, 2) dims.ndim = 5 # Test that new dims get appended to the beginning of lists assert dims.point == (0, 2, 0, 0, 0) assert dims.order == (0, 1, 2, 3, 4) assert dims.axis_labels == ('0', '1', '2', '3', '4') dims.set_range(2, (0, 4, 1)) dims.set_point(2, 3) dims.ndim = 3 # Test that dims get removed from the beginning of lists assert dims.point == (3, 0, 0) assert dims.order == (0, 1, 2) assert dims.axis_labels == ('2', '3', '4')
def test_set_axis_labels_after_ndim_changes(qtbot): """See https://github.com/napari/napari/issues/3753""" dims = Dims(ndim=3, ndisplay=2) view = QtDims(dims) qtbot.addWidget(view) dims.ndim = 2 dims.axis_labels = ['y', 'x'] assert len(view.slider_widgets) == 2 assert view.slider_widgets[0].axis_label.text() == 'y' assert view.slider_widgets[1].axis_label.text() == 'x'
def test_changing_focus(): """Test changing focus updates the last_used prop.""" # too-few dims, should have no sliders to update dims = Dims(ndim=2) assert dims.last_used == 0 dims._focus_down() dims._focus_up() assert dims.last_used == 0 dims.ndim = 5 # Note that with no view attached last used remains # None even though new non-displayed dimensions added assert dims.last_used == 0 dims._focus_down() assert dims.last_used == 2 dims._focus_down() assert dims.last_used == 1 dims._focus_up() assert dims.last_used == 2 dims._focus_up() assert dims.last_used == 0 dims._focus_down() assert dims.last_used == 2
def test_labels_order_when_changing_dims(): dims = Dims(ndim=4) dims.ndim = 5 assert dims.axis_labels == ('0', '1', '2', '3', '4')