Coverage for gws-app/gws/gis/zoom/_test.py: 0%

69 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-17 01:37 +0200

1"""Tests for the zoom module.""" 

2 

3import gws 

4import gws.test.util as u 

5import gws.gis.zoom as zoom 

6import gws.gis.crs 

7 

8 

9def test_resolutions_from_config_empty_cnfg(): 

10 cnfg = zoom.Config() 

11 assert zoom.resolutions_from_config(cnfg) == zoom.OSM_RESOLUTIONS 

12 

13 

14def test_resolutions_from_config(): 

15 resolutions = [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5] 

16 minresolution = 3.0 

17 maxresolution = 4.0 

18 minscale = 1.0 

19 maxscale = 2.0 

20 scales = [1, 2, 3, 4] 

21 cnfg = zoom.Config(resolutions=resolutions, minResolution=minresolution, maxResolution=maxresolution, 

22 minScale=minscale, maxScale=maxscale, scales=scales) 

23 assert zoom.resolutions_from_config(cnfg) == [3, 3.5, 4] 

24 

25 

26def test_resolutions_from_config_no_minmax(): 

27 resolutions = [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5] 

28 scales = [1, 2, 3, 4] 

29 cnfg = zoom.Config(resolutions=resolutions, scales=scales) 

30 assert zoom.resolutions_from_config(cnfg) == [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5] 

31 

32 

33def test_resolutions_from_config_parent(): 

34 parentresolutions = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] 

35 cnfg = zoom.Config(minResolution=2.0, maxResolution=5.0) 

36 assert zoom.resolutions_from_config(cnfg, parentresolutions) == [2.0, 3.0, 4.0, 5.0] 

37 

38 

39def test_resolutions_from_source_layers(): 

40 sl1 = gws.SourceLayer(scaleRange=[100, 100]) 

41 sl2 = gws.SourceLayer(scaleRange=[110, 200]) 

42 sl3 = gws.SourceLayer(scaleRange=[210, 30000]) 

43 parentresolutions = [0.0, 0.01, 0.02, 5.0, 6.0, 7.0, 9.0, 10.0, 10000.0] 

44 assert zoom.resolutions_from_source_layers([sl3, sl2, sl1], parentresolutions) == [0.02, 5.0, 6.0, 7.0, 9.0] 

45 

46 

47def test_resolutions_from_source_layers_no_scalerange(): 

48 sl1 = gws.SourceLayer() 

49 sl2 = gws.SourceLayer() 

50 sl3 = gws.SourceLayer() 

51 parentresolutions = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] 

52 assert zoom.resolutions_from_source_layers([sl3, sl2, sl1], parentresolutions) == parentresolutions 

53 

54 

55def test_resolutions_from_source_layers_empty(): 

56 sl1 = gws.SourceLayer(scaleRange=[0, 10]) 

57 parentresolutions = [1.0, 6.0] 

58 assert zoom.resolutions_from_source_layers([sl1], parentresolutions) == [] 

59 

60 

61def test_resolutions_from_bounds(): 

62 crs = gws.gis.crs.WGS84 

63 extent = (200, 200, 400, 400) 

64 bounds = gws.Bounds(crs=crs, extent=extent) 

65 assert zoom.resolutions_from_bounds(bounds, 3) == [66.66666666666667, 

66 33.333333333333336, 

67 16.666666666666668, 

68 8.333333333333334, 

69 4.166666666666667, 

70 2.0833333333333335, 

71 1.0416666666666667, 

72 0.5208333333333334, 

73 0.2604166666666667, 

74 0.13020833333333334, 

75 0.06510416666666667, 

76 0.032552083333333336, 

77 0.016276041666666668, 

78 0.008138020833333334, 

79 0.004069010416666667, 

80 0.0020345052083333335, 

81 0.0010172526041666667, 

82 0.0005086263020833334, 

83 0.0002543131510416667, 

84 0.00012715657552083334] 

85 

86 

87def test_resolutions_from_bounds_zero(): 

88 crs = gws.gis.crs.WGS84 

89 extent = (200, 200, 400, 400) 

90 bounds = gws.Bounds(crs=crs, extent=extent) 

91 with u.raises(Exception): 

92 zoom.resolutions_from_bounds(bounds, 0) 

93 

94 

95def test_resolutions_from_bounds_negative(): 

96 crs = gws.gis.crs.WGS84 

97 extent = (200, 200, 400, 400) 

98 bounds = gws.Bounds(crs=crs, extent=extent) 

99 assert zoom.resolutions_from_bounds(bounds, -3) == [-66.66666666666667, 

100 -33.333333333333336, 

101 -16.666666666666668, 

102 -8.333333333333334, 

103 -4.166666666666667, 

104 -2.0833333333333335, 

105 -1.0416666666666667, 

106 -0.5208333333333334, 

107 -0.2604166666666667, 

108 -0.13020833333333334, 

109 -0.06510416666666667, 

110 -0.032552083333333336, 

111 -0.016276041666666668, 

112 -0.008138020833333334, 

113 -0.004069010416666667, 

114 -0.0020345052083333335, 

115 -0.0010172526041666667, 

116 -0.0005086263020833334, 

117 -0.0002543131510416667, 

118 -0.00012715657552083334] 

119 

120 

121def test_init_resolution_res(): 

122 cnfg = zoom.Config(initResolution=2) 

123 resolutions = [1, 2, 3, 4, 5, 6] 

124 assert zoom.init_resolution(cnfg, resolutions) == 2 

125 

126 

127def test_init_resolution_scale(): 

128 cnfg = zoom.Config(initScale=5) 

129 resolutions = [1, 2, 3, 4, 5, 6] 

130 assert zoom.init_resolution(cnfg, resolutions) == 1 

131 

132 

133def test_init_resolution_empty(): 

134 cnfg = zoom.Config() 

135 resolutions = [1, 2, 3, 4, 5, 6] 

136 assert zoom.init_resolution(cnfg, resolutions) == 4