def test_DumpJsonToString(self): """ Since opencascade 7x, some objects can be serialized to json """ # create a sphere with a radius of 10. sph= BRepPrimAPI_MakeSphere(10.).Shape() # compute the Bnd box for this sphere bnd_box = Bnd_Box() brepbndlib_Add(sph, bnd_box) # check the result corner_min = bnd_box.CornerMin() self.assertEqual([round(corner_min.X(), 3), round(corner_min.Y(), 3), round(corner_min.Z(), 3)], [-10., -10., -10.]) # check dump json is working json_string = bnd_box.DumpJsonToString() expected_output = '"Bnd_Box": {"CornerMin": [-10, -10, -10], "CornerMax": [10, 10, 10], "Gap": 1e-07, "Flags": 0}' self.assertEqual(json_string, expected_output)
def test_DumpJsonToString(self) -> None: """ Since opencascade 7x, some objects can be serialized to json """ # create a sphere with a radius of 10. sph = BRepPrimAPI_MakeSphere(10.).Shape() # compute the Bnd box for this sphere bnd_box = Bnd_Box() brepbndlib_Add(sph, bnd_box) # check the result corner_min = bnd_box.CornerMin() self.assertEqual([round(corner_min.X(), 3), round(corner_min.Y(), 3), round(corner_min.Z(), 3)], [-10., -10., -10.]) # check dump json export is working json_string = bnd_box.DumpJsonToString() # try to load the output string json_imported_dict = json.loads("{" + json_string + "}") self.assertTrue(len(json_imported_dict) > 0) # at least one entry