diff --git a/tests/test_packet.py b/tests/test_packet.py
deleted file mode 100644
index 347957f..0000000
--- a/tests/test_packet.py
+++ /dev/null
@@ -1,1059 +0,0 @@
-import ast
-import datetime as dt
-from uuid import UUID
-
-import pytest
-
-from czml3 import CZML_VERSION, Document, Packet
-from czml3.enums import InterpolationAlgorithms, ReferenceFrames
-from czml3.properties import (
- Billboard,
- Box,
- BoxDimensions,
- Color,
- Corridor,
- Cylinder,
- Ellipse,
- Ellipsoid,
- EllipsoidRadii,
- Label,
- Material,
- Model,
- Orientation,
- Path,
- Point,
- Polygon,
- Polyline,
- PolylineArrow,
- PolylineArrowMaterial,
- PolylineDash,
- PolylineDashMaterial,
- PolylineGlow,
- PolylineGlowMaterial,
- PolylineMaterial,
- PolylineOutline,
- PolylineOutlineMaterial,
- Position,
- PositionList,
- Rectangle,
- RectangleCoordinates,
- SolidColorMaterial,
- Tileset,
- ViewFrom,
- Wall,
-)
-from czml3.types import (
- Cartesian3Value,
- StringValue,
- TimeInterval,
- TimeIntervalCollection,
-)
-
-
-def test_packet_has_given_name():
- expected_name = "document_00"
- packet = Packet(name=expected_name)
-
- assert packet.name == expected_name
-
-
-def test_Packet_has_given_description():
- expected_description = "czml document description"
- packet = Packet(description=expected_description, version=CZML_VERSION)
-
- assert packet.description == expected_description
-
-
-def test_auto_generated_id():
- packet = Packet()
-
- assert UUID(packet.id, version=4)
-
-
-def test_packet_custom_id():
- expected_id = "id_00"
- packet = Packet(id=expected_id)
-
- assert packet.id == expected_id
-
-
-def test_packet_repr_id_only():
- expected_result = """{
- "id": "id_00"
-}"""
- packet = Packet(id="id_00")
-
- assert str(packet) == expected_result
-
-
-def test_packet_label():
- expected_result = """{
- "id": "0",
- "label": {
- "font": "20px sans-serif",
- "fillColor": {
- "rgbaf": [
- 0.2,
- 0.3,
- 0.4,
- 1.0
- ]
- },
- "outlineColor": {
- "rgba": [
- 0.0,
- 233.0,
- 255.0,
- 2.0
- ]
- },
- "outlineWidth": 2.0
- }
-}"""
- packet = Packet(
- id="0",
- label=Label(
- font="20px sans-serif",
- fillColor=Color(rgbaf=[0.2, 0.3, 0.4, 1.0]),
- outlineColor=Color(rgba=[0, 233, 255, 2]),
- outlineWidth=2.0,
- ),
- )
-
- assert packet == Packet(**ast.literal_eval(expected_result))
- assert str(packet) == expected_result
-
-
-def test_packet_repr_id_name():
- expected_result = """{
- "id": "id_00",
- "name": "Test Packet"
-}"""
- packet = Packet(id="id_00", name="Test Packet")
-
- assert str(packet) == expected_result
-
-
-def test_packet_with_delete_has_nothing_else():
- expected_result = """{
- "id": "id_00",
- "delete": true
-}"""
- packet = Packet(id="id_00", delete=True, name="No Name In Packet")
-
- assert str(packet) == expected_result
-
-
-def test_packet_dumps():
- expected_result = """{"id":"id_00"}"""
- packet = Packet(id="id_00")
-
- assert packet.dumps() == expected_result
-
-
-def test_packet_constant_cartesian_position():
- expected_result = """{
- "id": "MyObject",
- "position": {
- "cartesian": [
- 0.0,
- 0.0,
- 0.0
- ]
- }
-}"""
- packet = Packet(id="MyObject", position=Position(cartesian=[0.0, 0.0, 0.0]))
-
- assert str(packet) == expected_result
-
-
-@pytest.mark.xfail
-def test_packet_dynamic_cartesian_position_perfect():
- # Trying to group the cartesian value by sample
- # is much more difficult than expected.
- # Pull requests welcome
- expected_result = """{
- "id": "InternationalSpaceStation",
- "position": {
- "interpolationAlgorithm": "LAGRANGE",
- "referenceFrame": "INERTIAL",
- "cartesian": [
- 0.0, -6668447.2211117, 1201886.45913705, 146789.427467256,
- 60.0, -6711432.84684144, 919677.673492462, -214047.552431458
- ]
- }
-}"""
- packet = Packet(
- id="InternationalSpaceStation",
- position=Position(
- interpolationAlgorithm=InterpolationAlgorithms.LAGRANGE,
- referenceFrame=ReferenceFrames.INERTIAL,
- cartesian=[
- 0.0,
- -6668447.2211117,
- 1201886.45913705,
- 146789.427467256,
- 60.0,
- -6711432.84684144,
- 919677.673492462,
- -214047.552431458,
- ],
- ),
- )
-
- assert str(packet) == expected_result
-
-
-def test_packet_dynamic_cartesian_position():
- expected_result = """{
- "id": "InternationalSpaceStation",
- "position": {
- "interpolationAlgorithm": "LAGRANGE",
- "referenceFrame": "INERTIAL",
- "cartesian": [
- 0.0,
- -6668447.2211117,
- 1201886.45913705,
- 146789.427467256,
- 60.0,
- -6711432.84684144,
- 919677.673492462,
- -214047.552431458
- ]
- }
-}"""
- packet = Packet(
- id="InternationalSpaceStation",
- position=Position(
- interpolationAlgorithm=InterpolationAlgorithms.LAGRANGE,
- referenceFrame=ReferenceFrames.INERTIAL,
- cartesian=[
- 0.0,
- -6668447.2211117,
- 1201886.45913705,
- 146789.427467256,
- 60.0,
- -6711432.84684144,
- 919677.673492462,
- -214047.552431458,
- ],
- ),
- )
-
- assert str(packet) == expected_result
-
-
-def test_packet_description():
- expected_result = """{
- "id": "id_00",
- "name": "Name",
- "description": "Description"
-}"""
- string = "Description"
- packet_str = Packet(id="id_00", name="Name", description=string)
- packet_val = Packet(id="id_00", name="Name", description=StringValue(string=string))
- assert str(packet_str) == str(packet_val) == expected_result
-
-
-def test_packet_custom_properties():
- expected_result = """{
- "id": "id_00",
- "properties": {
- "a": false,
- "b": 1,
- "c": "C",
- "ellipsoid": {
- "radii": {
- "cartesian": [
- 6378137.0,
- 6378137.0,
- 6356752.31414
- ]
- }
- }
- }
-}"""
- prop_dict = {
- "a": False,
- "b": 1,
- "c": "C",
- "ellipsoid": Ellipsoid(
- radii=EllipsoidRadii(
- cartesian=Cartesian3Value(values=[6378137, 6378137, 6356752.314140])
- )
- ),
- }
-
- packet = Packet(id="id_00", properties=prop_dict)
-
- assert str(packet) == expected_result
-
-
-def test_packet_billboard():
- expected_result = """{
- "id": "id_00",
- "billboard": {
- "image": "file://image.png"
- }
-}"""
- packet = Packet(id="id_00", billboard=Billboard(image="file://image.png"))
-
- assert str(packet) == expected_result
-
-
-def test_packet_point():
- expected_result = """{
- "id": "id_00",
- "point": {
- "color": {
- "rgba": [
- 255.0,
- 0.0,
- 0.0,
- 255.0
- ]
- }
- }
-}"""
- packet = Packet(id="id_00", point=Point(color=Color(rgba=[255, 0, 0, 255])))
-
- assert str(packet) == expected_result
-
-
-def test_packet_polyline():
- expected_result = """{
- "id": "id_00",
- "polyline": {
- "positions": {
- "cartographicDegrees": [
- -75.0,
- 43.0,
- 500000.0,
- -125.0,
- 43.0,
- 500000.0
- ]
- },
- "material": {
- "solidColor": {
- "color": {
- "rgba": [
- 255.0,
- 0.0,
- 0.0,
- 255.0
- ]
- }
- }
- }
- }
-}"""
- packet = Packet(
- id="id_00",
- polyline=Polyline(
- positions=PositionList(
- cartographicDegrees=[-75, 43, 500000, -125, 43, 500000]
- ),
- material=PolylineMaterial(
- solidColor=SolidColorMaterial(color=Color(rgba=[255, 0, 0, 255]))
- ),
- ),
- )
-
- assert str(packet) == expected_result
-
-
-def test_packet_polyline_outline():
- expected_result = """{
- "id": "id_00",
- "polyline": {
- "positions": {
- "cartographicDegrees": [
- -75.0,
- 43.0,
- 500000.0,
- -125.0,
- 43.0,
- 500000.0
- ]
- },
- "material": {
- "polylineOutline": {
- "color": {
- "rgba": [
- 255.0,
- 0.0,
- 0.0,
- 255.0
- ]
- },
- "outlineColor": {
- "rgba": [
- 255.0,
- 0.0,
- 0.0,
- 255.0
- ]
- },
- "outlineWidth": 2.0
- }
- }
- }
-}"""
- packet = Packet(
- id="id_00",
- polyline=Polyline(
- positions=PositionList(
- cartographicDegrees=[-75, 43, 500000, -125, 43, 500000]
- ),
- material=PolylineOutlineMaterial(
- polylineOutline=PolylineOutline(
- color=Color(rgba=[255, 0, 0, 255]),
- outlineColor=Color(rgba=[255, 0, 0, 255]),
- outlineWidth=2,
- )
- ),
- ),
- )
-
- assert str(packet) == expected_result
-
-
-# TODO:
-def test_packet_polyline_glow():
- expected_result = """{
- "id": "id_00",
- "polyline": {
- "positions": {
- "cartographicDegrees": [
- -75.0,
- 43.0,
- 500000.0,
- -125.0,
- 43.0,
- 500000.0
- ]
- },
- "material": {
- "polylineGlow": {
- "color": {
- "rgba": [
- 255.0,
- 0.0,
- 0.0,
- 255.0
- ]
- },
- "glowPower": 0.2,
- "taperPower": 0.5
- }
- }
- }
-}"""
- packet = Packet(
- id="id_00",
- polyline=Polyline(
- positions=PositionList(
- cartographicDegrees=[-75, 43, 500000, -125, 43, 500000]
- ),
- material=PolylineGlowMaterial(
- polylineGlow=PolylineGlow(
- color=Color(rgba=[255, 0, 0, 255]),
- glowPower=0.2,
- taperPower=0.5,
- )
- ),
- ),
- )
-
- assert str(packet) == expected_result
-
-
-def test_packet_polyline_arrow():
- expected_result = """{
- "id": "id_00",
- "polyline": {
- "positions": {
- "cartographicDegrees": [
- -75.0,
- 43.0,
- 500000.0,
- -125.0,
- 43.0,
- 500000.0
- ]
- },
- "material": {
- "polylineArrow": {
- "color": {
- "rgba": [
- 255.0,
- 0.0,
- 0.0,
- 255.0
- ]
- }
- }
- }
- }
-}"""
- packet = Packet(
- id="id_00",
- polyline=Polyline(
- positions=PositionList(
- cartographicDegrees=[-75, 43, 500000, -125, 43, 500000]
- ),
- material=PolylineArrowMaterial(
- polylineArrow=PolylineArrow(color=Color(rgba=[255, 0, 0, 255]))
- ),
- ),
- )
-
- assert str(packet) == expected_result
-
-
-def test_packet_polyline_dashed():
- expected_result = """{
- "id": "id_00",
- "polyline": {
- "positions": {
- "cartographicDegrees": [
- -75.0,
- 43.0,
- 500000.0,
- -125.0,
- 43.0,
- 500000.0
- ]
- },
- "material": {
- "polylineDash": {
- "color": {
- "rgba": [
- 255.0,
- 0.0,
- 0.0,
- 255.0
- ]
- }
- }
- }
- }
-}"""
- packet = Packet(
- id="id_00",
- polyline=Polyline(
- positions=PositionList(
- cartographicDegrees=[-75, 43, 500000, -125, 43, 500000]
- ),
- material=PolylineDashMaterial(
- polylineDash=PolylineDash(color=Color(rgba=[255, 0, 0, 255]))
- ),
- ),
- )
-
- assert str(packet) == expected_result
-
-
-def test_packet_polygon():
- expected_result = """{
- "id": "id_00",
- "polygon": {
- "positions": {
- "cartographicDegrees": [
- -115.0,
- 37.0,
- 0.0,
- -115.0,
- 32.0,
- 0.0,
- -107.0,
- 33.0,
- 0.0,
- -102.0,
- 31.0,
- 0.0,
- -102.0,
- 35.0,
- 0.0
- ]
- },
- "granularity": 1.0,
- "material": {
- "solidColor": {
- "color": {
- "rgba": [
- 255.0,
- 0.0,
- 0.0,
- 255.0
- ]
- }
- }
- }
- }
-}"""
- packet = Packet(
- id="id_00",
- polygon=Polygon(
- positions=PositionList(
- cartographicDegrees=[
- -115.0,
- 37.0,
- 0,
- -115.0,
- 32.0,
- 0,
- -107.0,
- 33.0,
- 0,
- -102.0,
- 31.0,
- 0,
- -102.0,
- 35.0,
- 0,
- ]
- ),
- granularity=1.0,
- material=Material(
- solidColor=SolidColorMaterial(color=Color(rgba=[255, 0, 0]))
- ),
- ),
- )
-
- assert str(packet) == expected_result
-
-
-def test_different_IDs():
- p1 = Packet()
- p2 = Packet()
- assert p1.id != p2.id
- assert str(p1.id) != str(p2.id)
-
-
-def test_different_availabilities():
- p1 = Packet(
- availability=TimeIntervalCollection(
- values=[
- TimeInterval(
- start=dt.datetime(2019, 3, 20, 12, tzinfo=dt.timezone.utc),
- end=dt.datetime(2019, 4, 20, 12, tzinfo=dt.timezone.utc),
- )
- ]
- )
- )
- p2 = Packet(
- availability=TimeIntervalCollection(
- values=[
- TimeInterval(
- start=dt.datetime(2019, 3, 20, 12, tzinfo=dt.timezone.utc),
- end=dt.datetime(2020, 4, 20, 12, tzinfo=dt.timezone.utc),
- )
- ]
- )
- )
- assert p1 != p2
- assert str(p1) != str(p2)
-
-
-def test_preamble_no_version():
- with pytest.raises(
- ValueError,
- match="The first packet must be a preamble and include 'version' and 'name' properties.",
- ):
- Document(packets=[Packet(name="Test Packet", id="document")])
-
-
-def test_preamble_no_name():
- with pytest.raises(
- ValueError,
- match="The first packet must be a preamble and include 'version' and 'name' properties.",
- ):
- Document(packets=[Packet(version="Test Packet", id="document")])
-
-
-def test_preamble_no_id():
- with pytest.raises(
- ValueError, match="The first packet must have an ID of 'document'."
- ):
- Document(packets=[Packet(version="Test Packet", name="Test Packet")])
-
-
-def test_preamble_bad_id():
- with pytest.raises(
- ValueError, match="The first packet must have an ID of 'document'."
- ):
- Document(packets=[Packet(version="Test Packet", name="Test Packet", id="name")])
-
-
-def test_preamble_wall_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'wall' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- wall=Wall(positions=PositionList(cartesian=[0, 0, 0])),
- )
- ]
- )
-
-
-def test_preamble_tileset_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'tileset' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- tileset=Tileset(uri="file://tileset.json"),
- )
- ]
- )
-
-
-def test_preamble_rectangle_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'rectangle' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- rectangle=Rectangle(
- coordinates=RectangleCoordinates(wsen=[0, 0, 0])
- ),
- )
- ]
- )
-
-
-def test_preamble_polyline_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'polyline' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- polyline=Polyline(
- positions=PositionList(cartographicDegrees=[0, 0, 0])
- ),
- )
- ]
- )
-
-
-def test_preamble_polygon_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'polygon' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- polygon=Polygon(
- positions=PositionList(cartographicDegrees=[0, 0, 0])
- ),
- )
- ]
- )
-
-
-def test_preamble_point_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'point' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- point=Point(),
- )
- ]
- )
-
-
-def test_preamble_availability_supplied():
- with pytest.raises(
- ValueError,
- match="The first packet must not include the 'availability' property",
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- availability=TimeIntervalCollection(
- values=[
- TimeInterval(
- start=dt.datetime(
- 2019, 3, 20, 12, tzinfo=dt.timezone.utc
- ),
- end=dt.datetime(
- 2019, 4, 20, 12, tzinfo=dt.timezone.utc
- ),
- )
- ]
- ),
- )
- ]
- )
-
-
-def test_preamble_model_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'model' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- model=Model(gltf="file://model.glb"),
- )
- ]
- )
-
-
-def test_preamble_path_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'path' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- path=Path(),
- )
- ]
- )
-
-
-def test_preamble_label_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'label' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- label=Label(),
- )
- ]
- )
-
-
-def test_preamble_ellipse_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'ellipse' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- ellipse=Ellipse(semiMajorAxis=1000.0, semiMinorAxis=1000.0),
- )
- ]
- )
-
-
-def test_preamble_ellipsoid_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'ellipsoid' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- ellipsoid=Ellipsoid(radii=EllipsoidRadii(cartesian=[0, 0, 0])),
- )
- ]
- )
-
-
-def test_preamble_cylinder_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'cylinder' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- cylinder=Cylinder(length=1, topRadius=1, bottomRadius=1),
- )
- ]
- )
-
-
-def test_preamble_corridor_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'corridor' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- corridor=Corridor(
- positions=PositionList(cartographicDegrees=[0, 0, 0]), width=2
- ),
- )
- ]
- )
-
-
-def test_preamble_box_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'box' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- box=Box(dimensions=BoxDimensions(cartesian=[0, 0, 0])),
- )
- ]
- )
-
-
-def test_preamble_billboard_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'billboard' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- billboard=Billboard(image="file://image.png"),
- )
- ]
- )
-
-
-def test_preamble_orientation_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'orientation' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- orientation=Orientation(unitQuaternion=[0, 0, 0, 1]),
- )
- ]
- )
-
-
-def test_preamble_viewFrom_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'viewFrom' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- viewFrom=ViewFrom(cartesian=[0, 0, 0]),
- )
- ]
- )
-
-
-def test_preamble_delete_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'delete' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- delete=False,
- )
- ]
- )
-
-
-def test_preamble_parent_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'parent' property"
- ):
- Document(
- packets=[
- Packet(
- version="Test Packet",
- name="Test Packet",
- id="document",
- parent="parent",
- )
- ]
- )
-
-
-def test_preamble_position_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'position' property"
- ):
- Document(
- packets=[
- Packet(
- id="document",
- version="1.0",
- name="Test Document",
- position=Position(cartesian=[0, 0, 0]),
- )
- ]
- )
-
-
-def test_preamble_properties_supplied():
- with pytest.raises(
- ValueError, match="The first packet must not include the 'properties' property"
- ):
- Document(
- packets=[
- Packet(
- id="document",
- version="1.0",
- name="Test Document",
- properties={"non_allowed_property": "value"},
- )
- ]
- )
diff --git a/tests/test_properties.py b/tests/test_properties.py
deleted file mode 100644
index 5e41e0a..0000000
--- a/tests/test_properties.py
+++ /dev/null
@@ -1,1800 +0,0 @@
-import datetime as dt
-
-import pytest
-from pydantic import ValidationError
-
-from czml3.enums import (
- ArcTypes,
- ClassificationTypes,
- ColorBlendModes,
- CornerTypes,
- HeightReferences,
- ShadowModes,
-)
-from czml3.properties import (
- ArcType,
- Billboard,
- Box,
- BoxDimensions,
- CheckerboardMaterial,
- ClassificationType,
- Color,
- ColorBlendMode,
- CornerType,
- DistanceDisplayCondition,
- Ellipsoid,
- EllipsoidRadii,
- EyeOffset,
- GridMaterial,
- HeightReference,
- ImageMaterial,
- Label,
- Material,
- Model,
- NearFarScalar,
- Orientation,
- Point,
- Polygon,
- Polyline,
- PolylineArrow,
- PolylineArrowMaterial,
- PolylineDash,
- PolylineDashMaterial,
- PolylineGlow,
- PolylineGlowMaterial,
- PolylineMaterial,
- PolylineOutline,
- PolylineOutlineMaterial,
- Position,
- PositionList,
- PositionListOfLists,
- RectangleCoordinates,
- ShadowMode,
- SolidColorMaterial,
- StripeMaterial,
- Tileset,
- Uri,
- ViewFrom,
-)
-from czml3.types import (
- Cartesian2Value,
- Cartesian3ListOfListsValue,
- Cartesian3ListValue,
- Cartesian3Value,
- Cartesian3VelocityValue,
- CartographicDegreesListOfListsValue,
- CartographicDegreesListValue,
- CartographicDegreesValue,
- CartographicRadiansListOfListsValue,
- CartographicRadiansListValue,
- CartographicRadiansValue,
- DistanceDisplayConditionValue,
- IntervalValue,
- NearFarScalarValue,
- ReferenceListOfListsValue,
- ReferenceListValue,
- ReferenceValue,
- TimeInterval,
- TimeIntervalCollection,
- UnitQuaternionValue,
- format_datetime_like,
-)
-
-
-def test_box():
- expected_result = """{
- "show": true,
- "dimensions": {
- "cartesian": [
- 5.0,
- 6.0,
- 3.0
- ]
- }
-}"""
-
- box = Box(
- show=True, dimensions=BoxDimensions(cartesian=Cartesian3Value(values=[5, 6, 3]))
- )
- assert str(box) == expected_result
-
-
-def test_eyeOffset():
- expected_result = """{
- "cartesian": [
- 1.0,
- 2.0,
- 3.0
- ]
-}"""
-
- eyeOffset = EyeOffset(cartesian=Cartesian3Value(values=[1, 2, 3]))
- assert str(eyeOffset) == expected_result
-
-
-def test_point():
- expected_result = """{
- "show": true,
- "pixelSize": 10.0,
- "scaleByDistance": {
- "nearFarScalar": [
- 150.0,
- 2.0,
- 15000000.0,
- 0.5
- ]
- },
- "disableDepthTestDistance": 1.2
-}"""
-
- pnt = Point(
- show=True,
- pixelSize=10,
- scaleByDistance=NearFarScalar(
- nearFarScalar=NearFarScalarValue(values=[150, 2.0, 15000000, 0.5])
- ),
- disableDepthTestDistance=1.2,
- )
- assert str(pnt) == expected_result
-
-
-def test_arc_type():
- expected_result = """{
- "arcType": "NONE"
-}"""
- arc_type = ArcType(arcType=ArcTypes.NONE)
- assert str(arc_type) == expected_result
-
-
-def test_shadow_mode():
- expected_result = """{
- "shadowMode": "ENABLED"
-}"""
- shadow_mode = ShadowMode(shadowMode=ShadowModes.ENABLED)
- assert str(shadow_mode) == expected_result
-
-
-def test_polyline():
- expected_result = """{
- "positions": {
- "cartographicDegrees": [
- 20.0,
- 30.0,
- 10.0
- ]
- },
- "arcType": {
- "arcType": "GEODESIC"
- },
- "distanceDisplayCondition": {
- "distanceDisplayCondition": [
- 14.0,
- 81.0
- ]
- },
- "classificationType": {
- "classificationType": "CESIUM_3D_TILE"
- }
-}"""
- pol = Polyline(
- positions=PositionList(
- cartographicDegrees=CartographicDegreesListValue(values=[20, 30, 10])
- ),
- arcType=ArcType(arcType="GEODESIC"),
- distanceDisplayCondition=DistanceDisplayCondition(
- distanceDisplayCondition=DistanceDisplayConditionValue(values=[14, 81])
- ),
- classificationType=ClassificationType(
- classificationType=ClassificationTypes.CESIUM_3D_TILE
- ),
- )
- assert str(pol) == expected_result
-
-
-def test_material_solid_color_with_reference():
- expected_result = """{
- "solidColor": {
- "color": {
- "rgba": [
- 200.0,
- 100.0,
- 30.0,
- 255.0
- ],
- "reference": "this#that"
- }
- }
-}"""
- pol_mat = PolylineMaterial(
- solidColor=SolidColorMaterial(
- color=Color(rgba=[200, 100, 30], reference="this#that")
- )
- )
- assert str(pol_mat) == expected_result
- pol_mat = PolylineMaterial(
- solidColor=SolidColorMaterial(
- color=Color(
- rgba=[200, 100, 30], reference=ReferenceValue(value="this#that")
- )
- )
- )
- assert str(pol_mat) == expected_result
-
-
-def test_material_solid_color():
- expected_result = """{
- "solidColor": {
- "color": {
- "rgba": [
- 200.0,
- 100.0,
- 30.0,
- 255.0
- ]
- }
- }
-}"""
- mat = Material(solidColor=SolidColorMaterial(color=Color(rgba=[200, 100, 30])))
-
- assert str(mat) == expected_result
-
- pol_mat = PolylineMaterial(
- solidColor=SolidColorMaterial(color=Color(rgba=[200, 100, 30]))
- )
- assert str(pol_mat) == expected_result
-
-
-def test_arrowmaterial_color():
- expected_result = """{
- "polylineArrow": {
- "color": {
- "rgba": [
- 200.0,
- 100.0,
- 30.0,
- 255.0
- ]
- }
- }
-}"""
- pamat = PolylineArrowMaterial(
- polylineArrow=PolylineArrow(color=Color(rgba=[200, 100, 30, 255])),
- )
-
- assert str(pamat) == expected_result
-
-
-def test_dashmaterial_colors():
- expected_result = """{
- "polylineDash": {
- "color": {
- "rgba": [
- 200.0,
- 100.0,
- 30.0,
- 255.0
- ]
- },
- "gapColor": {
- "rgba": [
- 100.0,
- 200.0,
- 0.0,
- 255.0
- ]
- },
- "dashLength": 16.0,
- "dashPattern": 255
- }
-}"""
- dashmat = PolylineDashMaterial(
- polylineDash=PolylineDash(
- color=Color(rgba=[200, 100, 30, 255]),
- gapColor=Color(rgba=[100, 200, 0, 255]),
- dashLength=16,
- dashPattern=255,
- ),
- )
-
- assert str(dashmat) == expected_result
-
-
-def test_glowmaterial_color():
- expected_result = """{
- "polylineGlow": {
- "color": {
- "rgba": [
- 200.0,
- 100.0,
- 30.0,
- 255.0
- ]
- },
- "glowPower": 0.7,
- "taperPower": 0.3
- }
-}"""
- glowmat = PolylineGlowMaterial(
- polylineGlow=PolylineGlow(
- color=Color(rgba=[200, 100, 30, 255]), glowPower=0.7, taperPower=0.3
- )
- )
- assert str(glowmat) == expected_result
-
-
-def test_outline_material_colors():
- expected_result = """{
- "polylineOutline": {
- "color": {
- "rgba": [
- 200.0,
- 100.0,
- 30.0,
- 255.0
- ]
- },
- "outlineColor": {
- "rgba": [
- 100.0,
- 200.0,
- 0.0,
- 255.0
- ]
- },
- "outlineWidth": 3.0
- }
-}"""
- omat = PolylineOutlineMaterial(
- polylineOutline=PolylineOutline(
- color=Color(rgba=[200, 100, 30, 255]),
- outlineColor=Color(rgba=[100, 200, 0, 255]),
- outlineWidth=3,
- )
- )
- assert str(omat) == expected_result
-
-
-def test_positionlist_epoch():
- expected_result = """{
- "epoch": "2019-06-11T12:26:58.000000Z",
- "cartographicDegrees": [
- 200.0,
- 100.0,
- 30.0
- ]
-}"""
- p = PositionList(
- epoch=dt.datetime(2019, 6, 11, 12, 26, 58, tzinfo=dt.timezone.utc),
- cartographicDegrees=[200, 100, 30],
- )
- assert str(p) == expected_result
-
-
-def test_colors_rgba():
- Color(rgba=[255, 204, 0, 55])
- Color(rgba=[255, 204, 55])
- Color(rgba=[0.5, 0.6, 0.2])
- Color(rgba="0xFF0000")
- Color(rgba="0xFFFFFFFF")
- Color(rgba="0xFF3223")
- Color(rgba="0xFF322332")
- Color(rgba="#FF3223")
- Color(rgba="#FF322332")
- Color(rgba=[255, 204, 55])
- Color(rgba=[255, 204, 55, 255])
- Color(rgba=[0.127568, 0.566949, 0.550556])
- Color(rgba=[0.127568, 0.566949, 0.550556, 1.0])
-
-
-def test_colors_rgbaf():
- Color(rgbaf=[1, 0.8, 0, 0.6])
- Color(rgbaf=[1, 0.8, 0.6])
- Color(rgbaf="0xFF3223")
- Color(rgbaf="0xFF322332")
- Color(rgbaf="#FF3223")
- Color(rgbaf="#FF322332")
- Color(rgbaf=[1, 0.8, 0.6])
- Color(rgbaf=[1, 0.8, 0.6, 1])
- Color(rgbaf=[0.127568, 0.566949, 0.550556])
- Color(rgbaf=[0.127568, 0.566949, 0.550556, 1.0])
-
-
-def test_color_invalid_colors_rgba():
- with pytest.raises(TypeError):
- Color(rgba=[256, 204, 0, 55])
- with pytest.raises(TypeError):
- Color(rgba=[-204, 0, 55])
- with pytest.raises(TypeError):
- Color(rgba=[255, 204])
- with pytest.raises(TypeError):
- Color(rgba=[255, 232, 300])
- with pytest.raises(ValidationError):
- Color(rgba=-3) # type: ignore
-
-
-def test_color_invalid_colors_rgbaf():
- with pytest.raises(TypeError):
- Color(rgbaf=[256, 204, 0, 55])
- with pytest.raises(TypeError):
- Color(rgbaf=[-204, 0, 55])
- with pytest.raises(TypeError):
- Color(rgbaf=[255, 204])
- with pytest.raises(TypeError):
- Color(rgbaf=[255, 232, 300])
- with pytest.raises(ValidationError):
- Color(rgbaf=-3) # type: ignore
- with pytest.raises(TypeError):
- Color(rgbaf=[255, 204, 55, 255, 42])
- with pytest.raises(TypeError):
- Color(rgbaf=[0.127568, 0.566949, 0.550556, 1.0, 3.0])
-
-
-def test_material_image():
- expected_result = """{
- "image": {
- "image": "https://site.com/image.png",
- "repeat": [
- 2,
- 2
- ],
- "color": {
- "rgba": [
- 200.0,
- 100.0,
- 30.0,
- 255.0
- ]
- }
- }
-}"""
-
- mat = Material(
- image=ImageMaterial(
- image=Uri(uri="https://site.com/image.png"),
- repeat=[2, 2],
- color=Color(rgba=[200, 100, 30]),
- )
- )
- assert str(mat) == expected_result
-
-
-def test_material_image_uri():
- expected_result = """{
- "image": {
- "image": "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
- "repeat": [
- 2,
- 2
- ],
- "color": {
- "rgba": [
- 200.0,
- 100.0,
- 30.0,
- 255.0
- ]
- }
- }
-}"""
-
- mat = Material(
- image=ImageMaterial(
- image=Uri(
- uri="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
- ),
- repeat=[2, 2],
- color=Color(rgba=[200, 100, 30]),
- )
- )
- assert str(mat) == expected_result
-
-
-def test_material_grid():
- expected_result = """{
- "color": {
- "rgba": [
- 20.0,
- 20.0,
- 30.0,
- 255.0
- ]
- },
- "cellAlpha": 1.0,
- "lineCount": [
- 16,
- 16
- ],
- "lineThickness": [
- 2.0,
- 2.0
- ],
- "lineOffset": [
- 0.3,
- 0.4
- ]
-}"""
-
- pol_mat = GridMaterial(
- color=Color(rgba=[20, 20, 30]),
- cellAlpha=1.0,
- lineCount=[16, 16],
- lineThickness=[2.0, 2.0],
- lineOffset=[0.3, 0.4],
- )
- assert str(pol_mat) == expected_result
-
-
-def test_nested_delete():
- expected_result = """{
- "color": {
- "delete": true
- },
- "cellAlpha": 1.0,
- "lineCount": [
- 16,
- 16
- ],
- "lineThickness": [
- 2.0,
- 2.0
- ],
- "lineOffset": [
- 0.3,
- 0.4
- ]
-}"""
-
- pol_mat = GridMaterial(
- color=Color(rgba=[20, 20, 30], delete=True),
- cellAlpha=1.0,
- lineCount=[16, 16],
- lineThickness=[2.0, 2.0],
- lineOffset=[0.3, 0.4],
- )
- assert str(pol_mat) == expected_result
-
-
-def test_material_stripe():
- expected_result = """{
- "evenColor": {
- "rgba": [
- 0.0,
- 0.0,
- 0.0,
- 255.0
- ]
- },
- "oddColor": {
- "rgba": [
- 255.0,
- 255.0,
- 255.0,
- 255.0
- ]
- },
- "offset": 0.3,
- "repeat": 4.0
-}"""
-
- pol_mat = StripeMaterial(
- evenColor=Color(rgba=[0, 0, 0]),
- oddColor=Color(rgba=[255, 255, 255]),
- offset=0.3,
- repeat=4.0,
- )
- assert str(pol_mat) == expected_result
-
-
-def test_material_checkerboard():
- expected_result = """{
- "evenColor": {
- "rgba": [
- 0.0,
- 0.0,
- 0.0,
- 255.0
- ]
- },
- "oddColor": {
- "rgba": [
- 255.0,
- 255.0,
- 255.0,
- 255.0
- ]
- },
- "repeat": [
- 4,
- 4
- ]
-}"""
-
- pol_mat = CheckerboardMaterial(
- evenColor=Color(rgba=[0, 0, 0]),
- oddColor=Color(rgba=[255, 255, 255]),
- repeat=[4, 4],
- )
- assert str(pol_mat) == expected_result
-
-
-def test_position_has_delete():
- pos = Position(delete=True, cartesian=[])
-
- assert pos.delete
-
-
-def test_position_list_has_delete():
- pos = PositionList(delete=True, cartesian=[])
-
- assert pos.delete
-
-
-def test_position_list_of_lists_has_delete():
- pos = PositionListOfLists(delete=True, cartesian=[])
-
- assert pos.delete
-
-
-def test_position_no_values_raises_error():
- with pytest.raises(TypeError) as exc:
- Position()
-
- assert (
- "One of cartesian, cartographicDegrees, cartographicRadians or reference must be given"
- in exc.exconly()
- )
-
-
-def test_position_list_of_lists_no_values_raises_error():
- with pytest.raises(TypeError) as exc:
- PositionListOfLists()
-
- assert (
- "One of cartesian, cartographicDegrees, cartographicRadians or reference must be given"
- in exc.exconly()
- )
-
-
-def test_position_list_no_values_raises_error():
- with pytest.raises(TypeError) as exc:
- PositionList()
-
- assert (
- "One of cartesian, cartographicDegrees, cartographicRadians or reference must be given"
- in exc.exconly()
- )
-
-
-def test_position_with_delete_has_nothing_else():
- expected_result = """{
- "delete": true
-}"""
- pos_list = Position(delete=True, cartesian=[1, 2, 3])
- pos_val = Position(delete=True, cartesian=Cartesian3Value(values=[1, 2, 3]))
- assert str(pos_list) == str(pos_val) == expected_result
- pos_list = Position(delete=True, cartographicRadians=[1, 2, 3])
- pos_val = Position(
- delete=True, cartographicRadians=CartographicRadiansValue(values=[1, 2, 3])
- )
- assert str(pos_list) == str(pos_val) == expected_result
- pos_list = Position(delete=True, cartographicDegrees=[1, 2, 3])
- pos_val = Position(
- delete=True, cartographicDegrees=CartographicDegreesValue(values=[1, 2, 3])
- )
- assert str(pos_list) == str(pos_val) == expected_result
- pos_list = Position(delete=True, cartesianVelocity=[1, 2, 3, 4, 5, 6])
- pos_val = Position(
- delete=True,
- cartesianVelocity=Cartesian3VelocityValue(values=[1, 2, 3, 4, 5, 6]),
- )
- assert str(pos_list) == str(pos_val) == expected_result
-
-
-def test_position_has_given_epoch():
- expected_epoch = format_datetime_like(
- dt.datetime(2019, 6, 11, 12, 26, 58, tzinfo=dt.timezone.utc)
- )
-
- pos = Position(epoch=expected_epoch, cartesian=[0, 0, 0])
-
- assert pos.epoch == expected_epoch
-
-
-def test_positionlist_has_given_epoch():
- expected_epoch = format_datetime_like(
- dt.datetime(2019, 6, 11, 12, 26, 58, tzinfo=dt.timezone.utc)
- )
-
- pos = PositionList(epoch=expected_epoch, cartesian=[0, 0, 0])
-
- assert pos.epoch == expected_epoch
-
-
-def test_position_renders_epoch():
- expected_result = """{
- "epoch": "2019-03-20T12:00:00.000000Z",
- "cartesian": [
- 0.0,
- 0.0,
- 0.0
- ]
-}"""
- pos = Position(
- epoch=dt.datetime(2019, 3, 20, 12, tzinfo=dt.timezone.utc), cartesian=[0, 0, 0]
- )
-
- assert str(pos) == expected_result
-
-
-def test_position_cartographic_degrees():
- expected_result = """{
- "cartographicDegrees": [
- 10.0,
- 20.0,
- 0.0
- ]
-}"""
- pos = Position(cartographicDegrees=[10.0, 20.0, 0.0])
-
- assert str(pos) == expected_result
-
-
-def test_position_reference():
- expected_result = """{
- "cartesian": [
- 0.0,
- 0.0,
- 0.0
- ],
- "reference": "this#satellite"
-}"""
- pos = Position(cartesian=[0, 0, 0], reference="this#satellite")
- assert str(pos) == expected_result
- pos = Position(
- cartesian=[0, 0, 0], reference=ReferenceValue(value="this#satellite")
- )
- assert str(pos) == expected_result
-
-
-def test_viewfrom_reference():
- expected_result = """{
- "cartesian": [
- 1.0,
- 1.0,
- 1.0
- ],
- "reference": "this#satellite"
-}"""
- v = ViewFrom(reference="this#satellite", cartesian=[1.0, 1.0, 1.0])
- assert str(v) == expected_result
- v = ViewFrom(
- reference=ReferenceValue(value="this#satellite"), cartesian=[1.0, 1.0, 1.0]
- )
- assert str(v) == expected_result
-
-
-def test_viewfrom_cartesian():
- expected_result = """{
- "cartesian": [
- -1000.0,
- 0.0,
- 300.0
- ]
-}"""
- v = ViewFrom(cartesian=Cartesian3Value(values=[-1000, 0, 300]))
-
- assert str(v) == expected_result
-
-
-def test_viewfrom_has_delete():
- v = ViewFrom(delete=True, cartesian=[14.0, 12.0])
-
- assert v.delete
-
-
-def test_viewfrom_no_values_raises_error():
- with pytest.raises(ValidationError) as _:
- ViewFrom() # type: ignore
-
-
-def test_single_interval_value():
- expected_result = """{
- "interval": "2019-01-01T00:00:00.000000Z/2019-01-02T00:00:00.000000Z",
- "boolean": true
-}"""
-
- start = dt.datetime(2019, 1, 1, tzinfo=dt.timezone.utc)
- end = dt.datetime(2019, 1, 2, tzinfo=dt.timezone.utc)
-
- prop = IntervalValue(start=start, end=end, value=True)
-
- assert str(prop) == expected_result
-
-
-def test_multiple_interval_value():
- expected_result = """[
- {
- "interval": "2019-01-01T00:00:00.000000Z/2019-01-02T00:00:00.000000Z",
- "boolean": true
- },
- {
- "interval": "2019-01-02T00:00:00.000000Z/2019-01-03T00:00:00.000000Z",
- "boolean": false
- }
-]"""
-
- start0 = dt.datetime(2019, 1, 1, tzinfo=dt.timezone.utc)
- end0 = start1 = dt.datetime(2019, 1, 2, tzinfo=dt.timezone.utc)
- end1 = dt.datetime(2019, 1, 3, tzinfo=dt.timezone.utc)
-
- prop = TimeIntervalCollection(
- values=[
- IntervalValue(start=start0, end=end0, value=True),
- IntervalValue(start=start1, end=end1, value=False),
- ]
- )
-
- assert str(prop) == expected_result
-
-
-def test_multiple_interval_decimal_value():
- expected_result = """[
- {
- "interval": "2019-01-01T01:02:03.456789Z/2019-01-02T01:02:03.456789Z",
- "boolean": true
- },
- {
- "interval": "2019-01-02T01:02:03.456789Z/2019-01-03T01:02:03.456789Z",
- "boolean": false
- }
-]"""
-
- start0 = dt.datetime(2019, 1, 1, 1, 2, 3, 456789, tzinfo=dt.timezone.utc)
- end0 = start1 = dt.datetime(2019, 1, 2, 1, 2, 3, 456789, tzinfo=dt.timezone.utc)
- end1 = dt.datetime(2019, 1, 3, 1, 2, 3, 456789, tzinfo=dt.timezone.utc)
-
- prop = TimeIntervalCollection(
- values=[
- IntervalValue(start=start0, end=end0, value=True),
- IntervalValue(start=start1, end=end1, value=False),
- ]
- )
-
- assert str(prop) == expected_result
-
-
-def test_orientation():
- expected_result = """{
- "unitQuaternion": [
- 0.0,
- 0.0,
- 0.0,
- 1.0
- ]
-}"""
-
- result = Orientation(unitQuaternion=UnitQuaternionValue(values=[0, 0, 0, 1]))
-
- assert str(result) == expected_result
-
-
-def test_model():
- expected_result = """{
- "gltf": "https://sandcastle.cesium.com/SampleData/models/CesiumAir/Cesium_Air.glb"
-}"""
-
- result = Model(
- gltf="https://sandcastle.cesium.com/SampleData/models/CesiumAir/Cesium_Air.glb"
- )
- result1 = Model(
- gltf=Uri(
- uri="https://sandcastle.cesium.com/SampleData/models/CesiumAir/Cesium_Air.glb"
- )
- )
-
- assert str(result) == str(result1) == expected_result
-
-
-@pytest.mark.xfail
-def test_bad_uri_raises_error():
- with pytest.raises(TypeError):
- Uri(uri="a")
-
-
-def test_ellipsoid():
- expected_result = """{
- "radii": {
- "cartesian": [
- 20.0,
- 30.0,
- 40.0
- ]
- },
- "fill": false,
- "outline": true
-}"""
-
- ell = Ellipsoid(
- radii=EllipsoidRadii(cartesian=[20.0, 30.0, 40.0]), fill=False, outline=True
- )
- assert str(ell) == expected_result
-
-
-def test_ellipsoid_parameters():
- expected_result = """{
- "radii": {
- "cartesian": [
- 500000.0,
- 500000.0,
- 500000.0
- ]
- },
- "innerRadii": {
- "cartesian": [
- 10000.0,
- 10000.0,
- 10000.0
- ]
- },
- "minimumClock": -15.0,
- "maximumClock": 15.0,
- "minimumCone": 75.0,
- "maximumCone": 105.0,
- "material": {
- "solidColor": {
- "color": {
- "rgba": [
- 255.0,
- 0.0,
- 0.0,
- 100.0
- ]
- }
- }
- },
- "outline": true,
- "outlineColor": {
- "rgbaf": [
- 0.0,
- 0.0,
- 0.0,
- 1.0
- ]
- }
-}"""
-
- ell = Ellipsoid(
- radii=EllipsoidRadii(cartesian=[500000.0, 500000.0, 500000.0]),
- innerRadii=EllipsoidRadii(cartesian=[10000.0, 10000.0, 10000.0]),
- minimumClock=-15.0,
- maximumClock=15.0,
- minimumCone=75.0,
- maximumCone=105.0,
- material=Material(
- solidColor=SolidColorMaterial(color=Color(rgba=[255, 0, 0, 100])),
- ),
- outline=True,
- outlineColor=Color(rgbaf=[0, 0, 0, 1]),
- )
- assert str(ell) == expected_result
-
-
-def test_polygon_with_hole():
- expected_result = """{
- "positions": {
- "cartographicDegrees": [
- 30.0,
- 40.0,
- 1.0
- ]
- },
- "holes": {
- "cartographicDegrees": [
- [
- 20.0,
- 20.0,
- 0.0
- ],
- [
- 10.0,
- 10.0,
- 0.0
- ]
- ]
- }
-}"""
-
- p = Polygon(
- positions=PositionList(cartographicDegrees=[30.0, 40.0, 1.0]),
- holes=PositionListOfLists(
- cartographicDegrees=[[20.0, 20.0, 0.0], [10.0, 10.0, 0.0]]
- ),
- )
- assert str(p) == expected_result
-
-
-def test_polygon_interval():
- """This only tests one interval"""
-
- expected_result = """{
- "positions": {
- "cartographicDegrees": [
- 10.0,
- 20.0,
- 0.0
- ],
- "interval": "2019-03-20T12:00:00.000000Z/2019-04-20T12:00:00.000000Z"
- }
-}"""
- t = TimeInterval(
- start=dt.datetime(2019, 3, 20, 12, tzinfo=dt.timezone.utc),
- end=dt.datetime(2019, 4, 20, 12, tzinfo=dt.timezone.utc),
- )
- poly = Polygon(
- positions=PositionList(cartographicDegrees=[10.0, 20.0, 0.0], interval=t)
- )
- assert str(poly) == expected_result
-
-
-def test_polygon_outline():
- expected_result = """{
- "positions": {
- "cartographicDegrees": [
- 10.0,
- 20.0,
- 0.0
- ]
- },
- "material": {
- "solidColor": {
- "color": {
- "rgba": [
- 255.0,
- 100.0,
- 0.0,
- 100.0
- ]
- }
- }
- },
- "outlineColor": {
- "rgba": [
- 0.0,
- 0.0,
- 0.0,
- 255.0
- ]
- },
- "outline": true,
- "extrudedHeight": 0.0,
- "perPositionHeight": true
-}"""
- poly = Polygon(
- positions=PositionList(cartographicDegrees=[10.0, 20.0, 0.0]),
- material=Material(
- solidColor=SolidColorMaterial(
- color=Color(
- rgba=[255, 100, 0, 100],
- ),
- ),
- ),
- outlineColor=Color(
- rgba=[0, 0, 0, 255],
- ),
- outline=True,
- extrudedHeight=0,
- perPositionHeight=True,
- )
- assert str(poly) == expected_result
-
-
-def test_polygon_interval_with_position():
- """This only tests one interval"""
-
- expected_result = """{
- "positions": {
- "cartographicDegrees": [
- 10.0,
- 20.0,
- 0.0
- ],
- "interval": "2019-03-20T12:00:00.000000Z/2019-04-20T12:00:00.000000Z"
- }
-}"""
- t = TimeInterval(
- start=dt.datetime(2019, 3, 20, 12, tzinfo=dt.timezone.utc),
- end=dt.datetime(2019, 4, 20, 12, tzinfo=dt.timezone.utc),
- )
- poly = Polygon(
- positions=PositionList(cartographicDegrees=[10.0, 20.0, 0.0], interval=t)
- )
- assert str(poly) == expected_result
-
-
-def test_label_offset():
- expected_result = """{
- "pixelOffset": {
- "cartesian2": [
- 5.0,
- 5.0
- ]
- }
-}"""
-
- label = Label(pixelOffset=Cartesian2Value(values=[5, 5]))
- assert str(label) == expected_result
-
-
-def test_tileset():
- expected_result = """{
- "uri": "../SampleData/Cesium3DTiles/Batched/BatchedColors/tileset.json",
- "show": true
-}"""
- tileset = Tileset(
- show=True, uri="../SampleData/Cesium3DTiles/Batched/BatchedColors/tileset.json"
- )
- tileset1 = Tileset(
- show=True,
- uri=Uri(uri="../SampleData/Cesium3DTiles/Batched/BatchedColors/tileset.json"),
- )
- assert str(tileset) == str(tileset1) == expected_result
-
-
-def test_check_classes_with_references_ViewFrom():
- assert (
- str(ViewFrom(cartesian=[0, 0, 0], reference="this#that"))
- == """{
- "cartesian": [
- 0.0,
- 0.0,
- 0.0
- ],
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_EllipsoidRadii():
- assert (
- str(EllipsoidRadii(cartesian=[0, 0, 0], reference="this#that"))
- == str(
- EllipsoidRadii(
- cartesian=[0, 0, 0], reference=ReferenceValue(value="this#that")
- )
- )
- == """{
- "cartesian": [
- 0.0,
- 0.0,
- 0.0
- ],
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_ArcType():
- assert (
- str(ArcType(arcType=ArcTypes.GEODESIC, reference="this#that"))
- == str(
- ArcType(
- arcType=ArcTypes.GEODESIC, reference=ReferenceValue(value="this#that")
- )
- )
- == """{
- "arcType": "GEODESIC",
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_Position():
- assert (
- str(Position(cartesian=[0, 0, 0], reference="this#that"))
- == """{
- "cartesian": [
- 0.0,
- 0.0,
- 0.0
- ],
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_Orientation():
- assert (
- str(Orientation(unitQuaternion=[0, 0, 0, 0], reference="this#that"))
- == str(
- Orientation(
- unitQuaternion=[0, 0, 0, 0], reference=ReferenceValue(value="this#that")
- )
- )
- == """{
- "unitQuaternion": [
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_NearFarScalar():
- assert (
- str(NearFarScalar(nearFarScalar=[0, 0, 0, 0], reference="this#that"))
- == str(
- NearFarScalar(
- nearFarScalar=[0, 0, 0, 0], reference=ReferenceValue(value="this#that")
- )
- )
- == """{
- "nearFarScalar": [
- 0.0,
- 0.0,
- 0.0,
- 0.0
- ],
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_CornerType():
- assert (
- str(CornerType(cornerType=CornerTypes.BEVELED, reference="this#that"))
- == str(
- CornerType(
- cornerType=CornerTypes.BEVELED,
- reference=ReferenceValue(value="this#that"),
- )
- )
- == """{
- "cornerType": "BEVELED",
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_ColorBlendMode():
- assert (
- str(
- ColorBlendMode(
- colorBlendMode=ColorBlendModes.HIGHLIGHT, reference="this#that"
- )
- )
- == str(
- ColorBlendMode(
- colorBlendMode=ColorBlendModes.HIGHLIGHT,
- reference=ReferenceValue(value="this#that"),
- )
- )
- == """{
- "colorBlendMode": "HIGHLIGHT",
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_HeightReference():
- assert (
- str(
- HeightReference(
- heightReference=HeightReferences.NONE, reference="this#that"
- )
- )
- == str(
- HeightReference(
- heightReference=HeightReferences.NONE,
- reference=ReferenceValue(value="this#that"),
- )
- )
- == """{
- "heightReference": "NONE",
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_EyeOffset():
- assert (
- str(EyeOffset(cartesian=[0, 0, 0], reference="this#that"))
- == str(
- EyeOffset(cartesian=[0, 0, 0], reference=ReferenceValue(value="this#that"))
- )
- == """{
- "cartesian": [
- 0.0,
- 0.0,
- 0.0
- ],
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_RectangleCoordinates():
- assert (
- str(RectangleCoordinates(wsen=[0, 0], reference="this#that"))
- == """{
- "wsen": [
- 0.0,
- 0.0
- ],
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_BoxDimensions():
- b1 = BoxDimensions(
- cartesian=Cartesian3Value(values=[0, 0, 1]), reference="this#that"
- )
- b2 = BoxDimensions(cartesian=[0, 0, 1], reference="this#that")
- b3 = BoxDimensions(cartesian=[0, 0, 1], reference=ReferenceValue(value="this#that"))
- assert (
- str(b1)
- == str(b2)
- == str(b3)
- == """{
- "cartesian": [
- 0.0,
- 0.0,
- 1.0
- ],
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_DistanceDisplayCondition():
- assert (
- str(
- DistanceDisplayCondition(
- distanceDisplayCondition=DistanceDisplayConditionValue(
- values=[0, 1, 2]
- ),
- reference="this#that",
- )
- )
- == str(
- DistanceDisplayCondition(
- distanceDisplayCondition=DistanceDisplayConditionValue(
- values=[0, 1, 2]
- ),
- reference=ReferenceValue(value="this#that"),
- )
- )
- == """{
- "distanceDisplayCondition": [
- 0.0,
- 1.0,
- 2.0
- ],
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_ClassificationType():
- assert (
- str(
- ClassificationType(
- classificationType=ClassificationTypes.BOTH, reference="this#that"
- )
- )
- == str(
- ClassificationType(
- classificationType=ClassificationTypes.BOTH,
- reference=ReferenceValue(value="this#that"),
- )
- )
- == """{
- "classificationType": "BOTH",
- "reference": "this#that"
-}"""
- )
-
-
-def test_check_classes_with_references_ShadowMode():
- assert (
- str(ShadowMode(shadowMode=ShadowModes.CAST_ONLY, reference="this#that"))
- == str(
- ShadowMode(
- shadowMode=ShadowModes.CAST_ONLY,
- reference=ReferenceValue(value="this#that"),
- )
- )
- == """{
- "shadowMode": "CAST_ONLY",
- "reference": "this#that"
-}"""
- )
-
-
-def test_rectangle_coordinates_delete():
- assert (
- str(RectangleCoordinates(wsen=[0, 0], reference="this#that", delete=True))
- == """{
- "delete": true
-}"""
- )
-
-
-def test_different_positions():
- pos1 = Position(cartographicDegrees=[1, 2, 3])
- pos2 = Position(cartographicRadians=[1, 2, 3])
- assert pos1 != pos2
- assert str(pos1) != str(pos2)
-
-
-def test_positionlist_bad_cartesian():
- with pytest.raises(TypeError):
- PositionList(cartesian=[0, 0, 0, 0, 0])
- with pytest.raises(TypeError):
- PositionList(cartesian=[0, 0])
- with pytest.raises(TypeError):
- PositionList(cartesian=[0])
- with pytest.raises(ValueError):
- PositionList(cartesian=[])
-
-
-def test_positionlist_bad_cartographicRadians():
- with pytest.raises(TypeError):
- PositionList(cartographicRadians=[0, 0, 0, 0, 0])
- with pytest.raises(TypeError):
- PositionList(cartographicRadians=[0, 0])
- with pytest.raises(TypeError):
- PositionList(cartographicRadians=[0])
- with pytest.raises(ValueError):
- PositionList(cartographicRadians=[])
-
-
-def test_positionlist_bad_cartographicDegrees():
- with pytest.raises(TypeError):
- PositionList(cartographicDegrees=[0, 0, 0, 0, 0])
- with pytest.raises(TypeError):
- PositionList(cartographicDegrees=[0, 0])
- with pytest.raises(TypeError):
- PositionList(cartographicDegrees=[0])
- with pytest.raises(ValueError):
- PositionList(cartographicDegrees=[])
-
-
-def test_position_bad_cartesian():
- with pytest.raises(TypeError):
- Position(cartesian=[0, 0])
- with pytest.raises(TypeError):
- Position(cartesian=[0])
- with pytest.raises(ValueError):
- Position(cartesian=[])
-
-
-def test_position_bad_cartographicRadians():
- with pytest.raises(TypeError):
- Position(cartographicRadians=[0, 0])
- with pytest.raises(TypeError):
- Position(cartographicRadians=[0])
- with pytest.raises(ValueError):
- Position(cartographicRadians=[])
-
-
-def test_position_bad_cartographicDegrees():
- with pytest.raises(TypeError):
- Position(cartographicDegrees=[0, 0])
- with pytest.raises(TypeError):
- Position(cartographicDegrees=[0])
- with pytest.raises(ValueError):
- Position(cartographicDegrees=[])
-
-
-def test_position_bad_cartesianVelocity():
- with pytest.raises(TypeError):
- Position(cartesianVelocity=[0, 0, 0, 0])
- with pytest.raises(TypeError):
- Position(cartesianVelocity=[0, 0])
- with pytest.raises(TypeError):
- Position(cartesianVelocity=[0])
- with pytest.raises(ValueError):
- Position(cartesianVelocity=[])
-
-
-def test_no_values():
- with pytest.raises(ValueError):
- Color(rgba=[])
-
-
-def test_SequenceTime_mix():
- with pytest.raises(ValidationError):
- TimeIntervalCollection(
- values=[ # type: ignore
- TimeInterval(
- start=dt.datetime(2019, 3, 20, 12, tzinfo=dt.timezone.utc),
- end=dt.datetime(2019, 4, 20, 12, tzinfo=dt.timezone.utc),
- ),
- IntervalValue(
- start=dt.datetime(2019, 3, 20, 12, tzinfo=dt.timezone.utc),
- end=dt.datetime(2019, 4, 20, 12, tzinfo=dt.timezone.utc),
- value=True,
- ),
- ]
- )
-
-
-def test_bad_PositionListOfLists():
- with pytest.raises(TypeError):
- PositionListOfLists(
- cartographicDegrees=[[20.0, 20.0, 0.0], [10.0, 10.0, 0.0, 0]]
- )
- with pytest.raises(ValidationError):
- PositionListOfLists(cartographicDegrees=[])
- with pytest.raises(ValidationError):
- PositionListOfLists(cartographicDegrees=[[0, 0, 0], []])
-
-
-def test_bad_PositionList():
- with pytest.raises(TypeError):
- PositionList(cartographicDegrees=[10.0, 10.0, 0.0, 0])
- with pytest.raises(ValidationError):
- PositionList(cartographicDegrees=[])
- with pytest.raises(TypeError):
- PositionList(cartographicDegrees=[0, 0, 0, 0, 0])
-
-
-def test_bad_Position():
- with pytest.raises(ValidationError):
- Position(cartographicDegrees=[])
- with pytest.raises(TypeError):
- Position(cartographicDegrees=[0, 0, 0, 0, 0])
-
-
-def test_position_list_with_references():
- expected_result = """{
- "cartographicDegrees": [
- 20.0,
- 30.0,
- 10.0
- ],
- "references": [
- "1#this"
- ]
-}"""
- p1 = PositionList(
- cartographicDegrees=CartographicDegreesListValue(values=[20, 30, 10]),
- references=["1#this"],
- )
- p2 = PositionList(
- cartographicDegrees=CartographicDegreesListValue(values=[20, 30, 10]),
- references=ReferenceListValue(values=["1#this"]),
- )
- assert str(p1) == str(p2) == expected_result
- expected_result = """{
- "cartographicRadians": [
- 20.0,
- 30.0,
- 10.0
- ],
- "references": [
- "1#this"
- ]
-}"""
- p1 = PositionList(
- cartographicRadians=CartographicRadiansListValue(values=[20, 30, 10]),
- references=["1#this"],
- )
- p2 = PositionList(
- cartographicRadians=CartographicRadiansListValue(values=[20, 30, 10]),
- references=ReferenceListValue(values=["1#this"]),
- )
- assert str(p1) == str(p2) == expected_result
- expected_result = """{
- "cartesian": [
- 20.0,
- 30.0,
- 10.0
- ],
- "references": [
- "1#this"
- ]
-}"""
- p1 = PositionList(
- cartesian=Cartesian3ListValue(values=[20, 30, 10]), references=["1#this"]
- )
- p2 = PositionList(
- cartesian=Cartesian3ListValue(values=[20, 30, 10]),
- references=ReferenceListValue(values=["1#this"]),
- )
- assert str(p1) == str(p2) == expected_result
-
-
-def test_position_list_of_lists_with_references():
- expected_result = """{
- "cartographicDegrees": [
- [
- 20.0,
- 30.0,
- 10.0
- ],
- [
- 20.0,
- 30.0,
- 10.0
- ]
- ],
- "references": [
- [
- "1#this"
- ],
- [
- "1#this"
- ]
- ]
-}"""
- p1 = PositionListOfLists(
- cartographicDegrees=CartographicDegreesListOfListsValue(
- values=[[20, 30, 10], [20, 30, 10]]
- ),
- references=[["1#this"], ["1#this"]],
- )
- p2 = PositionListOfLists(
- cartographicDegrees=CartographicDegreesListOfListsValue(
- values=[[20, 30, 10], [20, 30, 10]]
- ),
- references=ReferenceListOfListsValue(values=[["1#this"], ["1#this"]]),
- )
- p3 = PositionListOfLists(
- cartographicDegrees=[[20, 30, 10], [20, 30, 10]],
- references=[["1#this"], ["1#this"]],
- )
- p4 = PositionListOfLists(
- cartographicDegrees=[[20, 30, 10], [20, 30, 10]],
- references=ReferenceListOfListsValue(values=[["1#this"], ["1#this"]]),
- )
- assert str(p1) == str(p2) == str(p3) == str(p4) == expected_result
- expected_result = """{
- "cartographicRadians": [
- [
- 20.0,
- 30.0,
- 10.0
- ],
- [
- 20.0,
- 30.0,
- 10.0
- ]
- ],
- "references": [
- [
- "1#this"
- ],
- [
- "1#this"
- ]
- ]
-}"""
- p1 = PositionListOfLists(
- cartographicRadians=CartographicRadiansListOfListsValue(
- values=[[20, 30, 10], [20, 30, 10]]
- ),
- references=[["1#this"], ["1#this"]],
- )
- p2 = PositionListOfLists(
- cartographicRadians=CartographicRadiansListOfListsValue(
- values=[[20, 30, 10], [20, 30, 10]]
- ),
- references=ReferenceListOfListsValue(values=[["1#this"], ["1#this"]]),
- )
- p3 = PositionListOfLists(
- cartographicRadians=[[20, 30, 10], [20, 30, 10]],
- references=[["1#this"], ["1#this"]],
- )
- p4 = PositionListOfLists(
- cartographicRadians=[[20, 30, 10], [20, 30, 10]],
- references=ReferenceListOfListsValue(values=[["1#this"], ["1#this"]]),
- )
- assert str(p1) == str(p2) == str(p3) == str(p4) == expected_result
- expected_result = """{
- "cartesian": [
- [
- 20.0,
- 30.0,
- 10.0
- ],
- [
- 20.0,
- 30.0,
- 10.0
- ]
- ],
- "references": [
- [
- "1#this"
- ],
- [
- "1#this"
- ]
- ]
-}"""
- p1 = PositionListOfLists(
- cartesian=Cartesian3ListOfListsValue(values=[[20, 30, 10], [20, 30, 10]]),
- references=[["1#this"], ["1#this"]],
- )
- p2 = PositionListOfLists(
- cartesian=Cartesian3ListOfListsValue(values=[[20, 30, 10], [20, 30, 10]]),
- references=ReferenceListOfListsValue(values=[["1#this"], ["1#this"]]),
- )
- p3 = PositionListOfLists(
- cartesian=[[20, 30, 10], [20, 30, 10]],
- references=[["1#this"], ["1#this"]],
- )
- p4 = PositionListOfLists(
- cartesian=[[20, 30, 10], [20, 30, 10]],
- references=ReferenceListOfListsValue(values=[["1#this"], ["1#this"]]),
- )
- assert str(p1) == str(p2) == str(p3) == str(p4) == expected_result
-
-
-def test_position_list_with_bad_references():
- with pytest.raises(TypeError):
- PositionList(
- cartographicDegrees=CartographicDegreesListValue(values=[20, 30, 10]),
- references=["1#this", "1#this"],
- )
-
-
-def test_position_list_of_lists_with_bad_references():
- with pytest.raises(TypeError):
- PositionListOfLists(
- cartographicDegrees=CartographicDegreesListOfListsValue(
- values=[[20, 30, 10], [20, 30, 10]]
- ),
- references=[["1#this"], ["1#this"], ["2#this"]],
- )
- with pytest.raises(TypeError):
- PositionListOfLists(
- cartographicDegrees=CartographicDegreesListOfListsValue(
- values=[[20, 30, 10], [20, 30, 10]]
- ),
- references=ReferenceListOfListsValue(
- values=[["1#this"], ["1#this", "2#this"]]
- ),
- )
-
-
-def test_check_increasing_time():
- with pytest.raises(TypeError):
- Cartesian3Value(values=[0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0])
-
-
-def test_packet_billboard():
- expected_result = """{
- "image": "file://image.png",
- "eyeOffset": {
- "cartesian": [
- 1.0,
- 2.0,
- 3.0
- ]
- }
-}"""
- packet = Billboard(
- image="file://image.png",
- eyeOffset=EyeOffset(cartesian=Cartesian3Value(values=[1, 2, 3])),
- )
- assert str(packet) == expected_result
- packet = Billboard(image="file://image.png", eyeOffset=[1, 2, 3])
- assert str(packet) == expected_result
-
-
-# @pytest.mark.xfail(reason="Reference value needs further clarifying")
-# def test_uri_ref():
-# expected_result = """{
-# "uri": "file://image.png",
-# "reference": "this#that"
-# }"""
-# uri = Uri(uri="file://image.png", reference="this#that")
-# uri1 = Uri(uri="file://image.png", reference=ReferenceValue(value="this#that"))
-# assert str(uri) == str(uri1) == expected_result
diff --git a/tests/test_readme_examples.py b/tests/test_readme_examples.py
deleted file mode 100644
index f6459eb..0000000
--- a/tests/test_readme_examples.py
+++ /dev/null
@@ -1,83 +0,0 @@
-def test_example0():
- from czml3 import CZML_VERSION, Document, Packet
- from czml3.properties import (
- Box,
- BoxDimensions,
- Color,
- Material,
- Position,
- SolidColorMaterial,
- )
- from czml3.types import Cartesian3Value
-
- expected_result = """[
- {
- "id": "document",
- "name": "box",
- "version": "1.0"
- },
- {
- "id": "my_id",
- "position": {
- "cartographicDegrees": [
- -114.0,
- 40.0,
- 300000.0
- ]
- },
- "box": {
- "dimensions": {
- "cartesian": [
- 400000.0,
- 300000.0,
- 500000.0
- ]
- },
- "material": {
- "solidColor": {
- "color": {
- "rgba": [
- 0.0,
- 0.0,
- 255.0,
- 255.0
- ]
- }
- }
- }
- }
- }
-]"""
-
- packet_box = Packet(
- id="my_id", # fixing id here to ensure test passes
- position=Position(cartographicDegrees=[-114.0, 40.0, 300000.0]),
- box=Box(
- dimensions=BoxDimensions(
- cartesian=Cartesian3Value(values=[400000.0, 300000.0, 500000.0])
- ),
- material=Material(
- solidColor=SolidColorMaterial(color=Color(rgba=[0, 0, 255, 255]))
- ),
- ),
- )
- doc = Document(
- packets=[Packet(id="document", name="box", version=CZML_VERSION), packet_box]
- )
- assert str(doc) == expected_result
-
-
-def test_example1():
- import numpy as np
-
- from czml3.properties import Position
-
- expected_result = """{
- "cartographicDegrees": [
- -114.0,
- 40.0,
- 300000.0
- ]
-}"""
- p = Position(cartographicDegrees=np.array([-114, 40, 300000], dtype=int)) # type: ignore
- assert str(p) == expected_result
diff --git a/tests/test_rectangle_image.py b/tests/test_rectangle_image.py
deleted file mode 100644
index 0a86915..0000000
--- a/tests/test_rectangle_image.py
+++ /dev/null
@@ -1,106 +0,0 @@
-import base64
-import os
-import tempfile
-
-import pytest
-
-from czml3 import CZML_VERSION, Document, Packet
-from czml3.properties import (
- ImageMaterial,
- Material,
- Rectangle,
- RectangleCoordinates,
- Uri,
-)
-
-
-@pytest.fixture
-def image():
- filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "smiley.png")
- with open(filename, "rb") as fp:
- data = fp.read()
-
- base64_data = base64.b64encode(data)
- return base64_data.decode()
-
-
-def test_rectangle_coordinates_invalid_if_nothing_given():
- with pytest.raises(TypeError) as excinfo:
- RectangleCoordinates()
-
- assert "One of wsen or wsenDegrees must be given" in excinfo.exconly()
-
-
-def test_packet_rectangles(image):
- wsen = [20.0, 40.0, 21.0, 41.0]
-
- expected_result = """{{
- "id": "id_00",
- "rectangle": {{
- "coordinates": {{
- "wsenDegrees": [
- {},
- {},
- {},
- {}
- ]
- }},
- "fill": true,
- "material": {{
- "image": {{
- "image": "data:image/png;base64,{}",
- "transparent": true
- }}
- }}
- }}
-}}""".format(*wsen, image)
-
- rectangle_packet = Packet(
- id="id_00",
- rectangle=Rectangle(
- coordinates=RectangleCoordinates(wsenDegrees=wsen),
- fill=True,
- material=Material(
- image=ImageMaterial(
- transparent=True,
- repeat=None,
- image=Uri(uri="data:image/png;base64," + image),
- ),
- ),
- ),
- )
-
- assert str(rectangle_packet) == expected_result
-
-
-def test_make_czml_png_rectangle_file(image):
- rectangle_packet = Packet(
- id="id_00",
- rectangle=Rectangle(
- coordinates=RectangleCoordinates(wsenDegrees=[20, 40, 21, 41]),
- fill=True,
- material=Material(
- image=ImageMaterial(
- transparent=True,
- repeat=None,
- image=Uri(uri="data:image/png;base64," + image),
- ),
- ),
- ),
- )
-
- with tempfile.NamedTemporaryFile(mode="w", suffix=".czml") as out_file:
- out_file.write(
- str(
- Document(
- packets=[
- Packet(id="document", name="document", version=CZML_VERSION),
- rectangle_packet,
- ]
- )
- )
- )
- exists = os.path.isfile(out_file.name)
-
- # TODO: Should we be testing something else?
- assert exists
diff --git a/tests/test_types.py b/tests/test_types.py
deleted file mode 100644
index c96b476..0000000
--- a/tests/test_types.py
+++ /dev/null
@@ -1,500 +0,0 @@
-import datetime as dt
-
-import pytest
-from pydantic import ValidationError
-
-from czml3.types import (
- Cartesian2Value,
- Cartesian3Value,
- CartographicDegreesListValue,
- CartographicDegreesValue,
- CartographicRadiansListValue,
- CartographicRadiansValue,
- DistanceDisplayConditionValue,
- EpochValue,
- FontValue,
- IntervalValue,
- NearFarScalarValue,
- NumberValue,
- ReferenceListOfListsValue,
- ReferenceListValue,
- ReferenceValue,
- RgbafValue,
- RgbaValue,
- TimeInterval,
- UnitQuaternionValue,
- check_reference,
- format_datetime_like,
-)
-
-
-def test_invalid_near_far_scalar_value():
- with pytest.raises(TypeError):
- NearFarScalarValue(values=[0, 3.2, 1, 4, 2, 1, 0])
-
-
-def test_distance_display_condition_is_invalid():
- with pytest.raises(TypeError):
- DistanceDisplayConditionValue(
- values=[0, 150, 15000000, 300, 10000, 15000000, 600]
- )
-
-
-def test_distance_display_condition():
- expected_result = """[
- 0.0,
- 150.0,
- 15000000.0,
- 300.0,
- 10000.0,
- 15000000.0,
- 600.0,
- 150.0,
- 15000000.0
-]"""
- dist = DistanceDisplayConditionValue(
- values=[0, 150, 15000000, 300, 10000, 15000000, 600, 150, 15000000]
- )
- assert str(dist) == expected_result
-
-
-def test_cartographic_radian_list():
- expected_result = """[
- 0.0,
- 1.0,
- 0.0
-]"""
- car = CartographicRadiansListValue(values=[0, 1, 0])
- assert str(car) == expected_result
-
-
-def test_invalid_cartograpic_radian_list():
- with pytest.raises(TypeError):
- CartographicRadiansListValue(values=[1])
-
-
-def test_cartograpic_degree_list():
- expected_result = """[
- 15.0,
- 25.0,
- 50.0
-]"""
- car = CartographicDegreesListValue(values=[15, 25, 50])
- assert str(car) == expected_result
-
-
-def test_invalid_cartograpic_degree_list():
- with pytest.raises(TypeError):
- CartographicDegreesListValue(values=[15, 25, 50, 30])
-
-
-@pytest.mark.parametrize("values", [[2, 2], [5, 5, 5, 5, 5]])
-def test_bad_cartesian3_raises_error(values):
- with pytest.raises(TypeError):
- Cartesian3Value(values=values)
-
-
-@pytest.mark.parametrize("values", [[2, 2, 2, 2, 2], [5, 5, 5, 5, 5]])
-def test_bad_cartesian2_raises_error(values):
- with pytest.raises(TypeError):
- Cartesian2Value(values=values)
-
-
-def test_reference_value():
- expected_result = '"id#property"'
- reference = ReferenceValue(value="id#property")
-
- assert str(reference) == expected_result
-
-
-def test_invalid_reference_value():
- with pytest.raises(TypeError) as excinfo:
- ReferenceValue(value="id")
-
- assert (
- "Invalid reference string format. Input must be of the form id#property"
- in excinfo.exconly()
- )
-
-
-def test_invalid_reference_list_value():
- with pytest.raises(TypeError) as excinfo:
- ReferenceListValue(values=["id"])
-
- assert (
- "Invalid reference string format. Input must be of the form id#property"
- in excinfo.exconly()
- )
-
-
-def test_invalid_reference_list_of_lists_value():
- with pytest.raises(TypeError) as excinfo:
- ReferenceListOfListsValue(values=[["id"]])
-
- assert (
- "Invalid reference string format. Input must be of the form id#property"
- in excinfo.exconly()
- )
-
-
-def test_font_value():
- expected_result = '"20px sans-serif"'
- font = FontValue(font="20px sans-serif")
-
- assert str(font) == expected_result
-
-
-def test_font_property_value():
- expected_result = "20px sans-serif"
- font = FontValue(font="20px sans-serif")
-
- assert font.font == expected_result
-
-
-def test_bad_rgba_4_values_raises_error():
- with pytest.raises(TypeError):
- RgbaValue(values=[256, 0, 0, 255])
-
-
-def test_bad_rgba_5_color_values_raises_error():
- with pytest.raises(TypeError):
- RgbaValue(values=[0, 0.1, 0.3, 0.3, 256])
-
-
-def test_bad_rgbaf_4_values_raises_error():
- with pytest.raises(TypeError):
- RgbafValue(values=[0.3, 0, 0, 1.4])
-
-
-def test_bad_rgbaf_5_color_values_raises_error():
- with pytest.raises(TypeError):
- RgbafValue(values=[0, 0.1, 0.3, 0.3, 255])
-
-
-def test_default_time_interval():
- expected_result = '"0001-01-01T00:00:00Z/9999-12-31T23:59:59Z"'
- time_interval = TimeInterval()
-
- assert str(time_interval) == expected_result
-
-
-def test_bad_time_raises_error():
- with pytest.raises(ValueError):
- format_datetime_like("2019/01/01")
-
-
-def test_interval_value():
- start = "2019-01-01T12:00:00.000000Z"
- end = "2019-09-02T21:59:59.000000Z"
-
- # value is a boolean
- assert (
- str(IntervalValue(start=start, end=end, value=True))
- == """{
- "interval": "2019-01-01T12:00:00.000000Z/2019-09-02T21:59:59.000000Z",
- "boolean": true
-}"""
- )
-
- assert (
- str(
- IntervalValue(
- start=start,
- end=end,
- value=[
- EpochValue(value=start),
- NumberValue(values=[1, 2, 3, 4]),
- ],
- )
- )
- == """{
- "interval": "2019-01-01T12:00:00.000000Z/2019-09-02T21:59:59.000000Z",
- "epoch": "2019-01-01T12:00:00.000000Z",
- "number": [
- 1,
- 2,
- 3,
- 4
- ]
-}"""
- )
-
-
-def test_epoch_value():
- epoch: str = "2019-01-01T12:00:00.000000Z"
-
- assert (
- str(EpochValue(value=epoch))
- == """{
- "epoch": "2019-01-01T12:00:00.000000Z"
-}"""
- )
-
- assert (
- str(EpochValue(value=dt.datetime(2019, 1, 1, 12)))
- == """{
- "epoch": "2019-01-01T12:00:00.000000Z"
-}"""
- )
-
- with pytest.raises(ValueError):
- str(EpochValue(value="test"))
-
-
-@pytest.mark.xfail(reason="NumberValue class requires further explanaition")
-def test_numbers_value():
- expected_result = """{
- "number": [
- 1,
- 2,
- 3,
- 4
- ]
-}"""
- numbers = NumberValue(values=[1, 2, 3, 4])
-
- assert str(numbers) == expected_result
-
- expected_result = """{
- "number": 1.0
-}"""
- numbers = NumberValue(values=1.0)
-
- assert str(numbers) == expected_result
-
- with pytest.raises(ValidationError):
- NumberValue(values="test") # type: ignore
-
- with pytest.raises(ValidationError):
- NumberValue(values=[1, "test"]) # type: ignore
-
- with pytest.raises(ValidationError):
- NumberValue(values=[1, 2, 3, 4, 5])
-
-
-def test_quaternion_value_is_invalid():
- with pytest.raises(TypeError):
- UnitQuaternionValue(values=[0, 0, 0, 1, 0, 0])
-
-
-def test_quaternion_value():
- expected_result = """[
- 0.0,
- 0.0,
- 0.0,
- 1.0
-]"""
-
- result = UnitQuaternionValue(values=[0, 0, 0, 1])
-
- assert str(result) == expected_result
-
-
-def test_cartographic_radians_value():
- result = CartographicRadiansValue(values=[0, 0, 0, 1])
- assert (
- str(result)
- == """[
- 0.0,
- 0.0,
- 0.0,
- 1.0
-]"""
- )
- result = CartographicRadiansValue(values=[0, 0, 1])
- assert (
- str(result)
- == """[
- 0.0,
- 0.0,
- 1.0
-]"""
- )
- with pytest.raises(TypeError):
- CartographicRadiansValue(values=[0, 0, 1, 1, 1, 1, 1])
-
-
-def test_cartographic_degrees_value():
- result = CartographicDegreesValue(values=[0, 0, 0, 1])
- assert (
- str(result)
- == """[
- 0.0,
- 0.0,
- 0.0,
- 1.0
-]"""
- )
- result = CartographicDegreesValue(values=[0, 0, 1])
- assert (
- str(result)
- == """[
- 0.0,
- 0.0,
- 1.0
-]"""
- )
- with pytest.raises(TypeError):
- CartographicDegreesValue(values=[0, 0, 1, 1, 1, 1, 1])
-
-
-def test_rgba_value():
- assert (
- str(RgbaValue(values=[30, 30, 30, 30]))
- == """[
- 30.0,
- 30.0,
- 30.0,
- 30.0
-]"""
- )
-
-
-def test_rgbaf_value():
- assert (
- str(RgbafValue(values=[0.5, 0.5, 0.5, 0.5]))
- == """[
- 0.5,
- 0.5,
- 0.5,
- 0.5
-]"""
- )
-
-
-def test_check_reference():
- with pytest.raises(TypeError):
- check_reference("thisthat")
- assert check_reference("this#that") is None
-
-
-def test_format_datetime_like():
- assert format_datetime_like(None) is None
-
-
-def test_reference_list():
- expected_result = """[
- "1#this",
- "1#that"
-]"""
- r = ReferenceListValue(values=["1#this", "1#that"])
- assert expected_result == str(r)
-
-
-def test_reference_list_of_lists():
- expected_result = """[
- [
- "1#this"
- ],
- [
- "1#that"
- ]
-]"""
- r = ReferenceListOfListsValue(values=[["1#this"], ["1#that"]])
- assert expected_result == str(r)
-
-
-def test_rgbaf_with_time():
- assert (
- str(RgbafValue(values=[1, 0.5, 0.5, 0.5, 0.5]))
- == """[
- 1.0,
- 0.5,
- 0.5,
- 0.5,
- 0.5
-]"""
- )
- assert (
- str(
- RgbafValue(
- values=[
- 1,
- 0.5,
- 0.5,
- 0.5,
- 0.5,
- 2,
- 0.8,
- 0.8,
- 0.8,
- 0.8,
- 3,
- 0.5,
- 0.5,
- 0.5,
- 0.5,
- ]
- )
- )
- == """[
- 1.0,
- 0.5,
- 0.5,
- 0.5,
- 0.5,
- 2.0,
- 0.8,
- 0.8,
- 0.8,
- 0.8,
- 3.0,
- 0.5,
- 0.5,
- 0.5,
- 0.5
-]"""
- )
-
-
-def test_rgba_with_time():
- assert (
- str(RgbaValue(values=[1, 0.5, 0.5, 0.5, 0.5]))
- == """[
- 1.0,
- 0.5,
- 0.5,
- 0.5,
- 0.5
-]"""
- )
- assert (
- str(
- RgbaValue(
- values=[
- 1,
- 0.5,
- 0.5,
- 0.5,
- 0.5,
- 2,
- 0.8,
- 0.8,
- 0.8,
- 0.8,
- 3,
- 0.5,
- 0.5,
- 0.5,
- 0.5,
- ]
- )
- )
- == """[
- 1.0,
- 0.5,
- 0.5,
- 0.5,
- 0.5,
- 2.0,
- 0.8,
- 0.8,
- 0.8,
- 0.8,
- 3.0,
- 0.5,
- 0.5,
- 0.5,
- 0.5
-]"""
- )