Debian Codegraph @

tests/hypothesis/atom_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 """
17 Property-based tests for Link and Author classes using Hypothesis.
18
19 This module implements fuzz testing to verify the serialization/deserialization
20 roundtrip and string representation of Link and Author classes under various
21 input conditions.
22 """
23
24 from typing import Optional
25
26 from hypothesis import given
27 from hypothesis import strategies as st
28 from hypothesis.provisional import urls
29
30 import fastkml.atom
31 import fastkml.enums
32 from tests.base import Lxml
33 from tests.hypothesis.common import assert_repr_roundtrip
34 from tests.hypothesis.common import assert_str_roundtrip
35 from tests.hypothesis.common import assert_str_roundtrip_terse
36 from tests.hypothesis.common import assert_str_roundtrip_verbose
37 from tests.hypothesis.strategies import href_langs
38 from tests.hypothesis.strategies import media_types
39 from tests.hypothesis.strategies import xml_text
40
41
42 class TestLxml(Lxml):
43 @given(
44 href=urls(),
45 rel=st.one_of(st.none(), xml_text()),
46 type=st.one_of(st.none(), media_types()),
47 hreflang=st.one_of(st.none(), href_langs()),
48 title=st.one_of(st.none(), xml_text()),
49 length=st.one_of(st.none(), st.integers()),
50 )
51 def test_fuzz_link(
52 self,
53 href: Optional[str],
54 rel: Optional[str],
55 type: Optional[str],
56 hreflang: Optional[str],
57 title: Optional[str],
58 length: Optional[int],
59 ) -> None:
60 link = fastkml.atom.Link(
61 href=href,
62 rel=rel,
63 type=type,
64 hreflang=hreflang,
65 title=title,
66 length=length,
67 )
68
69 assert_repr_roundtrip(link)
70 assert_str_roundtrip(link)
71 assert_str_roundtrip_terse(link)
72 assert_str_roundtrip_verbose(link)
73
74 @given(
75 name=st.one_of(st.none(), xml_text()),
76 uri=st.one_of(st.none(), urls()),
77 email=st.one_of(st.none(), st.emails()),
78 )
79 def test_fuzz_author(
80 self,
81 name: Optional[str],
82 uri: Optional[str],
83 email: Optional[str],
84 ) -> None:
85 author = fastkml.atom.Author(name=name, uri=uri, email=email)
86
87 assert_repr_roundtrip(author)
88 assert_str_roundtrip(author)
89 assert_str_roundtrip_terse(author)
90 assert_str_roundtrip_verbose(author)