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'))))
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'))))
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'))))
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'))))
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'))))
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'))))
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'))))
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'))))
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'))))
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'))))