Coverage for tests/images/test_region_2d.py: 100%
34 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-31 11:24 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-31 11:24 +0000
1import pytest
2import shapely
3from qubalab.images.region_2d import Region2D
6def test_default_values():
7 expected_region = Region2D(x = 0, y = 0, width = -1, height = -1, z = 0, t = 0)
9 region = Region2D()
11 assert expected_region == region
14def test_geometry():
15 x = 4
16 y = 90
17 width = 34
18 height = 5
19 expected_geometry = shapely.box(x, y, x+width, y+height)
20 region = Region2D(x, y, width, height)
22 geometry = region.geometry
24 assert expected_geometry == geometry
27def test_downsampled_region_with_same_factor():
28 region = Region2D(x=1, y=2, width=3, height=4)
30 downsampled_region = region.downsample_region(1)
32 assert region == downsampled_region
35def test_downsampled_region_with_different_factor():
36 region = Region2D(x=1, y=2, width=3, height=4)
37 expected_downsampled_region = Region2D(x=0, y=1, width=2, height=2, z=0, t=0)
39 downsampled_region = region.downsample_region(2)
41 assert downsampled_region == expected_downsampled_region
44def test_scaled_region_with_different_factor():
45 region = Region2D(x=1, y=2, width=3, height=4)
46 expected_scaled_region = Region2D(x=2, y=4, width=6, height=8, z=0, t=0)
48 scaled_region = region.scale_region(2)
50 assert scaled_region == expected_scaled_region
53def test_downsampled_region_with_factor_of_zero():
54 region = Region2D(x=1, y=2, width=3, height=4)
56 with pytest.raises(ValueError):
57 region.downsample_region(0)