Skip to content

Commit

Permalink
Merge pull request #35 from gisce/root_with_attributes
Browse files Browse the repository at this point in the history
Root with attributes
  • Loading branch information
ecarreras committed Feb 10, 2015
2 parents 803c98a + 13186e3 commit 3a0ef57
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions libcomxml/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def build_tree(self):
"""
if self.built:
return
self.doc_root = self.root.element()
for key in self.sorted_fields():
if not key in self._fields:
continue
Expand Down
5 changes: 0 additions & 5 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
# -*- coding: utf-8 -*-
import sys

if sys.version_info[:2] < (2, 7):
import unittest2 as unittest
else:
import unittest
30 changes: 29 additions & 1 deletion tests/test_libcomxml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
from . import unittest
import sys

if sys.version_info[:2] < (2, 7):
import unittest2 as unittest
else:
import unittest
import locale
import re
from libcomxml.core import XmlField, XmlModel, clean_xml
Expand Down Expand Up @@ -185,3 +190,26 @@ def __init__(self):
feed.build_tree()

self.assertEqual(self.xml, str(feed))


class RootWithAttributes(unittest.TestCase):

def setUp(self):
self.xml = "<?xml version='1.0' encoding='UTF-8'?>\n"
self.xml += "<link href=\"http://example.com\"/>"

def test_root_with_attributes(self):

class Link(XmlModel):

_sort_order = ('tag', )

def __init__(self):
self.tag = XmlField('link')
super(Link, self).__init__('Link', 'tag', drop_empty=False)

l = Link()
l.tag.attributes.update({'href': 'http://example.com'})
l.build_tree()

self.assertEqual(self.xml, str(l))

0 comments on commit 3a0ef57

Please sign in to comment.