Debian Codegraph @

tests/hypothesis/links_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 import string
19 from typing import Optional
20 from typing import Union
21
22 import pytest
23 from hypothesis import given
24 from hypothesis import strategies as st
25 from hypothesis.provisional import urls
26
27 import fastkml
28 import fastkml.enums
29 from fastkml.validator import validate
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 query_strings
37
38 common_link = {
39 "id": st.one_of(st.none(), nc_name()),
40 "target_id": st.one_of(st.none(), nc_name()),
41 "href": st.one_of(st.none(), urls()),
42 "refresh_mode": st.one_of(st.none(), st.sampled_from(fastkml.enums.RefreshMode)),
43 "refresh_interval": st.one_of(
44 st.none(),
45 st.floats(allow_infinity=False, allow_nan=False),
46 ),
47 "view_refresh_mode": st.one_of(
48 st.none(),
49 st.sampled_from(fastkml.enums.ViewRefreshMode),
50 ),
51 "view_refresh_time": st.one_of(
52 st.none(),
53 st.floats(allow_infinity=False, allow_nan=False),
54 ),
55 "view_bound_scale": st.one_of(
56 st.none(),
57 st.floats(allow_infinity=False, allow_nan=False),
58 ),
59 "view_format": st.one_of(
60 st.none(),
61 st.text(string.ascii_letters + string.punctuation),
62 ),
63 "http_query": st.one_of(st.none(), query_strings()),
64 }
65
66
67 class TestLxml(Lxml):
68 @pytest.mark.parametrize("cls", [fastkml.Link, fastkml.Icon])
69 @given(**common_link)
70 def test_fuzz_link(
71 self,
72 cls: Union[type[fastkml.Link], type[fastkml.Icon]],
73 id: Optional[str],
74 target_id: Optional[str],
75 href: Optional[str],
76 refresh_mode: Optional[fastkml.enums.RefreshMode],
77 refresh_interval: Optional[float],
78 view_refresh_mode: Optional[fastkml.enums.ViewRefreshMode],
79 view_refresh_time: Optional[float],
80 view_bound_scale: Optional[float],
81 view_format: Optional[str],
82 http_query: Optional[str],
83 ) -> None:
84 link = cls(
85 id=id,
86 target_id=target_id,
87 href=href,
88 refresh_mode=refresh_mode,
89 refresh_interval=refresh_interval,
90 view_refresh_mode=view_refresh_mode,
91 view_refresh_time=view_refresh_time,
92 view_bound_scale=view_bound_scale,
93 view_format=view_format,
94 http_query=http_query,
95 )
96 assert validate(element=link.etree_element())
97 assert_repr_roundtrip(link)
98 assert_str_roundtrip(link)
99 assert_str_roundtrip_terse(link)
100 assert_str_roundtrip_verbose(link)