def test_parse_existing_namespace(): test_dict = { "all": { "work": { "no": { "play": { "dull_boy": {} } } } }, "hackers": { "on": { "planet": { "earth": {} } } } } ns = Namespace() nscp = NamespaceConfigParser2(namespace=ns) nscp.parse(dictConfig=test_dict) for nsid in get_nsid_ancestry('.all.work.no.play.dull_boy'): assert isinstance(ns.get(nsid), NamespaceNodeBase) for nsid in get_nsid_ancestry('.hackers.on.planet.earth'): assert isinstance(ns.get(nsid), NamespaceNodeBase)
def test_delete_node(self): ns = Namespace() new_nsid = '.a.b.c.d' ns.add(new_nsid) node = ns.remove(new_nsid) self.assertEqual(str(node.nsid), new_nsid) with self.assertRaises(NamespaceLookupError): ns.get(new_nsid)
def test_add_then_get_bad(self): ns = Namespace() new_nsid = '.a.b.c.d.e' bad_new_nsid = '.a.b.c.d.e.f' ns.add(new_nsid) with self.assertRaises(NamespaceLookupError): node = ns.get(bad_new_nsid)
def test_add_then_get_ancestor(self): ns = Namespace() parent_nsid = '.a.b.c.d.e' child_nsid = make_child_nsid(parent_nsid, 'f') ns.add(child_nsid) node = ns.get(parent_nsid) self.assertEqual(parent_nsid, str(node.nsid))
def test_add_then_get_new_node(self): ns = Namespace() new_nsid = '.a.b.c.d.e' ns.add(new_nsid) node = ns.get(new_nsid) self.assertEqual(new_nsid, str(node.nsid))
def test_bad_get2(self): ns = Namespace() ns.add('.something.that') with self.assertRaises(NamespaceLookupError): ns.get(".something.that.does.not.exist.and.is.long")
def test_get_root_node(self): ns = Namespace() root = ns.get('.') self.assertEqual(ns.root, root)