This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-issue-0092: add reproducing case
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
import logging | ||
import pyxb.binding.generate | ||
import pyxb.utils.domutils | ||
import xml.dom.minidom as dom | ||
|
||
|
||
if __name__ == '__main__': | ||
logging.basicConfig() | ||
_log = logging.getLogger(__name__) | ||
|
||
xsd = '''<?xml version="1.0" encoding="UTF-8"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<xs:element name="HOST"> | ||
<xs:complexType> | ||
<xs:sequence> | ||
<xs:element name="ID" type="xs:integer"/> | ||
<xs:element name="TEMPLATE" type="xs:anyType"/> | ||
</xs:sequence> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:schema> | ||
''' | ||
|
||
code = pyxb.binding.generate.GeneratePython(schema_text=xsd) | ||
|
||
rv = compile(code, 'test', 'exec') | ||
eval(rv) | ||
|
||
import unittest | ||
|
||
class TestIssue0092 (unittest.TestCase): | ||
def testCreateEmptyTemplate (self): | ||
xmlt = '<HOST><ID>1</ID><TEMPLATE/></HOST>'; | ||
xmld = xmlt.encode('utf-8'); | ||
doc = CreateFromDocument(xmld); | ||
self.assertEqual(doc.ID,1) | ||
|
||
def testCreateToDom (self): | ||
xmlt = '<HOST><ID>1</ID><TEMPLATE><NODE>1</NODE></TEMPLATE></HOST>'; | ||
xmld = xmlt.encode('utf-8'); | ||
doc = CreateFromDocument(xmld); | ||
templateFragment=doc.TEMPLATE.toDOM() | ||
self.assertEqual(templateFragment.toxml(), '''<?xml version="1.0" ?><TEMPLATE><NODE>1</NODE></TEMPLATE>''') | ||
|
||
def testCreateWithCDATAToDom (self): | ||
xmlt = '<HOST><ID>1</ID><TEMPLATE><NODE><![CDATA[text]]></NODE></TEMPLATE></HOST>'; | ||
xmld = xmlt.encode('utf-8'); | ||
doc = CreateFromDocument(xmld); | ||
templateFragment=doc.TEMPLATE.toDOM() | ||
self.assertEqual(templateFragment.toxml(), '''<?xml version="1.0" ?><TEMPLATE><NODE>text</NODE></TEMPLATE>''') | ||
|
||
def testCreateFromDOMWithCDATAToDom (self): | ||
xmlt = '<HOST><ID>1</ID><TEMPLATE><NODE><![CDATA[text]]></NODE></TEMPLATE></HOST>'; | ||
xmld = xmlt.encode('utf-8'); | ||
domDoc=dom.parseString(xmld); | ||
doc = CreateFromDOM(domDoc); | ||
templateFragment=doc.TEMPLATE.toDOM() | ||
self.assertEqual(templateFragment.toxml(), '''<?xml version="1.0" ?><TEMPLATE><NODE>text</NODE></TEMPLATE>''') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |