Updated SICS unit test infrastructure and test tests

This commit is contained in:
Douglas Clowes
2014-05-09 16:59:11 +10:00
parent f5f5ca33ea
commit 5699ae2747
3 changed files with 208 additions and 35 deletions

View File

@@ -76,20 +76,22 @@ class HipadabaTree(object):
self.root = root
def short_tree(self, tree=None):
"""
"""Creates a map from the tree/node that can be used or printed
"""
if tree is None:
tree = self.root
if isinstance(tree, type(self.root)):
if "attrib" not in dir(tree) or 'id' not in tree.attrib:
tree_part = {"name": "<root>"}
else:
tree_part = {"name": tree.attrib['id']}
tree_part["children"] = [ch.attrib['id'] for ch in tree.findall('component')]
tree_part["properties"] = [ch.attrib['id'] for ch in tree.findall('property')]
tree_part["children"] = sorted([ch.attrib['id'] for ch in tree.findall('component')])
tree_part["properties"] = sorted([ch.attrib['id'] for ch in tree.findall('property')])
return tree_part
def find_path(self, path, tree=None):
debug = True
"""Finds a node from the given tree and path
"""
debug = False
if tree is None:
tree = self.root
if debug:
@@ -115,7 +117,7 @@ class HipadabaTree(object):
if tree is None:
tree = self.root
text = []
if isinstance(tree, type(self.root)):
if "attrib" not in dir(tree) or 'id' not in tree.attrib:
text += [' '*indent + '* ' + '<root>']
else:
text += [' '*indent + '* ' + tree.attrib['id']]
@@ -138,6 +140,15 @@ class HipadabaTree(object):
def getNode(self, path, tree=None):
return self.find_path(path, tree)
def getValue(self, path, tree=None):
node = self.find_path(path, tree)
if node is None:
return None
items = [ch.text for ch in node.findall('value') if ch.text is not None]
if len(items) == 0:
return ""
return ','.join(items)
def getProperty(self, path, property, tree=None):
node = self.find_path(path, tree)
if node is None:
@@ -149,7 +160,7 @@ class HipadabaTree(object):
items = [ch.text for ch in node.findall('value') if ch.text is not None]
if len(items) == 0:
return ""
return ' '.join(items)
return ','.join(items)
def getProperties(self, path, tree=None):
node = self.find_path(path, tree)
@@ -159,11 +170,13 @@ class HipadabaTree(object):
def getChildren(self, path, tree=None):
node = self.find_path(path, tree)
if node:
if node is not None:
return sorted([ch.attrib['id'] for ch in node.findall('component')])
return None
if __name__ == "__main__":
"""this test uses a "junk.xml" file extracted for SICS
"""
filename = "junk.xml"
fd = open(filename, "r")
lines = fd.readlines()