Skip to content

Commit

Permalink
test placemarks and network links
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Nov 10, 2024
1 parent ced6b27 commit 0ff28f7
Show file tree
Hide file tree
Showing 27 changed files with 534 additions and 31 deletions.
2 changes: 1 addition & 1 deletion fastkml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def geometry(self) -> Optional[AnyGeometryType]:
registry.register(
Placemark,
RegistryItem(
ns_ids=("kml",),
ns_ids=("kml", "gx"),
attr_name="kml_geometry",
node_name=(
"Point,LineString,LinearRing,Polygon,MultiGeometry,"
Expand Down
1 change: 1 addition & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Base classes to run the tests both with the std library and lxml."""

import xml.etree.ElementTree as ET

import pytest
Expand Down
1 change: 0 additions & 1 deletion tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

"""Test the base classes."""


from fastkml import base
from fastkml import kml_base
from tests.base import Lxml
Expand Down
1 change: 0 additions & 1 deletion tests/containers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

"""Test the kml classes."""


import pytest

from fastkml import containers
Expand Down
47 changes: 47 additions & 0 deletions tests/features_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

"""Test the kml classes."""

import datetime

import pytest
from dateutil.tz import tzutc
from pygeoif import geometry as geo

from fastkml import atom
from fastkml import features
from fastkml import geometry
from fastkml import links
from fastkml import styles
from fastkml import times
from fastkml import views
from tests.base import Lxml
from tests.base import StdLibrary
Expand All @@ -46,6 +50,49 @@ def test_feature_base(self) -> None:
assert f.times is None
assert "_Feature>" in str(f.to_string())

def test_placemark_empty_str_roundtrip(self) -> None:
pm = features.Placemark()

new_pm = features.Placemark.from_string(str(pm.to_string()))

assert new_pm == pm

def test_placemark_camera_str_roundtrip(self) -> None:
camera = views.Camera(
latitude=37.0,
longitude=-122.0,
altitude=0.0,
roll=0.0,
tilt=0.0,
heading=0.0,
)
pm = features.Placemark(view=camera)

new_pm = features.Placemark.from_string(str(pm.to_string()))

assert new_pm == pm

def test_placemark_timespan_str_roundtrip(self) -> None:
time_span = times.TimeSpan(
begin=times.KmlDateTime(
dt=datetime.datetime(
2012,
3,
5,
0,
48,
32,
tzinfo=tzutc(),
),
),
end=times.KmlDateTime(dt=datetime.date(2012, 4, 5)),
)
pm = features.Placemark(times=time_span)

new_pm = features.Placemark.from_string(str(pm.to_string()))

assert new_pm == pm

def test_placemark_geometry_parameter_set(self) -> None:
"""Placemark object can be created with geometry parameter."""
geometry = geo.Point(10, 20)
Expand Down
1 change: 0 additions & 1 deletion tests/geometries/coordinates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

"""Test the coordinates class."""


from fastkml.geometry import Coordinates
from tests.base import Lxml
from tests.base import StdLibrary
Expand Down
1 change: 1 addition & 0 deletions tests/geometries/functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Test the geometry error handling."""

from typing import Callable
from unittest.mock import Mock
from unittest.mock import patch
Expand Down
1 change: 1 addition & 0 deletions tests/geometries/geometry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Test the geometry classes."""

import pytest
from pygeoif import geometry as geo

Expand Down
1 change: 1 addition & 0 deletions tests/geometries/multigeometry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Test the geometry classes."""

import pygeoif.geometry as geo
import pytest

Expand Down
1 change: 1 addition & 0 deletions tests/gx_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Test the gx classes."""

import datetime

import pygeoif.geometry as geo
Expand Down
1 change: 1 addition & 0 deletions tests/helper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# along with this library; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Test the helper functions edge cases."""

from enum import Enum
from typing import Callable
from unittest.mock import Mock
Expand Down
1 change: 0 additions & 1 deletion tests/hypothesis/atom_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@


class TestLxml(Lxml):

@given(
href=urls(),
rel=st.one_of(st.none(), xml_text()),
Expand Down
Loading

0 comments on commit 0ff28f7

Please sign in to comment.