def test_load_save_protocols(self): a_val = int64(10) b_val = int64(20) c_val = float64(30.0) # n = Node() n['a'] = a_val n['b'] = b_val n['c'] = c_val self.assertTrue(n['a'] == a_val) self.assertTrue(n['b'] == b_val) self.assertTrue(n['c'] == c_val) protos = ["conduit_bin", "json", "conduit_json", "conduit_base64_json"] # only test hdf5 if relay was built with hdf5 support if relay.about()["io/protocols/hdf5"] == "enabled": protos.append("hdf5") for proto in protos: print("testing protocol: ", proto) ftest = "tout_python_relay_io_save_load_proto." + proto relay.io.save(n,ftest) # now load the value n_load = Node() relay.io.load(n_load,ftest) self.assertTrue(n_load['a'] == a_val) self.assertTrue(n_load['b'] == b_val) self.assertTrue(n_load['c'] == c_val) # only test silo if relay was built with hdf5 support if relay.about()["io/protocols/conduit_silo"] == "enabled": # silo needs a subpath print("testing protocol: silo") ftest = "tout_python_relay_io_save_load_proto.silo:obj" relay.io.save(n,ftest) # now load the value n_load = Node() relay.io.load(n_load,ftest) self.assertTrue(n_load['a'] == a_val) self.assertTrue(n_load['b'] == b_val) self.assertTrue(n_load['c'] == c_val)
def test_hdf5_generic_save_opts(self): # only run if we have hdf5 if not relay.about()["io/protocols/hdf5"] == "enabled": return # 5k float64 zeros, will compress well, but below default # thresh n = Node() opts = Node() opts["hdf5/chunking/threshold"] = 2000 opts["hdf5/chunking/chunk_size"] = 2000 # hdf5 requires object at top level ... n['value'].set(DataType.float64(5000)) tout_std = "tout_python_relay_io_hdf5_generic_std.hdf5" tout_cmp = "tout_python_relay_io_hdf5_generic_cmp.hdf5" relay.io.save(n, tout_std) relay.io.save(n, tout_cmp, options=opts) tout_std_fs = os.path.getsize(tout_std) tout_std_cmp = os.path.getsize(tout_cmp) self.assertTrue(os.path.isfile(tout_std)) self.assertTrue(os.path.isfile(tout_cmp)) print("fs compare: std = ", tout_std_fs, " cmp = ", tout_std_cmp) self.assertTrue(tout_std_cmp < tout_std_fs)
def test_about(self): print(relay.about())