Ejemplo n.º 1
0
 def get_lossy_tree(self):
     tree = Tree()
     with tree.node('root', 'tale') as root:
         root.node('level', 'absurd')
         root.node('level', 'stupid')
         root.node('handle', 'lame')
     return tree
Ejemplo n.º 2
0
    def test_render_child_node_as_root(self):
        tree = Tree()
        with tree.node('root') as root:
            child = root.node('name')
            child.node('first', 'Bob')
            child.node('last', 'Wiley')

        self.assertIsInstance(child.render(), basestring)
Ejemplo n.º 3
0
 def test_data_node_with_children_and_text(self):
     tree = Tree()
     with tree.node('a', 'A', href="http://bigjason.com") as a:
         a.node('b', "Link")
     self.assertEqual(
         tree(),
         '<a href="http://bigjason.com">A<b>Link</b></a>'
     )
Ejemplo n.º 4
0
    def test_run_as_callable(self):
        tree = Tree()

        with tree.node('root') as root:
            root.node('item', 1)

        actual = tree('dict')
        expected = {'root': {'item': 1}}
        self.assertDictEqual(actual, expected)
Ejemplo n.º 5
0
 def get_dirty_tree(self):
     tree = Tree()
     with tree.node("author") as author:
         author.node('name', 'Terry Pratchett')
         with author.node('genre') as genre:
             genre.node('fantasy', 'true')
             genre.node('comedy', 'true')
             genre.node('horror', 'false')
     return tree
Ejemplo n.º 6
0
 def get_dirty_tree(self):
     tree = Tree()
     with tree.node("author") as author:
         author.node('name', 'Terry Pratchett')
         with author.node('genre') as genre:
             genre.node('fantasy', 'true')
             genre.node('comedy', 'true')
             genre.node('horror', 'false')
     return tree
Ejemplo n.º 7
0
 def get_unified_tree(self):
     tree = Tree()
     with tree.node("author") as author:
         author.node('name', 'Terry Pratchett')
         author.node('genre', 'Fantasy/Comedy')
         with author.node('novels', count=2) as novels:
             novels.node('novel', 'Small Gods', year=1992)
             novels.node('novel', 'The Fifth Elephant', year=1999)
             novels.node('novel', 'Feet of Clay', year=1996)
     return tree
Ejemplo n.º 8
0
 def get_unified_tree(self):
     tree = Tree()
     with tree.node("author") as author:
         author.node('name', 'Terry Pratchett')
         author.node('genre', 'Fantasy/Comedy')
         with author.node('novels', count=2) as novels:
             novels.node('novel', 'Small Gods', year=1992)
             novels.node('novel', 'The Fifth Elephant', year=1999)
             novels.node('novel', 'Feet of Clay', year=1996)
     return tree
Ejemplo n.º 9
0
 def test_children_distinct_names_are_different(self):
     tree = Tree()
     with tree.node('root') as root:
         root.node('person', 'One')
         root.node('different', 'Two')
         root.node('strokes', 'Three')
     render = DictRenderer()
     self.assertSetEqual(
         render._children_distinct_names(root.__children__),
         set(["person", "different", "strokes"])
     )
Ejemplo n.º 10
0
    def test_render_child_node_as_root(self):
        tree = Tree()
        with tree.node('root') as root:
            child = root.node('name')
            child.node('first', 'Bob')
            child.node('last', 'Wiley')

        self.assertIsInstance(
            child.render(),
            basestring
        )
Ejemplo n.º 11
0
    def test_children_distinct_names(self):
        tree = Tree()
        with tree.node('tree') as root:
            root.node('person', 'One')
            root.node('person', 'Two')
            root.node('person', 'Three')

        render = DictRenderer()
        self.assertSetEqual(
            render._children_distinct_names(root.__children__),
            set(["person"])
        )
Ejemplo n.º 12
0
 def get_author(self):
     tree = Tree()
     with tree.node('author', rating="<b>5/6 Stars</b>") as author:
         author.node('name', 'Terry Pratchett')
         author.node('genere', 'Fantasy/Comedy')
         author.node('country', abbreviation="UK")
         author.node('living')
         with author.node('novels', count=2) as novels:
             novels.node('novel', 'Small Gods', year=1992)
             novels.node('novel', 'The Fifth Elephant', year=1999)
             with novels.node('shorts', count=2) as shorts:
                 shorts.node('short', "Short Story 1")
                 shorts.node('short', "Short Story 2")
     return tree
