Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ea719141f | |||
| a47f568f69 | |||
| b174802451 | |||
| 87a7e7482d | |||
| e888339dda | |||
| 3417557405 | |||
| 4ce61f4e89 | |||
| 6d6e1e7650 | |||
| 95de5cbb30 | |||
| 5f56818d63 | |||
| 825097e1a6 | |||
| d3ab26240a | |||
| ce6be1a98e |
@@ -1,5 +1,3 @@
|
||||
# ignoring "line too long" check from linter
|
||||
# ruff: noqa: E501
|
||||
"""This module provides an abstraction layer above the Speckle Automate runtime."""
|
||||
|
||||
import time
|
||||
@@ -75,7 +73,7 @@ class AutomationContext:
|
||||
speckle_client.authenticate_with_token(speckle_token)
|
||||
if not speckle_client.account:
|
||||
msg = (
|
||||
f"Could not autenticate to {automation_run_data.speckle_server_url}",
|
||||
f"Could not authenticate to {automation_run_data.speckle_server_url}",
|
||||
"with the provided token",
|
||||
)
|
||||
raise ValueError(msg)
|
||||
@@ -109,18 +107,24 @@ class AutomationContext:
|
||||
)
|
||||
except SpeckleException as err:
|
||||
raise ValueError(
|
||||
f"""\
|
||||
Could not receive specified version.
|
||||
Is your environment configured correctly?
|
||||
project_id: {self.automation_run_data.project_id}
|
||||
model_id: {self.automation_run_data.triggers[0].payload.model_id}
|
||||
version_id: {self.automation_run_data.triggers[0].payload.version_id}
|
||||
"""
|
||||
f"""Could not receive specified version.
|
||||
Is your environment configured correctly?
|
||||
project_id: {self.automation_run_data.project_id}
|
||||
model_id: {self.automation_run_data.triggers[0].payload.model_id}
|
||||
version_id: {self.automation_run_data.triggers[0].payload.version_id}
|
||||
"""
|
||||
) from err
|
||||
|
||||
if not version.referenced_object:
|
||||
raise Exception(
|
||||
"This version is past the version history limit,",
|
||||
" cannot execute an automation on it",
|
||||
)
|
||||
|
||||
base = operations.receive(
|
||||
version.referenced_object, self._server_transport, self._memory_transport
|
||||
)
|
||||
# self._closure_tree = base["__closure"]
|
||||
print(
|
||||
f"It took {self.elapsed():.2f} seconds to receive",
|
||||
f" the speckle version {version_id}",
|
||||
@@ -242,7 +246,7 @@ class AutomationContext:
|
||||
)
|
||||
if self.run_status in [AutomationStatus.SUCCEEDED, AutomationStatus.FAILED]:
|
||||
object_results = {
|
||||
"version": 1,
|
||||
"version": 2,
|
||||
"values": {
|
||||
"objectResults": self._automation_result.model_dump(by_alias=True)[
|
||||
"objectResults"
|
||||
@@ -332,26 +336,24 @@ class AutomationContext:
|
||||
def attach_error_to_objects(
|
||||
self,
|
||||
category: str,
|
||||
object_ids: Union[str, List[str]],
|
||||
affected_objects: Union[Base, List[Base]],
|
||||
message: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None,
|
||||
visual_overrides: Optional[Dict[str, Any]] = None,
|
||||
) -> None:
|
||||
"""Add a new error case to the run results.
|
||||
|
||||
If the error cause has already created an error case,
|
||||
the error will be extended with a new case refering to the causing objects.
|
||||
Args:
|
||||
error_tag (str): A short tag for the error type.
|
||||
causing_object_ids (str[]): A list of object_id-s that are causing the error
|
||||
error_messagge (Optional[str]): Optional error message.
|
||||
category (str): A short tag for the event type.
|
||||
affected_objects (Union[Base, List[Base]]): A single object or a list of
|
||||
objects that are causing the error case.
|
||||
message (Optional[str]): Optional message.
|
||||
metadata: User provided metadata key value pairs
|
||||
visual_overrides: Case specific 3D visual overrides.
|
||||
"""
|
||||
self.attach_result_to_objects(
|
||||
ObjectResultLevel.ERROR,
|
||||
category,
|
||||
object_ids,
|
||||
affected_objects,
|
||||
message,
|
||||
metadata,
|
||||
visual_overrides,
|
||||
@@ -360,16 +362,25 @@ class AutomationContext:
|
||||
def attach_warning_to_objects(
|
||||
self,
|
||||
category: str,
|
||||
object_ids: Union[str, List[str]],
|
||||
affected_objects: Union[Base, List[Base]],
|
||||
message: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None,
|
||||
visual_overrides: Optional[Dict[str, Any]] = None,
|
||||
) -> None:
|
||||
"""Add a new warning case to the run results."""
|
||||
"""Add a new warning case to the run results.
|
||||
|
||||
Args:
|
||||
category (str): A short tag for the event type.
|
||||
affected_objects (Union[Base, List[Base]]): A single object or a list of
|
||||
objects that are causing the warning case.
|
||||
message (Optional[str]): Optional message.
|
||||
metadata: User provided metadata key value pairs
|
||||
visual_overrides: Case specific 3D visual overrides.
|
||||
"""
|
||||
self.attach_result_to_objects(
|
||||
ObjectResultLevel.WARNING,
|
||||
category,
|
||||
object_ids,
|
||||
affected_objects,
|
||||
message,
|
||||
metadata,
|
||||
visual_overrides,
|
||||
@@ -378,16 +389,25 @@ class AutomationContext:
|
||||
def attach_success_to_objects(
|
||||
self,
|
||||
category: str,
|
||||
object_ids: Union[str, List[str]],
|
||||
affected_objects: Union[Base, List[Base]],
|
||||
message: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None,
|
||||
visual_overrides: Optional[Dict[str, Any]] = None,
|
||||
) -> None:
|
||||
"""Add a new success case to the run results."""
|
||||
"""Add a new success case to the run results.
|
||||
|
||||
Args:
|
||||
category (str): A short tag for the event type.
|
||||
affected_objects (Union[Base, List[Base]]): A single object or a list of
|
||||
objects that are causing the success case.
|
||||
message (Optional[str]): Optional message.
|
||||
metadata: User provided metadata key value pairs
|
||||
visual_overrides: Case specific 3D visual overrides.
|
||||
"""
|
||||
self.attach_result_to_objects(
|
||||
ObjectResultLevel.SUCCESS,
|
||||
category,
|
||||
object_ids,
|
||||
affected_objects,
|
||||
message,
|
||||
metadata,
|
||||
visual_overrides,
|
||||
@@ -396,16 +416,25 @@ class AutomationContext:
|
||||
def attach_info_to_objects(
|
||||
self,
|
||||
category: str,
|
||||
object_ids: Union[str, List[str]],
|
||||
affected_objects: Union[Base, List[Base]],
|
||||
message: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None,
|
||||
visual_overrides: Optional[Dict[str, Any]] = None,
|
||||
) -> None:
|
||||
"""Add a new info case to the run results."""
|
||||
"""Add a new info case to the run results.
|
||||
|
||||
Args:
|
||||
category (str): A short tag for the event type.
|
||||
affected_objects (Union[Base, List[Base]]): A single object or a list of
|
||||
objects that are causing the info case.
|
||||
message (Optional[str]): Optional message.
|
||||
metadata: User provided metadata key value pairs
|
||||
visual_overrides: Case specific 3D visual overrides.
|
||||
"""
|
||||
self.attach_result_to_objects(
|
||||
ObjectResultLevel.INFO,
|
||||
category,
|
||||
object_ids,
|
||||
affected_objects,
|
||||
message,
|
||||
metadata,
|
||||
visual_overrides,
|
||||
@@ -415,19 +444,39 @@ class AutomationContext:
|
||||
self,
|
||||
level: ObjectResultLevel,
|
||||
category: str,
|
||||
object_ids: Union[str, List[str]],
|
||||
affected_objects: Union[Base, List[Base]],
|
||||
message: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None,
|
||||
visual_overrides: Optional[Dict[str, Any]] = None,
|
||||
) -> None:
|
||||
if isinstance(object_ids, list):
|
||||
if len(object_ids) < 1:
|
||||
"""Add a new result case to the run results.
|
||||
|
||||
Args:
|
||||
level: Result level.
|
||||
category (str): A short tag for the event type.
|
||||
affected_objects (Union[Base, List[Base]]): A single object or a list of
|
||||
objects that are causing the info case.
|
||||
message (Optional[str]): Optional message.
|
||||
metadata: User provided metadata key value pairs
|
||||
visual_overrides: Case specific 3D visual overrides.
|
||||
"""
|
||||
if isinstance(affected_objects, list):
|
||||
if len(affected_objects) < 1:
|
||||
raise ValueError(
|
||||
f"Need atleast one object_id to report a(n) {level.value.upper()}"
|
||||
f"Need atleast one object to report a(n) {level.value.upper()}"
|
||||
)
|
||||
id_list = object_ids
|
||||
object_list = affected_objects
|
||||
else:
|
||||
id_list = [object_ids]
|
||||
object_list = [affected_objects]
|
||||
|
||||
ids: Dict[str, Optional[str]] = {}
|
||||
for o in object_list:
|
||||
# validate that the Base.id is not None. If its a None, throw an Exception
|
||||
if not o.id:
|
||||
raise Exception(
|
||||
f"You can only attach {level} results to objects with an id."
|
||||
)
|
||||
ids[o.id] = o.applicationId
|
||||
print(
|
||||
f"Created new {level.value.upper()}"
|
||||
f" category: {category} caused by: {message}"
|
||||
@@ -436,7 +485,7 @@ class AutomationContext:
|
||||
ResultCase(
|
||||
category=category,
|
||||
level=level,
|
||||
object_ids=id_list,
|
||||
object_app_ids=ids,
|
||||
message=message,
|
||||
metadata=metadata,
|
||||
visual_overrides=visual_overrides,
|
||||
|
||||
@@ -80,7 +80,7 @@ class ResultCase(AutomateBase):
|
||||
|
||||
category: str
|
||||
level: ObjectResultLevel
|
||||
object_ids: List[str]
|
||||
object_app_ids: Dict[str, Optional[str]]
|
||||
message: Optional[str]
|
||||
metadata: Optional[Dict[str, Any]]
|
||||
visual_overrides: Optional[Dict[str, Any]]
|
||||
|
||||
@@ -2,9 +2,15 @@ from enum import Enum
|
||||
|
||||
|
||||
class ProjectVisibility(str, Enum):
|
||||
"""Supported project visibility types"""
|
||||
|
||||
PRIVATE = "PRIVATE"
|
||||
PUBLIC = "PUBLIC"
|
||||
UNLISTED = "UNLISTED"
|
||||
WORKSPACE = "WORKSPACE"
|
||||
|
||||
|
||||
foo = ProjectVisibility.PRIVATE
|
||||
|
||||
|
||||
class UserProjectsUpdatedMessageType(str, Enum):
|
||||
|
||||
@@ -155,6 +155,8 @@ class ModelWithVersions(Model):
|
||||
class ProjectPermissionChecks(GraphQLBaseModel):
|
||||
can_create_model: "PermissionCheckResult"
|
||||
can_delete: "PermissionCheckResult"
|
||||
can_load: "PermissionCheckResult"
|
||||
can_publish: "PermissionCheckResult"
|
||||
|
||||
|
||||
class Project(GraphQLBaseModel):
|
||||
|
||||
@@ -252,6 +252,10 @@ class ActiveUserResource(ResourceBase):
|
||||
updatedAt
|
||||
readOnly
|
||||
description
|
||||
creationState
|
||||
{
|
||||
completed
|
||||
}
|
||||
permissions {
|
||||
canCreateProject {
|
||||
authorized
|
||||
|
||||
@@ -73,6 +73,16 @@ class ProjectResource(ResourceBase):
|
||||
code
|
||||
message
|
||||
}
|
||||
canLoad {
|
||||
authorized
|
||||
code
|
||||
message
|
||||
}
|
||||
canPublish {
|
||||
authorized
|
||||
code
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ class WorkspaceResource(ResourceBase):
|
||||
}
|
||||
|
||||
return self.make_request_and_parse_response(
|
||||
DataResponse[DataResponse[Workspace]], QUERY, variables
|
||||
).data.data
|
||||
DataResponse[Workspace], QUERY, variables
|
||||
).data
|
||||
|
||||
def get_projects(
|
||||
self,
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
from .data_objects import Base, DataObject, QgisObject
|
||||
from .data_objects import Base, DataObject, QgisObject, BlenderObject # noqa: I001
|
||||
|
||||
__all__ = [
|
||||
"Base",
|
||||
"DataObject",
|
||||
"QgisObject",
|
||||
]
|
||||
__all__ = ["Base", "DataObject", "QgisObject", "BlenderObject"]
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
from .text import AlignmentHorizontal, AlignmentVertical, Text
|
||||
|
||||
# re-export them at the geometry package level
|
||||
__all__ = [
|
||||
"Text",
|
||||
"AlignmentHorizontal",
|
||||
"AlignmentVertical",
|
||||
]
|
||||
@@ -0,0 +1,54 @@
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from typing import Optional
|
||||
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.objects.geometry import Plane, Point
|
||||
from specklepy.objects.interfaces import IHasUnits
|
||||
|
||||
|
||||
class AlignmentHorizontal(Enum):
|
||||
Left = 0
|
||||
Center = 1
|
||||
Right = 2
|
||||
|
||||
|
||||
class AlignmentVertical(Enum):
|
||||
Top = 0
|
||||
Center = 1
|
||||
Bottom = 2
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class Text(Base, IHasUnits, speckle_type="Objects.Annotation.Text"):
|
||||
"""
|
||||
Text class for representation in the viewer.
|
||||
Units will be 'Units.None' if the text size is defined in pixels.
|
||||
"""
|
||||
|
||||
value: str # Plain text, without formatting
|
||||
origin: Point # Relation to the text is defined by AlignmentH and AlignmentV
|
||||
height: float # Font height in linear units or pixels (if Units.None)
|
||||
alignmentH: AlignmentHorizontal = field(
|
||||
default_factory=lambda: AlignmentHorizontal.Left
|
||||
)
|
||||
alignmentV: AlignmentVertical = field(default_factory=lambda: AlignmentVertical.Top)
|
||||
plane: Optional[Plane] = field(
|
||||
default_factory=lambda: None
|
||||
) # None if the text object orientation follows camera view
|
||||
maxWidth: Optional[float] = field(
|
||||
default_factory=lambda: None
|
||||
) # Maximum width of the text field. None, if don't split into lines
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"{self.__class__.__name__}("
|
||||
f"value: {self.value}, "
|
||||
f"origin: {self.origin}, "
|
||||
f"height: {self.height}, "
|
||||
f"alignmentH: {self.alignmentH}, "
|
||||
f"alignmentV: {self.alignmentV}, "
|
||||
f"plane: {self.plane}, "
|
||||
f"maxWidth: {self.maxWidth}, "
|
||||
f"units: {self.units})"
|
||||
)
|
||||
@@ -3,7 +3,12 @@ from typing import Dict, List
|
||||
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.objects.interfaces import IDataObject, IGisObject, IHasUnits
|
||||
from specklepy.objects.interfaces import (
|
||||
IBlenderObject,
|
||||
IDataObject,
|
||||
IGisObject,
|
||||
IHasUnits,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
@@ -79,3 +84,24 @@ class QgisObject(
|
||||
raise SpeckleException(
|
||||
f"'type' value should be string, received {type(value)}"
|
||||
)
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class BlenderObject(
|
||||
DataObject, IBlenderObject, IHasUnits, speckle_type="Objects.Data.BlenderObject"
|
||||
):
|
||||
type: str
|
||||
_type: str = field(repr=False, init=False)
|
||||
|
||||
@property
|
||||
def type(self) -> str:
|
||||
return self._type
|
||||
|
||||
@type.setter
|
||||
def type(self, value: str):
|
||||
if isinstance(value, str):
|
||||
self._type = value
|
||||
else:
|
||||
raise SpeckleException(
|
||||
f"'type' value should be string, received {type(value)}"
|
||||
)
|
||||
|
||||
@@ -47,7 +47,6 @@ class Region(
|
||||
|
||||
@property
|
||||
def displayValue(self) -> List[Mesh]:
|
||||
print(self._displayValue)
|
||||
return self._displayValue
|
||||
|
||||
@displayValue.setter
|
||||
|
||||
@@ -3,6 +3,7 @@ from typing import Optional
|
||||
import pytest
|
||||
|
||||
from specklepy.api.client import SpeckleClient
|
||||
from specklepy.core.api.enums import ProjectVisibility
|
||||
from specklepy.core.api.inputs.project_inputs import (
|
||||
ProjectCreateInput,
|
||||
ProjectInviteCreateInput,
|
||||
@@ -22,7 +23,9 @@ class TestProjectInviteResource:
|
||||
@pytest.fixture
|
||||
def project(self, client: SpeckleClient):
|
||||
return client.project.create(
|
||||
ProjectCreateInput(name="test", description=None, visibility=None)
|
||||
ProjectCreateInput(
|
||||
name="test", description=None, visibility=ProjectVisibility.PUBLIC
|
||||
)
|
||||
)
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -51,8 +51,8 @@ class TestProjectResource:
|
||||
assert result.name == name
|
||||
assert result.description == (description or "")
|
||||
# we've disabled creation of public projects for now, they fall back to unlisted
|
||||
if visibility == ProjectVisibility.PUBLIC:
|
||||
assert result.visibility == ProjectVisibility.UNLISTED
|
||||
if visibility == ProjectVisibility.UNLISTED:
|
||||
assert result.visibility == ProjectVisibility.PUBLIC
|
||||
else:
|
||||
assert result.visibility == visibility
|
||||
|
||||
@@ -78,7 +78,7 @@ class TestProjectResource:
|
||||
def test_project_update(self, client: SpeckleClient, test_project: Project):
|
||||
new_name = "MY new name"
|
||||
new_description = "MY new desc"
|
||||
new_visibility = ProjectVisibility.PUBLIC
|
||||
new_visibility = ProjectVisibility.UNLISTED
|
||||
|
||||
update_data = ProjectUpdateInput(
|
||||
id=test_project.id,
|
||||
@@ -94,8 +94,8 @@ class TestProjectResource:
|
||||
assert updated_project.name == new_name
|
||||
assert updated_project.description == new_description
|
||||
# we've disabled creation of public projects for now, they fall back to unlisted
|
||||
if new_visibility == ProjectVisibility.PUBLIC:
|
||||
assert updated_project.visibility == ProjectVisibility.UNLISTED
|
||||
if new_visibility == ProjectVisibility.UNLISTED:
|
||||
assert updated_project.visibility == ProjectVisibility.PUBLIC
|
||||
else:
|
||||
assert updated_project.visibility == new_visibility
|
||||
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
import pytest
|
||||
|
||||
from specklepy.core.api.operations import deserialize, serialize
|
||||
from specklepy.logging.exceptions import SpeckleException
|
||||
from specklepy.objects.base import Base
|
||||
from specklepy.objects.data_objects import BlenderObject, DataObject, QgisObject
|
||||
from specklepy.objects.interfaces import (
|
||||
IBlenderObject,
|
||||
IDataObject,
|
||||
IGisObject,
|
||||
IHasUnits,
|
||||
)
|
||||
from specklepy.objects.models.units import Units
|
||||
|
||||
|
||||
def test_data_object_creation():
|
||||
display_value = [Base()]
|
||||
data_obj = DataObject(
|
||||
name="Test Data Object",
|
||||
properties={"key1": "value1", "key2": 2},
|
||||
displayValue=display_value,
|
||||
)
|
||||
|
||||
assert data_obj.name == "Test Data Object"
|
||||
assert data_obj.properties == {"key1": "value1", "key2": 2}
|
||||
assert data_obj.displayValue == display_value
|
||||
assert data_obj.speckle_type == "Objects.Data.DataObject"
|
||||
|
||||
|
||||
def test_inheritance_relationships():
|
||||
data_obj = DataObject(
|
||||
name="Test Data Object",
|
||||
properties={"key": "value"},
|
||||
displayValue=[Base()],
|
||||
)
|
||||
assert isinstance(data_obj, DataObject)
|
||||
assert isinstance(data_obj, Base)
|
||||
assert isinstance(data_obj, IDataObject)
|
||||
|
||||
qgis_obj = QgisObject(
|
||||
name="Test QGIS Object",
|
||||
properties={"key": "value"},
|
||||
displayValue=[Base()],
|
||||
type="Feature",
|
||||
units=Units.m,
|
||||
)
|
||||
assert isinstance(qgis_obj, QgisObject)
|
||||
assert isinstance(qgis_obj, DataObject)
|
||||
assert isinstance(qgis_obj, Base)
|
||||
assert isinstance(qgis_obj, IDataObject)
|
||||
assert isinstance(qgis_obj, IGisObject)
|
||||
assert isinstance(qgis_obj, IHasUnits)
|
||||
|
||||
blender_obj = BlenderObject(
|
||||
name="Test Blender Object",
|
||||
properties={"key": "value"},
|
||||
displayValue=[Base()],
|
||||
type="Mesh",
|
||||
units=Units.m,
|
||||
)
|
||||
assert isinstance(blender_obj, BlenderObject)
|
||||
assert isinstance(blender_obj, DataObject)
|
||||
assert isinstance(blender_obj, Base)
|
||||
assert isinstance(blender_obj, IDataObject)
|
||||
assert isinstance(blender_obj, IBlenderObject)
|
||||
assert isinstance(blender_obj, IHasUnits)
|
||||
|
||||
|
||||
def test_data_object_invalid_types():
|
||||
data_obj = DataObject(
|
||||
name="Test Object",
|
||||
properties={"key": "value"},
|
||||
displayValue=[Base()],
|
||||
)
|
||||
|
||||
class ComplexObject:
|
||||
def __str__(self):
|
||||
raise ValueError("Can't convert to string")
|
||||
|
||||
complex_obj = ComplexObject()
|
||||
|
||||
with pytest.raises((ValueError, SpeckleException)):
|
||||
data_obj.name = complex_obj # should be string
|
||||
|
||||
with pytest.raises(SpeckleException):
|
||||
data_obj.properties = [1, 2, 3] # should be dict, not list
|
||||
|
||||
with pytest.raises(SpeckleException):
|
||||
data_obj.displayValue = {"key": "value"} # should be list, not dict
|
||||
|
||||
|
||||
def test_data_object_serialization():
|
||||
display_value = [Base()]
|
||||
data_obj = DataObject(
|
||||
name="Test Data Object",
|
||||
properties={"key1": "value1", "key2": 2},
|
||||
displayValue=display_value,
|
||||
)
|
||||
|
||||
serialized = serialize(data_obj)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert isinstance(deserialized, DataObject)
|
||||
assert deserialized.name == data_obj.name
|
||||
assert deserialized.properties == data_obj.properties
|
||||
assert len(deserialized.displayValue) == len(data_obj.displayValue)
|
||||
assert deserialized.speckle_type == data_obj.speckle_type
|
||||
|
||||
|
||||
def test_qgis_object_creation():
|
||||
display_value = [Base()]
|
||||
qgis_obj = QgisObject(
|
||||
name="Test QGIS Object",
|
||||
properties={"key1": "value1"},
|
||||
displayValue=display_value,
|
||||
type="Feature",
|
||||
units=Units.m,
|
||||
)
|
||||
|
||||
assert qgis_obj.name == "Test QGIS Object"
|
||||
assert qgis_obj.properties == {"key1": "value1"}
|
||||
assert qgis_obj.displayValue == display_value
|
||||
assert qgis_obj.type == "Feature"
|
||||
assert qgis_obj.units == Units.m.value
|
||||
assert "Objects.Data.QgisObject" in qgis_obj.speckle_type
|
||||
|
||||
|
||||
def test_qgis_object_serialization():
|
||||
display_value = [Base()]
|
||||
qgis_obj = QgisObject(
|
||||
name="Test QGIS Object",
|
||||
properties={"key1": "value1"},
|
||||
displayValue=display_value,
|
||||
type="Feature",
|
||||
units=Units.m,
|
||||
)
|
||||
|
||||
serialized = serialize(qgis_obj)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert isinstance(deserialized, QgisObject)
|
||||
assert deserialized.name == qgis_obj.name
|
||||
assert deserialized.properties == qgis_obj.properties
|
||||
assert len(deserialized.displayValue) == len(qgis_obj.displayValue)
|
||||
assert deserialized.type == qgis_obj.type
|
||||
assert deserialized.units == qgis_obj.units
|
||||
assert "Objects.Data.QgisObject" in deserialized.speckle_type
|
||||
|
||||
|
||||
def test_blender_object_creation():
|
||||
display_value = [Base()]
|
||||
blender_obj = BlenderObject(
|
||||
name="Test Blender Object",
|
||||
properties={"key1": "value1"},
|
||||
displayValue=display_value,
|
||||
type="Mesh",
|
||||
units=Units.m,
|
||||
)
|
||||
|
||||
assert blender_obj.name == "Test Blender Object"
|
||||
assert blender_obj.properties == {"key1": "value1"}
|
||||
assert blender_obj.displayValue == display_value
|
||||
assert blender_obj.type == "Mesh"
|
||||
assert blender_obj.units == Units.m.value
|
||||
assert "Objects.Data.BlenderObject" in blender_obj.speckle_type
|
||||
|
||||
|
||||
def test_blender_object_invalid_types():
|
||||
blender_obj = BlenderObject(
|
||||
name="Test Object",
|
||||
properties={"key": "value"},
|
||||
displayValue=[Base()],
|
||||
type="Mesh",
|
||||
units=Units.m,
|
||||
)
|
||||
|
||||
class ComplexObject:
|
||||
def __str__(self):
|
||||
raise ValueError("Can't convert to string")
|
||||
|
||||
complex_obj = ComplexObject()
|
||||
|
||||
with pytest.raises((ValueError, SpeckleException)):
|
||||
blender_obj.type = complex_obj # should be string
|
||||
|
||||
|
||||
def test_blender_object_serialization():
|
||||
display_value = [Base()]
|
||||
blender_obj = BlenderObject(
|
||||
name="Test Blender Object",
|
||||
properties={"key1": "value1"},
|
||||
displayValue=display_value,
|
||||
type="Mesh",
|
||||
units=Units.m,
|
||||
)
|
||||
|
||||
serialized = serialize(blender_obj)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert isinstance(deserialized, BlenderObject)
|
||||
assert deserialized.name == blender_obj.name
|
||||
assert deserialized.properties == blender_obj.properties
|
||||
assert len(deserialized.displayValue) == len(blender_obj.displayValue)
|
||||
assert deserialized.type == blender_obj.type
|
||||
assert deserialized.units == blender_obj.units
|
||||
assert "Objects.Data.BlenderObject" in deserialized.speckle_type
|
||||
|
||||
|
||||
def test_data_object_property_modification():
|
||||
data_obj = DataObject(
|
||||
name="Original Name",
|
||||
properties={"original": "value"},
|
||||
displayValue=[Base()],
|
||||
)
|
||||
|
||||
data_obj.name = "Updated Name"
|
||||
data_obj.properties = {"updated": "property"}
|
||||
new_display_value = [Base(), Base()]
|
||||
data_obj.displayValue = new_display_value
|
||||
|
||||
assert data_obj.name == "Updated Name"
|
||||
assert data_obj.properties == {"updated": "property"}
|
||||
assert data_obj.displayValue == new_display_value
|
||||
|
||||
|
||||
def test_qgis_object_property_modification():
|
||||
"""Test modification of QgisObject properties after creation."""
|
||||
qgis_obj = QgisObject(
|
||||
name="Original Name",
|
||||
properties={"original": "value"},
|
||||
displayValue=[Base()],
|
||||
type="OriginalType",
|
||||
units=Units.m,
|
||||
)
|
||||
|
||||
qgis_obj.type = "UpdatedType"
|
||||
|
||||
assert qgis_obj.type == "UpdatedType"
|
||||
|
||||
|
||||
def test_blender_object_property_modification():
|
||||
blender_obj = BlenderObject(
|
||||
name="Original Name",
|
||||
properties={"original": "value"},
|
||||
displayValue=[Base()],
|
||||
type="OriginalType",
|
||||
units=Units.m,
|
||||
)
|
||||
|
||||
blender_obj.type = "UpdatedType"
|
||||
|
||||
assert blender_obj.type == "UpdatedType"
|
||||
@@ -0,0 +1,100 @@
|
||||
import pytest
|
||||
|
||||
from specklepy.core.api.operations import deserialize, serialize
|
||||
from specklepy.objects.annotation import AlignmentHorizontal, AlignmentVertical, Text
|
||||
from specklepy.objects.geometry import Plane, Point, Vector
|
||||
from specklepy.objects.models.units import Units
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_point() -> Point:
|
||||
return Point(x=0.0, y=0.0, z=0.0, units=Units.m)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_plane(sample_point: Point) -> Plane:
|
||||
normal = Vector(x=0.0, y=0.0, z=1.0, units=Units.m)
|
||||
xdir = Vector(x=1.0, y=0.0, z=0.0, units=Units.m)
|
||||
ydir = Vector(x=0.0, y=1.0, z=0.0, units=Units.m)
|
||||
return Plane(
|
||||
origin=sample_point, normal=normal, xdir=xdir, ydir=ydir, units=Units.m
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_text(sample_point: Point) -> Text:
|
||||
return Text(value="text", origin=sample_point, height=0.5, units=Units.m)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_text_all_properties(sample_point: Point, sample_plane: Plane) -> Text:
|
||||
return Text(
|
||||
value="text",
|
||||
origin=sample_point,
|
||||
height=0.5,
|
||||
alignmentH=AlignmentHorizontal.Center,
|
||||
alignmentV=AlignmentVertical.Center,
|
||||
plane=sample_plane,
|
||||
maxWidth=20,
|
||||
units=Units.m,
|
||||
)
|
||||
|
||||
|
||||
def test_text_creation_minimal(sample_point: Point):
|
||||
text_value = "text"
|
||||
|
||||
text_obj = Text(value=text_value, origin=sample_point, height=0.5, units=Units.m)
|
||||
assert text_obj.value == text_value
|
||||
assert text_obj.origin == sample_point
|
||||
assert text_obj.height == 0.5
|
||||
assert text_obj.alignmentH == AlignmentHorizontal.Left
|
||||
assert text_obj.alignmentV == AlignmentVertical.Top
|
||||
assert text_obj.plane is None
|
||||
assert text_obj.maxWidth is None
|
||||
assert text_obj.units == Units.m.value
|
||||
|
||||
|
||||
def test_text_creation_extended(sample_point: Point, sample_plane: Plane):
|
||||
text_value = "text"
|
||||
max_width = 20
|
||||
|
||||
text_obj = Text(
|
||||
value=text_value,
|
||||
origin=sample_point,
|
||||
height=0.5,
|
||||
alignmentH=AlignmentHorizontal.Center,
|
||||
alignmentV=AlignmentVertical.Center,
|
||||
plane=sample_plane,
|
||||
maxWidth=max_width,
|
||||
units=Units.m,
|
||||
)
|
||||
assert text_obj.value == text_value
|
||||
assert text_obj.origin == sample_point
|
||||
assert text_obj.height == 0.5
|
||||
assert text_obj.alignmentH == AlignmentHorizontal.Center
|
||||
assert text_obj.alignmentV == AlignmentVertical.Center
|
||||
assert text_obj.plane == sample_plane
|
||||
assert text_obj.maxWidth == max_width
|
||||
assert text_obj.units == Units.m.value
|
||||
|
||||
|
||||
def test_point_serialization(sample_text_all_properties: Text):
|
||||
serialized = serialize(sample_text_all_properties)
|
||||
deserialized = deserialize(serialized)
|
||||
|
||||
assert isinstance(deserialized, Text)
|
||||
assert deserialized.value == sample_text_all_properties.value
|
||||
assert deserialized.origin.x == sample_text_all_properties.origin.x
|
||||
assert deserialized.origin.y == sample_text_all_properties.origin.y
|
||||
assert deserialized.origin.z == sample_text_all_properties.origin.z
|
||||
assert deserialized.height == sample_text_all_properties.height
|
||||
assert deserialized.alignmentH == sample_text_all_properties.alignmentH
|
||||
assert deserialized.alignmentV == sample_text_all_properties.alignmentV
|
||||
assert deserialized.plane.origin.x == sample_text_all_properties.plane.origin.x
|
||||
assert deserialized.plane.origin.y == sample_text_all_properties.plane.origin.y
|
||||
assert deserialized.plane.origin.z == sample_text_all_properties.plane.origin.z
|
||||
assert deserialized.plane.normal.x == sample_text_all_properties.plane.normal.x
|
||||
assert deserialized.plane.normal.y == sample_text_all_properties.plane.normal.y
|
||||
assert deserialized.plane.normal.z == sample_text_all_properties.plane.normal.z
|
||||
assert deserialized.maxWidth == sample_text_all_properties.maxWidth
|
||||
assert deserialized.units == sample_text_all_properties.units
|
||||
Reference in New Issue
Block a user