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