def test_handle_add(self): ns = Namespace() ns.add(".more.stuff.here.too") handle = ns.get_handle(".more.stuff.here.too") new_node = handle.add(".subtree")[0] assert isinstance(handle.subtree, NamespaceNodeBase)
def test_handle_get(self): ns = Namespace() ns.add(".add.some.stuff.here") ns.add(".other.stuff.added.here.now") handle = ns.get_handle(".other.stuff") assert isinstance(handle.get('.added.here'), NamespaceNodeBase)
def test_handle_remove(self): ns = Namespace() ns.add(".more.stuff.here.too") handle = ns.get_handle(".more.stuff.here") node = handle.remove(".too") assert node.nsid.nsid == ".more.stuff.here.too"
def test_get_subnodes_from_handle(): ns = Namespace() ns.add(".a.few.nodes.here.and.there.and.everywhere") handle = ns.get_handle(".a.few") subnodes = handle.get_subnodes('.nodes.here.and.there') nsids = [str(x.nsid) for x in subnodes] assert nsids == [ '.a.few.nodes.here.and.there.and', '.a.few.nodes.here.and.there.and.everywhere' ]
def test_get_subnodes_from_nested_handles(caplog): ns = Namespace() #caplog.set_level(logging.DEBUG) ns.add(".a.few.nodes.here.and.there.and.everywhere") handle1 = ns.get_handle(".a.few") handle2 = handle1.get_handle(".nodes") subnodes = handle2.get_subnodes('.here.and.there') nsids = [str(x.nsid) for x in subnodes] assert nsids == [ '.a.few.nodes.here.and.there.and', '.a.few.nodes.here.and.there.and.everywhere' ]
def test_get_nonexisting_handle_fail(self): ns = Namespace() with self.assertRaises(NamespaceLookupError): handle = ns.get_handle(".something.totally.new")
def test_get_nonexisting_handle(self): ns = Namespace() handle = ns.get_handle(".something.totally.new", create_nodes=True) assert handle.get('.').nsid.nsid == ".something.totally.new"