-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
374 add hypothesis tests for times and views #379
Changes from all commits
45bbc7b
44978db
53aef73
871fe7c
36f0573
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
from typing import Any | ||
from typing import Dict | ||
from typing import Optional | ||
from typing import Union | ||
|
||
from fastkml import config | ||
from fastkml.base import _XMLObject | ||
|
@@ -35,8 +34,8 @@ | |
from fastkml.mixins import TimeMixin | ||
from fastkml.registry import RegistryItem | ||
from fastkml.registry import registry | ||
from fastkml.times import TimeSpan | ||
from fastkml.times import TimeStamp | ||
|
||
__all__ = ["Camera", "LatLonAltBox", "Lod", "LookAt", "Region"] | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -100,7 +99,6 @@ def __init__( | |
heading: Optional[float] = None, | ||
tilt: Optional[float] = None, | ||
altitude_mode: Optional[AltitudeMode] = None, | ||
time_primitive: Union[TimeSpan, TimeStamp, None] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
""" | ||
|
@@ -128,8 +126,6 @@ def __init__( | |
The tilt angle of the view. | ||
altitude_mode : Optional[AltitudeMode] | ||
The altitude mode of the view. | ||
time_primitive : Union[TimeSpan, TimeStamp, None] | ||
The time primitive associated with the view. | ||
kwargs : Any | ||
Additional keyword arguments. | ||
|
||
|
@@ -151,7 +147,6 @@ def __init__( | |
self.heading = heading | ||
self.tilt = tilt | ||
self.altitude_mode = altitude_mode | ||
self.times = time_primitive | ||
|
||
def __repr__(self) -> str: | ||
"""Create a string (c)representation for _AbstractView.""" | ||
|
@@ -167,7 +162,6 @@ def __repr__(self) -> str: | |
f"heading={self.heading!r}, " | ||
f"tilt={self.tilt!r}, " | ||
f"altitude_mode={self.altitude_mode}, " | ||
cleder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
f"time_primitive={self.times!r}, " | ||
f"**{self._get_splat()!r}," | ||
")" | ||
) | ||
|
@@ -233,29 +227,6 @@ def __repr__(self) -> str: | |
default=0.0, | ||
), | ||
) | ||
registry.register( | ||
_AbstractView, | ||
RegistryItem( | ||
ns_ids=("kml",), | ||
attr_name="altitude_mode", | ||
node_name="altitudeMode", | ||
classes=(AltitudeMode,), | ||
get_kwarg=subelement_enum_kwarg, | ||
set_element=enum_subelement, | ||
default=AltitudeMode.clamp_to_ground, | ||
), | ||
) | ||
registry.register( | ||
_AbstractView, | ||
RegistryItem( | ||
ns_ids=("kml",), | ||
attr_name="time_primitive", | ||
node_name="TimeStamp", | ||
classes=(TimeSpan, TimeStamp), | ||
get_kwarg=xml_subelement_kwarg, | ||
set_element=xml_subelement, | ||
), | ||
) | ||
|
||
|
||
class Camera(_AbstractView): | ||
|
@@ -300,7 +271,6 @@ def __init__( | |
tilt: Optional[float] = None, | ||
roll: Optional[float] = None, | ||
altitude_mode: Optional[AltitudeMode] = None, | ||
time_primitive: Union[TimeSpan, TimeStamp, None] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
""" | ||
|
@@ -319,8 +289,6 @@ def __init__( | |
tilt (Optional[float]): The tilt of the view. | ||
roll (Optional[float]): The roll of the view. | ||
altitude_mode (AltitudeMode): The altitude mode of the view. | ||
time_primitive (Union[TimeSpan, TimeStamp, None]): The time primitive of the | ||
view. | ||
**kwargs (Any): Additional keyword arguments. | ||
|
||
Returns: | ||
|
@@ -339,7 +307,6 @@ def __init__( | |
heading=heading, | ||
tilt=tilt, | ||
altitude_mode=altitude_mode, | ||
time_primitive=time_primitive, | ||
**kwargs, | ||
) | ||
self.roll = roll | ||
|
@@ -359,7 +326,6 @@ def __repr__(self) -> str: | |
f"tilt={self.tilt!r}, " | ||
f"roll={self.roll!r}, " | ||
f"altitude_mode={self.altitude_mode}, " | ||
f"time_primitive={self.times!r}, " | ||
f"**{self._get_splat()!r}," | ||
")" | ||
) | ||
|
@@ -377,6 +343,18 @@ def __repr__(self) -> str: | |
default=0.0, | ||
), | ||
) | ||
registry.register( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider extracting the altitude_mode registration logic into a reusable helper function The altitude_mode registration is duplicated across Camera, LookAt, and LatLonAltBox classes. Consider creating a helper function to reduce duplication while preserving namespace flexibility: def register_altitude_mode(cls, ns_ids=("kml",)):
"""Helper to register altitude_mode with custom namespaces."""
registry.register(
cls,
RegistryItem(
ns_ids=ns_ids,
attr_name="altitude_mode",
node_name="altitudeMode",
classes=(AltitudeMode,),
get_kwarg=subelement_enum_kwarg,
set_element=enum_subelement,
default=AltitudeMode.clamp_to_ground,
),
)
# Usage:
register_altitude_mode(Camera, ns_ids=("kml", "gx", ""))
register_altitude_mode(LookAt, ns_ids=("kml", "gx", ""))
register_altitude_mode(LatLonAltBox, ns_ids=("kml", "gx", "")) This maintains the namespace customization while eliminating code duplication. |
||
Camera, | ||
RegistryItem( | ||
ns_ids=("kml", "gx", ""), | ||
attr_name="altitude_mode", | ||
node_name="altitudeMode", | ||
classes=(AltitudeMode,), | ||
get_kwarg=subelement_enum_kwarg, | ||
set_element=enum_subelement, | ||
default=AltitudeMode.clamp_to_ground, | ||
), | ||
) | ||
|
||
|
||
class LookAt(_AbstractView): | ||
|
@@ -407,7 +385,6 @@ def __init__( | |
tilt: Optional[float] = None, | ||
range: Optional[float] = None, | ||
altitude_mode: Optional[AltitudeMode] = None, | ||
time_primitive: Union[TimeSpan, TimeStamp, None] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
""" | ||
|
@@ -427,7 +404,6 @@ def __init__( | |
range (Optional[float]): The range value. | ||
altitude_mode (AltitudeMode): The altitude mode. Defaults to | ||
AltitudeMode.relative_to_ground. | ||
time_primitive (Union[TimeSpan, TimeStamp, None]): The time primitive. | ||
**kwargs (Any): Additional keyword arguments. | ||
|
||
Returns: | ||
|
@@ -446,7 +422,6 @@ def __init__( | |
heading=heading, | ||
tilt=tilt, | ||
altitude_mode=altitude_mode, | ||
time_primitive=time_primitive, | ||
**kwargs, | ||
) | ||
self.range = range | ||
|
@@ -466,7 +441,6 @@ def __repr__(self) -> str: | |
f"tilt={self.tilt!r}, " | ||
f"range={self.range!r}, " | ||
f"altitude_mode={self.altitude_mode}, " | ||
f"time_primitive={self.times!r}, " | ||
f"**{self._get_splat()!r}," | ||
")" | ||
) | ||
|
@@ -483,6 +457,18 @@ def __repr__(self) -> str: | |
set_element=float_subelement, | ||
), | ||
) | ||
registry.register( | ||
LookAt, | ||
RegistryItem( | ||
ns_ids=("kml", "gx", ""), | ||
attr_name="altitude_mode", | ||
node_name="altitudeMode", | ||
classes=(AltitudeMode,), | ||
get_kwarg=subelement_enum_kwarg, | ||
set_element=enum_subelement, | ||
default=AltitudeMode.clamp_to_ground, | ||
), | ||
) | ||
|
||
|
||
class LatLonAltBox(_XMLObject): | ||
|
@@ -653,7 +639,7 @@ def __bool__(self) -> bool: | |
registry.register( | ||
LatLonAltBox, | ||
RegistryItem( | ||
ns_ids=("kml",), | ||
ns_ids=("kml", "gx", ""), | ||
attr_name="altitude_mode", | ||
node_name="altitudeMode", | ||
classes=(AltitudeMode,), | ||
|
@@ -701,10 +687,10 @@ def __init__( | |
ns (Optional[str]): The namespace for the view. | ||
name_spaces (Optional[Dict[str, str]]): The dictionary of namespace prefixes | ||
and URIs. | ||
min_lod_pixels (Optional[float]): The minimum level of detail in pixels. | ||
max_lod_pixels (Optional[float]): The maximum level of detail in pixels. | ||
min_fade_extent (Optional[float]): The minimum fade extent in pixels. | ||
max_fade_extent (Optional[float]): The maximum fade extent in pixels. | ||
min_lod_pixels (Optional[int]): The minimum level of detail in pixels. | ||
max_lod_pixels (Optional[int]): The maximum level of detail in pixels. | ||
min_fade_extent (Optional[int]): The minimum fade extent in pixels. | ||
max_fade_extent (Optional[int]): The maximum fade extent in pixels. | ||
**kwargs (Any): Additional keyword arguments. | ||
|
||
Returns: | ||
|
@@ -775,8 +761,8 @@ def __bool__(self) -> bool: | |
attr_name="min_fade_extent", | ||
node_name="minFadeExtent", | ||
classes=(float,), | ||
get_kwarg=subelement_float_kwarg, | ||
set_element=float_subelement, | ||
get_kwarg=subelement_int_kwarg, | ||
set_element=int_subelement, | ||
default=0, | ||
), | ||
) | ||
|
@@ -787,8 +773,8 @@ def __bool__(self) -> bool: | |
attr_name="max_fade_extent", | ||
node_name="maxFadeExtent", | ||
classes=(float,), | ||
get_kwarg=subelement_float_kwarg, | ||
set_element=float_subelement, | ||
get_kwarg=subelement_int_kwarg, | ||
set_element=int_subelement, | ||
default=0, | ||
), | ||
) | ||
|
@@ -902,10 +888,3 @@ def __bool__(self) -> bool: | |
set_element=xml_subelement, | ||
), | ||
) | ||
|
||
|
||
__all__ = [ | ||
"Camera", | ||
"LookAt", | ||
"Region", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,10 @@ | |
# along with this library; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
"""Test gx Track and MultiTrack.""" | ||
import datetime | ||
import typing | ||
|
||
from hypothesis import given | ||
from hypothesis import strategies as st | ||
from hypothesis.extra.dateutil import timezones | ||
from pygeoif.hypothesis.strategies import epsg4326 | ||
from pygeoif.hypothesis.strategies import points | ||
|
||
|
@@ -29,12 +27,12 @@ | |
import fastkml.types | ||
from fastkml.gx import Angle | ||
from fastkml.gx import TrackItem | ||
from fastkml.times import KmlDateTime | ||
from tests.base import Lxml | ||
from tests.hypothesis.common import assert_repr_roundtrip | ||
from tests.hypothesis.common import assert_str_roundtrip | ||
from tests.hypothesis.common import assert_str_roundtrip_terse | ||
from tests.hypothesis.common import assert_str_roundtrip_verbose | ||
from tests.hypothesis.strategies import kml_datetimes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Don't import test modules. ( ExplanationDon't import test modules.Tests should be self-contained and don't depend on each other. If a helper function is used by multiple tests, |
||
from tests.hypothesis.strategies import nc_name | ||
|
||
track_items = st.builds( | ||
|
@@ -51,15 +49,7 @@ | |
), | ||
), | ||
coord=points(srs=epsg4326), | ||
when=st.builds( | ||
KmlDateTime, | ||
dt=st.datetimes( | ||
allow_imaginary=False, | ||
timezones=timezones(), | ||
min_value=datetime.datetime(2000, 1, 1), # noqa: DTZ001 | ||
max_value=datetime.datetime(2050, 1, 1), # noqa: DTZ001 | ||
), | ||
), | ||
when=kml_datetimes(), | ||
) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Documentation change to
absolute
altitudeMode is inconsistent with implementationThe documentation change to use
absolute
altitudeMode in the example doesn't align with the codebase implementation, where:clampToGround
(seefastkml/views.py
,fastkml/geometry.py
, etc.)relativeToGround
orclampToGround
(seetests/views_test.py
,tests/overlays_test.py
)absolute
mode is in specific test cases, not as a default or common patternThe documentation should maintain consistency with the codebase's default behavior and common usage patterns.
🔗 Analysis chain
Verify altitudeMode documentation consistency with code changes.
The change from an unspecified previous value to
absolute
in the documentation example needs verification to ensure it accurately reflects the current implementation in the views module.Let's verify the altitudeMode implementation in the views module:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 164
Script:
Length of output: 45072