[Checkins] SVN: zope.testbrowser/trunk/ - Remove vendor import of
mechanize.
Benji York
benji at zope.com
Sun Mar 23 21:15:13 EDT 2008
Log message for revision 84900:
- Remove vendor import of mechanize.
- Fix bug that caused HTTP exception tracebacks to differ between
version 3.4.0 and 3.4.1.
- Workaround for bug in Python Cookie.SimpleCookie when handling
unicode strings.
- Fix bug introduced in 3.4.1 that created incompatible tracebacks in
doctests. This necessitated adding a patched mechanize to the
source tree; patches have been sent to the mechanize project.
Changed:
U zope.testbrowser/trunk/CHANGES.txt
U zope.testbrowser/trunk/buildout.cfg
D zope.testbrowser/trunk/mechanize/
U zope.testbrowser/trunk/setup.py
U zope.testbrowser/trunk/src/zope/testbrowser/browser.py
A zope.testbrowser/trunk/src/zope/testbrowser/fixed-bugs.txt
U zope.testbrowser/trunk/src/zope/testbrowser/over_the_wire.txt
U zope.testbrowser/trunk/src/zope/testbrowser/tests.py
-=-
Modified: zope.testbrowser/trunk/CHANGES.txt
===================================================================
--- zope.testbrowser/trunk/CHANGES.txt 2008-03-24 00:49:38 UTC (rev 84899)
+++ zope.testbrowser/trunk/CHANGES.txt 2008-03-24 01:15:11 UTC (rev 84900)
@@ -2,9 +2,17 @@
CHANGES
=======
-3.4.3 (unreleased)
+3.5.0 (unreleased)
------------------
+- Remove vendor import of mechanize.
+
+- Fix bug that caused HTTP exception tracebacks to differ between version 3.4.0
+ and 3.4.1.
+
+- Workaround for bug in Python Cookie.SimpleCookie when handling unicode
+ strings.
+
- Fix bug introduced in 3.4.1 that created incompatible tracebacks in doctests.
This necessitated adding a patched mechanize to the source tree; patches have
been sent to the mechanize project.
Modified: zope.testbrowser/trunk/buildout.cfg
===================================================================
--- zope.testbrowser/trunk/buildout.cfg 2008-03-24 00:49:38 UTC (rev 84899)
+++ zope.testbrowser/trunk/buildout.cfg 2008-03-24 01:15:11 UTC (rev 84900)
@@ -1,8 +1,14 @@
[buildout]
-develop = . mechanize
+develop = .
parts = test interpreter
-index = http://download.zope.org/zope3.4
+versions = versions
+extends = http://download.zope.org/zope3.4/versions.cfg
+[versions]
+zope.testbrowser =
+zope.publisher = 3.5.1
+zope.app.publication = 3.4.2
+
[test]
recipe = zc.recipe.testrunner
defaults = ['--tests-pattern', '^f?tests$']
Modified: zope.testbrowser/trunk/setup.py
===================================================================
--- zope.testbrowser/trunk/setup.py 2008-03-24 00:49:38 UTC (rev 84899)
+++ zope.testbrowser/trunk/setup.py 2008-03-24 01:15:11 UTC (rev 84900)
@@ -29,7 +29,7 @@
setup(
name = 'zope.testbrowser',
- version = '3.4.3dev',
+ version = '3.5.0dev',
url = 'http://pypi.python.org/pypi/zope.testbrowser',
license = 'ZPL 2.1',
description = 'Programmable browser for functional black-box tests',
@@ -51,7 +51,7 @@
tests_require = ['zope.testing'],
install_requires = [
'setuptools',
- #'mechanize', XXX uncomment when we can use a released mechanize again
+ 'mechanize',
'ClientForm',
'zope.interface',
'zope.schema',
Modified: zope.testbrowser/trunk/src/zope/testbrowser/browser.py
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/browser.py 2008-03-24 00:49:38 UTC (rev 84899)
+++ zope.testbrowser/trunk/src/zope/testbrowser/browser.py 2008-03-24 01:15:11 UTC (rev 84900)
@@ -75,7 +75,15 @@
raise ValueError(
"Supply no more than one of %s as arguments" % description)
+def fix_exception_name(e):
+ # mechanize unceremoniously changed the repr of HTTPErrors, in
+ # in order not to break existing doctests, we have to undo that
+ if hasattr(e, '_exc_class_name'):
+ name = e._exc_class_name
+ name = name.rsplit('.', 1)[-1]
+ e.__class__.__name__ = name
+
class SetattrErrorsMixin(object):
_enable_setattr_errors = False
@@ -215,10 +223,15 @@
def open(self, url, data=None):
"""See zope.testbrowser.interfaces.IBrowser"""
+ url = str(url)
self._start_timer()
try:
try:
- self.mech_browser.open(url, data)
+ try:
+ self.mech_browser.open(url, data)
+ except Exception, e:
+ fix_exception_name(e)
+ raise
except urllib2.HTTPError, e:
if e.code >= 200 and e.code <= 299:
# 200s aren't really errors
@@ -268,7 +281,7 @@
def addHeader(self, key, value):
"""See zope.testbrowser.interfaces.IBrowser"""
- self.mech_browser.addheaders.append( (key, value) )
+ self.mech_browser.addheaders.append( (str(key), str(value)) )
def getLink(self, text=None, url=None, id=None, index=0):
"""See zope.testbrowser.interfaces.IBrowser"""
@@ -374,8 +387,12 @@
else:
label = None
self._start_timer()
- self.mech_browser.open(form.click(
- id=control.id, name=control.name, label=label, coord=coord))
+ try:
+ self.mech_browser.open(form.click(
+ id=control.id, name=control.name, label=label, coord=coord))
+ except Exception, e:
+ fix_exception_name(e)
+ raise
self._stop_timer()
def _changed(self):
Copied: zope.testbrowser/trunk/src/zope/testbrowser/fixed-bugs.txt (from rev 84899, zope.testbrowser/branches/benji-remove-mechanize-vendor-import/src/zope/testbrowser/fixed-bugs.txt)
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/fixed-bugs.txt (rev 0)
+++ zope.testbrowser/trunk/src/zope/testbrowser/fixed-bugs.txt 2008-03-24 01:15:11 UTC (rev 84900)
@@ -0,0 +1,27 @@
+Unicode URLs
+============
+
+Unicode URLs or headers cause the entire constructed request to be unicode, and
+(as of Python 2.4.4) Cookie.SimpleCookie checks the type of the input against
+type(""), so it handles the value inappropriately, causing exceptions that
+ended with::
+
+ File "/home/benji/Python-2.4.4/lib/python2.4/Cookie.py", line 623, in load
+ self.update(rawdata)
+ ValueError: dictionary update sequence element #0 has length 1; 2 is required
+
+As a work-around, unicode strings passed to Browser.open() are now converted to
+ASCII before being passed on, as well as the key and value passed to
+Browser.addHeader().
+
+The tests below failed before the change was put in place.
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.addHeader('Cookie', 'test')
+ >>> browser.open(u'http://localhost/@@/testbrowser/simple.html')
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.addHeader(u'Cookie', 'test')
+ >>> browser.open('http://localhost/@@/testbrowser/simple.html')
Modified: zope.testbrowser/trunk/src/zope/testbrowser/over_the_wire.txt
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/over_the_wire.txt 2008-03-24 00:49:38 UTC (rev 84899)
+++ zope.testbrowser/trunk/src/zope/testbrowser/over_the_wire.txt 2008-03-24 01:15:11 UTC (rev 84900)
@@ -33,6 +33,6 @@
>>> browser.getControl('Google Search').click()
Traceback (most recent call last):
...
- HTTPError: HTTP Error 403: request disallowed by robots.txt
+ RobotExclusionError: HTTP Error 403: request disallowed by robots.txt
Oops! Google doesn't let robots use their search engine. Oh well.
Modified: zope.testbrowser/trunk/src/zope/testbrowser/tests.py
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/tests.py 2008-03-24 00:49:38 UTC (rev 84899)
+++ zope.testbrowser/trunk/src/zope/testbrowser/tests.py 2008-03-24 01:15:11 UTC (rev 84900)
@@ -20,6 +20,7 @@
from zope.app.testing import functional
from zope.app.testing.functional import FunctionalDocFileSuite
from zope.testbrowser import browser
+from zope.testing import doctest
from zope.testing import renormalizing, doctest
import httplib
import mechanize
@@ -380,17 +381,22 @@
__name__, 'TestBrowserLayer', allow_teardown=True)
def test_suite():
- from zope.testing import doctest
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
+
readme = FunctionalDocFileSuite('README.txt', optionflags=flags,
checker=checker)
readme.layer = TestBrowserLayer
+
+ fixed_bugs = FunctionalDocFileSuite('fixed-bugs.txt', optionflags=flags)
+ fixed_bugs.layer = TestBrowserLayer
+
wire = FunctionalDocFileSuite('over_the_wire.txt', optionflags=flags)
wire.level = 2
wire.layer = TestBrowserLayer
+
this_file = doctest.DocTestSuite(checker=checker)
- return unittest.TestSuite((this_file, readme, wire))
+ return unittest.TestSuite((this_file, readme, fixed_bugs, wire))
+
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
-
More information about the Checkins
mailing list