Debian Codegraph @

tests/hypothesis/times_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 the times module.
18
19 These tests use the hypothesis library to generate random input for the
20 functions under test. The tests are run with pytest.
21 """
22
23 from typing import Optional
24
25 from hypothesis import given
26 from hypothesis import strategies as st
27
28 import fastkml
29 import fastkml.enums
30 import fastkml.times
31 from tests.base import Lxml
32 from tests.hypothesis.common import assert_repr_roundtrip
33 from tests.hypothesis.common import assert_str_roundtrip
34 from tests.hypothesis.common import assert_str_roundtrip_terse
35 from tests.hypothesis.common import assert_str_roundtrip_verbose
36 from tests.hypothesis.strategies import kml_datetimes
37 from tests.hypothesis.strategies import nc_name
38
39
40 class TestTimes(Lxml):
41 @given(
42 id=st.one_of(st.none(), nc_name()),
43 target_id=st.one_of(st.none(), nc_name()),
44 timestamp=st.one_of(st.none(), kml_datetimes()),
45 )
46 def test_fuzz_time_stamp(
47 self,
48 id: Optional[str],
49 target_id: Optional[str],
50 timestamp: Optional[fastkml.times.KmlDateTime],
51 ) -> None:
52 time_stamp = fastkml.TimeStamp(id=id, target_id=target_id, timestamp=timestamp)
53
54 assert_repr_roundtrip(time_stamp)
55 assert_str_roundtrip(time_stamp)
56 assert_str_roundtrip_terse(time_stamp)
57 assert_str_roundtrip_verbose(time_stamp)
58
59 @given(
60 id=st.one_of(st.none(), nc_name()),
61 target_id=st.one_of(st.none(), nc_name()),
62 begin=st.one_of(st.none(), kml_datetimes()),
63 end=st.one_of(st.none(), kml_datetimes()),
64 )
65 def test_fuzz_time_span(
66 self,
67 id: Optional[str],
68 target_id: Optional[str],
69 begin: Optional[fastkml.times.KmlDateTime],
70 end: Optional[fastkml.times.KmlDateTime],
71 ) -> None:
72 time_span = fastkml.TimeSpan(id=id, target_id=target_id, begin=begin, end=end)
73
74 assert_repr_roundtrip(time_span)
75 assert_str_roundtrip(time_span)
76 assert_str_roundtrip_terse(time_span)
77 assert_str_roundtrip_verbose(time_span)