Skip to content

Commit 3a0ef57

Browse files
committed
Merge pull request #35 from gisce/root_with_attributes
Root with attributes
2 parents 803c98a + 13186e3 commit 3a0ef57

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

libcomxml/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def build_tree(self):
228228
"""
229229
if self.built:
230230
return
231+
self.doc_root = self.root.element()
231232
for key in self.sorted_fields():
232233
if not key in self._fields:
233234
continue

tests/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
import sys
32

4-
if sys.version_info[:2] < (2, 7):
5-
import unittest2 as unittest
6-
else:
7-
import unittest

tests/test_libcomxml.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
from . import unittest
2+
import sys
3+
4+
if sys.version_info[:2] < (2, 7):
5+
import unittest2 as unittest
6+
else:
7+
import unittest
38
import locale
49
import re
510
from libcomxml.core import XmlField, XmlModel, clean_xml
@@ -185,3 +190,26 @@ def __init__(self):
185190
feed.build_tree()
186191

187192
self.assertEqual(self.xml, str(feed))
193+
194+
195+
class RootWithAttributes(unittest.TestCase):
196+
197+
def setUp(self):
198+
self.xml = "<?xml version='1.0' encoding='UTF-8'?>\n"
199+
self.xml += "<link href=\"http://example.com\"/>"
200+
201+
def test_root_with_attributes(self):
202+
203+
class Link(XmlModel):
204+
205+
_sort_order = ('tag', )
206+
207+
def __init__(self):
208+
self.tag = XmlField('link')
209+
super(Link, self).__init__('Link', 'tag', drop_empty=False)
210+
211+
l = Link()
212+
l.tag.attributes.update({'href': 'http://example.com'})
213+
l.build_tree()
214+
215+
self.assertEqual(self.xml, str(l))

0 commit comments

Comments
 (0)