[Checkins] SVN: zope.webdav/trunk/src/zope/webdav/ Use the recent changes to zope.etree to make some of the tests in zope.webdav

Michael Kerrin michael.kerrin at openapp.biz
Wed Apr 4 14:24:59 EDT 2007


Log message for revision 74011:
  Use the recent changes to zope.etree to make some of the tests in zope.webdav
  more readable.
  

Changed:
  U   zope.webdav/trunk/src/zope/webdav/datamodel.txt
  U   zope.webdav/trunk/src/zope/webdav/tests/test_doctests.py
  U   zope.webdav/trunk/src/zope/webdav/utils.py

-=-
Modified: zope.webdav/trunk/src/zope/webdav/datamodel.txt
===================================================================
--- zope.webdav/trunk/src/zope/webdav/datamodel.txt	2007-04-04 18:20:41 UTC (rev 74010)
+++ zope.webdav/trunk/src/zope/webdav/datamodel.txt	2007-04-04 18:24:58 UTC (rev 74011)
@@ -57,8 +57,7 @@
   >>> import zope.webdav.publisher
   >>> import zope.webdav.widgets
   >>> from cStringIO import StringIO
-  >>> from zope.etree.testing import etreeSetup, etreeTearDown, assertXMLEqual
-  >>> etree = etreeSetup()
+
   >>> component.getGlobalSiteManager().registerAdapter(
   ...    zope.webdav.widgets.IntDAVWidget,
   ...    (zope.schema.interfaces.IInt, zope.webdav.interfaces.IWebDAVRequest),
@@ -149,8 +148,8 @@
 render this type of property.
 
   >>> davwidget = zope.webdav.properties.getWidget(prop, adapter, request)
-  >>> assertXMLEqual(davwidget.render(),
-  ...    """<E:age xmlns:E="examplens:">10</E:age>""")
+  >>> print etree.tostring(davwidget.render()) #doctest:+XMLDATA
+  <E:age xmlns:E="examplens:">10</E:age>
 
 Finally the *zope.webdav.properties.getAllProperties* method contains one entry:
 
@@ -377,4 +376,3 @@
   True
   >>> component.getGlobalSiteManager().unregisterAdapter(DeadProperties)
   True
-  >>> etreeTearDown()

Modified: zope.webdav/trunk/src/zope/webdav/tests/test_doctests.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/tests/test_doctests.py	2007-04-04 18:20:41 UTC (rev 74010)
+++ zope.webdav/trunk/src/zope/webdav/tests/test_doctests.py	2007-04-04 18:24:58 UTC (rev 74011)
@@ -34,7 +34,7 @@
      queryInteraction
 from zope.traversing.browser.interfaces import IAbsoluteURL
 
-from zope.etree.testing import etreeSetup, etreeTearDown
+import zope.etree.testing
 
 
 class IDemo(IContained):
@@ -192,9 +192,14 @@
         doctest.DocTestSuite("zope.webdav.properties",
                              setUp = contentSetup, tearDown = contentTeardown),
         doctest.DocTestSuite("zope.webdav.utils",
-                             setUp = etreeSetup, tearDown = etreeTearDown),
+                             checker = zope.etree.testing.xmlOutputChecker,
+                             setUp = zope.etree.testing.etreeSetup,
+                             tearDown = zope.etree.testing.etreeTearDown),
         doctest.DocTestSuite("zope.webdav.coreproperties"),
-        doctest.DocFileSuite("datamodel.txt", package = "zope.webdav"),
+        doctest.DocFileSuite("datamodel.txt", package = "zope.webdav",
+                             checker = zope.etree.testing.xmlOutputChecker,
+                             setUp = zope.etree.testing.etreeSetup,
+                             tearDown = zope.etree.testing.etreeTearDown),
         doctest.DocTestSuite("zope.webdav.lockingutils",
                              setUp = lockingSetUp, tearDown = lockingTearDown),
         doctest.DocTestSuite("zope.webdav.deadproperties"),

Modified: zope.webdav/trunk/src/zope/webdav/utils.py
===================================================================
--- zope.webdav/trunk/src/zope/webdav/utils.py	2007-04-04 18:20:41 UTC (rev 74010)
+++ zope.webdav/trunk/src/zope/webdav/utils.py	2007-04-04 18:24:58 UTC (rev 74011)
@@ -33,8 +33,6 @@
 """
 __docformat__ = 'restructuredtext'
 
-import types
-
 from zope import component
 from zope import interface
 from zope.publisher.http import status_reasons
@@ -67,6 +65,7 @@
         """Render this propstat object to a etree XML element.
         """
 
+
 class IResponse(interface.Interface):
     """Helper object to render a response XML element.
     """
@@ -152,20 +151,29 @@
 
 def makedavelement(tagname, text_or_el = None):
     """
