summaryrefslogtreecommitdiff
path: root/src/lxml/tests/test_incremental_xmlfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/lxml/tests/test_incremental_xmlfile.py')
-rw-r--r--src/lxml/tests/test_incremental_xmlfile.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/lxml/tests/test_incremental_xmlfile.py b/src/lxml/tests/test_incremental_xmlfile.py
index 81f49ac6..c2f162b2 100644
--- a/src/lxml/tests/test_incremental_xmlfile.py
+++ b/src/lxml/tests/test_incremental_xmlfile.py
@@ -2,11 +2,9 @@
"""
Tests for the incremental XML serialisation API.
-
-Tests require Python 2.5 or later.
"""
-from __future__ import with_statement
+from __future__ import with_statement, absolute_import
import unittest
import tempfile, os, sys
@@ -17,7 +15,8 @@ this_dir = os.path.dirname(__file__)
if this_dir not in sys.path:
sys.path.insert(0, this_dir) # needed for Py3
-from common_imports import etree, BytesIO, HelperTestCase, skipIf
+from .common_imports import etree, BytesIO, HelperTestCase, skipIf, _str
+
class _XmlFileTestCaseBase(HelperTestCase):
_file = None # to be set by specific subtypes below
@@ -454,6 +453,20 @@ class HtmlFileTestCase(_XmlFileTestCaseBase):
'</root>')
self._file = BytesIO()
+ def test_attribute_quoting(self):
+ with etree.htmlfile(self._file) as xf:
+ with xf.element("tagname", attrib={"attr": '"misquoted"'}):
+ xf.write("foo")
+
+ self.assertXml('<tagname attr="&quot;misquoted&quot;">foo</tagname>')
+
+ def test_attribute_quoting_unicode(self):
+ with etree.htmlfile(self._file) as xf:
+ with xf.element("tagname", attrib={"attr": _str('"misquöted\\u3344\\U00013344"')}):
+ xf.write("foo")
+
+ self.assertXml('<tagname attr="&quot;misqu&#246;ted&#13124;&#78660;&quot;">foo</tagname>')
+
def test_unescaped_script(self):
with etree.htmlfile(self._file) as xf:
elt = etree.Element('script')