From f1536cbd5de0dfe7198851be5ba1a76109b0f8ec Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 09:15:51 +0200 Subject: [PATCH 01/13] format_datetime_like() returns object within if statements --- src/czml3/types.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/czml3/types.py b/src/czml3/types.py index 98df5e3..db37e78 100644 --- a/src/czml3/types.py +++ b/src/czml3/types.py @@ -97,7 +97,7 @@ def check_reference(r): def format_datetime_like(dt_object): if dt_object is None: - result = dt_object + return dt_object elif isinstance(dt_object, str): try: @@ -105,15 +105,13 @@ def format_datetime_like(dt_object): except Exception: raise else: - result = dt_object + return dt_object elif isinstance(dt_object, dt.datetime): - result = dt_object.strftime(ISO8601_FORMAT_Z) + return dt_object.strftime(ISO8601_FORMAT_Z) else: - result = dt_object.strftime(ISO8601_FORMAT_Z) - - return result + return dt_object.strftime(ISO8601_FORMAT_Z) class FontValue(BaseCZMLObject): From 31cd8e009b8b52c6ad8a70c94a1afd74584d3b38 Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 09:21:21 +0200 Subject: [PATCH 02/13] Remove HasAlignment() class --- src/czml3/properties.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/czml3/properties.py b/src/czml3/properties.py index 531728a..1ca692e 100644 --- a/src/czml3/properties.py +++ b/src/czml3/properties.py @@ -5,7 +5,6 @@ from urllib.parse import urlparse from pydantic import ( - BaseModel, Field, field_validator, model_serializer, @@ -54,19 +53,6 @@ ) -class HasAlignment(BaseModel): - """A property that can be horizontally or vertically aligned.""" - - horizontalOrigin: None | HorizontalOrigins | TimeIntervalCollection = Field( - default=None - ) - """ See `here `__ for it's definition.""" - verticalOrigin: None | VerticalOrigins | TimeIntervalCollection = Field( - default=None - ) - """ See `here `__ for it's definition.""" - - class Material(BaseCZMLObject): """A definition of how a surface is colored or shaded. @@ -458,7 +444,7 @@ def validate_reference(cls, r): return r -class Billboard(BaseCZMLObject, HasAlignment): +class Billboard(BaseCZMLObject): """A billboard, or viewport-aligned image. The billboard is positioned in the scene by the position property. A billboard is sometimes called a marker. See `here `__ for it's definition.""" @@ -477,6 +463,14 @@ class Billboard(BaseCZMLObject, HasAlignment): """The eye offset of the billboard, which is the offset in eye coordinates at which to place the billboard relative to the position property. Eye coordinates are a left-handed coordinate system where the X-axis points toward the viewer's right, the Y-axis points up, and the Z-axis points into the screen. See `here `__ for it's definition.""" color: None | Color | str | TimeIntervalCollection = Field(default=None) """The color of the billboard. This color value is multiplied with the values of the billboard's image to produce the final color. See `here `__ for it's definition.""" + horizontalOrigin: None | HorizontalOrigins | TimeIntervalCollection = Field( + default=None + ) + """ See `here `__ for it's definition.""" + verticalOrigin: None | VerticalOrigins | TimeIntervalCollection = Field( + default=None + ) + """ See `here `__ for it's definition.""" @field_validator("eyeOffset") @classmethod @@ -1457,7 +1451,7 @@ def validate_nearFarScalar(cls, r): return r -class Label(BaseCZMLObject, HasAlignment): +class Label(BaseCZMLObject): """A string of text. See `here `__ for it's definition.""" @@ -1488,6 +1482,14 @@ class Label(BaseCZMLObject, HasAlignment): """The offset, in viewport pixels, of the label origin from the position. A pixel offset is the number of pixels up and to the right to place the label, relative to the `position`. See `here `__ for it's definition.""" eyeOffset: None | EyeOffset | TimeIntervalCollection = Field(default=None) """The eye offset of the label, which is the offset in eye coordinates at which to place the label relative to the position property. Eye coordinates are a left-handed coordinate system where the X-axis points toward the viewer's right, the Y-axis points up, and the Z-axis points into the screen. See `here `__ for it's definition.""" + horizontalOrigin: None | HorizontalOrigins | TimeIntervalCollection = Field( + default=None + ) + """ See `here `__ for it's definition.""" + verticalOrigin: None | VerticalOrigins | TimeIntervalCollection = Field( + default=None + ) + """ See `here `__ for it's definition.""" class Orientation(BaseCZMLObject, Interpolatable, Deletable): From 8bfbf583c44a1eb7db26c9b4cd14f0b51737bf49 Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 09:21:43 +0200 Subject: [PATCH 03/13] FIX: PositionList() is not Interpolatable --- src/czml3/properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/czml3/properties.py b/src/czml3/properties.py index 1ca692e..4ceab0d 100644 --- a/src/czml3/properties.py +++ b/src/czml3/properties.py @@ -949,7 +949,7 @@ def validate_cartographicDegrees(cls, r): return r -class PositionList(BaseCZMLObject, Interpolatable, Deletable): +class PositionList(BaseCZMLObject, Deletable): """A list of positions. See `here `__ for it's definition.""" From f7bf7b8aef8f74ca0f57ad5eacb03b6eb614da99 Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 09:22:30 +0200 Subject: [PATCH 04/13] FIX: BoxDimensions() is Deletable --- src/czml3/properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/czml3/properties.py b/src/czml3/properties.py index 4ceab0d..e8f6db3 100644 --- a/src/czml3/properties.py +++ b/src/czml3/properties.py @@ -1122,7 +1122,7 @@ class Box(BaseCZMLObject): """The display condition specifying the distance from the camera at which this box will be displayed. See `here `__ for it's definition.""" -class BoxDimensions(BaseCZMLObject, Interpolatable): +class BoxDimensions(BaseCZMLObject, Interpolatable, Deletable): """The width, depth, and height of a box. See `here `__ for it's definition.""" From b8d51f8fd5f909532cc8e0405746a1814caaabbd Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 09:22:49 +0200 Subject: [PATCH 05/13] Rectangle() is not Interpolatable nor Deletable --- src/czml3/properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/czml3/properties.py b/src/czml3/properties.py index e8f6db3..26fa5d2 100644 --- a/src/czml3/properties.py +++ b/src/czml3/properties.py @@ -1151,7 +1151,7 @@ def validate_reference(cls, r): return r -class Rectangle(BaseCZMLObject, Interpolatable, Deletable): +class Rectangle(BaseCZMLObject): """A cartographic rectangle, which conforms to the curvature of the globe and can be placed on the surface or at altitude and can optionally be extruded into a volume. See `here `__ for it's definition.""" From 74f4b9d6d3f2601f5887a22e49bfd39545e566fd Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 10:28:55 +0200 Subject: [PATCH 06/13] Format Material() docstring --- src/czml3/properties.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/czml3/properties.py b/src/czml3/properties.py index 26fa5d2..2c5055f 100644 --- a/src/czml3/properties.py +++ b/src/czml3/properties.py @@ -56,8 +56,7 @@ class Material(BaseCZMLObject): """A definition of how a surface is colored or shaded. - See `here `__ for it's definition. - """ + See `here `__ for it's definition.""" solidColor: None | SolidColorMaterial | str | TimeIntervalCollection = Field( default=None From 8ddf8e0122bc28d5f06a1dac7052bd0856075f1c Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 11:15:24 +0200 Subject: [PATCH 07/13] Bump to v2.2.3 --- src/czml3/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/czml3/__init__.py b/src/czml3/__init__.py index d24e851..1b50d81 100644 --- a/src/czml3/__init__.py +++ b/src/czml3/__init__.py @@ -1,5 +1,5 @@ from .core import CZML_VERSION, Document, Packet -__version__ = "2.2.2" +__version__ = "2.2.3" __all__ = ["Document", "Packet", "CZML_VERSION"] From 0b4d28ca90d2d3a9aedd442897b991dbccc3d3e5 Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 11:16:32 +0200 Subject: [PATCH 08/13] Change expected result of test_positionlist_epoch() --- tests/test_properties.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_properties.py b/tests/test_properties.py index 5e41e0a..bcc1152 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -356,12 +356,12 @@ def test_outline_material_colors(): def test_positionlist_epoch(): expected_result = """{ - "epoch": "2019-06-11T12:26:58.000000Z", "cartographicDegrees": [ 200.0, 100.0, 30.0 - ] + ], + "epoch": "2019-06-11T12:26:58.000000Z" }""" p = PositionList( epoch=dt.datetime(2019, 6, 11, 12, 26, 58, tzinfo=dt.timezone.utc), From ebd620a6caf9fe89eb95bac62d78c3b00c2cf40e Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 11:22:59 +0200 Subject: [PATCH 09/13] Add typing to types.format_datetime_like() --- src/czml3/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/czml3/types.py b/src/czml3/types.py index db37e78..a921e19 100644 --- a/src/czml3/types.py +++ b/src/czml3/types.py @@ -95,7 +95,7 @@ def check_reference(r): ) -def format_datetime_like(dt_object): +def format_datetime_like(dt_object: None | str | dt.datetime) -> str | None: if dt_object is None: return dt_object From 879c1439f1353e1637c58d3cc0e021c0fe5025f0 Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 11:23:17 +0200 Subject: [PATCH 10/13] types.format_datetime_like() raises an error on incrorrect type --- src/czml3/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/czml3/types.py b/src/czml3/types.py index a921e19..f3a016f 100644 --- a/src/czml3/types.py +++ b/src/czml3/types.py @@ -111,7 +111,7 @@ def format_datetime_like(dt_object: None | str | dt.datetime) -> str | None: return dt_object.strftime(ISO8601_FORMAT_Z) else: - return dt_object.strftime(ISO8601_FORMAT_Z) + raise TypeError(f"Invalid datetime format: {dt_object}") class FontValue(BaseCZMLObject): From 4a88d4826757a971e91f0c91b984780f7914fb7a Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 11:23:33 +0200 Subject: [PATCH 11/13] Expand testing of types.test_format_datetime_like() --- tests/test_types.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_types.py b/tests/test_types.py index c96b476..dfd485f 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -370,6 +370,10 @@ def test_check_reference(): def test_format_datetime_like(): assert format_datetime_like(None) is None + assert format_datetime_like("2019-01-01T12:00:00.000000Z") == "2019-01-01T12:00:00.000000Z" + assert format_datetime_like(dt.datetime(2019, 1, 1, 12)) == "2019-01-01T12:00:00.000000Z" + with pytest.raises(ValueError): + format_datetime_like("test") def test_reference_list(): From cbb1905b4b368be355b7dbc52949be532af57809 Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 11:27:11 +0200 Subject: [PATCH 12/13] Format --- tests/test_types.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_types.py b/tests/test_types.py index dfd485f..ca8ef4c 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -370,8 +370,14 @@ def test_check_reference(): def test_format_datetime_like(): assert format_datetime_like(None) is None - assert format_datetime_like("2019-01-01T12:00:00.000000Z") == "2019-01-01T12:00:00.000000Z" - assert format_datetime_like(dt.datetime(2019, 1, 1, 12)) == "2019-01-01T12:00:00.000000Z" + assert ( + format_datetime_like("2019-01-01T12:00:00.000000Z") + == "2019-01-01T12:00:00.000000Z" + ) + assert ( + format_datetime_like(dt.datetime(2019, 1, 1, 12)) + == "2019-01-01T12:00:00.000000Z" + ) with pytest.raises(ValueError): format_datetime_like("test") From 39b116ec3c37b0227a6ab3e1873d4a0cbaa4f9c9 Mon Sep 17 00:00:00 2001 From: Daniel Stoops Date: Thu, 9 Jan 2025 11:29:01 +0200 Subject: [PATCH 13/13] Expand test_format_datetime_like() --- tests/test_types.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_types.py b/tests/test_types.py index ca8ef4c..350c1e1 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -380,6 +380,8 @@ def test_format_datetime_like(): ) with pytest.raises(ValueError): format_datetime_like("test") + with pytest.raises(TypeError): + format_datetime_like(1) # type: ignore[arg-type] def test_reference_list():