| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
"""Property-based tests for the views module.""" |
| 17 |
|
| 18 |
import itertools |
| 19 |
from collections.abc import Iterable |
| 20 |
|
| 21 |
from hypothesis import given |
| 22 |
from hypothesis import strategies as st |
| 23 |
from hypothesis.provisional import urls |
| 24 |
|
| 25 |
import fastkml.containers |
| 26 |
import fastkml.data |
| 27 |
import fastkml.features |
| 28 |
import fastkml.links |
| 29 |
import fastkml.overlays |
| 30 |
import fastkml.views |
| 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 nc_name |
| 37 |
|
| 38 |
|
| 39 |
class TestLxml(Lxml): |
| 40 |
@given( |
| 41 |
features_tuple=st.tuples( |
| 42 |
st.lists( |
| 43 |
st.builds( |
| 44 |
fastkml.containers.Document, |
| 45 |
), |
| 46 |
), |
| 47 |
st.lists( |
| 48 |
st.builds( |
| 49 |
fastkml.containers.Folder, |
| 50 |
), |
| 51 |
), |
| 52 |
st.lists( |
| 53 |
st.builds( |
| 54 |
fastkml.features.Placemark, |
| 55 |
), |
| 56 |
), |
| 57 |
st.lists( |
| 58 |
st.builds( |
| 59 |
fastkml.overlays.GroundOverlay, |
| 60 |
), |
| 61 |
), |
| 62 |
st.lists( |
| 63 |
st.builds( |
| 64 |
fastkml.overlays.PhotoOverlay, |
| 65 |
), |
| 66 |
), |
| 67 |
st.lists( |
| 68 |
st.builds( |
| 69 |
fastkml.features.NetworkLink, |
| 70 |
link=st.builds( |
| 71 |
fastkml.links.Link, |
| 72 |
href=urls(), |
| 73 |
), |
| 74 |
), |
| 75 |
), |
| 76 |
), |
| 77 |
) |
| 78 |
def test_fuzz_folder( |
| 79 |
self, |
| 80 |
features_tuple: tuple[Iterable[fastkml.features._Feature]], |
| 81 |
) -> None: |
| 82 |
features = itertools.chain(*features_tuple) |
| 83 |
folder = fastkml.containers.Folder( |
| 84 |
features=features, |
| 85 |
) |
| 86 |
|
| 87 |
assert_repr_roundtrip(folder) |
| 88 |
assert_str_roundtrip(folder) |
| 89 |
assert_str_roundtrip_terse(folder) |
| 90 |
assert_str_roundtrip_verbose(folder) |
| 91 |
|
| 92 |
@given( |
| 93 |
features_tuple=st.tuples( |
| 94 |
st.lists( |
| 95 |
st.builds( |
| 96 |
fastkml.containers.Document, |
| 97 |
), |
| 98 |
), |
| 99 |
st.lists( |
| 100 |
st.builds( |
| 101 |
fastkml.containers.Folder, |
| 102 |
), |
| 103 |
), |
| 104 |
st.lists( |
| 105 |
st.builds( |
| 106 |
fastkml.features.Placemark, |
| 107 |
), |
| 108 |
), |
| 109 |
st.lists( |
| 110 |
st.builds( |
| 111 |
fastkml.overlays.GroundOverlay, |
| 112 |
), |
| 113 |
), |
| 114 |
st.lists( |
| 115 |
st.builds( |
| 116 |
fastkml.overlays.PhotoOverlay, |
| 117 |
), |
| 118 |
), |
| 119 |
st.lists( |
| 120 |
st.builds( |
| 121 |
fastkml.features.NetworkLink, |
| 122 |
link=st.builds( |
| 123 |
fastkml.links.Link, |
| 124 |
href=urls(), |
| 125 |
), |
| 126 |
), |
| 127 |
), |
| 128 |
), |
| 129 |
schemata=st.lists( |
| 130 |
st.builds( |
| 131 |
fastkml.data.Schema, |
| 132 |
id=nc_name(), |
| 133 |
), |
| 134 |
max_size=1, |
| 135 |
), |
| 136 |
) |
| 137 |
def test_fuzz_document( |
| 138 |
self, |
| 139 |
features_tuple: tuple[Iterable[fastkml.features._Feature]], |
| 140 |
schemata: Iterable[fastkml.data.Schema], |
| 141 |
) -> None: |
| 142 |
features: Iterable[fastkml.features._Feature] = itertools.chain( |
| 143 |
*features_tuple, |
| 144 |
) |
| 145 |
document = fastkml.containers.Document( |
| 146 |
features=features, |
| 147 |
schemata=schemata, |
| 148 |
) |
| 149 |
|
| 150 |
assert_repr_roundtrip(document) |
| 151 |
assert_str_roundtrip(document) |
| 152 |
assert_str_roundtrip_terse(document) |
| 153 |
assert_str_roundtrip_verbose(document) |