def test_add_branch_attrib(self):
     import xml.etree.ElementTree as ET
     element = ET.Element('test')
     evaluate.set_node_element(element, 'branch', 'my_name', 'Erik')
     evaluate.set_node_element(element, 'branch', 'time', 0)
     self.assertEqual(
         evaluate.get_node_element(element, 'branch', 'my_name'), 'Erik')
     self.assertEqual(evaluate.get_node_element(element, 'branch', 'time'),
                      0)
示例#2
0
def _get_tree_output(tree_element):
    if tree_element.find('name') is None:
        return ''
    if get_node_element(tree_element, 'node_is_true') == 'true':
        element_entry = '[' + str(get_node_element(
            tree_element, 'index')) + '] ' + get_node_element(
                tree_element, 'output') + '\n'
        return element_entry + ''.join(
            [_get_tree_output(subnode) for subnode in tree_element])
    return ''
 def test_add_branch_attribute_for_subnodes(self):
     xml_file = '../unit_test_classes_tags/Rootnode_add_branch_attr.xml'
     tree = evaluate.evaluate(xml_file)
     for subnode in tree.iter('node'):
         if subnode.find('name').text in ['Subnode31', 'Subnode32']:
             with self.assertRaises(BranchElementError):
                 evaluate.get_node_element(subnode, 'branch', 'test')
         else:
             name = subnode.find('name').text
             node_element = evaluate.get_node_element(
                 subnode, 'branch', 'test')
             self.assertEqual(node_element, 'value')
示例#4
0
def get_result_for_node(tree_element):
    if tree_element.find('name') is None:
        return ''
    index = ''
    if has_node_element(tree_element, 'exception'):
        result = get_node_element(tree_element, 'exception')
    elif has_node_element(tree_element, 'node_is_true'):
        result = get_node_element(tree_element, 'node_is_true')
        if result == 'true':
            index = '[' + str(get_node_element(tree_element, 'index')) + '] '
    else:
        result = None
    return result, index
 def test_create_node_elements_from_xml_attrib(self):
     tree_object = evaluate.create_tree_object_from_xml(
         '../unit_test_classes_branch_attrib/Rootnode_ma.xml')
     tree_root_element = evaluate.get_tree_root_element(tree_object)
     self.assertEqual(tree_root_element.attrib, {
         'name': 'Rootnode_ma',
         'register': 'Rootnode_ma_REG'
     })
     evaluate._create_node_elements_from_xml_attrib(tree_root_element)
     self.assertEqual(tree_root_element.attrib, {})
     self.assertEqual(
         evaluate.get_node_element(tree_root_element, 'register'),
         'Rootnode_ma_REG')
     self.assertEqual(evaluate.get_node_element(tree_root_element, 'name'),
                      'Rootnode_ma')
示例#6
0
def _make_annotated_tree(tree_element, depth=0):
    if get_node_element(tree_element, 'node_is_true') == 'true':
        element_entry = ' ' * 4 * depth + '[' + str(
            get_node_element(
                tree_element,
                'index')) + '] ' + tree_element.find('name').text + ': True\n'
        return element_entry + ''.join([
            _make_annotated_tree(subnode, depth + 1)
            for subnode in tree_element.findall('node')
        ])
    else:
        entry_indent = ' ' * (4 * depth + len('[ ] '))
        try:
            get_node_element(tree_element, 'exception')
        except (NoAttributeType, NoAttributeTypeName):
            return entry_indent + tree_element.find('name').text + ': False\n'
        return entry_indent + tree_element.find(
            'name').text + ': Exception raised\n'
示例#7
0
def _get_tree_exception_tb(tree_element):
    if tree_element.find('name') is None:
        return ''
    element_entry = ''
    if has_node_element(tree_element, 'traceback'):
        node_exception = get_node_element(tree_element, 'traceback')
        element_entry = tree_element.find('name').text + ': ' + str(
            node_exception) + '\n'
    return element_entry + ''.join(
        [_get_tree_exception_tb(subnode) for subnode in tree_element])
示例#8
0
 def get_element(self, key):
     return get_node_element(self.tree_element, key)
示例#9
0
 def get_branch_element(self, key):
     return get_node_element(self.tree_element, 'branch', key)