From e1829976f1fb8492f7ec454a62eeac1bc1755170 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Sat, 14 Jan 2023 13:45:05 +0000 Subject: [PATCH 01/91] fix some type errors in views --- fastkml/views.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fastkml/views.py b/fastkml/views.py index 5b7d9e77..f0164027 100644 --- a/fastkml/views.py +++ b/fastkml/views.py @@ -1,5 +1,6 @@ import logging from typing import Optional +from typing import SupportsFloat from typing import Union import fastkml.config as config @@ -89,7 +90,7 @@ def longitude(self) -> Optional[float]: return self._longitude @longitude.setter - def longitude(self, value) -> None: + def longitude(self, value: Optional[SupportsFloat]) -> None: if isinstance(value, (str, int, float)) and (-180 <= float(value) <= 180): self._longitude = float(value) elif value is None: @@ -102,7 +103,7 @@ def latitude(self) -> Optional[float]: return self._latitude @latitude.setter - def latitude(self, value) -> None: + def latitude(self, value: Optional[SupportsFloat]) -> None: if isinstance(value, (str, int, float)) and (-90 <= float(value) <= 90): self._latitude = float(value) elif value is None: @@ -115,7 +116,7 @@ def altitude(self) -> Optional[float]: return self._altitude @altitude.setter - def altitude(self, value) -> None: + def altitude(self, value: Optional[SupportsFloat]) -> None: if isinstance(value, (str, int, float)): self._altitude = float(value) elif value is None: @@ -128,7 +129,7 @@ def heading(self) -> Optional[float]: return self._heading @heading.setter - def heading(self, value) -> None: + def heading(self, value: Optional[SupportsFloat]) -> None: if isinstance(value, (str, int, float)) and (-180 <= float(value) <= 180): self._heading = float(value) elif value is None: @@ -141,7 +142,7 @@ def tilt(self) -> Optional[float]: return self._tilt @tilt.setter - def tilt(self, value) -> None: + def tilt(self, value: Optional[SupportsFloat]) -> None: if isinstance(value, (str, int, float)) and (0 <= float(value) <= 180): self._tilt = float(value) elif value is None: From a8bc5b784f91ac05edbc2e58aa751ea212722bf2 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Sat, 14 Jan 2023 14:58:32 +0000 Subject: [PATCH 02/91] scaffold classes --- fastkml/geometry.py | 22 ++++++++++++++++++++-- tests/oldunit_test.py | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/fastkml/geometry.py b/fastkml/geometry.py index 62b0c5ab..ce9566a4 100644 --- a/fastkml/geometry.py +++ b/fastkml/geometry.py @@ -57,6 +57,7 @@ def __init__( self, ns: Optional[str] = None, id: Optional[str] = None, + target_id: Optional[str] = None, geometry: Optional[Any] = None, extrude: bool = False, tessellate: bool = False, @@ -108,7 +109,7 @@ def __init__( https://developers.google.com/kml/documentation/kmlreference#geometry """ - super().__init__(ns, id) + super().__init__(ns=ns, id=id, target_id=target_id) self.extrude = extrude self.tessellate = tessellate self.altitude_mode = altitude_mode @@ -470,4 +471,21 @@ def from_element(self, element: Element) -> None: logger.warning("No geometries found") -__all__ = ["Geometry"] +class Point(Geometry): + ... + + +class LineString(Geometry): + ... + + +class LinearRing(Geometry): + ... + + +class Polygon(Geometry): + ... + + +class MultiGeometry(Geometry): + ... diff --git a/tests/oldunit_test.py b/tests/oldunit_test.py index 76b7ecbf..a83294c7 100644 --- a/tests/oldunit_test.py +++ b/tests/oldunit_test.py @@ -1631,7 +1631,7 @@ def test_geometrycollection(self): # po.__geo_interface__, p.__geo_interface__, # ls.__geo_interface__, lr.__geo_interface__]} g = Geometry(geometry=GeometryCollection([po, p, ls, lr])) - # g1 = Geometry(geometry=as_shape(geo_if)) + # g1 = Geometry(geometry=shape(geo_if)) # self.assertEqual(g1.__geo_interface__, g.__geo_interface__) assert "MultiGeometry" in str(g.to_string()) assert "Polygon" in str(g.to_string()) From 12e400ef78079a72344f7adf25ee510213a6ad05 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Sat, 14 Jan 2023 15:04:50 +0000 Subject: [PATCH 03/91] scaffold classes --- fastkml/geometry.py | 105 ++++++++++++++++++++---------------------- tests/oldunit_test.py | 16 +++---- 2 files changed, 58 insertions(+), 63 deletions(-) diff --git a/fastkml/geometry.py b/fastkml/geometry.py index ce9566a4..ea7c6014 100644 --- a/fastkml/geometry.py +++ b/fastkml/geometry.py @@ -23,15 +23,8 @@ from typing import Union from typing import cast +import pygeoif.geometry as geo from pygeoif.factories import shape -from pygeoif.geometry import GeometryCollection -from pygeoif.geometry import LinearRing -from pygeoif.geometry import LineString -from pygeoif.geometry import MultiLineString -from pygeoif.geometry import MultiPoint -from pygeoif.geometry import MultiPolygon -from pygeoif.geometry import Point -from pygeoif.geometry import Polygon from pygeoif.types import PointType from fastkml import config @@ -40,8 +33,10 @@ logger = logging.getLogger(__name__) -GeometryType = Union[Polygon, LineString, LinearRing, Point] -MultiGeometryType = Union[MultiPoint, MultiLineString, MultiPolygon, GeometryCollection] +GeometryType = Union[geo.Polygon, geo.LineString, geo.LinearRing, geo.Point] +MultiGeometryType = Union[ + geo.MultiPoint, geo.MultiLineString, geo.MultiPolygon, geo.GeometryCollection +] AnyGeometryType = Union[GeometryType, MultiGeometryType] @@ -117,14 +112,14 @@ def __init__( if isinstance( geometry, ( - Point, - LineString, - Polygon, - MultiPoint, - MultiLineString, - MultiPolygon, - LinearRing, - GeometryCollection, + geo.Point, + geo.LineString, + geo.Polygon, + geo.MultiPoint, + geo.MultiLineString, + geo.MultiPolygon, + geo.LinearRing, + geo.GeometryCollection, ), ): self.geometry = geometry @@ -183,11 +178,11 @@ def _etree_coordinates( element.text = " ".join(tuples) return element - def _etree_point(self, point: Point) -> Element: + def _etree_point(self, point: geo.Point) -> Element: element = self._extrude_and_altitude_mode("Point") return self._extracted_from__etree_linearring_5(point, element) - def _etree_linestring(self, linestring: LineString) -> Element: + def _etree_linestring(self, linestring: geo.LineString) -> Element: element = self._extrude_and_altitude_mode("LineString") if self.tessellate and self.altitude_mode in [ "clampToGround", @@ -199,18 +194,18 @@ def _etree_linestring(self, linestring: LineString) -> Element: ts_element.text = "1" return self._extracted_from__etree_linearring_5(linestring, element) - def _etree_linearring(self, linearring: LinearRing) -> Element: + def _etree_linearring(self, linearring: geo.LinearRing) -> Element: element = self._extrude_and_altitude_mode("LinearRing") return self._extracted_from__etree_linearring_5(linearring, element) def _extracted_from__etree_linearring_5( - self, arg0: Union[LineString, LinearRing, Point], element: Element + self, arg0: Union[geo.LineString, geo.LinearRing, geo.Point], element: Element ) -> Element: coords = list(arg0.coords) element.append(self._etree_coordinates(coords)) return element - def _etree_polygon(self, polygon: Polygon) -> Element: + def _etree_polygon(self, polygon: geo.Polygon) -> Element: element = self._extrude_and_altitude_mode("Polygon") outer_boundary = cast( Element, @@ -242,7 +237,7 @@ def _extrude_and_altitude_mode(self, kml_geometry: str) -> Element: self._set_altitude_mode(result) return result - def _etree_multipoint(self, points: MultiPoint) -> Element: + def _etree_multipoint(self, points: geo.MultiPoint) -> Element: element = cast( Element, config.etree.Element( # type: ignore[attr-defined] @@ -253,7 +248,7 @@ def _etree_multipoint(self, points: MultiPoint) -> Element: element.append(self._etree_point(point)) return element - def _etree_multilinestring(self, linestrings: MultiLineString) -> Element: + def _etree_multilinestring(self, linestrings: geo.MultiLineString) -> Element: element = cast( Element, config.etree.Element( # type: ignore[attr-defined] @@ -264,7 +259,7 @@ def _etree_multilinestring(self, linestrings: MultiLineString) -> Element: element.append(self._etree_linestring(linestring)) return element - def _etree_multipolygon(self, polygons: MultiPolygon) -> Element: + def _etree_multipolygon(self, polygons: geo.MultiPolygon) -> Element: element = cast( Element, config.etree.Element( # type: ignore[attr-defined] @@ -275,7 +270,7 @@ def _etree_multipolygon(self, polygons: MultiPolygon) -> Element: element.append(self._etree_polygon(polygon)) return element - def _etree_collection(self, features: GeometryCollection) -> Element: + def _etree_collection(self, features: geo.GeometryCollection) -> Element: element = cast( Element, config.etree.Element( # type: ignore[attr-defined] @@ -284,33 +279,33 @@ def _etree_collection(self, features: GeometryCollection) -> Element: ) for feature in features.geoms: if feature.geom_type == "Point": - element.append(self._etree_point(cast(Point, feature))) + element.append(self._etree_point(cast(geo.Point, feature))) elif feature.geom_type == "LinearRing": - element.append(self._etree_linearring(cast(LinearRing, feature))) + element.append(self._etree_linearring(cast(geo.LinearRing, feature))) elif feature.geom_type == "LineString": - element.append(self._etree_linestring(cast(LineString, feature))) + element.append(self._etree_linestring(cast(geo.LineString, feature))) elif feature.geom_type == "Polygon": - element.append(self._etree_polygon(cast(Polygon, feature))) + element.append(self._etree_polygon(cast(geo.Polygon, feature))) else: raise ValueError("Illegal geometry type.") return element def etree_element(self) -> Element: - if isinstance(self.geometry, Point): + if isinstance(self.geometry, geo.Point): return self._etree_point(self.geometry) - elif isinstance(self.geometry, LinearRing): + elif isinstance(self.geometry, geo.LinearRing): return self._etree_linearring(self.geometry) - elif isinstance(self.geometry, LineString): + elif isinstance(self.geometry, geo.LineString): return self._etree_linestring(self.geometry) - elif isinstance(self.geometry, Polygon): + elif isinstance(self.geometry, geo.Polygon): return self._etree_polygon(self.geometry) - elif isinstance(self.geometry, MultiPoint): + elif isinstance(self.geometry, geo.MultiPoint): return self._etree_multipoint(self.geometry) - elif isinstance(self.geometry, MultiLineString): + elif isinstance(self.geometry, geo.MultiLineString): return self._etree_multilinestring(self.geometry) - elif isinstance(self.geometry, MultiPolygon): + elif isinstance(self.geometry, geo.MultiPolygon): return self._etree_multipolygon(self.geometry) - elif isinstance(self.geometry, GeometryCollection): + elif isinstance(self.geometry, geo.GeometryCollection): return self._etree_collection(self.geometry) else: raise ValueError("Illegal geometry type.") @@ -366,12 +361,12 @@ def _get_coordinates(self, element: Element) -> List[PointType]: for latlon in latlons ] - def _get_linear_ring(self, element: Element) -> Optional[LinearRing]: + def _get_linear_ring(self, element: Element) -> Optional[geo.LinearRing]: # LinearRing in polygon lr = element.find(f"{self.ns}LinearRing") if lr is not None: coords = self._get_coordinates(lr) - return LinearRing(coords) + return geo.LinearRing(coords) return None # type: ignore[unreachable] def _get_geometry(self, element: Element) -> Optional[GeometryType]: @@ -380,11 +375,11 @@ def _get_geometry(self, element: Element) -> Optional[GeometryType]: if element.tag == f"{self.ns}Point": coords = self._get_coordinates(element) self._get_geometry_spec(element) - return Point.from_coordinates(coords) + return geo.Point.from_coordinates(coords) if element.tag == f"{self.ns}LineString": coords = self._get_coordinates(element) self._get_geometry_spec(element) - return LineString(coords) + return geo.LineString(coords) if element.tag == f"{self.ns}Polygon": self._get_geometry_spec(element) outer_boundary = element.find(f"{self.ns}outerBoundaryIs") @@ -396,11 +391,11 @@ def _get_geometry(self, element: Element) -> Optional[GeometryType]: self._get_linear_ring(inner_boundary) for inner_boundary in inner_boundaries ] - return Polygon.from_linear_rings(ob, *[b for b in ibs if b]) + return geo.Polygon.from_linear_rings(ob, *[b for b in ibs if b]) if element.tag == f"{self.ns}LinearRing": coords = self._get_coordinates(element) self._get_geometry_spec(element) - return LinearRing(coords) + return geo.LinearRing(coords) return None def _get_multigeometry(self, element: Element) -> Optional[MultiGeometryType]: @@ -410,11 +405,11 @@ def _get_multigeometry(self, element: Element) -> Optional[MultiGeometryType]: points = element.findall(f"{self.ns}Point") for point in points: self._get_geometry_spec(point) - geoms.append(Point.from_coordinates(self._get_coordinates(point))) + geoms.append(geo.Point.from_coordinates(self._get_coordinates(point))) linestrings = element.findall(f"{self.ns}LineString") for ls in linestrings: self._get_geometry_spec(ls) - geoms.append(LineString(self._get_coordinates(ls))) + geoms.append(geo.LineString(self._get_coordinates(ls))) polygons = element.findall(f"{self.ns}Polygon") for polygon in polygons: self._get_geometry_spec(polygon) @@ -427,34 +422,34 @@ def _get_multigeometry(self, element: Element) -> Optional[MultiGeometryType]: self._get_linear_ring(inner_boundary) for inner_boundary in inner_boundaries ] - ibs: List[LinearRing] = [ib for ib in inner_bs if ib] - geoms.append(Polygon.from_linear_rings(ob, *ibs)) + ibs: List[geo.LinearRing] = [ib for ib in inner_bs if ib] + geoms.append(geo.Polygon.from_linear_rings(ob, *ibs)) linearings = element.findall(f"{self.ns}LinearRing") if linearings: for lr in linearings: self._get_geometry_spec(lr) - geoms.append(LinearRing(self._get_coordinates(lr))) + geoms.append(geo.LinearRing(self._get_coordinates(lr))) clean_geoms: List[AnyGeometryType] = [g for g in geoms if g] if clean_geoms: geom_types = {geom.geom_type for geom in clean_geoms} if len(geom_types) > 1: - return GeometryCollection( + return geo.GeometryCollection( clean_geoms, # type: ignore[arg-type] ) if "Point" in geom_types: - return MultiPoint.from_points( + return geo.MultiPoint.from_points( *clean_geoms, # type: ignore[arg-type] ) elif "LineString" in geom_types: - return MultiLineString.from_linestrings( + return geo.MultiLineString.from_linestrings( *clean_geoms, # type: ignore[arg-type] ) elif "Polygon" in geom_types: - return MultiPolygon.from_polygons( + return geo.MultiPolygon.from_polygons( *clean_geoms, # type: ignore[arg-type] ) elif "LinearRing" in geom_types: - return GeometryCollection( + return geo.GeometryCollection( clean_geoms, # type: ignore[arg-type] ) return None diff --git a/tests/oldunit_test.py b/tests/oldunit_test.py index a83294c7..837ff858 100644 --- a/tests/oldunit_test.py +++ b/tests/oldunit_test.py @@ -16,6 +16,14 @@ import xml.etree.ElementTree import pytest +from pygeoif.geometry import GeometryCollection +from pygeoif.geometry import LinearRing +from pygeoif.geometry import LineString +from pygeoif.geometry import MultiLineString +from pygeoif.geometry import MultiPoint +from pygeoif.geometry import MultiPolygon +from pygeoif.geometry import Point +from pygeoif.geometry import Polygon from fastkml import atom from fastkml import base @@ -24,14 +32,6 @@ from fastkml import kml from fastkml import styles from fastkml.geometry import Geometry -from fastkml.geometry import GeometryCollection -from fastkml.geometry import LinearRing -from fastkml.geometry import LineString -from fastkml.geometry import MultiLineString -from fastkml.geometry import MultiPoint -from fastkml.geometry import MultiPolygon -from fastkml.geometry import Point -from fastkml.geometry import Polygon from fastkml.gx import GxGeometry try: From cd123154b64f5eabf841bd68d4f6fe38c6b8f46c Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Sat, 14 Jan 2023 16:07:04 +0000 Subject: [PATCH 04/91] use Enum for altitudeMode #194 --- fastkml/enums.py | 48 +++++++++++++++++++++++++++++++ fastkml/geometry.py | 51 ++++++++++++++++----------------- tests/oldunit_test.py | 66 +++++++++++++------------------------------ 3 files changed, 92 insertions(+), 73 deletions(-) diff --git a/fastkml/enums.py b/fastkml/enums.py index b875796c..1e6ae08e 100644 --- a/fastkml/enums.py +++ b/fastkml/enums.py @@ -25,3 +25,51 @@ class DateTimeResolution(Enum): date = "date" year_month = "gYearMonth" year = "gYear" + + +@unique +class AltitudeMode(Enum): + """ + Enum to represent the different altitude modes. + + Specifies how altitude components in the element are interpreted. + Possible values are + - clampToGround - (default) Indicates to ignore an altitude specification + (for example, in the tag). + - relativeToGround - Sets the altitude of the element relative to the actual + ground elevation of a particular location. + For example, if the ground elevation of a location is exactly at sea level + and the altitude for a point is set to 9 meters, + then the elevation for the icon of a point placemark elevation is 9 meters + with this mode. + However, if the same coordinate is set over a location where the ground + elevation is 10 meters above sea level, then the elevation of the coordinate + is 19 meters. + A typical use of this mode is for placing telephone poles or a ski lift. + - absolute - Sets the altitude of the coordinate relative to sea level, + regardless of the actual elevation of the terrain beneath the element. + For example, if you set the altitude of a coordinate to 10 meters with an + absolute altitude mode, the icon of a point placemark will appear to be at + ground level if the terrain beneath is also 10 meters above sea level. + If the terrain is 3 meters above sea level, the placemark will appear elevated + above the terrain by 7 meters. + A typical use of this mode is for aircraft placement. + - relativeToSeaFloor - Interprets the altitude as a value in meters above the + sea floor. + If the point is above land rather than sea, the altitude will be interpreted + as being above the ground. + - clampToSeaFloor - The altitude specification is ignored, and the point will be + positioned on the sea floor. + If the point is on land rather than at sea, the point will be positioned on + the ground. + + The Values relativeToSeaFloor and clampToSeaFloor are not part of the KML definition + but of the a KML extension in the Google extension namespace, + allowing altitudes relative to the sea floor. + """ + + clamp_to_ground = "clampToGround" + relative_to_ground = "relativeToGround" + absolute = "absolute" + clamp_to_sea_floor = "clampToSeaFloor" + relative_to_sea_floor = "relativeToSeaFloor" diff --git a/fastkml/geometry.py b/fastkml/geometry.py index ea7c6014..12f22530 100644 --- a/fastkml/geometry.py +++ b/fastkml/geometry.py @@ -29,6 +29,7 @@ from fastkml import config from fastkml.base import _BaseObject +from fastkml.enums import AltitudeMode from fastkml.types import Element logger = logging.getLogger(__name__) @@ -46,7 +47,7 @@ class Geometry(_BaseObject): geometry = None extrude = False tessellate = False - altitude_mode = None + altitude_mode = Optional[AltitudeMode] def __init__( self, @@ -56,7 +57,7 @@ def __init__( geometry: Optional[Any] = None, extrude: bool = False, tessellate: bool = False, - altitude_mode: Optional[str] = None, + altitude_mode: Optional[AltitudeMode] = None, ) -> None: """ geometry: a geometry that implements the __geo_interface__ convention @@ -131,22 +132,22 @@ def __init__( def _set_altitude_mode(self, element: Element) -> None: if self.altitude_mode: # XXX add 'relativeToSeaFloor', 'clampToSeaFloor', - assert self.altitude_mode in [ - "clampToGround", - "relativeToGround", - "absolute", - ] - if self.altitude_mode != "clampToGround": - am_element = config.etree.SubElement( # type: ignore[attr-defined] - element, f"{self.ns}altitudeMode" - ) - am_element.text = self.altitude_mode + # assert self.altitude_mode in [ + # "clampToGround", + # "relativeToGround", + # "absolute", + # ] + # if self.altitude_mode != "clampToGround": + am_element = config.etree.SubElement( # type: ignore[attr-defined] + element, f"{self.ns}altitudeMode" + ) + am_element.text = self.altitude_mode.value def _set_extrude(self, element: Element) -> None: if self.extrude and self.altitude_mode in [ - "relativeToGround", - # 'relativeToSeaFloor', - "absolute", + AltitudeMode.relative_to_ground, + AltitudeMode.relative_to_sea_floor, + AltitudeMode.absolute, ]: et_element = cast( Element, @@ -165,10 +166,7 @@ def _etree_coordinates( config.etree.Element(f"{self.ns}coordinates"), # type: ignore[attr-defined] ) if len(coordinates[0]) == 2: - if config.FORCE3D: # and not clampToGround: - tuples = (f"{c[0]:f},{c[1]:f},0.000000" for c in coordinates) - else: - tuples = (f"{c[0]:f},{c[1]:f}" for c in coordinates) + tuples = (f"{c[0]:f},{c[1]:f}" for c in coordinates) elif len(coordinates[0]) == 3: tuples = ( f"{c[0]:f},{c[1]:f},{c[2]:f}" for c in coordinates # type: ignore[misc] @@ -180,7 +178,9 @@ def _etree_coordinates( def _etree_point(self, point: geo.Point) -> Element: element = self._extrude_and_altitude_mode("Point") - return self._extracted_from__etree_linearring_5(point, element) + coords = list(point.coords) + element.append(self._etree_coordinates(coords)) + return element def _etree_linestring(self, linestring: geo.LineString) -> Element: element = self._extrude_and_altitude_mode("LineString") @@ -192,16 +192,13 @@ def _etree_linestring(self, linestring: geo.LineString) -> Element: element, f"{self.ns}tessellate" ) ts_element.text = "1" - return self._extracted_from__etree_linearring_5(linestring, element) + coords = list(linestring.coords) + element.append(self._etree_coordinates(coords)) + return element def _etree_linearring(self, linearring: geo.LinearRing) -> Element: element = self._extrude_and_altitude_mode("LinearRing") - return self._extracted_from__etree_linearring_5(linearring, element) - - def _extracted_from__etree_linearring_5( - self, arg0: Union[geo.LineString, geo.LinearRing, geo.Point], element: Element - ) -> Element: - coords = list(arg0.coords) + coords = list(linearring.coords) element.append(self._etree_coordinates(coords)) return element diff --git a/tests/oldunit_test.py b/tests/oldunit_test.py index 837ff858..dbc5cbb2 100644 --- a/tests/oldunit_test.py +++ b/tests/oldunit_test.py @@ -31,6 +31,7 @@ from fastkml import data from fastkml import kml from fastkml import styles +from fastkml.enums import AltitudeMode from fastkml.geometry import Geometry from fastkml.gx import GxGeometry @@ -1464,16 +1465,16 @@ def test_altitude_mode(self): assert geom.altitude_mode is None assert "altitudeMode" not in str(geom.to_string()) geom.altitude_mode = "unknown" - pytest.raises(AssertionError, geom.to_string) - geom.altitude_mode = "clampToSeaFloor" - pytest.raises(AssertionError, geom.to_string) - geom.altitude_mode = "relativeToSeaFloor" - pytest.raises(AssertionError, geom.to_string) - geom.altitude_mode = "clampToGround" - assert "altitudeMode" not in str(geom.to_string()) - geom.altitude_mode = "relativeToGround" + pytest.raises(AttributeError, geom.to_string) + geom.altitude_mode = AltitudeMode("clampToSeaFloor") + assert "altitudeMode>clampToSeaFloorrelativeToSeaFloorclampToGroundrelativeToGroundabsolute1111 Date: Sat, 14 Jan 2023 16:32:35 +0000 Subject: [PATCH 05/91] move tests to geometry_test fix enum #194 --- fastkml/geometry.py | 12 +- tests/geometry_test.py | 287 +++++++++++++++++++++++++++++++++++++++++ tests/oldunit_test.py | 277 --------------------------------------- 3 files changed, 290 insertions(+), 286 deletions(-) diff --git a/fastkml/geometry.py b/fastkml/geometry.py index 12f22530..31a49811 100644 --- a/fastkml/geometry.py +++ b/fastkml/geometry.py @@ -131,7 +131,6 @@ def __init__( def _set_altitude_mode(self, element: Element) -> None: if self.altitude_mode: - # XXX add 'relativeToSeaFloor', 'clampToSeaFloor', # assert self.altitude_mode in [ # "clampToGround", # "relativeToGround", @@ -331,14 +330,9 @@ def _get_geometry_spec(self, element: Element) -> None: altitude_mode = element.find(f"{self.ns}altitudeMode") if altitude_mode is not None: am = altitude_mode.text.strip() - if am in [ - "clampToGround", - # 'relativeToSeaFloor', 'clampToSeaFloor', - "relativeToGround", - "absolute", - ]: - self.altitude_mode = am - else: + try: + self.altitude_mode = AltitudeMode(am) + except ValueError: self.altitude_mode = None else: self.altitude_mode = None # type: ignore[unreachable] diff --git a/tests/geometry_test.py b/tests/geometry_test.py index 25499538..c04c9126 100644 --- a/tests/geometry_test.py +++ b/tests/geometry_test.py @@ -15,6 +15,13 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """Test the geometry classes.""" +import pytest +from pygeoif.geometry import LineString +from pygeoif.geometry import Point +from pygeoif.geometry import Polygon + +from fastkml.geometry import AltitudeMode +from fastkml.geometry import Geometry from tests.base import Lxml from tests.base import StdLibrary @@ -22,6 +29,286 @@ class TestStdLibrary(StdLibrary): """Test with the standard library.""" + def test_altitude_mode(self) -> None: + geom = Geometry() + geom.geometry = Point(0, 1) + assert geom.altitude_mode is None + assert "altitudeMode" not in str(geom.to_string()) + geom.altitude_mode = "unknown" + pytest.raises(AttributeError, geom.to_string) + geom.altitude_mode = AltitudeMode("clampToSeaFloor") + assert "altitudeMode>clampToSeaFloorrelativeToSeaFloorclampToGroundrelativeToGroundabsolute None: + geom = Geometry() + assert geom.extrude is False + geom.geometry = Point(0, 1) + geom.extrude = False + assert "extrude" not in str(geom.to_string()) + geom.extrude = True + geom.altitude_mode = AltitudeMode("clampToGround") + assert "extrude" not in str(geom.to_string()) + geom.altitude_mode = AltitudeMode("relativeToGround") + assert "extrude>11 None: + geom = Geometry() + assert geom.tessellate is False + geom.geometry = LineString([(0, 0), (1, 1)]) + assert "tessellate" not in str(geom.to_string()) + geom.altitude_mode = AltitudeMode("clampToGround") + assert "tessellate" not in str(geom.to_string()) + geom.altitude_mode = AltitudeMode("relativeToGround") + assert "tessellate" not in str(geom.to_string()) + geom.altitude_mode = AltitudeMode("absolute") + assert "tessellate" not in str(geom.to_string()) + geom.tessellate = True + geom.altitude_mode = None + assert "tessellate" not in str(geom.to_string()) + geom.altitude_mode = AltitudeMode("relativeToGround") + assert "tessellate" not in str(geom.to_string()) + geom.altitude_mode = AltitudeMode("absolute") + assert "tessellate" not in str(geom.to_string()) + geom.altitude_mode = AltitudeMode("clampToGround") + # XXX assert "tessellate>1 + 0.000000,1.000000 + clampToGround + """ + + g = Geometry() + assert g.altitude_mode is None + g.from_string(doc) + assert g.altitude_mode == AltitudeMode("clampToGround") + + def test_extrude(self): + doc = """ + 0.000000,1.000000 + 1 + """ + + g = Geometry() + assert g.extrude is False + g.from_string(doc) + assert g.extrude is True + + def test_tesselate(self): + doc = """ + 0.000000,1.000000 + 1 + """ + + g = Geometry() + assert g.tessellate is False + g.from_string(doc) + assert g.tessellate is True + + def test_point(self): + doc = """ + 0.000000,1.000000 + """ + + g = Geometry() + g.from_string(doc) + assert g.geometry.__geo_interface__ == { + "type": "Point", + "bbox": (0.0, 1.0, 0.0, 1.0), + "coordinates": (0.0, 1.0), + } + + def test_linestring(self): + doc = """ + 0.000000,0.000000 1.000000,1.000000 + """ + + g = Geometry() + g.from_string(doc) + assert g.geometry.__geo_interface__ == { + "type": "LineString", + "bbox": (0.0, 0.0, 1.0, 1.0), + "coordinates": ((0.0, 0.0), (1.0, 1.0)), + } + + def test_linearring(self): + doc = """ + 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 + + """ + + g = Geometry() + g.from_string(doc) + assert g.geometry.__geo_interface__ == { + "type": "LinearRing", + "bbox": (0.0, 0.0, 1.0, 1.0), + "coordinates": ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)), + } + + def test_polygon(self): + doc = """ + + + 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 + + + + """ + + g = Geometry() + g.from_string(doc) + assert g.geometry.__geo_interface__ == { + "type": "Polygon", + "bbox": (0.0, 0.0, 1.0, 1.0), + "coordinates": (((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)),), + } + doc = """ + + + -1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.000000 + + + + + 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 + + + + """ + + g.from_string(doc) + assert g.geometry.__geo_interface__ == { + "type": "Polygon", + "bbox": (-1.0, -1.0, 2.0, 2.0), + "coordinates": ( + ((-1.0, -1.0), (2.0, -1.0), (2.0, 2.0), (-1.0, -1.0)), + ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)), + ), + } + + def test_multipoint(self): + doc = """ + + + 0.000000,1.000000 + + + 1.000000,1.000000 + + + """ + + g = Geometry() + g.from_string(doc) + assert len(g.geometry) == 2 + + def test_multilinestring(self): + doc = """ + + + 0.000000,0.000000 1.000000,0.000000 + + + 0.000000,1.000000 1.000000,1.000000 + + + """ + + g = Geometry() + g.from_string(doc) + assert len(g.geometry) == 2 + + def test_multipolygon(self): + doc = """ + + + + + -1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.000000 + + + + + 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 + + + + + + + 3.000000,0.000000 4.000000,0.000000 4.000000,1.000000 3.000000,0.000000 + + + + + """ + + g = Geometry() + g.from_string(doc) + assert len(g.geometry) == 2 + + def test_geometrycollection(self): + doc = """ + + + + + 3,0 4,0 4,1 3,0 + + + + + 0.000000,1.000000 + + + 0.000000,0.000000 1.000000,1.000000 + + + 0.0,0.0 1.0,0.0 1.0,1.0 0.0,1.0 0.0,0.0 + + + """ + + g = Geometry() + g.from_string(doc) + assert len(g.geometry) == 4 + doc = """ + + + 3.0,0.0 4.0,0.0 4.0,1.0 3.0,0.0 + + + 0.0,0.0 1.0,0.0 1.0,1.0 0.0,0.0 + + + """ + + g = Geometry() + g.from_string(doc) + assert len(g.geometry) == 2 + assert g.geometry.geom_type == "GeometryCollection" + class TestLxml(Lxml, TestStdLibrary): """Test with lxml.""" + + +class TestGetGeometryLxml(Lxml, TestGetGeometry): + """Test with lxml.""" diff --git a/tests/oldunit_test.py b/tests/oldunit_test.py index dbc5cbb2..87408b7e 100644 --- a/tests/oldunit_test.py +++ b/tests/oldunit_test.py @@ -31,7 +31,6 @@ from fastkml import data from fastkml import kml from fastkml import styles -from fastkml.enums import AltitudeMode from fastkml.geometry import Geometry from fastkml.gx import GxGeometry @@ -1459,64 +1458,6 @@ def test_get_style_by_url(self): class TestSetGeometry: - def test_altitude_mode(self): - geom = Geometry() - geom.geometry = Point(0, 1) - assert geom.altitude_mode is None - assert "altitudeMode" not in str(geom.to_string()) - geom.altitude_mode = "unknown" - pytest.raises(AttributeError, geom.to_string) - geom.altitude_mode = AltitudeMode("clampToSeaFloor") - assert "altitudeMode>clampToSeaFloorrelativeToSeaFloorclampToGroundrelativeToGroundabsolute1110.000000,1.000000 - 0.000000,1.000000 - clampToGround - """ - - g = Geometry() - assert g.altitude_mode is None - g.from_string(doc) - assert g.altitude_mode == "clampToGround" - - def test_extrude(self): - doc = """ - 0.000000,1.000000 - 1 - """ - - g = Geometry() - assert g.extrude is False - g.from_string(doc) - assert g.extrude is True - - def test_tesselate(self): - doc = """ - 0.000000,1.000000 - 1 - """ - - g = Geometry() - assert g.tessellate is False - g.from_string(doc) - assert g.tessellate is True - - def test_point(self): - doc = """ - 0.000000,1.000000 - """ - - g = Geometry() - g.from_string(doc) - assert g.geometry.__geo_interface__ == { - "type": "Point", - "bbox": (0.0, 1.0, 0.0, 1.0), - "coordinates": (0.0, 1.0), - } - - def test_linestring(self): - doc = """ - 0.000000,0.000000 1.000000,1.000000 - """ - - g = Geometry() - g.from_string(doc) - assert g.geometry.__geo_interface__ == { - "type": "LineString", - "bbox": (0.0, 0.0, 1.0, 1.0), - "coordinates": ((0.0, 0.0), (1.0, 1.0)), - } - - def test_linearring(self): - doc = """ - 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 - - """ - - g = Geometry() - g.from_string(doc) - assert g.geometry.__geo_interface__ == { - "type": "LinearRing", - "bbox": (0.0, 0.0, 1.0, 1.0), - "coordinates": ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)), - } - - def test_polygon(self): - doc = """ - - - 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 - - - - """ - - g = Geometry() - g.from_string(doc) - assert g.geometry.__geo_interface__ == { - "type": "Polygon", - "bbox": (0.0, 0.0, 1.0, 1.0), - "coordinates": (((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)),), - } - doc = """ - - - -1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.000000 - - - - - 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 - - - - """ - - g.from_string(doc) - assert g.geometry.__geo_interface__ == { - "type": "Polygon", - "bbox": (-1.0, -1.0, 2.0, 2.0), - "coordinates": ( - ((-1.0, -1.0), (2.0, -1.0), (2.0, 2.0), (-1.0, -1.0)), - ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)), - ), - } - - def test_multipoint(self): - doc = """ - - - 0.000000,1.000000 - - - 1.000000,1.000000 - - - """ - - g = Geometry() - g.from_string(doc) - assert len(g.geometry) == 2 - - def test_multilinestring(self): - doc = """ - - - 0.000000,0.000000 1.000000,0.000000 - - - 0.000000,1.000000 1.000000,1.000000 - - - """ - - g = Geometry() - g.from_string(doc) - assert len(g.geometry) == 2 - - def test_multipolygon(self): - doc = """ - - - - - -1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.000000 - - - - - 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 - - - - - - - 3.000000,0.000000 4.000000,0.000000 4.000000,1.000000 3.000000,0.000000 - - - - - """ - - g = Geometry() - g.from_string(doc) - assert len(g.geometry) == 2 - - def test_geometrycollection(self): - doc = """ - - - - - 3,0 4,0 4,1 3,0 - - - - - 0.000000,1.000000 - - - 0.000000,0.000000 1.000000,1.000000 - - - 0.0,0.0 1.0,0.0 1.0,1.0 0.0,1.0 0.0,0.0 - - - """ - - g = Geometry() - g.from_string(doc) - assert len(g.geometry) == 4 - doc = """ - - - 3.0,0.0 4.0,0.0 4.0,1.0 3.0,0.0 - - - 0.0,0.0 1.0,0.0 1.0,1.0 0.0,0.0 - - - """ - - g = Geometry() - g.from_string(doc) - assert len(g.geometry) == 2 - assert g.geometry.geom_type == "GeometryCollection" - - class TestGetGxGeometry: def test_track(self): doc = """ From 8cba4b04a47ca2515348d914b922b3863c5e1f29 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Sat, 14 Jan 2023 16:58:29 +0000 Subject: [PATCH 06/91] type annotate tests with infer-types --- fastkml/geometry.py | 2 +- tests/geometry_test.py | 43 ++++---- tests/oldunit_test.py | 238 ++++++++++++++++++++--------------------- tests/times_test.py | 60 +++++------ 4 files changed, 175 insertions(+), 168 deletions(-) diff --git a/fastkml/geometry.py b/fastkml/geometry.py index 31a49811..837a90e1 100644 --- a/fastkml/geometry.py +++ b/fastkml/geometry.py @@ -140,7 +140,7 @@ def _set_altitude_mode(self, element: Element) -> None: am_element = config.etree.SubElement( # type: ignore[attr-defined] element, f"{self.ns}altitudeMode" ) - am_element.text = self.altitude_mode.value + am_element.text = self.altitude_mode.value # type: ignore[attr-defined] def _set_extrude(self, element: Element) -> None: if self.extrude and self.altitude_mode in [ diff --git a/tests/geometry_test.py b/tests/geometry_test.py index c04c9126..04b6b261 100644 --- a/tests/geometry_test.py +++ b/tests/geometry_test.py @@ -89,7 +89,7 @@ def test_tesselate(self) -> None: class TestGetGeometry(StdLibrary): - def test_altitude_mode(self): + def test_altitude_mode(self) -> None: doc = """ 0.000000,1.000000 clampToGround @@ -100,7 +100,7 @@ def test_altitude_mode(self): g.from_string(doc) assert g.altitude_mode == AltitudeMode("clampToGround") - def test_extrude(self): + def test_extrude(self) -> None: doc = """ 0.000000,1.000000 1 @@ -111,7 +111,7 @@ def test_extrude(self): g.from_string(doc) assert g.extrude is True - def test_tesselate(self): + def test_tesselate(self) -> None: doc = """ 0.000000,1.000000 1 @@ -122,7 +122,7 @@ def test_tesselate(self): g.from_string(doc) assert g.tessellate is True - def test_point(self): + def test_point(self) -> None: doc = """ 0.000000,1.000000 """ @@ -135,7 +135,7 @@ def test_point(self): "coordinates": (0.0, 1.0), } - def test_linestring(self): + def test_linestring(self) -> None: doc = """ 0.000000,0.000000 1.000000,1.000000 """ @@ -148,9 +148,10 @@ def test_linestring(self): "coordinates": ((0.0, 0.0), (1.0, 1.0)), } - def test_linearring(self): + def test_linearring(self) -> None: doc = """ - 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 + 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 + 0.000000,0.000000 """ @@ -162,11 +163,12 @@ def test_linearring(self): "coordinates": ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)), } - def test_polygon(self): + def test_polygon(self) -> None: doc = """ - 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 + 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 + 0.000000,0.000000 @@ -182,12 +184,14 @@ def test_polygon(self): doc = """ - -1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.000000 + -1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 + -1.000000,-1.000000 - 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 + 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 + 0.000000,0.000000 @@ -203,7 +207,7 @@ def test_polygon(self): ), } - def test_multipoint(self): + def test_multipoint(self) -> None: doc = """ @@ -219,7 +223,7 @@ def test_multipoint(self): g.from_string(doc) assert len(g.geometry) == 2 - def test_multilinestring(self): + def test_multilinestring(self) -> None: doc = """ @@ -235,25 +239,28 @@ def test_multilinestring(self): g.from_string(doc) assert len(g.geometry) == 2 - def test_multipolygon(self): + def test_multipolygon(self) -> None: doc = """ - -1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.000000 + -1.000000,-1.000000 2.000000,-1.000000 + 2.000000,2.000000 -1.000000,-1.000000 - 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000 + 0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 + 0.000000,0.000000 - 3.000000,0.000000 4.000000,0.000000 4.000000,1.000000 3.000000,0.000000 + 3.000000,0.000000 4.000000,0.000000 4.000000,1.000000 + 3.000000,0.000000 @@ -264,7 +271,7 @@ def test_multipolygon(self): g.from_string(doc) assert len(g.geometry) == 2 - def test_geometrycollection(self): + def test_geometrycollection(self) -> None: doc = """ diff --git a/tests/oldunit_test.py b/tests/oldunit_test.py index 87408b7e..5e7bbe75 100644 --- a/tests/oldunit_test.py +++ b/tests/oldunit_test.py @@ -51,7 +51,7 @@ def setup_method(self) -> None: config.set_etree_implementation(xml.etree.ElementTree) config.set_default_namespaces() - def test_base_object(self): + def test_base_object(self) -> None: bo = base._BaseObject(id="id0") assert bo.id == "id0" assert bo.ns == config.KMLNS @@ -78,7 +78,7 @@ def test_base_object(self): assert not bo.etree_element(), None assert len(bo.to_string()) > 1 - def test_feature(self): + def test_feature(self) -> None: f = kml._Feature(name="A Feature") pytest.raises(NotImplementedError, f.etree_element) assert f.name == "A Feature" @@ -102,7 +102,7 @@ def test_feature(self): assert "Feature>" in str(f.to_string()) assert "#default" in str(f.to_string()) - def test_container(self): + def test_container(self) -> None: f = kml._Container(name="A Container") # apparently you can add documents to containes # d = kml.Document() @@ -111,7 +111,7 @@ def test_container(self): f.append(p) pytest.raises(NotImplementedError, f.etree_element) - def test_overlay(self): + def test_overlay(self) -> None: o = kml._Overlay(name="An Overlay") assert o._color is None assert o._draw_order is None @@ -127,7 +127,7 @@ def setup_method(self) -> None: config.set_etree_implementation(xml.etree.ElementTree) config.set_default_namespaces() - def test_kml(self): + def test_kml(self) -> None: """kml file without contents""" k = kml.KML() assert not list(k.features()) @@ -139,7 +139,7 @@ def test_kml(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_folder(self): + def test_folder(self) -> None: """KML file with folders""" ns = "{http://www.opengis.net/kml/2.2}" # noqa: FS003 k = kml.KML() @@ -156,7 +156,7 @@ def test_folder(self): k2.from_string(s) assert s == k2.to_string() - def test_placemark(self): + def test_placemark(self) -> None: ns = "{http://www.opengis.net/kml/2.2}" # noqa: FS003 k = kml.KML(ns=ns) p = kml.Placemark(ns, "id", "name", "description") @@ -170,7 +170,7 @@ def test_placemark(self): k2.from_string(k.to_string(prettyprint=True)) assert k.to_string() == k2.to_string() - def test_schema(self): + def test_schema(self) -> None: ns = "{http://www.opengis.net/kml/2.2}" # noqa: FS003 pytest.raises(ValueError, kml.Schema, ns) s = kml.Schema(ns, "some_id") @@ -199,7 +199,7 @@ def test_schema(self): assert list(s.simple_fields)[1]["name"] == "Float" assert list(s.simple_fields)[1]["displayName"] is None - def test_schema_data(self): + def test_schema_data(self) -> None: ns = "{http://www.opengis.net/kml/2.2}" # noqa: FS003 pytest.raises(ValueError, data.SchemaData, ns) pytest.raises(ValueError, data.SchemaData, ns, "") @@ -216,7 +216,7 @@ def test_schema_data(self): assert sd.data[0] == {"value": "Some new Text", "name": "text"} assert sd.data[1] == {"value": 2, "name": "Integer"} - def test_untyped_extended_data(self): + def test_untyped_extended_data(self) -> None: ns = "{http://www.opengis.net/kml/2.2}" # noqa: FS003 k = kml.KML(ns=ns) @@ -246,7 +246,7 @@ def test_untyped_extended_data(self): assert extended_data.elements[1].value == "blue skies" assert extended_data.elements[1].display_name == "Weather" - def test_untyped_extended_data_nested(self): + def test_untyped_extended_data_nested(self) -> None: ns = "{http://www.opengis.net/kml/2.2}" # noqa: FS003 k = kml.KML(ns=ns) @@ -275,7 +275,7 @@ def test_untyped_extended_data_nested(self): assert folder_data.elements[0].name == "type" assert folder_data.elements[0].value == "Folder" - def test_document(self): + def test_document(self) -> None: k = kml.KML() ns = "{http://www.opengis.net/kml/2.2}" # noqa: FS003 d = kml.Document(ns, "docid", "doc name", "doc description") @@ -298,7 +298,7 @@ def test_document(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_author(self): + def test_author(self) -> None: d = kml.Document() d.author = "Christian Ledermann" assert "Christian Ledermann" in str(d.to_string()) @@ -316,7 +316,7 @@ def test_author(self): assert d.to_string() == d2.to_string() d.author = None - def test_link(self): + def test_link(self) -> None: d = kml.Document() d.link = "http://localhost" assert "http://localhost" in str(d.to_string()) @@ -329,14 +329,14 @@ def test_link(self): assert d.to_string() == d2.to_string() d.link = None - def test_address(self): + def test_address(self) -> None: address = "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA" d = kml.Document() d.address = address assert address in str(d.to_string()) assert "address>" in str(d.to_string()) - def test_phone_number(self): + def test_phone_number(self) -> None: phone = "+1 234 567 8901" d = kml.Document() d.phone_number = phone @@ -345,7 +345,7 @@ def test_phone_number(self): class TestKmlFromString: - def test_document(self): + def test_document(self) -> None: doc = """ Document.kml @@ -380,7 +380,7 @@ def test_document(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_document_booleans(self): + def test_document_booleans(self) -> None: doc = """ Document.kml @@ -406,7 +406,7 @@ def test_document_booleans(self): assert list(k.features())[0].visibility == 0 assert list(k.features())[0].isopen == 0 - def test_folders(self): + def test_folders(self) -> None: doc = """ Folder.kml @@ -455,7 +455,7 @@ def test_folders(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_placemark(self): + def test_placemark(self) -> None: doc = """ Simple placemark @@ -475,7 +475,7 @@ def test_placemark(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_extended_data(self): + def test_extended_data(self) -> None: doc = """ Simple placemark @@ -523,7 +523,7 @@ def test_extended_data(self): assert sd.data[0]["name"] == "TrailHeadName" assert sd.data[1]["value"] == "347.45" - def test_polygon(self): + def test_polygon(self) -> None: doc = """ @@ -647,7 +647,7 @@ def test_polygon(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_multipoints(self): + def test_multipoints(self) -> None: doc = """ MultiPoint @@ -701,7 +701,7 @@ def test_multipoints(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_multilinestrings(self): + def test_multilinestrings(self) -> None: doc = """ Dnipro (Dnieper) @@ -722,7 +722,7 @@ def test_multilinestrings(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_multipolygon(self): + def test_multipolygon(self) -> None: doc = """ Italy @@ -737,10 +737,10 @@ def test_multipolygon(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_atom(self): + def test_atom(self) -> None: pass - def test_schema(self): + def test_schema(self) -> None: doc = """ Trail Head Name]]> @@ -789,7 +789,7 @@ def test_schema(self): assert "SimpleField" in k1.to_string() assert k1.to_string() == k.to_string() - def test_schema_data(self): + def test_schema_data(self) -> None: doc = """ Pi in the sky 3.14159 @@ -807,7 +807,7 @@ def test_schema_data(self): assert sd1.schema_url == "#TrailHeadTypeId" assert sd.to_string() == sd1.to_string() - def test_snippet(self): + def test_snippet(self) -> None: doc = """ Short Desc @@ -827,11 +827,11 @@ def test_snippet(self): assert "maxLines" not in k.to_string() assert "Diffrent Snippet" in k.to_string() - def test_from_wrong_string(self): + def test_from_wrong_string(self) -> None: doc = kml.KML() pytest.raises(TypeError, doc.from_string, "") - def test_from_string_with_unbound_prefix(self): + def test_from_string_with_unbound_prefix(self) -> None: doc = """ @@ -847,7 +847,7 @@ def test_from_string_with_unbound_prefix(self): k = kml.KML() pytest.raises(xml.etree.ElementTree.ParseError, k.from_string, doc) - def test_address(self): + def test_address(self) -> None: doc = kml.Document() doc.from_string( @@ -865,7 +865,7 @@ def test_address(self): doc2.from_string(doc.to_string()) assert doc.to_string() == doc2.to_string() - def test_phone_number(self): + def test_phone_number(self) -> None: doc = kml.Document() doc.from_string( @@ -883,7 +883,7 @@ def test_phone_number(self): doc2.from_string(doc.to_string()) assert doc.to_string() == doc2.to_string() - def test_groundoverlay(self): + def test_groundoverlay(self) -> None: doc = kml.KML() doc.from_string( @@ -916,7 +916,7 @@ def test_groundoverlay(self): doc2.from_string(doc.to_string()) assert doc.to_string() == doc2.to_string() - def test_linarring_placemark(self): + def test_linarring_placemark(self) -> None: doc = kml.KML() doc.from_string( """ @@ -933,7 +933,7 @@ def test_linarring_placemark(self): class TestStyle: - def test_styleurl(self): + def test_styleurl(self) -> None: f = kml.Document() f.style_url = "#somestyle" assert f.style_url == "#somestyle" @@ -946,7 +946,7 @@ def test_styleurl(self): f2.from_string(f.to_string()) assert f.to_string() == f2.to_string() - def test_style(self): + def test_style(self) -> None: lstyle = styles.LineStyle(color="red", width=2.0) style = styles.Style(styles=[lstyle]) f = kml.Document(styles=[style]) @@ -954,15 +954,15 @@ def test_style(self): f2.from_string(f.to_string(prettyprint=True)) assert f.to_string() == f2.to_string() - def test_polystyle_fill(self): + def test_polystyle_fill(self) -> None: styles.PolyStyle() - def test_polystyle_outline(self): + def test_polystyle_outline(self) -> None: styles.PolyStyle() class TestStyleUsage: - def test_create_document_style(self): + def test_create_document_style(self) -> None: style = styles.Style(styles=[styles.PolyStyle(color="7f000000")]) doc = kml.Document(styles=[style]) @@ -990,7 +990,7 @@ def test_create_document_style(self): assert doc2.to_string() == doc3.to_string() assert doc.to_string() == doc3.to_string() - def test_create_placemark_style(self): + def test_create_placemark_style(self) -> None: style = styles.Style(styles=[styles.PolyStyle(color="7f000000")]) place = kml.Placemark(styles=[style]) @@ -1019,7 +1019,7 @@ def test_create_placemark_style(self): class TestStyleFromString: - def test_styleurl(self): + def test_styleurl(self) -> None: doc = """ Document.kml @@ -1036,7 +1036,7 @@ def test_styleurl(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_balloonstyle(self): + def test_balloonstyle(self) -> None: doc = """ Document.kml @@ -1078,7 +1078,7 @@ def test_balloonstyle(self): k2.from_string(k.to_string()) assert k2.to_string() == k.to_string() - def test_balloonstyle_old_color(self): + def test_balloonstyle_old_color(self) -> None: doc = """ Document.kml @@ -1102,7 +1102,7 @@ def test_balloonstyle_old_color(self): k2.from_string(k.to_string()) assert k2.to_string() == k.to_string() - def test_labelstyle(self): + def test_labelstyle(self) -> None: doc = """ Document.kml @@ -1127,7 +1127,7 @@ def test_labelstyle(self): k2.from_string(k.to_string()) assert k.to_string() == k2.to_string() - def test_iconstyle(self): + def test_iconstyle(self) -> None: doc = """