-      >>> assertXMLEqual(etree.tostring(makedavelement('foo')),
-      ...    '<ns0:foo xmlns:ns0="DAV:" />')
-      >>> assertXMLEqual(etree.tostring(makedavelement('foo', 'foo content')),
-      ...    '<ns0:foo xmlns:ns0="DAV:">foo content</ns0:foo>')
+      >>> etree.tostring(makedavelement('foo')) #doctest:+XMLDATA
+      '<foo xmlns="DAV:" />'
+
+      >>> etree.tostring(makedavelement('foo', 'foo content')) #doctest:+XMLDATA
+      '<foo xmlns="DAV:">foo content</foo>'
     """
     return makeelement('DAV:', tagname, text_or_el)
 
 
 def makestatuselement(status):
     """
-      >>> etree.tostring(makestatuselement(200))
-      '<ns0:status xmlns:ns0="DAV:">HTTP/1.1 200 OK</ns0:status>'
+      >>> etree.tostring(makestatuselement(200)) #doctest:+XMLDATA
+      '<status xmlns="DAV:">HTTP/1.1 200 OK</status>'
+
+      >>> etree.tostring(makestatuselement(200L)) #doctest:+XMLDATA
+      '<status xmlns="DAV:">HTTP/1.1 200 OK</status>'
+
+    Do we want this?
+
+      >>> etree.tostring(makestatuselement('XXX')) #doctest:+XMLDATA
+      '<status xmlns="DAV:">XXX</status>'
     """
-    if isinstance(status, types.IntType):
+    if isinstance(status, (int, long)):
         status = 'HTTP/1.1 %d %s' %(status, status_reasons[status])
 
     return makedavelement('status', status)
@@ -201,20 +209,48 @@
       >>> pstat.status = 200
 
       >>> pstat.properties.append(makedavelement(u'testprop', u'Test Property'))
-      >>> assertXMLEqual(etree.tostring(pstat()),
-      ...    '<ns0:propstat xmlns:ns0="DAV:"><ns0:prop><ns0:testprop>Test Property</ns0:testprop></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat>')
+      >>> print etree.tostring(pstat()) #doctest:+XMLDATA
+      <propstat xmlns="DAV:">
+        <prop>
+          <testprop>Test Property</testprop>
+        </prop>
+        <status>HTTP/1.1 200 OK</status>
+      </propstat>
 
       >>> pstat.properties.append(makedavelement(u'test2', u'Second Test'))
-      >>> assertXMLEqual(etree.tostring(pstat()),
-      ...    '<ns0:propstat xmlns:ns0="DAV:"><ns0:prop><ns0:testprop>Test Property</ns0:testprop><ns0:test2>Second Test</ns0:test2></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat>')
+      >>> print etree.tostring(pstat()) #doctest:+XMLDATA
+      <propstat xmlns="DAV:">
+        <prop>
+          <testprop>Test Property</testprop>
+          <test2>Second Test</test2>
+        </prop>
+        <status>HTTP/1.1 200 OK</status>
+      </propstat>
 
       >>> pstat.responsedescription = u'This is ok'
-      >>> assertXMLEqual(etree.tostring(pstat()),
-      ...    '<ns0:propstat xmlns:ns0="DAV:"><ns0:prop><ns0:testprop>Test Property</ns0:testprop><ns0:test2>Second Test</ns0:test2></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status><ns0:responsedescription>This is ok</ns0:responsedescription></ns0:propstat>')
+      >>> print etree.tostring(pstat()) #doctest:+XMLDATA
+      <propstat xmlns="DAV:">
+        <prop>
+          <testprop>Test Property</testprop>
+          <test2>Second Test</test2>
+        </prop>
+        <status>HTTP/1.1 200 OK</status>
+        <responsedescription>This is ok</responsedescription>
+      </propstat>
 
       >>> pstat.error = [makedavelement(u'precondition-error')]
-      >>> assertXMLEqual(etree.tostring(pstat()),
-      ...     '<ns0:propstat xmlns:ns0="DAV:"><ns0:prop><ns0:testprop>Test Property</ns0:testprop><ns0:test2>Second Test</ns0:test2></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status><ns0:error><ns0:precondition-error /></ns0:error><ns0:responsedescription>This is ok</ns0:responsedescription></ns0:propstat>')
+      >>> print etree.tostring(pstat()) #doctest:+XMLDATA
+      <propstat xmlns="DAV:">
+        <prop>
+          <testprop>Test Property</testprop>
+          <test2>Second Test</test2>
+        </prop>
+        <status>HTTP/1.1 200 OK</status>
+        <error>
+          <precondition-error />
+        </error>
+        <responsedescription>This is ok</responsedescription>
+      </propstat>
 
     The status must be set.
 
@@ -271,13 +307,22 @@
       >>> response = Response('/container')
       >>> verifyObject(IResponse, response)
       True
-      >>> assertXMLEqual(etree.tostring(response()),
-      ...                '<ns0:response xmlns:ns0="DAV:"><ns0:href>/container</ns0:href></ns0:response>')
+
+      >>> print etree.tostring(response()) #doctest:+XMLDATA
+      <response xmlns="DAV:">
+        <href>/container</href>
+      </response>
+
       >>> response.status = 200
       >>> response.href.append('/container2')
-      >>> assertXMLEqual(etree.tostring(response()),
-      ...                '<ns0:response xmlns:ns0="DAV:"><ns0:href>/container</ns0:href><ns0:href>/container2</ns0:href><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:response>')
 
+      >>> print etree.tostring(response()) #doctest:+XMLDATA
+      <response xmlns="DAV:">
+        <href>/container</href>
+        <href>/container2</href>
+        <status>HTTP/1.1 200 OK</status>
+      </response>
+
     The response XML element can contain a number of Propstat elements
     organized by status code.
 
@@ -290,20 +335,91 @@
       >>> pstat2.status = 404
       >>> pstat2.properties.append(makedavelement(u'test2'))
       >>> response.addPropstats(404, pstat2)
-      >>> assertXMLEqual(etree.tostring(response()),
-      ... '<ns0:response xmlns:ns0="DAV:"><ns0:href>/container</ns0:href><ns0:propstat><ns0:prop><ns0:test1>test one</ns0:test1></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat><ns0:propstat><ns0:prop><ns0:test2 /></ns0:prop><ns0:status>HTTP/1.1 404 Not Found</ns0:status></ns0:propstat></ns0:response>')
 
+      >>> print etree.tostring(response()) #doctest:+XMLDATA
+      <response xmlns="DAV:">
+        <href>/container</href>
+        <propstat>
+          <prop>
+            <test1>test one</test1>
+          </prop>
+          <status>HTTP/1.1 200 OK</status>
+        </propstat>
+        <propstat>
+          <prop>
+            <test2 />
+          </prop>
+          <status>HTTP/1.1 404 Not Found</status>
+        </propstat>
+      </response>
+
       >>> response.error = [makedavelement(u'precondition-failed')]
-      >>> assertXMLEqual(etree.tostring(response()),
-      ... '<ns0:response xmlns:ns0="DAV:"><ns0:href>/container</ns0:href><ns0:propstat><ns0:prop><ns0:test1>test one</ns0:test1></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat><ns0:propstat><ns0:prop><ns0:test2 /></ns0:prop><ns0:status>HTTP/1.1 404 Not Found</ns0:status></ns0:propstat><ns0:error><ns0:precondition-failed /></ns0:error></ns0:response>')
+      >>> print etree.tostring(response()) #doctest:+XMLDATA
+      <response xmlns="DAV:">
+        <href>/container</href>
+        <propstat>
+          <prop>
+            <test1>test one</test1>
+          </prop>
+          <status>HTTP/1.1 200 OK</status>
+        </propstat>
+        <propstat>
+          <prop>
+            <test2 />
+          </prop>
+          <status>HTTP/1.1 404 Not Found</status>
+        </propstat>
+        <error>
+          <precondition-failed />
+        </error>
+      </response>
 
       >>> response.responsedescription = u'webdav description'
-      >>> assertXMLEqual(etree.tostring(response()),
-      ... '<ns0:response xmlns:ns0="DAV:"><ns0:href>/container</ns0:href><ns0:propstat><ns0:prop><ns0:test1>test one</ns0:test1></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat><ns0:propstat><ns0:prop><ns0:test2 /></ns0:prop><ns0:status>HTTP/1.1 404 Not Found</ns0:status></ns0:propstat><ns0:error><ns0:precondition-failed /></ns0:error><ns0:responsedescription>webdav description</ns0:responsedescription></ns0:response>')
+      >>> print etree.tostring(response()) #doctest:+XMLDATA
+      <response xmlns="DAV:">
+        <href>/container</href>
+        <propstat>
+          <prop>
+            <test1>test one</test1>
+          </prop>
+          <status>HTTP/1.1 200 OK</status>
+        </propstat>
+        <propstat>
+          <prop>
+            <test2 />
+          </prop>
+          <status>HTTP/1.1 404 Not Found</status>
+        </propstat>
+        <error>
+          <precondition-failed />
+        </error>
+        <responsedescription>webdav description</responsedescription>
+      </response>
 
       >>> response.location = '/container2'
-      >>> assertXMLEqual(etree.tostring(response()),
-      ... '<ns0:response xmlns:ns0="DAV:"><ns0:href>/container</ns0:href><ns0:propstat><ns0:prop><ns0:test1>test one</ns0:test1></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat><ns0:propstat><ns0:prop><ns0:test2 /></ns0:prop><ns0:status>HTTP/1.1 404 Not Found</ns0:status></ns0:propstat><ns0:error><ns0:precondition-failed /></ns0:error><ns0:responsedescription>webdav description</ns0:responsedescription><ns0:location><ns0:href>/container2</ns0:href></ns0:location></ns0:response>')
+      >>> print etree.tostring(response()) #doctest:+XMLDATA
+      <response xmlns="DAV:">
+        <href>/container</href>
+        <propstat>
+          <prop>
+            <test1>test one</test1>
+          </prop>
+          <status>HTTP/1.1 200 OK</status>
+        </propstat>
+        <propstat>
+          <prop>
+            <test2 />
+          </prop>
+          <status>HTTP/1.1 404 Not Found</status>
+        </propstat>
+        <error>
+          <precondition-failed />
+        </error>
+        <responsedescription>webdav description</responsedescription>
+        <location>
+          <href>/container2</href>
+        </location>
+      </response>
 
       >>> response = Response('/container1')
       >>> response.href.append('/container2')
@@ -325,15 +441,49 @@
 
       >>> resp = Response('/container')
       >>> resp.addProperty(200, makedavelement(u'testprop', u'Test Property'))
-      >>> assertXMLEqual(etree.tostring(resp()),
-      ... '<ns0:response xmlns:ns0="DAV:"><ns0:href>/container</ns0:href><ns0:propstat><ns0:prop><ns0:testprop>Test Property</ns0:testprop></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat></ns0:response>')
+      >>> print etree.tostring(resp()) #doctest:+XMLDATA
+      <response xmlns="DAV:">
+        <href>/container</href>
+        <propstat>
+          <prop>
+            <testprop>Test Property</testprop>
+          </prop>
+          <status>HTTP/1.1 200 OK</status>
+        </propstat>
+      </response>
+
       >>> resp.addProperty(200, makedavelement(u'testprop2',
       ...                                      u'Test Property Two'))
-      >>> assertXMLEqual(etree.tostring(resp()),
-      ... '<ns0:response xmlns:ns0="DAV:"><ns0:href>/container</ns0:href><ns0:propstat><ns0:prop><ns0:testprop>Test Property</ns0:testprop><ns0:testprop2>Test Property Two</ns0:testprop2></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat></ns0:response>')
+      >>> print etree.tostring(resp()) #doctest:+XMLDATA
+      <response xmlns="DAV:">
+        <href>/container</href>
+        <propstat>
+          <prop>
+            <testprop>Test Property</testprop>
+            <testprop2>Test Property Two</testprop2>
+          </prop>
+          <status>HTTP/1.1 200 OK</status>
+        </propstat>
+      </response>
+
       >>> resp.addProperty(404, makedavelement(u'missing'))
-      >>> assertXMLEqual(etree.tostring(resp()),
-      ... '<ns0:response xmlns:ns0="DAV:"><ns0:href>/container</ns0:href><ns0:propstat><ns0:prop><ns0:testprop>Test Property</ns0:testprop><ns0:testprop2>Test Property Two</ns0:testprop2></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat><ns0:propstat><ns0:prop><ns0:missing /></ns0:prop><ns0:status>HTTP/1.1 404 Not Found</ns0:status></ns0:propstat></ns0:response>')
+      >>> print etree.tostring(resp()) #doctest:+XMLDATA
+      <response xmlns="DAV:">
+        <href>/container</href>
+        <propstat>
+          <prop>
+            <testprop>Test Property</testprop>
+            <testprop2>Test Property Two</testprop2>
+          </prop>
+          <status>HTTP/1.1 200 OK</status>
+          </propstat>
+          <propstat>
+            <prop>
+              <missing />
+            </prop>
+            <status>HTTP/1.1 404 Not Found</status>
+         </propstat>
+       </response>
 
     """
     interface.implements(IResponse)
