Skip to content

Commit

Permalink
move tests, test times
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Dec 14, 2022
1 parent a0225ee commit 49767cf
Show file tree
Hide file tree
Showing 21 changed files with 317 additions and 269 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
- id: name-tests-test
exclude: ^fastkml/tests/base.py
exclude: ^tests/base.py
- id: no-commit-to-branch
- id: pretty-format-json
- id: requirements-txt-fixer
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ include *.txt
recursive-include docs *.py
recursive-include docs *.rst
recursive-include docs Makefile
recursive-include tests *.py
4 changes: 2 additions & 2 deletions docs/installing.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Installation
============

fastkml works with CPython and Pypy version 3.6+ and is
fastkml works with CPython and Pypy version 3.7+ and is
continually tested for these version.
Jython and IronPython are not tested but *should* work.

Expand All @@ -10,7 +10,7 @@ Jython and IronPython are not tested but *should* work.

fastkml works on Unix/Linux, OS X, and Windows.

Install it with ``pip install fastkml`` or ``easy_install fastkml``.
Install it with ``pip install fastkml``.

If you use fastkml extensively or need to process big KML files, consider
installing lxml_ as it speeds up processing.
Expand Down
16 changes: 16 additions & 0 deletions fastkml/data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Copyright (C) 2022 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
"""Add Custom Data"""
from typing import Dict
from typing import List
from typing import Optional
Expand Down
2 changes: 1 addition & 1 deletion fastkml/kml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2012 Christian Ledermann
# Copyright (C) 2012-2022 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
Expand Down
10 changes: 5 additions & 5 deletions fastkml/times.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Date and time handling in KML."""
from datetime import date
from datetime import datetime
from typing import List
from typing import Optional
from typing import Tuple
from typing import Union

# note that there are some ISO 8601 timeparsers at pypi
Expand Down Expand Up @@ -52,7 +52,7 @@ def get_resolution(
resolution = None
return resolution

def parse_str(self, datestr: str) -> List[Union[datetime, str]]:
def parse_str(self, datestr: str) -> Tuple[datetime, str]:
resolution = "dateTime"
year = 0
month = 1
Expand All @@ -79,7 +79,7 @@ def parse_str(self, datestr: str) -> List[Union[datetime, str]]:
dt = dateutil.parser.parse(datestr)
else:
raise ValueError
return [dt, resolution]
return dt, resolution

def date_to_string(
self,
Expand Down Expand Up @@ -107,7 +107,7 @@ class TimeStamp(_TimePrimitive):
"""Represents a single moment in time."""

__name__ = "TimeStamp"
timestamp = None
timestamp: Optional[Tuple[datetime, str]] = None

def __init__(
self,
Expand All @@ -119,7 +119,7 @@ def __init__(
) -> None:
super().__init__(ns=ns, id=id, target_id=target_id)
resolution = self.get_resolution(timestamp, resolution)
self.timestamp = [timestamp, resolution]
self.timestamp = (timestamp, resolution)

def etree_element(self) -> Element:
element = super().etree_element()
Expand Down
48 changes: 25 additions & 23 deletions fastkml/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import logging
from typing import Optional
from typing import Union
Expand All @@ -18,32 +19,32 @@ class _AbstractView(_BaseObject):
This element is extended by the <Camera> and <LookAt> elements.
"""

_longitude = None
_longitude: Optional[float] = None
# Longitude of the virtual camera (eye point). Angular distance in degrees,
# relative to the Prime Meridian. Values west of the Meridian range from
# −180 to 0 degrees. Values east of the Meridian range from 0 to 180 degrees.

_latitude = None
_latitude: Optional[float] = None
# Latitude of the virtual camera. Degrees north or south of the Equator
# (0 degrees). Values range from −90 degrees to 90 degrees.

_altitude = None
_altitude: Optional[float] = None
# Distance of the camera from the earth's surface, in meters. Interpreted
# according to the Camera's <altitudeMode> or <gx:altitudeMode>.

_heading = None
_heading: Optional[float] = None
# Direction (azimuth) of the camera, in degrees. Default=0 (true North).
# (See diagram.) Values range from 0 to 360 degrees.

_tilt = None
_tilt: Optional[float] = None
# Rotation, in degrees, of the camera around the X axis. A value of 0
# indicates that the view is aimed straight down toward the earth (the
# most common case). A value for 90 for <tilt> indicates that the view
# is aimed toward the horizon. Values greater than 90 indicate that the
# view is pointed up into the sky. Values for <tilt> are clamped at +180
# degrees.

_altitude_mode = "relativeToGround"
_altitude_mode: str = "relativeToGround"
# Specifies how the <altitude> specified for the Camera is interpreted.
# Possible values are as follows:
# relativeToGround -
Expand All @@ -58,8 +59,8 @@ class _AbstractView(_BaseObject):
# absolute -
# Interprets the <altitude> as a value in meters above sea level.

_timespan = None
_timestamp = None
_timespan: Optional[TimeSpan] = None
_timestamp: Optional[TimeStamp] = None

