Skip to content

Commit

Permalink
add property-based tests for KML features including Document, Folder,…
Browse files Browse the repository at this point in the history
… Placemark, and Overlays
  • Loading branch information
cleder committed Nov 11, 2024
1 parent edcd8b0 commit 6e20e19
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/hypothesis/kml_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (C) 2024 Christian Ledermann
#
# This library is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Property-based tests for the views module."""

from hypothesis import given
from hypothesis import strategies as st
from hypothesis.provisional import urls

import fastkml.containers
import fastkml.features
import fastkml.kml
import fastkml.links
import fastkml.overlays
from tests.base import Lxml
from tests.hypothesis.common import assert_repr_roundtrip
from tests.hypothesis.common import assert_str_roundtrip
from tests.hypothesis.common import assert_str_roundtrip_terse
from tests.hypothesis.common import assert_str_roundtrip_verbose


class TestLxml(Lxml):
@given(
feature=st.one_of(
st.builds(
fastkml.containers.Document,
),
st.builds(
fastkml.containers.Folder,
),
st.builds(
fastkml.features.Placemark,
),
st.builds(
fastkml.overlays.GroundOverlay,
),
st.builds(
fastkml.overlays.PhotoOverlay,
),
st.builds(
fastkml.features.NetworkLink,
link=st.builds(
fastkml.links.Link,
href=urls(),
),
),
),
)
def test_fuzz_document(
self,
feature: fastkml.features._Feature,
) -> None:
kml = fastkml.kml.KML(
features=[feature], # type: ignore[list-item]
)

assert_repr_roundtrip(kml)
assert_str_roundtrip(kml)
assert_str_roundtrip_terse(kml)
assert_str_roundtrip_verbose(kml)

0 comments on commit 6e20e19

Please sign in to comment.