-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add property-based tests for KML features including Document, Folder,…
… Placemark, and Overlays
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |