Author: gchapelle
Date: Wed Nov 16 14:42:12 2005
New Revision: 1839

Modified:
   azax/trunk/azaxresponse.py
   azax/trunk/tests/test_azaxresponse.py
Log:
tests for all elementtree implementations



Modified: azax/trunk/azaxresponse.py
==============================================================================
--- azax/trunk/azaxresponse.py  (original)
+++ azax/trunk/azaxresponse.py  Wed Nov 16 14:42:12 2005
@@ -23,7 +23,7 @@
 from zope.interface import implements
 
 from interfaces import IAzaxResponse
-from config import etree
+import config
 
 class AzaxSelector:
     """ azax selector
@@ -32,6 +32,7 @@
     """
 
     def __init__(self, selectors_ob, selector):
+        etree = config.etree
         self.ob = etree.SubElement(selectors_ob, 'selector')
         self.value = etree.SubElement(self.ob, 'value')
         self.commands = etree.SubElement(self.ob, 'commands')
@@ -42,11 +43,13 @@
 
 class AzaxCommand:
     def __init__(self, commands_ob, name):
+        etree = config.etree
         self.ob = etree.SubElement(commands_ob, 'command')
         name_ob = etree.SubElement(self.ob, 'name')
         name_ob.text = name
 
     def addData(self, name):
+        etree = config.etree
         data = etree.SubElement(self.ob, 'data')
         data.set('name', name)
         return data
@@ -58,12 +61,14 @@
     implements(IAzaxResponse)
 
     def __init__(self, response=None):
+        etree = config.etree
         self._selectors = etree.Element('selectors')
         self.selectors = {}
         self._response = response
 
     def __str__(self):
         """ renders the xml """
+        etree = config.etree
         return etree.tostring(self._selectors)
 
     def __call__(self):
@@ -101,6 +106,7 @@
 
     def wrapInHtmlNamespace(self, new_value, data):
         new_value = '<root>%s</root>' % new_value
+        etree = config.etree
         valuetree = etree.fromstring(new_value)
         data.text = valuetree.text
         for elem in valuetree.getchildren():

Modified: azax/trunk/tests/test_azaxresponse.py
==============================================================================
--- azax/trunk/tests/test_azaxresponse.py       (original)
+++ azax/trunk/tests/test_azaxresponse.py       Wed Nov 16 14:42:12 2005
@@ -23,7 +23,7 @@
 from Testing.ZopeTestCase import ZopeTestCase
 
 from Products.azax.azaxresponse import AzaxResponse
-from Products.azax.config import etree
+from Products.azax import config 
 
 class FakeResponse:
     _stuff = {}
@@ -50,7 +50,7 @@
         self.assertEquals(self.cleanupXMLForTesting(str(ob)),
          
'<selectors><selector><value>div.class</value><commands/></selector></selectors>')
 
-        
self.assertEquals(self.cleanupXMLForTesting(etree.tostring(selector.ob)),
+        
self.assertEquals(self.cleanupXMLForTesting(config.etree.tostring(selector.ob)),
          '<selector><value>div.class</value><commands/></selector>')
 
     def test_setHtmlAsChildTextOnly(self):
@@ -106,9 +106,41 @@
         ob()
         self.assertEquals(response._stuff['Content-Type'], 'text/xml')
 
+class ElementTreeTestCase(AzaxResponseTestCase):
+    def __init__(self, methodName):
+        from elementtree import ElementTree as etree
+        config.etree = etree
+        AzaxResponseTestCase.__init__(self, methodName)
+
+class CElementTreeTestCase(AzaxResponseTestCase):
+    def __init__(self, methodName):
+        import cElementTree as etree
+        config.etree = etree
+        AzaxResponseTestCase.__init__(self, methodName)
+
+class LxmlTestCase(AzaxResponseTestCase):
+    def __init__(self, methodName):
+        from lxml import etree
+        config.etree = etree
+        AzaxResponseTestCase.__init__(self, methodName)
+
 def test_suite():
-    return unittest.TestSuite((
-        unittest.makeSuite(AzaxResponseTestCase),
-        doctest.DocTestSuite('Products.azax.azaxresponse'),
-        ))
+    suites = []
+    try:
+        from lxml import etree
+        suites.append(unittest.makeSuite(LxmlTestCase))
+    except ImportError:
+        pass
+    try:
+        from elementtree import ElementTree as etree
+        suites.append(unittest.makeSuite(ElementTreeTestCase))
+    except ImportError:
+        pass
+    try:
+        import cElementTree as etree
+        suites.append(unittest.makeSuite(CElementTreeTestCase))
+    except ImportError:
+        pass
+    suites.append(doctest.DocTestSuite('Products.azax.azaxresponse'))
+    return unittest.TestSuite(suites)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to