File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed
src/compas/datastructures/assembly
tests/compas/datastructures Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919* Fixed ` area_polygon ` that was, in some cases, returning a negative area
2020* Fixed support for ` System.Decimal ` data type on json serialization.
2121* Fixed ` AttributeError ` in Plotter's ` PolylineArtist ` and ` SegementArtist ` .
22+ * Fixed wrong key type when de-serializing ` Graph ` with integer keys leading to node not found.
2223
2324### Removed
2425
Original file line number Diff line number Diff line change @@ -58,14 +58,14 @@ def JSONSCHEMANAME(self):
5858 def data (self ):
5959 data = {
6060 "attributes" : self .attributes ,
61- "graph" : self .graph . data ,
61+ "graph" : self .graph ,
6262 }
6363 return data
6464
6565 @data .setter
6666 def data (self , data ):
6767 self .attributes .update (data ["attributes" ] or {})
68- self .graph . data = data ["graph" ]
68+ self .graph = data ["graph" ]
6969 self ._parts = {part .guid : part .key for part in self .parts ()}
7070
7171 # ==========================================================================
Original file line number Diff line number Diff line change 11import pytest
22
3+ from compas .data import json_dumps
4+ from compas .data import json_loads
35from compas .datastructures import Assembly
46from compas .datastructures import AssemblyError
57from compas .datastructures import Part
@@ -69,9 +71,22 @@ def test_find_by_key():
6971 assert assembly .find_by_key ("100" ) is None
7072
7173
72- def test_find_by_key_after_deserialization ():
74+ def test_find_by_key_after_from_data ():
7375 assembly = Assembly ()
7476 part = Part ()
7577 assembly .add_part (part , key = 2 )
7678 assembly = Assembly .from_data (assembly .to_data ())
7779 assert assembly .find_by_key (2 ) == part
80+
81+
82+ def test_find_by_key_after_deserialization ():
83+ assembly = Assembly ()
84+ part = Part (name = "test_part" )
85+ assembly .add_part (part , key = 2 )
86+ assembly = json_loads (json_dumps (assembly ))
87+
88+ deserialized_part = assembly .find_by_key (2 )
89+ assert deserialized_part .name == part .name
90+ assert deserialized_part .key == part .key
91+ assert deserialized_part .guid == part .guid
92+ assert deserialized_part .attributes == part .attributes
You can’t perform that action at this time.
0 commit comments