def test_schema_remove(self): s = Schema() s['a'] = DataType.float64(1) s['b'] = DataType.float64(1) s['c'] = DataType.float64(1) self.assertEqual(s.number_of_children(), 3) s.remove(path='c') self.assertEqual(s.number_of_children(), 2) paths = s.child_names() for v in ['a', 'b']: self.assertTrue(v in paths) s.remove(index=0) paths = s.child_names() for v in ['b']: self.assertTrue(v in paths)
def test_create_node_using_schema_object(self): s = Schema() s["a"] = DataType.float64(10) s["b"] = DataType.float32(10) n = Node() n.set(s) sr = n.schema() self.assertEqual(sr.total_strided_bytes(), 8 * 10 + 4 * 10) self.assertEqual(sr["a"].total_strided_bytes(), 8 * 10) self.assertEqual(sr["b"].total_strided_bytes(), 4 * 10)
def test_schema_child_rename(self): s = Schema() with self.assertRaises(Exception): s.rename_child('a', 'b') s["a"] = DataType.float64(10) s["b"] = DataType.float32(10) with self.assertRaises(Exception): s.rename_child('bad', 'good') with self.assertRaises(Exception): s.rename_child('b', 'a') s.rename_child("b", "c") n = Node() n.set(s) sr = n.schema() self.assertEqual(sr.total_strided_bytes(), 8 * 10 + 4 * 10) self.assertEqual(sr["a"].total_strided_bytes(), 8 * 10) self.assertEqual(sr["c"].total_strided_bytes(), 4 * 10)
def test_simple(self): n = default_node() n_schema = n.to_json("conduit_json") print("result detailed json", n_schema) g = Generator(schema=n_schema) ng = Node() sg = Schema() g.walk(node=ng) g.walk(schema=sg) print(ng) print(sg) for p in ["a", "b", "c"]: orig = n.fetch(p).value() curr = ng.fetch(p).value() print(ng) print(p, orig, curr) orig = n[p] curr = ng[p] print(ng) print(p, orig, curr) self.assertEqual(orig, curr)
def test_compact_to(self): a_val = uint32(10) b_val = uint32(20) c_val = float64(30.0) n = Node() n['a'] = a_val n['b'] = b_val n['c'] = c_val s = n.schema() n_info = n.info() print(n_info) self.assertEqual(n_info["mem_spaces"].number_of_children(), 3) s2 = Schema() s.compact_to(s2) n2 = Node() n2.set(s2) n2_info = n2.info() print(n2_info) self.assertEqual(n2_info["mem_spaces"].number_of_children(), 1)
def test_key_with_slash(self): s = Schema() s["normal/path"] = DataType.float64(1) s.add_child("child_with_/_inside").set(DataType.float64(1)) print(s) self.assertTrue(s.has_path("normal/path")) self.assertFalse(s.has_child("normal/path")) self.assertFalse(s.has_path("child_with_/_inside")) self.assertTrue(s.has_child("child_with_/_inside")) self.assertEqual(2, s.number_of_children()) self.assertEqual(s.child(1).dtype().id(), DataType.float64().id()) self.assertEqual( s.child(name="child_with_/_inside").dtype().id(), DataType.float64().id()) s["normal"].remove_child("path") self.assertFalse(s.has_path("normal/path"))