Ejemplo n.º 13
0
 def get_author(self):
     tree = Tree()        
     with tree.node('author', rating="<b>5/6 Stars</b>") as author:
         author.node('name', 'Terry Pratchett')
         author.node('genere', 'Fantasy/Comedy')
         author.node('country', abbreviation="UK")
         author.node('living')
         with author.node('novels', count=2) as novels:
             novels.node('novel', 'Small Gods', year=1992)
             novels.node('novel', 'The Fifth Elephant', year=1999)
             with novels.node('shorts', count=2) as shorts:
                 shorts.node('short', "Short Story 1")
                 shorts.node('short', "Short Story 2")
     return tree
Ejemplo n.º 14
0
def translate_story(entry, project_id, requestor_id):
    tree = Tree()
    # tree.instruct("xml", version="1.0", encoding="UTF-8") # Not supported by datatree 0.2.0 :(
    with tree.story() as story:
        story.project_id(project_id, type="integer")
        story.story_type(entry["Story Type"])
        story.current_state(entry["Current State"])
        story.description(entry["Description"])
        story.name(entry["Story"])
        if requestor_id:
            story.requested_by(requestor_id)  # not using entry["Requested By"] to prevent invalid membership error at PT end
        story.created_at(entry["Created at"], type="datetime")
        # story.updated_at(entry["Updated at"], type="datetime")
        story.labels(entry["Labels"])
        with story.notes(type="array") as notes:
            for n in entry["Notes Full"]:
                with notes.note() as note:
                    note.text(n[0])
                    note.noted_at(translate_time(n[1], quotes=False), type="datetime")
                    # note.author(n[2]) # prevent valid membership check at PT end
    return tree(pretty=True)
Ejemplo n.º 15
0
 def _get_complex_structure(self):
     tree = Tree()
     tree.instruct('xml')
     #tree.cdata(r"<b>I am some text.</b>")
     tree.declare('DOCTYPE', __.author, __.SYSTEM, 'SomeDTD.dtd')
     with tree.node('author') as author:
         author.node('name', 'Terry Pratchett')
         author.node('genre', 'Fantasy/Comedy')
         author.comment("Only 2 books listed")
         with author.node('novels', count=2) as novels:
             novels.node('novel', 'Small Gods', year=1992)
             novels.node('novel', 'The Fifth Elephant', year=1999)
     return tree
Ejemplo n.º 16
0
 def _get_complex_structure(self):        
     tree = Tree()
     tree.instruct('xml')
     #tree.cdata(r"<b>I am some text.</b>")
     tree.declare('DOCTYPE', __.author, __.SYSTEM,  'SomeDTD.dtd')
     with tree.node('author') as author:
         author.node('name', 'Terry Pratchett')
         author.node('genre', 'Fantasy/Comedy')
         author.comment("Only 2 books listed")
         with author.node('novels', count=2) as novels:
             novels.node('novel', 'Small Gods', year=1992)
             novels.node('novel', 'The Fifth Elephant', year=1999)
     return tree
Ejemplo n.º 17
0
 def test_render_instruction(self):
     tree = Tree()
     tree.instruct('process', do="Good")
     self.assertIn(tree(), '<?process do="Good"?>')
Ejemplo n.º 18
0
 def test_render_instruction_xml(self):
     tree = Tree()
     tree.instruct('xml')
     self.assertIn(tree(), '<?xml version="1.0" encoding="UTF-8"?>')
Ejemplo n.º 19
0
 def test_render_declaration_no_values(self):
     tree = Tree()
     tree.declare('ELEMENT')
     self.assertIn(tree(), r'<!ELEMENT>')
Ejemplo n.º 20
0
from datatree import Tree

if __name__ == '__main__':
    tree = Tree()
    #tree.instruct('xml', version='1.0')
    with tree.node("author") as author:
        author.node('name', 'Terry Pratchett')
        author.node('genre', 'Fantasy/Comedy')
        author.comment("Only 2 books listed")
        with author.node('novels', count=2) as novels:
            novels.node('novel', 'Small Gods', year=1992)
            novels.node('novel', 'The Fifth Elephant', year=1999)
            novels.node("novel", "Guards! Guards!", year=1989)

    print 'XML:'
    print author(pretty=True)
    print
    print
    print 'JSON:'
    print author('json', pretty=True)
    print
    print
    print 'YAML:'
    print author('yaml')
    print
    print
    print 'Dict:'
    print author('dict', pretty_string=True)
