| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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) |