Debian Codegraph @

tests/hypothesis/gx/data_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 SimpleArrayData and SimpleArrayField."""
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
24 import fastkml
25 import fastkml.gx.data
26 import fastkml.types
27 from fastkml.enums import DataType
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 nc_name
34 from tests.hypothesis.strategies import xml_text
35
36
37 class TestLxml(Lxml):
38 @given(
39 id=st.one_of(st.none(), nc_name()),
40 target_id=st.one_of(st.none(), nc_name()),
41 name=st.one_of(st.none(), xml_text()),
42 data=st.one_of(st.none(), st.lists(xml_text())),
43 )
44 def test_fuzz_simple_array_data(
45 self,
46 id: Optional[str],
47 target_id: Optional[str],
48 name: Optional[str],
49 data: Optional[Iterable[str]],
50 ) -> None:
51 simple_array_data = fastkml.gx.data.SimpleArrayData(
52 id=id,
53 target_id=target_id,
54 name=name,
55 data=data,
56 )
57
58 assert_repr_roundtrip(simple_array_data)
59 assert_str_roundtrip(simple_array_data)
60 assert_str_roundtrip_terse(simple_array_data)
61 assert_str_roundtrip_verbose(simple_array_data)
62
63 @given(
64 name=st.one_of(st.none(), xml_text()),
65 type_=st.one_of(st.none(), st.sampled_from(DataType)),
66 display_name=st.one_of(st.none(), xml_text()),
67 )
68 def test_fuzz_simple_array_field(
69 self,
70 name: Optional[str],
71 type_: Optional[DataType],
72 display_name: Optional[str],
73 ) -> None:
74 simple_array_field = fastkml.gx.data.SimpleArrayField(
75 name=name,
76 type_=type_,
77 display_name=display_name,
78 )
79
80 assert_repr_roundtrip(simple_array_field)
81 assert_str_roundtrip(simple_array_field)
82 assert_str_roundtrip_terse(simple_array_field)
83 assert_str_roundtrip_verbose(simple_array_field)