1010
1111
1212def test_json_native ():
13- before = [[], (), {}, '' , 1 , 1.0 , True , None ]
13+ before = [[], (), {}, "" , 1 , 1.0 , True , None ]
1414 after = compas .json_loads (compas .json_dumps (before ))
15- assert after == [[], [], {}, '' , 1 , 1.0 , True , None ]
15+ assert after == [[], [], {}, "" , 1 , 1.0 , True , None ]
1616
1717
1818if not compas .IPY :
1919 import numpy as np
2020
2121 def test_json_numpy ():
22- before = [np .array ([1 , 2 , 3 ]), np .array ([1.0 , 2.0 , 3.0 ]), np .float64 (1.0 ), np .int32 (1 )]
22+ before = [
23+ np .array ([1 , 2 , 3 ]),
24+ np .array ([1.0 , 2.0 , 3.0 ]),
25+ np .float64 (1.0 ),
26+ np .int32 (1 ),
27+ ]
2328 after = compas .json_loads (compas .json_dumps (before ))
2429 assert after == [[1 , 2 , 3 ], [1.0 , 2.0 , 3.0 ], 1.0 , 1 ]
2530
@@ -29,20 +34,23 @@ def test_json_primitive():
2934 after = compas .json_loads (compas .json_dumps (before ))
3035 assert before .dtype == after .dtype
3136 assert all (a == b for a , b in zip (before , after ))
37+ assert before .guid == after .guid
3238
3339
3440def test_json_shape ():
3541 before = Box (Frame (Point (0 , 0 , 0 ), Vector (1 , 0 , 0 ), Vector (0 , 1 , 0 )), 1 , 1 , 1 )
3642 after = compas .json_loads (compas .json_dumps (before ))
3743 assert before .dtype == after .dtype
3844 assert all (a == b for a , b in zip (before .vertices , after .vertices ))
45+ assert before .guid == after .guid
3946
4047
4148def test_json_xform ():
4249 before = Transformation .from_frame_to_frame (Frame .worldXY (), Frame .worldXY ())
4350 after = compas .json_loads (compas .json_dumps (before ))
4451 assert before .dtype == after .dtype
4552 assert all (a == b for a , b in zip (before , after ))
53+ assert before .guid == after .guid
4654
4755
4856def test_json_network ():
@@ -57,10 +65,13 @@ def test_json_network():
5765 assert all (after .has_node (node ) for node in before .nodes ())
5866 assert all (before .has_edge (* edge ) for edge in after .edges ())
5967 assert all (after .has_edge (* edge ) for edge in before .edges ())
68+ assert before .guid == after .guid
6069
6170
6271def test_json_mesh ():
63- before = Mesh .from_vertices_and_faces ([[0 , 0 , 0 ], [1 , 0 , 0 ], [1 , 1 , 0 ], [0 , 1 , 0 ]], [[0 , 1 , 2 , 3 ]])
72+ before = Mesh .from_vertices_and_faces (
73+ [[0 , 0 , 0 ], [1 , 0 , 0 ], [1 , 1 , 0 ], [0 , 1 , 0 ]], [[0 , 1 , 2 , 3 ]]
74+ )
6475 after = compas .json_loads (compas .json_dumps (before ))
6576 assert before .dtype == after .dtype
6677 assert before .attributes == after .attributes
@@ -70,13 +81,36 @@ def test_json_mesh():
7081 assert all (after .has_face (face ) for face in before .faces ())
7182 assert all (before .has_edge (edge ) for edge in after .edges ())
7283 assert all (after .has_edge (edge ) for edge in before .edges ())
73- assert all (before .face_vertices (a ) == after .face_vertices (b ) for a , b in zip (before .faces (), after .faces ()))
84+ assert all (
85+ before .face_vertices (a ) == after .face_vertices (b )
86+ for a , b in zip (before .faces (), after .faces ())
87+ )
88+ assert before .guid == after .guid
7489
7590
7691def test_json_volmesh ():
7792 before = VolMesh .from_vertices_and_cells (
78- [[0 , 0 , 0 ], [1 , 0 , 0 ], [1 , 1 , 0 ], [0 , 1 , 0 ], [0 , 0 , 1 ], [1 , 0 , 1 ], [1 , 1 , 1 ], [0 , 1 , 1 ]],
79- [[[0 , 1 , 5 , 4 ], [1 , 2 , 5 , 6 ], [2 , 3 , 7 , 6 ], [3 , 0 , 4 , 7 ], [4 , 5 , 6 , 7 ], [0 , 3 , 2 , 1 ]]])
93+ [
94+ [0 , 0 , 0 ],
95+ [1 , 0 , 0 ],
96+ [1 , 1 , 0 ],
97+ [0 , 1 , 0 ],
98+ [0 , 0 , 1 ],
99+ [1 , 0 , 1 ],
100+ [1 , 1 , 1 ],
101+ [0 , 1 , 1 ],
102+ ],
103+ [
104+ [
105+ [0 , 1 , 5 , 4 ],
106+ [1 , 2 , 5 , 6 ],
107+ [2 , 3 , 7 , 6 ],
108+ [3 , 0 , 4 , 7 ],
109+ [4 , 5 , 6 , 7 ],
110+ [0 , 3 , 2 , 1 ],
111+ ]
112+ ],
113+ )
80114 after = compas .json_loads (compas .json_dumps (before ))
81115 assert before .dtype == after .dtype
82116 assert before .attributes == after .attributes
@@ -88,12 +122,13 @@ def test_json_volmesh():
88122 # assert all(after.has_cell(cell) for cell in before.cells())
89123 # assert all(before.has_edge(edge) for edge in after.edges())
90124 # assert all(after.has_edge(edge) for edge in before.edges())
125+ assert before .guid == after .guid
91126
92127
93128def test_json_pretty ():
94129 result = compas .json_dumps (dict (a = 12 , b = 6565 ), pretty = True )
95130 # strip some spacing to make the test pass on ironpython
96- result = ' \n ' .join ([line .strip () for line in result .split (' \n ' )])
131+ result = " \n " .join ([line .strip () for line in result .split (" \n " )])
97132 assert result == """{\n "a": 12,\n "b": 6565\n }"""
98133
99134
0 commit comments