Debian Codegraph @

tests/hypothesis/kml_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 """Property-based tests for the views module."""
17
18 from hypothesis import given
19 from hypothesis import strategies as st
20 from hypothesis.provisional import urls
21
22 import fastkml.containers
23 import fastkml.features
24 import fastkml.kml
25 import fastkml.links
26 import fastkml.overlays
27 from tests.base import Lxml
28 from tests.hypothesis.common import assert_repr_roundtrip
29 from tests.hypothesis.common import assert_str_roundtrip
30 from tests.hypothesis.common import assert_str_roundtrip_terse
31 from tests.hypothesis.common import assert_str_roundtrip_verbose
32
33
34 class TestLxml(Lxml):
35 @given(
36 feature=st.one_of(
37 st.builds(
38 fastkml.containers.Document,
39 ),
40 st.builds(
41 fastkml.containers.Folder,
42 ),
43 st.builds(
44 fastkml.features.Placemark,
45 ),
46 st.builds(
47 fastkml.overlays.GroundOverlay,
48 ),
49 st.builds(
50 fastkml.overlays.PhotoOverlay,
51 ),
52 st.builds(
53 fastkml.features.NetworkLink,
54 link=st.builds(
55 fastkml.links.Link,
56 href=urls(),
57 ),
58 ),
59 ),
60 )
61 def test_fuzz_document(
62 self,
63 feature: fastkml.features._Feature,
64 ) -> None:
65 kml = fastkml.kml.KML(
66 features=[feature], # type: ignore[list-item]
67 )
68
69 assert_repr_roundtrip(kml)
70 assert_str_roundtrip(kml)
71 assert_str_roundtrip_terse(kml)
72 assert_str_roundtrip_verbose(kml)