Debian Codegraph @

tests/hypothesis/network_link_control_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 """Hypothesis tests for the fastkml.network_link_control module."""
17
18 from typing import Optional
19 from typing import Union
20
21 from hypothesis import given
22 from hypothesis import strategies as st
23
24 import fastkml
25 import fastkml.enums
26 import fastkml.model
27 import fastkml.views
28 from tests.base import Lxml
29 from tests.hypothesis.common import assert_repr_roundtrip
30 from tests.hypothesis.common import assert_str_roundtrip
31 from tests.hypothesis.common import assert_str_roundtrip_terse
32 from tests.hypothesis.common import assert_str_roundtrip_verbose
33 from tests.hypothesis.strategies import kml_datetimes
34 from tests.hypothesis.strategies import xml_text
35
36
37 class TestLxml(Lxml):
38 @given(
39 min_refresh_period=st.one_of(
40 st.none(),
41 st.floats(allow_nan=False, allow_infinity=False).filter(lambda x: x != 0),
42 ),
43 max_session_length=st.one_of(
44 st.none(),
45 st.floats(allow_nan=False, allow_infinity=False).filter(lambda x: x != -1),
46 ),
47 cookie=st.one_of(st.none(), xml_text()),
48 message=st.one_of(st.none(), xml_text()),
49 link_name=st.one_of(st.none(), xml_text()),
50 link_description=st.one_of(st.none(), xml_text()),
51 link_snippet=st.one_of(st.none(), xml_text()),
52 expires=st.one_of(
53 st.none(),
54 kml_datetimes(),
55 ),
56 view=st.one_of(
57 st.none(),
58 st.builds(
59 fastkml.views.Camera,
60 longitude=st.floats(
61 allow_nan=False,
62 allow_infinity=False,
63 min_value=-180,
64 max_value=180,
65 ).filter(lambda x: x != 0),
66 latitude=st.floats(
67 allow_nan=False,
68 allow_infinity=False,
69 min_value=-90,
70 max_value=90,
71 ).filter(lambda x: x != 0),
72 altitude=st.floats(allow_nan=False, allow_infinity=False).filter(
73 lambda x: x != 0,
74 ),
75 ),
76 st.builds(
77 fastkml.views.LookAt,
78 longitude=st.floats(
79 allow_nan=False,
80 allow_infinity=False,
81 min_value=-180,
82 max_value=180,
83 ).filter(lambda x: x != 0),
84 latitude=st.floats(
85 allow_nan=False,
86 allow_infinity=False,
87 min_value=-90,
88 max_value=90,
89 ).filter(lambda x: x != 0),
90 altitude=st.floats(allow_nan=False, allow_infinity=False).filter(
91 lambda x: x != 0,
92 ),
93 ),
94 ),
95 )
96 def test_fuzz_network_link_control(
97 self,
98 min_refresh_period: Optional[float],
99 max_session_length: Optional[float],
100 cookie: Optional[str],
101 message: Optional[str],
102 link_name: Optional[str],
103 link_description: Optional[str],
104 link_snippet: Optional[str],
105 expires: Optional[fastkml.KmlDateTime],
106 view: Union[fastkml.Camera, fastkml.LookAt, None],
107 ) -> None:
108 nlc = fastkml.NetworkLinkControl(
109 min_refresh_period=min_refresh_period,
110 max_session_length=max_session_length,
111 cookie=cookie,
112 message=message,
113 link_name=link_name,
114 link_description=link_description,
115 link_snippet=link_snippet,
116 expires=expires,
117 view=view,
118 )
119
120 assert_repr_roundtrip(nlc)
121 assert_str_roundtrip(nlc)
122 assert_str_roundtrip_terse(nlc)
123 assert_str_roundtrip_verbose(nlc)