From d30f680428b2c3ffa1d825c810aa872a8a558fbd Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Sat, 2 Dec 2023 14:41:43 +0000 Subject: [PATCH] Fix namespaces gx.py and views.py, unskip tests --- fastkml/gx.py | 4 +++- fastkml/views.py | 4 +++- tests/times_test.py | 8 +++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fastkml/gx.py b/fastkml/gx.py index a17d57fe..546a1d35 100644 --- a/fastkml/gx.py +++ b/fastkml/gx.py @@ -450,6 +450,8 @@ def _get_kwargs( element=element, strict=strict, ) + name_spaces = kwargs["name_spaces"] + assert name_spaces is not None kwargs["interpolate"] = cls._get_interpolate( ns=ns, name_spaces=name_spaces, @@ -457,7 +459,7 @@ def _get_kwargs( strict=strict, ) kwargs["tracks"] = cls._get_track_kwargs_from_element( - ns=kwargs["name_spaces"].get("gx", ""), + ns=name_spaces["gx"], name_spaces=name_spaces, element=element, strict=strict, diff --git a/fastkml/views.py b/fastkml/views.py index 27b8ecbd..a939fe15 100644 --- a/fastkml/views.py +++ b/fastkml/views.py @@ -239,6 +239,8 @@ def _get_kwargs( element=element, strict=strict, ) + name_spaces = kwargs["name_spaces"] + assert name_spaces is not None longitude = element.find(f"{ns}longitude") if longitude is not None: kwargs["longitude"] = float(longitude.text) @@ -256,7 +258,7 @@ def _get_kwargs( kwargs["tilt"] = float(tilt.text) altitude_mode = element.find(f"{ns}altitudeMode") if altitude_mode is None: - altitude_mode = element.find(f"{kwargs['name_spaces']['gx']}altitudeMode") + altitude_mode = element.find(f"{name_spaces['gx']}altitudeMode") if altitude_mode is not None: kwargs["altitude_mode"] = AltitudeMode(altitude_mode.text) timespan = element.find(f"{ns}TimeSpan") diff --git a/tests/times_test.py b/tests/times_test.py index 33fdb674..8afb0b52 100644 --- a/tests/times_test.py +++ b/tests/times_test.py @@ -236,13 +236,11 @@ def test_feature_timestamp(self) -> None: f._times = None assert "TimeStamp>" not in str(f.to_string()) - @pytest.mark.skip(reason="not yet implemented") def test_feature_timespan(self) -> None: now = datetime.datetime.now() y2k = datetime.datetime(2000, 1, 1) f = kml.Document() - f.begin = KmlDateTime(y2k) - f.end = KmlDateTime(now) + f._times = kml.TimeSpan(begin=KmlDateTime(y2k), end=KmlDateTime(now)) assert f.begin == KmlDateTime(y2k) assert f.end == KmlDateTime(now) assert now.isoformat() in str(f.to_string()) @@ -250,13 +248,13 @@ def test_feature_timespan(self) -> None: assert "TimeSpan>" in str(f.to_string()) assert "begin>" in str(f.to_string()) assert "end>" in str(f.to_string()) - f.end = None + f._times = kml.TimeSpan(begin=KmlDateTime(y2k)) assert now.isoformat() not in str(f.to_string()) assert "2000-01-01" in str(f.to_string()) assert "TimeSpan>" in str(f.to_string()) assert "begin>" in str(f.to_string()) assert "end>" not in str(f.to_string()) - f.begin = None + f._times = None assert "TimeSpan>" not in str(f.to_string()) def test_read_timestamp_year(self) -> None: