uo 051205.py :  » XML » 4Suite » 4Suite-XML-1.0.2 » test » Xml » Borrowed » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » XML » 4Suite 
4Suite » 4Suite XML 1.0.2 » test » Xml » Borrowed » uo-051205.py
import cStringIO
from Ft.Xml.Domlette import implementation,Print,PrettyPrint

EXPECTED1_PRINTED = """\
<?xml version="1.0" encoding="UTF-8"?>
<x:foo xmlns:x="http://example.com/1"><bar/></x:foo>"""

EXPECTED1_PRETTY = """\
<?xml version="1.0" encoding="UTF-8"?>
<x:foo xmlns:x="http://example.com/1">
  <bar/>
</x:foo>
"""

EXPECTED2_PRINTED = """\
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns="http://example.com/1"><bar xmlns=""/></foo>"""

EXPECTED2_PRETTY = """\
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns="http://example.com/1">
  <bar xmlns=""/>
</foo>
"""

EXPECTED3_PRINTED = """\
<?xml version="1.0" encoding="UTF-8"?>
<foo><bar xmlns="http://example.com/1"/></foo>"""

EXPECTED3_PRETTY = """\
<?xml version="1.0" encoding="UTF-8"?>
<foo>
  <bar xmlns="http://example.com/1"/>
</foo>
"""

EXPECTED4_PRINTED = """\
<?xml version="1.0" encoding="UTF-8"?>
<foo><bar xmlns="http://example.com/1"><baz xmlns=""/></bar></foo>"""

EXPECTED4_PRETTY = """\
<?xml version="1.0" encoding="UTF-8"?>
<foo>
  <bar xmlns="http://example.com/1">
    <baz xmlns=""/>
  </bar>
</foo>
"""


def Test(tester):
    tester.startGroup('Uche finds nested default namespace munging')
    doc = implementation.createDocument(None, None, None)
    elem1 = doc.createElementNS("http://example.com/1", "x:foo")
    doc.appendChild(elem1)
    elem2 = doc.createElementNS(None, "bar")
    elem1.appendChild(elem2)
    tester.startTest('Outer with prefix.  Print')
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED1_PRINTED, result)
    tester.testDone()
    tester.startTest('Outer with prefix.  PrettyPrint')
    stream = cStringIO.StringIO()
    PrettyPrint(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED1_PRETTY, result)
    tester.testDone()

    doc = implementation.createDocument(None, None, None)
    elem1 = doc.createElementNS("http://example.com/1", "foo")
    doc.appendChild(elem1)
    elem2 = doc.createElementNS(None, "bar")
    elem1.appendChild(elem2)
    tester.startTest('Outer without prefix.  Print')
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED2_PRINTED, result)
    tester.testDone()
    tester.startTest('Outer without prefix.  PrettyPrint')
    stream = cStringIO.StringIO()
    PrettyPrint(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED2_PRETTY, result)
    tester.testDone()

    doc = implementation.createDocument(None, None, None)
    elem1 = doc.createElementNS(None, "foo")
    doc.appendChild(elem1)
    elem2 = doc.createElementNS("http://example.com/1", "bar")
    elem1.appendChild(elem2)
    tester.startTest('outer no prefix or ns, inner ns no prefix.  Print')
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED3_PRINTED, result)
    tester.testDone()
    tester.startTest('outer no prefix or ns, inner ns no prefix.  PrettyPrint')
    stream = cStringIO.StringIO()
    PrettyPrint(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED3_PRETTY, result)
    tester.testDone()

    doc = implementation.createDocument(None, None, None)
    elem1 = doc.createElementNS(None, "foo")
    doc.appendChild(elem1)
    elem2 = doc.createElementNS("http://example.com/1", "bar")
    elem1.appendChild(elem2)
    elem3 = doc.createElementNS(None, "baz")
    elem2.appendChild(elem3)
    tester.startTest('outer no prefix or ns, then ns no prefix then no prefix no ns.  Print')
    stream = cStringIO.StringIO()
    Print(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED4_PRINTED, result)
    tester.testDone()
    tester.startTest('outer no prefix or ns, then ns no prefix then no prefix no ns.  PrettyPrint')
    stream = cStringIO.StringIO()
    PrettyPrint(doc, stream=stream)
    result = stream.getvalue()
    tester.compare(EXPECTED4_PRETTY, result)
    tester.testDone()
    tester.groupDone()
    return


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.