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

1import pytest 

2import shapely 

3from qubalab.images.region_2d import Region2D 

4 

5 

6def test_default_values(): 

7 expected_region = Region2D(x = 0, y = 0, width = -1, height = -1, z = 0, t = 0) 

8 

9 region = Region2D() 

10 

11 assert expected_region == region 

12 

13 

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) 

21 

22 geometry = region.geometry 

23 

24 assert expected_geometry == geometry 

25 

26 

27def test_downsampled_region_with_same_factor(): 

28 region = Region2D(x=1, y=2, width=3, height=4) 

29 

30 downsampled_region = region.downsample_region(1) 

31 

32 assert region == downsampled_region 

33 

34 

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) 

38 

39 downsampled_region = region.downsample_region(2) 

40 

41 assert downsampled_region == expected_downsampled_region 

42 

43 

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) 

47 

48 scaled_region = region.scale_region(2) 

49 

50 assert scaled_region == expected_scaled_region 

51 

52 

53def test_downsampled_region_with_factor_of_zero(): 

54 region = Region2D(x=1, y=2, width=3, height=4) 

55 

56 with pytest.raises(ValueError): 

57 region.downsample_region(0)