[Zope3-checkins] CVS: zopeproducts/xml/dom/tests - __init__.py:1.1 test_contextwrapperpain.py:1.1 test_dom.py:1.1

Philipp von Weitershausen philikon@philikon.de
Fri, 20 Jun 2003 11:11:39 -0400


Update of /cvs-repository/zopeproducts/xml/dom/tests
In directory cvs.zope.org:/tmp/cvs-serv15767/xml/dom/tests

Added Files:
	__init__.py test_contextwrapperpain.py test_dom.py 
Log Message:
Moved the xml_examples, xslt, xslt_examples and xmldom products to one
xml product.


=== Added File zopeproducts/xml/dom/tests/__init__.py ===
# this is a package 


=== Added File zopeproducts/xml/dom/tests/test_contextwrapperpain.py ===
##############################################################################
#
# Copyright (c) 2001-2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test that checks the fragility of using context wrappers to
indicate tree hierarchy.

The current implementation of the DOM uses context wrappers to
store references to a node's parent node.  While this allows very
efficient access to the parent, it is fragile in the case of multiple
wrappers referring to the same node.  If client code holds two
wrappers for a node and modifies the node's position in the tree using
one of them, the other will store incorrect information on the shape
of the tree.

For context wrappers to be used to adequately present the
containment hierarchy for a node, a complete chain of wrappers would
need to be constructed each time a node is reparented, starting from
the outermost node in the ancestor chain.  Application code would need
to be wary that old references to a node are replaced by the new
wrapper.  The Python DOM API makes no such requirement at the present
time, nor should it need to.

This script shows a contrived example that exercises this DOM bug.
While this particular code is unlikely in real applications, the ease
with which multiple context wrappers can be produced in more
complex application code is easy to see.

"""

import unittest

from zopeproducts.xml.dom.expatbuilder import ExpatBuilder

class ContextWrapperPain(unittest.TestCase):

    def setUp(self):
        self.doc = ExpatBuilder().parseString("<doc><e1/><e2/></doc>")

# uncomment this code if you want to see a test failure..

##     def checkParentReferenceIntegrity(self):
##         e1a = self.doc.documentElement.firstChild
##         e1b = self.doc.documentElement.firstChild
##         e2 = e1b.nextSibling
##         e2.appendChild(e1b)
##         assert e1a.parentNode.isSameNode(e1b.parentNode), \
##                "Two references to the same node return different parent nodes."

def test_suite():
    """Return a test suite for the Zope testing framework."""

    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(ContextWrapperPain, 'check'))
    return suite



=== Added File zopeproducts/xml/dom/tests/test_dom.py ===
##############################################################################
#
# Copyright (c) 2001-2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

from zopeproducts.xml.dom.core import theDOMImplementation
from zopeproducts.xml.dom.expatbuilder import ExpatBuilder
from domapi.suite import DOMImplementationTestSuite

from StringIO import StringIO

def xmldomParseString(self, xml):
    file = StringIO(xml)
    return ExpatBuilder().parseFile(file)

def test_suite():
    '''Return a test suite for the Zope testing framework.'''
    return DOMImplementationTestSuite(theDOMImplementation, xmldomParseString)