def test_deep_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2 ((c3 ((c4)))))))')
     tree = parser.node()
     nodes = []
     for node in depth_first_iterator(tree):
         nodes.append(node.name)
     self.assertEqual(nodes, ['c1', 'c2', 'c3', 'c4'])
Exemple #2
0
 def test_deep_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2 ((c3 ((c4)))))))')
     tree = parser.node()
     nodes = []
     for node in depth_first_iterator(tree):
         nodes.append(node.name)
     self.assertEqual(nodes, ['c1', 'c2', 'c3', 'c4'])
 def test_single_node(self):
     parser = NodeParser()
     parser.parse('(c1)')
     tree = parser.node()
     nodes = []
     for node in depth_first_iterator(tree):
         nodes.append(node.name)
     self.assertEqual(nodes, ['c1'])
 def test_empty_tree(self):
     parser = NodeParser()
     parser.parse('()')
     tree = parser.node()
     nodes = []
     for node in depth_first_iterator(tree):
         nodes.append(node.name)
     self.assertEqual(nodes, [])
Exemple #5
0
 def test_single_node(self):
     parser = NodeParser()
     parser.parse('(c1)')
     tree = parser.node()
     nodes = []
     for node in depth_first_iterator(tree):
         nodes.append(node.name)
     self.assertEqual(nodes, ['c1'])
Exemple #6
0
 def test_empty_tree(self):
     parser = NodeParser()
     parser.parse('()')
     tree = parser.node()
     nodes = []
     for node in depth_first_iterator(tree):
         nodes.append(node.name)
     self.assertEqual(nodes, [])
def main():
    '''Function that will parse the given file and convert the tree to the
       format specified'''
    arg_parser = ArgumentParser(description='tree structured data '
                                            'converter')
    arg_parser.add_argument('file', type=FileType('r'),
                            help='file to parse')
    arg_parser.add_argument('--format', type=str, default='string',
                            help='format to convert to, default = string')
    options = arg_parser.parse_args()
    tree_str = '\n'.join(options.file.readlines())
    options.file.close()
    node_parser = NodeParser()
    node_parser.parse(tree_str)
    tree = node_parser.node()
    if options.format == 'xml':
        writer = XmlWriter()
    elif options.format == 'relational':
        writer = RelationalWriter()
    else:
        writer = IndentedStringWriter()
    print(writer.write(tree))
def main():
    '''Function that will parse the given file and convert the tree to the
       format specified'''
    arg_parser = ArgumentParser(description='tree structured data '
                                'converter')
    arg_parser.add_argument('file', type=FileType('r'), help='file to parse')
    arg_parser.add_argument('--format',
                            type=str,
                            default='string',
                            help='format to convert to, default = string')
    options = arg_parser.parse_args()
    tree_str = '\n'.join(options.file.readlines())
    options.file.close()
    node_parser = NodeParser()
    node_parser.parse(tree_str)
    tree = node_parser.node()
    if options.format == 'xml':
        writer = XmlWriter()
    elif options.format == 'relational':
        writer = RelationalWriter()
    else:
        writer = IndentedStringWriter()
    print(writer.write(tree))
Exemple #9
0
 def test_deep_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2 ((c3 ((c4)))))))')
     tree = parser.node()
     self.assertEqual(depth(tree), 4)
Exemple #10
0
 def test_single_node(self):
     parser = NodeParser()
     parser.parse('(c1)')
     tree = parser.node()
     self.assertEqual(depth(tree), 1)
Exemple #11
0
 def test_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2) (c3 ((c4) (c5))) (c6)))')
     tree = parser.node()
     self.assertEqual(depth(tree), 3)
Exemple #12
0
 def test_deep_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2 ((c3 ((c4)))))))')
     tree = parser.node()
     self.assertEqual(nr_leaf_nodes(tree), 1)
Exemple #13
0
 def test_empty_tree(self):
     parser = NodeParser()
     parser.parse('()')
     tree = parser.node()
     self.assertEqual(depth(tree), 0)
 def test_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2) (c3 ((c4) (c5))) (c6)))')
     tree = parser.node()
     self.assertEqual(nr_leaf_nodes(tree), 4)
Exemple #15
0
 def test_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2) (c3 ((c4) (c5))) (c6)))')
     tree = parser.node()
     self.assertEqual(nr_leaf_nodes(tree), 4)
 def test_deep_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2 ((c3 ((c4)))))))')
     tree = parser.node()
     self.assertEqual(nr_leaf_nodes(tree), 1)
 def test_empty_tree(self):
     parser = NodeParser()
     parser.parse('()')
     tree = parser.node()
     self.assertEqual(depth(tree), 0)
 def test_single_node(self):
     parser = NodeParser()
     parser.parse('(c1)')
     tree = parser.node()
     self.assertEqual(depth(tree), 1)
 def test_deep_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2 ((c3 ((c4)))))))')
     tree = parser.node()
     self.assertEqual(depth(tree), 4)
 def test_tree(self):
     parser = NodeParser()
     parser.parse('(c1 ((c2) (c3 ((c4) (c5))) (c6)))')
     tree = parser.node()
     self.assertEqual(depth(tree), 3)
Exemple #21
0
 def test_empty_tree(self):
     parser = NodeParser()
     parser.parse('()')
     tree = parser.node()
     self.assertEqual(nr_leaf_nodes(tree), 0)
 def test_empty_tree(self):
     parser = NodeParser()
     parser.parse('()')
     tree = parser.node()
     self.assertEqual(nr_leaf_nodes(tree), 0)