Debian Codegraph @

tests/hypothesis/gx/track_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 gx Track and MultiTrack."""
17
18 from collections.abc import Iterable
19 from typing import Optional
20
21 from hypothesis import given
22 from hypothesis import strategies as st
23 from hypothesis.provisional import urls
24
25 import fastkml
26 import fastkml.data
27 import fastkml.enums
28 import fastkml.gx.data
29 import fastkml.types
30 from tests.base import Lxml
31 from tests.hypothesis.common import assert_repr_roundtrip
32 from tests.hypothesis.common import assert_str_roundtrip
33 from tests.hypothesis.common import assert_str_roundtrip_terse
34 from tests.hypothesis.common import assert_str_roundtrip_verbose
35 from tests.hypothesis.strategies import nc_name
36 from tests.hypothesis.strategies import track_items
37 from tests.hypothesis.strategies import xml_text
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 altitude_mode=st.one_of(st.none(), st.sampled_from(fastkml.enums.AltitudeMode)),
45 track_items=st.one_of(
46 st.none(),
47 st.lists(
48 track_items(),
49 ),
50 ),
51 extended_data=st.builds(
52 fastkml.ExtendedData,
53 elements=st.tuples(
54 st.builds(
55 fastkml.data.Data,
56 name=xml_text().filter(lambda x: x.strip() != ""),
57 value=xml_text().filter(lambda x: x.strip() != ""),
58 display_name=st.one_of(st.none(), xml_text()),
59 ),
60 st.builds(
61 fastkml.SchemaData,
62 schema_url=urls(),
63 data=st.lists(
64 st.builds(
65 fastkml.data.SimpleData,
66 name=xml_text().filter(lambda x: x.strip() != ""),
67 value=xml_text().filter(lambda x: x.strip() != ""),
68 ),
69 min_size=1,
70 max_size=3,
71 ),
72 array_data=st.lists(
73 st.builds(
74 fastkml.gx.data.SimpleArrayData,
75 name=xml_text().filter(lambda x: x.strip() != ""),
76 data=st.lists(
77 xml_text().filter(lambda x: x.strip() != ""),
78 min_size=1,
79 ),
80 ),
81 min_size=1,
82 max_size=3,
83 ),
84 ),
85 ),
86 ),
87 )
88 def test_fuzz_track_track_items(
89 self,
90 id: Optional[str],
91 target_id: Optional[str],
92 altitude_mode: Optional[fastkml.enums.AltitudeMode],
93 track_items: Optional[Iterable[fastkml.gx.TrackItem]],
94 extended_data: Optional[fastkml.ExtendedData],
95 ) -> None:
96 track = fastkml.gx.Track(
97 id=id,
98 target_id=target_id,
99 altitude_mode=altitude_mode,
100 track_items=track_items,
101 extended_data=extended_data,
102 )
103
104 assert_repr_roundtrip(track)
105 assert_str_roundtrip(track)
106 assert_str_roundtrip_terse(track)
107 assert_str_roundtrip_verbose(track)
108
109 @given(
110 id=st.one_of(st.none(), nc_name()),
111 target_id=st.one_of(st.none(), nc_name()),
112 altitude_mode=st.one_of(st.none(), st.sampled_from(fastkml.enums.AltitudeMode)),
113 tracks=st.one_of(
114 st.none(),
115 st.lists(
116 st.builds(
117 fastkml.gx.Track,
118 altitude_mode=st.one_of(
119 st.none(),
120 st.sampled_from(fastkml.enums.AltitudeMode),
121 ),
122 track_items=st.lists(
123 track_items(),
124 ),
125 ),
126 ),
127 ),
128 interpolate=st.one_of(st.none(), st.booleans()),
129 )
130 def test_fuzz_multi_track(
131 self,
132 id: Optional[str],
133 target_id: Optional[str],
134 altitude_mode: Optional[fastkml.enums.AltitudeMode],
135 tracks: Optional[Iterable[fastkml.gx.Track]],
136 interpolate: Optional[bool],
137 ) -> None:
138 multi_track = fastkml.gx.MultiTrack(
139 id=id,
140 target_id=target_id,
141 altitude_mode=altitude_mode,
142 tracks=tracks,
143 interpolate=interpolate,
144 )
145
146 assert_repr_roundtrip(multi_track)
147 assert_str_roundtrip(multi_track)
148 assert_str_roundtrip_terse(multi_track)
149 assert_str_roundtrip_verbose(multi_track)