Skip to content

Commit

Permalink
Merge branch 'main' into geometry-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Jul 27, 2023
2 parents 1c7558d + 8f8fb33 commit 2d2e4cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed `compas.data.DataEncoder` and `compas.data.DataDecoder` to support `to_jsondata` and `from_jsondata`.
* Moved all API level docstrings from the `__init__.py` to the correspoding `.rst` file in the docs.
* Fixed `AttributeError` in Plotter's `PolylineArtist` and `SegementArtist`.
* Fixed wrong key type when de-serializing `Graph` with integer keys leading to node not found.
* Changed base class for `compas.geometry.Transformation` to `compas.data.Data`.
* Moved all core transformation functions to `compas.geometry._core`.
* Changed base class of `compas.geometry.Arc` to `compas.geometry.Curve.`
Expand Down
4 changes: 2 additions & 2 deletions src/compas/datastructures/assembly/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ def JSONSCHEMANAME(self):
def data(self):
data = {
"attributes": self.attributes,
"graph": self.graph.data,
"graph": self.graph,
}
return data

@data.setter
def data(self, data):
self.attributes.update(data["attributes"] or {})
self.graph.data = data["graph"]
self.graph = data["graph"]
self._parts = {part.guid: part.key for part in self.parts()}

# ==========================================================================
Expand Down
17 changes: 16 additions & 1 deletion tests/compas/datastructures/test_assembly.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from compas.data import json_dumps
from compas.data import json_loads
from compas.datastructures import Assembly
from compas.datastructures import AssemblyError
from compas.datastructures import Part
Expand Down Expand Up @@ -69,9 +71,22 @@ def test_find_by_key():
assert assembly.find_by_key("100") is None


def test_find_by_key_after_deserialization():
def test_find_by_key_after_from_data():
assembly = Assembly()
part = Part()
assembly.add_part(part, key=2)
assembly = Assembly.from_data(assembly.to_data())
assert assembly.find_by_key(2) == part


def test_find_by_key_after_deserialization():
assembly = Assembly()
part = Part(name="test_part")
assembly.add_part(part, key=2)
assembly = json_loads(json_dumps(assembly))

deserialized_part = assembly.find_by_key(2)
assert deserialized_part.name == part.name
assert deserialized_part.key == part.key
assert deserialized_part.guid == part.guid
assert deserialized_part.attributes == part.attributes

0 comments on commit 2d2e4cd

Please sign in to comment.