Ejemplo n.º 21
0
 def test_render_instruction_xml(self):
     tree = Tree()
     tree.instruct('xml')
     self.assertIn(tree(), '<?xml version="1.0" encoding="UTF-8"?>')
Ejemplo n.º 22
0
 def test_render_instruction(self):
     tree = Tree()
     tree.instruct('process', do="Good")
     self.assertIn(tree(), '<?process do="Good"?>')
Ejemplo n.º 23
0
 def test_add_child_node(self):
     tree = Tree()
     node = tree.node('A Value')
     self.assertEqual(tree.__children__[0], node)
Ejemplo n.º 24
0
 def test_render_declaration_no_values(self):
     tree = Tree()
     tree.declare('ELEMENT')
     self.assertIn(tree(), r'<!ELEMENT>')
Ejemplo n.º 25
0
 def test_render_comment(self):
     tree = Tree()
     tree.node('root').comment("Something Here")
     self.assertIn('<!-- Something Here -->', tree('xml'))
Ejemplo n.º 26
0
 def test_render_cdata_not_string(self):
     int_val = 1234567891011121314151617181920
     tree = Tree()
     tree.node('root').cdata(int_val)
     self.assertIn('<![cdata[{0}]]>'.format(str(int_val)), tree('xml'))
Ejemplo n.º 27
0
 def get_flat_tree(self):
     tree = Tree()
     with tree.node("author") as author:
         author.node('name', 'Terry Pratchett')
         author.node('genre', 'Fantasy/Comedy')
     return tree
Ejemplo n.º 28
0
 def test_add_node_return(self):
     tree = Tree()
     root = tree.node('root')
     self.assertEqual(root, tree.__children__[0])
Ejemplo n.º 29
0
 def test_render_cdata_string(self):
     tree = Tree()
     tree.node('root').cdata("Some Value")
     self.assertIn('<![cdata[Some Value]]>', tree('xml'))
Ejemplo n.º 30
0
 def test_add_child_node(self):
     tree = Tree()
     node = tree.node('A Value')
     self.assertEqual(tree.__children__[0], node)
Ejemplo n.º 31
0
 def test_render_comment(self):
     tree = Tree()
     tree.node('root').comment("Something Here")
     self.assertIn('<!-- Something Here -->', tree('xml'))
Ejemplo n.º 32
0
 def test_render_cdata_string(self):
     tree = Tree()
     tree.node('root').cdata("Some Value")
     self.assertIn('<![cdata[Some Value]]>', tree('xml'))
Ejemplo n.º 33
0
 def test_render_cdata_not_string(self):
     int_val = 1234567891011121314151617181920
     tree = Tree()
     tree.node('root').cdata(int_val)
     self.assertIn('<![cdata[{0}]]>'.format(str(int_val)), tree('xml'))
Ejemplo n.º 34
0
 def get_flat_tree(self):
     tree = Tree()
     with tree.node("author") as author:
         author.node('name', 'Terry Pratchett')
         author.node('genre', 'Fantasy/Comedy')
     return tree
Ejemplo n.º 35
0
 def test_render_declaration(self):
     tree = Tree()
     tree.declare('ELEMENT', __.Value, 'A value here.')
     self.assertIn(tree(), r'<!ELEMENT Value "A value here.">')
Ejemplo n.º 36
0
 def test_render_declaration(self):
     tree = Tree()
     tree.declare('ELEMENT', __.Value, 'A value here.')
     self.assertIn(tree(), r'<!ELEMENT Value "A value here.">')
Ejemplo n.º 37
0
 def _get_test_tree(self):
     tree = Tree()
     tree.instruct()
     tree.node('name', 'Bob')
     tree.node('age', 12)
     return tree
Ejemplo n.º 38
0
 def _get_test_tree(self):
     tree = Tree()
     tree.instruct()
     tree.node('name', 'Bob')
     tree.node('age', 12)
     return tree
Ejemplo n.º 39
0
 def test_data_node_with_children_and_text(self):
     tree = Tree()
     with tree.node('a', 'A', href="http://bigjason.com") as a:
         a.node('b', "Link")
     self.assertEqual(tree(),
                      '<a href="http://bigjason.com">A<b>Link</b></a>')