|
23 | 23 | [ 0, 6, 7, 8, 0], |
24 | 24 | [10, 11, 12, 13, 14], |
25 | 25 | [ 0, 0, 17, 0, 0]]), # fmt: skip |
26 | | - |
27 | 26 | ] |
| 27 | +bbox_expected = [(1.0, 5.0, 1.0, 4.0), |
| 28 | + (1.0, 5.0, 1.0, 4.0), |
| 29 | + (0.0, 4.0, 0.0, 5.0)] |
28 | 30 |
|
29 | 31 | # rectangle crop |
30 | 32 | # array([[ 6, 7, 8], |
@@ -62,6 +64,22 @@ def test_crop_function_values_2d(make_napari_viewer, shape, shape_type, |
62 | 64 | assert np.array_equal(crop_expected, cropped_actual_arrays) |
63 | 65 |
|
64 | 66 |
|
| 67 | +@pytest.mark.parametrize( |
| 68 | + "shape,shape_type,bbox_expected", |
| 69 | + zip(shapes, shape_types, bbox_expected) |
| 70 | +) |
| 71 | +def test_bbox_values(make_napari_viewer, shape, shape_type, |
| 72 | + bbox_expected): |
| 73 | + """Test that the bbox returned in metadata is correct.""" |
| 74 | + |
| 75 | + viewer = make_napari_viewer() |
| 76 | + img_layer = viewer.add_image(arr_2d) |
| 77 | + shapes_layer = viewer.add_shapes(shape, shape_type=shape_type) |
| 78 | + cropped_actual = crop_region(img_layer, shapes_layer)[0][1] # get layer properties |
| 79 | + bbox = cropped_actual['metadata']['bbox'] |
| 80 | + assert np.array_equal(bbox_expected, bbox) |
| 81 | + |
| 82 | + |
65 | 83 | def test_crop_multiple_shapes(make_napari_viewer): |
66 | 84 | """Test that 'n' drawn shapes return 'n' new cropped layers""" |
67 | 85 |
|
|
0 commit comments