Debian Codegraph @

tests/hypothesis/overlay_test.py

raw symbols SCIP
1 # Copyright (C) 2024 Christian Ledermann
2 #
3 # This library is free software; you can redistribute it and/or modify it under
4 # the terms of the GNU Lesser General Public License as published by the Free
5 # Software Foundation; either version 2.1 of the License, or (at your option)
6 # any later version.
7 #
8 # This library is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 # details.
12 #
13 # You should have received a copy of the GNU Lesser General Public License
14 # along with this library; if not, write to the Free Software Foundation, Inc.,
15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 """Test Link and Icon."""
17
18 from typing import Optional
19 from typing import Union
20
21 import pytest
22 from hypothesis import given
23 from hypothesis import strategies as st
24 from pygeoif.hypothesis.strategies import epsg4326
25 from pygeoif.hypothesis.strategies import points
26
27 import fastkml
28 import fastkml.enums
29 import fastkml.geometry
30 import fastkml.overlays
31 from tests.base import Lxml
32 from tests.hypothesis.common import assert_repr_roundtrip
33 from tests.hypothesis.common import assert_str_roundtrip
34 from tests.hypothesis.common import assert_str_roundtrip_terse
35 from tests.hypothesis.common import assert_str_roundtrip_verbose
36 from tests.hypothesis.strategies import nc_name
37 from tests.hypothesis.strategies import xy
38
39
40 class TestLxml(Lxml):
41 @given(
42 id=st.one_of(st.none(), nc_name()),
43 target_id=st.one_of(st.none(), nc_name()),
44 left_fov=st.one_of(st.none(), st.floats(min_value=-180, max_value=180)).filter(
45 lambda x: x != 0,
46 ),
47 right_fov=st.one_of(st.none(), st.floats(min_value=-180, max_value=180)).filter(
48 lambda x: x != 0,
49 ),
50 bottom_fov=st.one_of(st.none(), st.floats(min_value=-90, max_value=90)).filter(
51 lambda x: x != 0,
52 ),
53 top_fov=st.one_of(st.none(), st.floats(min_value=-90, max_value=90)).filter(
54 lambda x: x != 0,
55 ),
56 near=st.one_of(
57 st.none(),
58 st.floats(allow_nan=False, allow_infinity=False),
59 ).filter(lambda x: x != 0),
60 )
61 def test_fuzz_view_volume(
62 self,
63 id: Optional[str],
64 target_id: Optional[str],
65 left_fov: Optional[float],
66 right_fov: Optional[float],
67 bottom_fov: Optional[float],
68 top_fov: Optional[float],
69 near: Optional[float],
70 ) -> None:
71 view_volume = fastkml.overlays.ViewVolume(
72 id=id,
73 target_id=target_id,
74 left_fov=left_fov,
75 right_fov=right_fov,
76 bottom_fov=bottom_fov,
77 top_fov=top_fov,
78 near=near,
79 )
80
81 assert_repr_roundtrip(view_volume)
82 assert_str_roundtrip(view_volume)
83 assert_str_roundtrip_terse(view_volume)
84 assert_str_roundtrip_verbose(view_volume)
85
86 @given(
87 id=st.one_of(st.none(), nc_name()),
88 target_id=st.one_of(st.none(), nc_name()),
89 tile_size=st.one_of(st.none(), st.integers(min_value=0, max_value=2**31 - 1)),
90 max_width=st.one_of(st.none(), st.integers(min_value=0, max_value=2**31 - 1)),
91 max_height=st.one_of(st.none(), st.integers(min_value=0, max_value=2**31 - 1)),
92 grid_origin=st.one_of(st.none(), st.sampled_from(fastkml.enums.GridOrigin)),
93 )
94 def test_fuzz_image_pyramid(
95 self,
96 id: Optional[str],
97 target_id: Optional[str],
98 tile_size: Optional[int],
99 max_width: Optional[int],
100 max_height: Optional[int],
101 grid_origin: Optional[fastkml.enums.GridOrigin],
102 ) -> None:
103 image_pyramid = fastkml.overlays.ImagePyramid(
104 id=id,
105 target_id=target_id,
106 tile_size=tile_size,
107 max_width=max_width,
108 max_height=max_height,
109 grid_origin=grid_origin,
110 )
111
112 assert_repr_roundtrip(image_pyramid)
113 assert_str_roundtrip(image_pyramid)
114 assert_str_roundtrip_terse(image_pyramid)
115 assert_str_roundtrip_verbose(image_pyramid)
116
117 @given(
118 id=st.one_of(st.none(), nc_name()),
119 target_id=st.one_of(st.none(), nc_name()),
120 north=st.one_of(
121 st.none(),
122 st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
123 ),
124 south=st.one_of(
125 st.none(),
126 st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
127 ),
128 east=st.one_of(
129 st.none(),
130 st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
131 ),
132 west=st.one_of(
133 st.none(),
134 st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
135 ),
136 rotation=st.one_of(
137 st.none(),
138 st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
139 ),
140 )
141 def test_fuzz_lat_lon_box(
142 self,
143 id: Optional[str],
144 target_id: Optional[str],
145 north: Optional[float],
146 south: Optional[float],
147 east: Optional[float],
148 west: Optional[float],
149 rotation: Optional[float],
150 ) -> None:
151 lat_lon_box = fastkml.overlays.LatLonBox(
152 id=id,
153 target_id=target_id,
154 north=north,
155 south=south,
156 east=east,
157 west=west,
158 rotation=rotation,
159 )
160
161 assert_repr_roundtrip(lat_lon_box)
162 assert_str_roundtrip(lat_lon_box)
163 assert_str_roundtrip_terse(lat_lon_box)
164 assert_str_roundtrip_verbose(lat_lon_box)
165
166 @given(
167 rotation=st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
168 view_volume=st.one_of(
169 st.none(),
170 st.builds(
171 fastkml.overlays.ViewVolume,
172 left_fov=st.floats(min_value=-180, max_value=180).filter(
173 lambda x: x != 0,
174 ),
175 right_fov=st.floats(min_value=-180, max_value=180).filter(
176 lambda x: x != 0,
177 ),
178 bottom_fov=st.floats(min_value=-90, max_value=90).filter(
179 lambda x: x != 0,
180 ),
181 top_fov=st.floats(min_value=-90, max_value=90).filter(lambda x: x != 0),
182 near=st.floats(allow_nan=False, allow_infinity=False).filter(
183 lambda x: x != 0,
184 ),
185 ),
186 ),
187 image_pyramid=st.one_of(
188 st.none(),
189 st.builds(
190 fastkml.overlays.ImagePyramid,
191 tile_size=st.integers(min_value=0, max_value=2**31 - 1),
192 max_width=st.integers(min_value=0, max_value=2**31 - 1),
193 max_height=st.integers(min_value=0, max_value=2**31 - 1),
194 grid_origin=st.sampled_from(fastkml.enums.GridOrigin),
195 ),
196 ),
197 point=st.one_of(
198 st.none(),
199 st.builds(
200 fastkml.geometry.Point,
201 geometry=points(srs=epsg4326),
202 ),
203 ),
204 shape=st.one_of(st.none(), st.sampled_from(fastkml.enums.Shape)),
205 )
206 def test_fuzz_photo_overlay(
207 self,
208 rotation: Optional[float],
209 view_volume: Optional[fastkml.overlays.ViewVolume],
210 image_pyramid: Optional[fastkml.overlays.ImagePyramid],
211 point: Optional[fastkml.geometry.Point],
212 shape: Optional[fastkml.enums.Shape],
213 ) -> None:
214 photo_overlay = fastkml.overlays.PhotoOverlay(
215 id="photo_overlay1",
216 name="photo_overlay",
217 rotation=rotation,
218 image_pyramid=image_pyramid,
219 view_volume=view_volume,
220 point=point,
221 shape=shape,
222 )
223
224 assert_repr_roundtrip(photo_overlay)
225 assert_str_roundtrip(photo_overlay)
226 assert_str_roundtrip_terse(photo_overlay)
227 assert_str_roundtrip_verbose(photo_overlay)
228
229 @given(
230 altitude=st.one_of(
231 st.none(),
232 st.floats(allow_nan=False, allow_infinity=False).filter(lambda x: x != 0),
233 ),
234 altitude_mode=st.one_of(st.none(), st.sampled_from(fastkml.enums.AltitudeMode)),
235 lat_lon_box=st.one_of(
236 st.none(),
237 st.builds(
238 fastkml.overlays.LatLonBox,
239 north=st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
240 south=st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
241 east=st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
242 west=st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
243 rotation=st.floats(min_value=-180, max_value=180).filter(
244 lambda x: x != 0,
245 ),
246 ),
247 ),
248 )
249 def test_fuzz_ground_overlay(
250 self,
251 altitude: Optional[float],
252 altitude_mode: Optional[fastkml.enums.AltitudeMode],
253 lat_lon_box: Optional[fastkml.overlays.LatLonBox],
254 ) -> None:
255 ground_overlay = fastkml.overlays.GroundOverlay(
256 id="ground_overlay1",
257 name="ground_overlay",
258 altitude=altitude,
259 altitude_mode=altitude_mode,
260 lat_lon_box=lat_lon_box,
261 )
262
263 assert_repr_roundtrip(ground_overlay)
264 assert_str_roundtrip(ground_overlay)
265 assert_str_roundtrip_terse(ground_overlay)
266 assert_str_roundtrip_verbose(ground_overlay)
267
268 @pytest.mark.parametrize(
269 "cls",
270 [
271 fastkml.overlays.OverlayXY,
272 fastkml.overlays.RotationXY,
273 fastkml.overlays.ScreenXY,
274 fastkml.overlays.Size,
275 ],
276 )
277 @given(
278 x=st.one_of(st.none(), st.floats(allow_nan=False, allow_infinity=False)),
279 y=st.one_of(st.none(), st.floats(allow_nan=False, allow_infinity=False)),
280 x_units=st.one_of(st.none(), st.sampled_from(fastkml.enums.Units)),
281 y_units=st.one_of(st.none(), st.sampled_from(fastkml.enums.Units)),
282 )
283 def test_fuzz_xy(
284 self,
285 cls: Union[
286 type[fastkml.overlays.OverlayXY],
287 type[fastkml.overlays.RotationXY],
288 type[fastkml.overlays.ScreenXY],
289 type[fastkml.overlays.Size],
290 ],
291 x: Optional[float],
292 y: Optional[float],
293 x_units: Optional[fastkml.enums.Units],
294 y_units: Optional[fastkml.enums.Units],
295 ) -> None:
296 xy = cls(x=x, y=y, x_units=x_units, y_units=y_units)
297
298 assert_repr_roundtrip(xy)
299 assert_str_roundtrip(xy)
300 assert_str_roundtrip_terse(xy)
301 assert_str_roundtrip_verbose(xy)
302
303 @given(
304 overlay_xy=xy(fastkml.overlays.OverlayXY),
305 screen_xy=xy(fastkml.overlays.ScreenXY),
306 rotation_xy=xy(fastkml.overlays.RotationXY),
307 size=xy(fastkml.overlays.Size),
308 rotation=st.floats(min_value=-180, max_value=180).filter(lambda x: x != 0),
309 )
310 def test_screen_overlay(
311 self,
312 overlay_xy: Optional[fastkml.overlays.OverlayXY],
313 screen_xy: Optional[fastkml.overlays.ScreenXY],
314 rotation_xy: Optional[fastkml.overlays.RotationXY],
315 size: Optional[fastkml.overlays.Size],
316 rotation: Optional[float],
317 ) -> None:
318 screen_overlay = fastkml.overlays.ScreenOverlay(
319 id="screen_overlay1",
320 name="screen_overlay",
321 overlay_xy=overlay_xy,
322 screen_xy=screen_xy,
323 rotation_xy=rotation_xy,
324 size=size,
325 rotation=rotation,
326 )
327
328 assert_repr_roundtrip(screen_overlay)
329 assert_str_roundtrip(screen_overlay)
330 assert_str_roundtrip_terse(screen_overlay)
331 assert_str_roundtrip_verbose(screen_overlay)