Exemple #1
0
 def test_children_multiple(self):
     """
     Multiple child elements with the same tag name are coalesced into
     a ``list``.
     """
     self.assertEqual(
         {'root': {'child': [{'@attr': 'value'}, 'hello']}},
         element_to_dict(
             L.root(L.child(attr='value'), L.child('hello'))))
Exemple #2
0
 def test_children_multiple(self):
     """
     Multiple child elements with the same tag name are coalesced into
     a ``list``.
     """
     self.assertEqual({'root': {
         'child': [{
             '@attr': 'value'
         }, 'hello']
     }}, element_to_dict(L.root(L.child(attr='value'), L.child('hello'))))
Exemple #3
0
 def test_namespaced(self):
     """
     `element_to_dict` supports namespaced element names and namespaced
     attributes.
     """
     ns = Namespace('http://example.com', 'ex')
     self.assertEqual(
         {str(ns.root): {
             'child': [
                 {'@' + str(ns.attr): 'value'},
                 {'@attr2': 'value2',
                  '#text': 'hello'},
                 'world']}},
         element_to_dict(
             ns.root(
                 L.child({ns.attr: 'value'}),
                 L.child('hello', attr2='value2'),
                 L.child('world'))))
Exemple #4
0
    def test_children_text(self):
        """
        Child elements are recursively nested.

        An element containing only text content, has its text keyed against its
        tag name.
        """
        self.assertEqual({'root': {
            'child': 'hello'
        }}, element_to_dict(L.root(L.child('hello'))))
Exemple #5
0
 def test_namespaced(self):
     """
     `element_to_dict` supports namespaced element names and namespaced
     attributes.
     """
     ns = Namespace('http://example.com', 'ex')
     self.assertEqual(
         {
             str(ns.root): {
                 'child': [{
                     '@' + str(ns.attr): 'value'
                 }, {
                     '@attr2': 'value2',
                     '#text': 'hello'
                 }, 'world']
             }
         },
         element_to_dict(
             ns.root(L.child({ns.attr: 'value'}),
                     L.child('hello', attr2='value2'), L.child('world'))))
Exemple #6
0
    def test_children_text_attributes(self):
        """
        Child elements are recursively nested.

        An element containing attributes and text content, has its
        attributes, prefixed with an ``@`` keyed against its tag name and its
        text keyed against ``#text``.
        """
        self.assertEqual(
            {'root': {'child': {'#text': 'hello', '@attr': 'value'}}},
            element_to_dict(L.root(L.child('hello', attr='value'))))
Exemple #7
0
    def test_children_attributes(self):
        """
        Child elements are recursively nested.

        An element containing only attributes, and no content, has its
        attributes, prefixed with an ``@`` keyed against its tag name.
        """
        self.assertEqual(
            {'root': {'child': {'@attr': 'value'}}},
            element_to_dict(
                L.root(L.child(attr='value'))))
Exemple #8
0
    def test_children_text(self):
        """
        Child elements are recursively nested.

        An element containing only text content, has its text keyed against its
        tag name.
        """
        self.assertEqual(
            {'root': {'child': 'hello'}},
            element_to_dict(
                L.root(L.child('hello'))))
Exemple #9
0
    def test_children_attributes(self):
        """
        Child elements are recursively nested.

        An element containing only attributes, and no content, has its
        attributes, prefixed with an ``@`` keyed against its tag name.
        """
        self.assertEqual({'root': {
            'child': {
                '@attr': 'value'
            }
        }}, element_to_dict(L.root(L.child(attr='value'))))
Exemple #10
0
    def test_children_text_attributes(self):
        """
        Child elements are recursively nested.

        An element containing attributes and text content, has its
        attributes, prefixed with an ``@`` keyed against its tag name and its
        text keyed against ``#text``.
        """
        self.assertEqual(
            {'root': {
                'child': {
                    '#text': 'hello',
                    '@attr': 'value'
                }
            }}, element_to_dict(L.root(L.child('hello', attr='value'))))