@@ -401,24 +551,43 @@
       >>> ms = MultiStatus()
       >>> verifyObject(IMultiStatus, ms)
       True
-      >>> assertXMLEqual(etree.tostring(ms()),
-      ... '<ns0:multistatus xmlns:ns0="DAV:" />')
 
+      >>> print etree.tostring(ms()) #doctest:+XMLDATA
+      <ns0:multistatus xmlns:ns0="DAV:" />
+
       >>> ms.responsedescription = u'simple description'
-      >>> assertXMLEqual(etree.tostring(ms()),
-      ... '<ns0:multistatus xmlns:ns0="DAV:"><ns0:responsedescription>simple description</ns0:responsedescription></ns0:multistatus>')
+      >>> print etree.tostring(ms()) #doctest:+XMLDATA
+      <multistatus xmlns="DAV:">
+        <responsedescription>simple description</responsedescription>
+      </multistatus>
 
       >>> response = Response('/container')
       >>> ms.responses.append(response)
-      >>> assertXMLEqual(etree.tostring(ms()),
-      ... '<ns0:multistatus xmlns:ns0="DAV:"><ns0:response><ns0:href>/container</ns0:href></ns0:response><ns0:responsedescription>simple description</ns0:responsedescription></ns0:multistatus>')
+      >>> print etree.tostring(ms()) #doctest:+XMLDATA
+      <multistatus xmlns="DAV:">
+        <response>
+          <href>/container</href>
+        </response>
+        <responsedescription>simple description</responsedescription>
+      </multistatus>
 
       >>> pstat1 = Propstat()
       >>> pstat1.status = 200
       >>> pstat1.properties.append(makedavelement(u'test1', u'test one'))
       >>> response.addPropstats(200, pstat1)
