basic_test.py :  » XML » 4Suite » 4Suite-XML-1.0.2 » test » Xml » XPointer » 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 » XPointer » basic_test.py
import os, string
from xml.dom import Node
from Ft.Lib import Uri,UriException

def Test(tester):
    base_uri = Uri.OsPathToUri(__file__, attemptAbsolute=True)
    tester.startTest('Creating test environment')
    from Ft.Xml import XPointer
    from Ft.Xml import Domlette
    r = Domlette.NonvalidatingReader
    doc_uri = Uri.Absolutize('addrbook.xml', base_uri)
    doc = r.parseUri(doc_uri)
    ADDRBOOK = doc.documentElement
    elementType = lambda n, nt=Node.ELEMENT_NODE: n.nodeType == nt
    ENTRIES = filter(elementType, ADDRBOOK.childNodes)
    PA = ENTRIES[0]
    children = filter(elementType, PA.childNodes)
    PA_NAME = children[0]
    PA_ADDR = children[1]
    PA_WORK = children[2]
    PA_FAX = children[3]
    PA_PAGER = children[4]
    PA_EMAIL = children[5]
    EN = ENTRIES[1]
    children = filter(elementType, EN.childNodes)
    EN_NAME = children[0]
    EN_ADDR = children[1]
    EN_WORK = children[2]
    EN_FAX = children[3]
    EN_PAGER = children[4]
    EN_EMAIL = children[5]

    VZ = ENTRIES[2]


    tester.testDone()

    # Just one; it can be too confusing to compare much else
    # because the documents are different
    uri = Uri.Absolutize('addrbook.xml#element(/1)', base_uri)
    tester.startTest('SelectUri(%s)' % uri)
    result = XPointer.SelectUri(uri)
    tester.compare(1, len(result))
    tester.compare(ADDRBOOK.nodeName, result[0].nodeName)
    tester.testDone()

    tester.startTest('SelectNode()')
    frag = 'element(pa/2)'
    result = XPointer.SelectNode(doc, frag)
    tester.compare([PA_ADDR], result, 'frag=%s' % frag)

    frag = 'xpointer(//ENTRY[@ID="en"]/EMAIL)'
    result = XPointer.SelectNode(doc, frag)
    tester.compare([EN_EMAIL], result, 'frag=%s' % frag)
    tester.testDone()

    if tester.offline:
        # No further testing
        return

    tester.startTest('Testing remote lookup')
    nss = {'xsl':'http://www.w3.org/1999/XSL/Transform'}
    uri = "http://www.w3.org/Style/XSL/stylesheets/public2html.xsl#xpointer(//xsl:template[@match='/'])"
    try:
        result = XPointer.SelectUri(uri, nss=nss)
    except UriException, error:
        if error.errorCode != UriException.RESOURCE_ERROR:
            raise
        tester.warning("No internet connection available")
    else:
        tester.compare(1, len(result), 'Wrong number of subresources')
        compared = result[0].localName
        tester.compare('template', compared, 'Wrong localName')
        compared = result[0].attributes[(None, 'match')].value
        tester.compare('/', compared, 'Wrong attribute')
    tester.testDone()
    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.