def __init__(
self,
Expand Down Expand Up @@ -87,19 +88,20 @@ def __init__(
self._timestamp = time_primitive

@property
def timestamp(self):
def timestamp(self) -> Optional[datetime.datetime]:
if self._timestamp is not None:
return self._timestamp.timestamp[0]
return None

@timestamp.setter
def timestamp(self, dt):
def timestamp(self, dt: datetime.datetime) -> None:
self._timestamp = None if dt is None else TimeStamp(timestamp=dt)
if self._timestamp is not None:
logger.warning("Setting a TimeStamp, TimeSpan deleted")
self._timespan = None

@property
def begin(self):
def begin(self) -> Optional[datetime.datetime]:
if self._timespan is None:
return None
return self._timespan.begin[0]
Expand All @@ -117,11 +119,11 @@ def begin(self, dt) -> None:
self._timestamp = None

@property
def end(self):
def end(self) -> Optional[datetime.datetime]:
return None if self._timespan is None else self._timespan.end[0]

@end.setter
def end(self, dt):
def end(self, dt) -> None:
if self._timespan is None:
self._timespan = TimeSpan(end=dt)
elif self._timespan.end is None:
Expand Down Expand Up @@ -202,7 +204,7 @@ def altitude_mode(self) -> str:
return self._altitude_mode

@altitude_mode.setter
def altitude_mode(self, mode) -> None:
def altitude_mode(self, mode: str) -> None:
if mode in ("relativeToGround", "clampToGround", "absolute"):
self._altitude_mode = str(mode)
else:
Expand All @@ -211,7 +213,7 @@ def altitude_mode(self, mode) -> None:
# "altitude_mode must be one of " "relativeToGround,
# clampToGround, absolute")

def from_element(self, element):
def from_element(self, element: Element):
super().from_element(element)
longitude = element.find(f"{self.ns}longitude")
if longitude is not None:
Expand Down Expand Up @@ -245,7 +247,7 @@ def from_element(self, element):
s.from_element(timestamp)
self._timestamp = s

def etree_element(self):
def etree_element(self) -> Element:
element = super().etree_element()
if self.longitude:
longitude = config.etree.SubElement(element, f"{self.ns}longitude")
Expand Down Expand Up @@ -303,7 +305,7 @@ class Camera(_AbstractView):

__name__ = "Camera"

_roll = None
_roll: Optional[float] = None
# Rotation, in degrees, of the camera around the Z axis. Values range from
# −180 to +180 degrees.

Expand Down Expand Up @@ -335,7 +337,7 @@ def __init__(
)
self._roll = roll

def from_element(self, element) -> None:
def from_element(self, element: Element) -> None:
super().from_element(element)
roll = element.find(f"{self.ns}roll")
if roll is not None:
Expand Down Expand Up @@ -366,7 +368,7 @@ class LookAt(_AbstractView):

__name__ = "LookAt"

_range = None
_range: Optional[float] = None
# Distance in meters from the point specified by <longitude>, <latitude>,
# and <altitude> to the LookAt position. (See diagram below.)

Expand Down Expand Up @@ -399,25 +401,25 @@ def __init__(
self._range = range

@property
def range(self):
def range(self) -> Optional[float]:
return self._range

@range.setter
def range(self, value):
def range(self, value) -> None:
if isinstance(value, (str, int, float)):
self._range = float(value)
elif value is None:
self._range = None
else:
raise ValueError

def from_element(self, element):
def from_element(self, element: Element) -> None:
super().from_element(element)
range_var = element.find(f"{self.ns}range")
if range_var is not None:
self.range = range_var.text

def etree_element(self):
def etree_element(self) -> Element:
element = super().etree_element()
if self.range:
range_var = config.etree.SubElement(element, f"{self.ns}range")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ show_error_codes = true

[[tool.mypy.overrides]]
module = [
"fastkml.kml", "fastkml.views", "fastkml.times",
"fastkml.kml", "fastkml.views",
"fastkml.tests.oldunit_test", "fastkml.tests.config_test"
]
ignore_errors = true
File renamed without changes.
4 changes: 2 additions & 2 deletions fastkml/tests/atom_test.py → tests/atom_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"""Test the Atom classes."""

from fastkml import atom
from fastkml.tests.base import Lxml
from fastkml.tests.base import StdLibrary
from tests.base import Lxml
from tests.base import StdLibrary


class TestStdLibrary(StdLibrary):
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions fastkml/tests/base_test.py → tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from fastkml import base
from fastkml import config
from fastkml import types
from fastkml.tests.base import Lxml
from fastkml.tests.base import StdLibrary
from tests.base import Lxml
from tests.base import StdLibrary


class TestStdLibrary(StdLibrary):
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions fastkml/tests/geometry_test.py → tests/geometry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Test the geometry classes."""
from fastkml.tests.base import Lxml
from fastkml.tests.base import StdLibrary
from tests.base import Lxml
from tests.base import StdLibrary


class TestStdLibrary(StdLibrary):
Expand Down
4 changes: 2 additions & 2 deletions fastkml/tests/gx_test.py → tests/gx_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Test the gx classes."""
from fastkml.tests.base import Lxml
from fastkml.tests.base import StdLibrary
from tests.base import Lxml
from tests.base import StdLibrary


class TestStdLibrary(StdLibrary):
Expand Down
4 changes: 2 additions & 2 deletions fastkml/tests/kml_test.py → tests/kml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

"""Test the kml classes."""
from fastkml import kml
from fastkml.tests.base import Lxml
from fastkml.tests.base import StdLibrary
from tests.base import Lxml
from tests.base import StdLibrary


class TestStdLibrary(StdLibrary):
Expand Down

0 comments on commit 49767cf

Please sign in to comment.