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