[Checkins] SVN: z3c.etestbrowser/branches/1.2/ fix bug in
normalized_contents with non-xml/empty pages
Christian Theune
ct at gocept.com
Wed Jun 18 06:43:31 EDT 2008
Log message for revision 87500:
fix bug in normalized_contents with non-xml/empty pages
Changed:
U z3c.etestbrowser/branches/1.2/CHANGES.txt
U z3c.etestbrowser/branches/1.2/README.txt
U z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/README.txt
A z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/empty.pt
U z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/ftesting.zcml
A z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/funny.pt
U z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/testing.py
-=-
Modified: z3c.etestbrowser/branches/1.2/CHANGES.txt
===================================================================
--- z3c.etestbrowser/branches/1.2/CHANGES.txt 2008-06-18 09:51:22 UTC (rev 87499)
+++ z3c.etestbrowser/branches/1.2/CHANGES.txt 2008-06-18 10:43:30 UTC (rev 87500)
@@ -1,8 +1,14 @@
-=======
CHANGES
=======
-1.2 (unreleased)
+1.2.1 (unreleased)
+------------------
+
+- Fixed bug with `normalized_contents` which would break the `open` function
+ of test browser if content wasn't parsable as HTML/XML.
+
+
+1.2 (2008-05-29)
----------------
- Added `normalized_contents` attribute that reindents and normalizes the
Modified: z3c.etestbrowser/branches/1.2/README.txt
===================================================================
--- z3c.etestbrowser/branches/1.2/README.txt 2008-06-18 09:51:22 UTC (rev 87499)
+++ z3c.etestbrowser/branches/1.2/README.txt 2008-06-18 10:43:30 UTC (rev 87500)
@@ -7,6 +7,6 @@
external products, like lxml.
Extension: lxml-support
------------------------
+=======================
All HTML pages are parsed and provided as an element-tree.
Modified: z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/README.txt
===================================================================
--- z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/README.txt 2008-06-18 09:51:22 UTC (rev 87499)
+++ z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/README.txt 2008-06-18 10:43:30 UTC (rev 87500)
@@ -64,7 +64,24 @@
>>> browser.etree.xpath("//span")[0].text
u'K\xfcgelblitz.'
+Invalid XML/HTML responses
+--------------------------
+Responses that contain a body with invalid XML/HTML will cause an error when
+accessing the etree or normalized_contents attribute, but will load fine for
+general TestBrowser use:
+
+ >>> browser.open("http://localhost/empty.html")
+ >>> browser.contents
+ ''
+ >>> browser.etree
+ Traceback (most recent call last):
+ XMLSyntaxError: ...
+ >>> browser.normalized_contents
+ Traceback (most recent call last):
+ XMLSyntaxError: ...
+
+
Pretty printing
===============
Copied: z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/empty.pt (from rev 87498, z3c.etestbrowser/trunk/src/z3c/etestbrowser/empty.pt)
===================================================================
Modified: z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/ftesting.zcml
===================================================================
--- z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/ftesting.zcml 2008-06-18 09:51:22 UTC (rev 87499)
+++ z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/ftesting.zcml 2008-06-18 10:43:30 UTC (rev 87500)
@@ -37,4 +37,11 @@
permission="zope.View"
/>
+ <browser:page
+ name="empty.html"
+ for="*"
+ template="empty.pt"
+ permission="zope.View"
+ />
+
</configure>
Copied: z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/funny.pt (from rev 87498, z3c.etestbrowser/trunk/src/z3c/etestbrowser/funny.pt)
===================================================================
--- z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/funny.pt (rev 0)
+++ z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/funny.pt 2008-06-18 10:43:30 UTC (rev 87500)
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>Foo</title>
+</head>
+ <body>
+ <h1>
+ Title
+ </h1>
+ </body>
+ </html>
Modified: z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/testing.py
===================================================================
--- z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/testing.py 2008-06-18 09:51:22 UTC (rev 87499)
+++ z3c.etestbrowser/branches/1.2/src/z3c/etestbrowser/testing.py 2008-06-18 10:43:30 UTC (rev 87500)
@@ -55,9 +55,9 @@
"""
xml_strict = False
- normalized_contents = ''
_etree = None
+ _normalized_contents = None
@property
def etree(self):
@@ -82,12 +82,18 @@
return self._etree
+ @property
+ def normalized_contents(self):
+ if self._normalized_contents is None:
+ indent(self.etree)
+ self._normalized_contents = lxml.etree.tostring(self.etree,
+ pretty_print=True)
+ return self._normalized_contents
+
def _changed(self):
super(ExtendedTestBrowser, self)._changed()
self._etree = None
- tree = self.etree
- indent(tree)
- self.normalized_contents = lxml.etree.tostring(tree, pretty_print=True)
+ self._normalized_contents = None
def pretty_print(self):
"""Print a pretty (formatted) version of the HTML content.
More information about the Checkins
mailing list