-      >>> assertXMLEqual(etree.tostring(ms()),
-      ... '<ns0:multistatus xmlns:ns0="DAV:"><ns0:response><ns0:href>/container</ns0:href><ns0:propstat><ns0:prop><ns0:test1>test one</ns0:test1></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat></ns0:response><ns0:responsedescription>simple description</ns0:responsedescription></ns0:multistatus>')
+      >>> print etree.tostring(ms()) #doctest:+XMLDATA
+      <multistatus xmlns="DAV:">
+        <response>
+          <href>/container</href>
+          <propstat>
+            <prop>
+              <test1>test one</test1>
+            </prop>
+            <status>HTTP/1.1 200 OK</status>
+          </propstat>
+        </response>
+        <responsedescription>simple description</responsedescription>
+      </multistatus>
 
       >>> response2 = Response('/container2')
       >>> pstat2 = Propstat()
@@ -426,8 +595,28 @@
       >>> pstat2.properties.append(makedavelement(u'test2'))
       >>> response2.addPropstats(404, pstat2)
       >>> ms.responses.append(response2)
-      >>> assertXMLEqual(etree.tostring(ms()),
-      ... '<ns0:multistatus xmlns:ns0="DAV:"><ns0:response><ns0:href>/container</ns0:href>   <ns0:propstat><ns0:prop><ns0:test1>test one</ns0:test1></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat></ns0:response><ns0:response><ns0:href>/container2</ns0:href><ns0:propstat><ns0:prop><ns0:test2 /></ns0:prop><ns0:status>HTTP/1.1 404 Not Found</ns0:status></ns0:propstat></ns0:response><ns0:responsedescription>simple description</ns0:responsedescription></ns0:multistatus>''')
+      >>> print etree.tostring(ms()) #doctest:+XMLDATA
+      <multistatus xmlns="DAV:">
+        <response>
+          <href>/container</href>
+          <propstat>
+            <prop>
+              <test1>test one</test1>
+            </prop>
+            <status>HTTP/1.1 200 OK</status>
+          </propstat>
+        </response>
+        <response>
+          <href>/container2</href>
+          <propstat>
+            <prop>
+              <test2 />
+            </prop>
+            <status>HTTP/1.1 404 Not Found</status>
+          </propstat>
+        </response>
+        <responsedescription>simple description</responsedescription>
+      </multistatus>
 
     """
     interface.implements(IMultiStatus)



More information about the Checkins mailing list