diff --git a/fastkml/features.py b/fastkml/features.py index 721f27b4..7d6702a8 100644 --- a/fastkml/features.py +++ b/fastkml/features.py @@ -6,7 +6,6 @@ import logging from dataclasses import dataclass -from typing import Any from typing import Dict from typing import Iterator from typing import List @@ -64,7 +63,6 @@ class _Feature(TimeMixin, _BaseObject): * Container (Document, Folder) * Placemark * Overlay - Not Implemented Yet: * NetworkLink. """ @@ -231,39 +229,20 @@ def view(self, camera: Optional[Union[Camera, LookAt]]) -> None: self._view = camera @property - def link(self): - return self._atom_link.href + def link(self) -> atom.Link: + return self._atom_link @link.setter - def link(self, url) -> None: - if isinstance(url, str): - self._atom_link = atom.Link(href=url) - elif isinstance(url, atom.Link): - self._atom_link = url - elif url is None: - self._atom_link = None - else: - raise TypeError + def link(self, link: Optional[atom.Link]) -> None: + self._atom_link = link @property - def author(self) -> None: - if self._atom_author: - return self._atom_author.name - return None + def author(self) -> Optional[atom.Author]: + return self._atom_author @author.setter - def author(self, name) -> None: - if isinstance(name, atom.Author): - self._atom_author = name - elif isinstance(name, str): - if self._atom_author is None: - self._atom_author = atom.Author(ns=config.ATOMNS, name=name) - else: - self._atom_author.name = name - elif name is None: - self._atom_author = None - else: - raise TypeError + def author(self, author: Optional[atom.Author]) -> None: + self._atom_author = author def append_style(self, style: Union[Style, StyleMap]) -> None: """Append a style to the feature.""" @@ -481,7 +460,7 @@ def __init__( atom_author: Optional[atom.Author] = None, address: Optional[str] = None, phone_number: Optional[str] = None, - snippet: Optional[Union[str, Dict[str, Any]]] = None, + snippet: Optional[Snippet] = None, description: Optional[str] = None, view: Optional[Union[Camera, LookAt]] = None, times: Optional[Union[TimeSpan, TimeStamp]] = None, @@ -654,7 +633,7 @@ def __init__( atom_author: Optional[atom.Author] = None, address: Optional[str] = None, phone_number: Optional[str] = None, - snippet: Optional[Union[str, Dict[str, Any]]] = None, + snippet: Optional[Snippet] = None, description: Optional[str] = None, view: Optional[Union[Camera, LookAt]] = None, times: Optional[Union[TimeSpan, TimeStamp]] = None, diff --git a/tests/oldunit_test.py b/tests/oldunit_test.py index 05d512c3..454cd95a 100644 --- a/tests/oldunit_test.py +++ b/tests/oldunit_test.py @@ -169,7 +169,10 @@ def test_document(self) -> None: def test_author(self) -> None: d = kml.Document() - d.author = "Christian Ledermann" + d.author = atom.Author( + ns="{http://www.w3.org/2005/Atom}", + name="Christian Ledermann", + ) assert "Christian Ledermann" in str(d.to_string()) a = atom.Author( ns="{http://www.w3.org/2005/Atom}", @@ -178,7 +181,6 @@ def test_author(self) -> None: email="cl@donotreply.com", ) d.author = a - assert d.author == "Nobody" assert "Christian Ledermann" not in str(d.to_string()) assert "Nobody" in str(d.to_string()) assert "http://localhost" in str(d.to_string()) @@ -190,11 +192,10 @@ def test_author(self) -> None: def test_link(self) -> None: d = kml.Document() - d.link = "http://localhost" + d.link = atom.Link(ns=config.ATOMNS, href="http://localhost") assert "http://localhost" in str(d.to_string()) d.link = atom.Link(ns=config.ATOMNS, href="#here") assert "#here" in str(d.to_string()) - # pytest.raises(TypeError, d.link, object) d2 = kml.Document() d2.from_string(d.to_string()) assert d.to_string() == d2.to_string() @@ -538,7 +539,8 @@ def test_snippet(self) -> None: assert next(iter(k.features())).snippet.text == "Short Desc" assert next(iter(k.features())).snippet.max_lines == 2 next(iter(k.features()))._snippet = features.Snippet( - text="Another Snippet", max_lines=3 + text="Another Snippet", + max_lines=3, ) assert 'maxLines="3"' in k.to_string() next(iter(k.features())).snippet = features.Snippet(text="Another Snippet")