[Zope3-checkins] SVN: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/ more tests pass (about 3/4)

Benji York benji at zope.com
Thu Aug 17 00:33:15 EDT 2006


Log message for revision 69581:
  more tests pass (about 3/4)

Changed:
  U   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/forms.py
  U   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py
  U   Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt

-=-
Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/forms.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/forms.py	2006-08-17 03:47:29 UTC (rev 69580)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/forms.py	2006-08-17 04:33:15 UTC (rev 69581)
@@ -72,7 +72,22 @@
 
     return disambiguate(matching_forms, '', index)
 
+def controlFactory(control, form, browser):
+    if isinstance(control, ClientForm.Item):
+        # it is a subcontrol
+        return ItemControl(control, form, browser)
+    else:
+        t = control.type
+        if t in ('checkbox', 'select', 'radio'):
+            return ListControl(control, form, browser)
+        elif t in ('submit', 'submitbutton'):
+            return SubmitControl(control, form, browser)
+        elif t=='image':
+            return ImageControl(control, form, browser)
+        else:
+            return Control(control, form, browser)
 
+
 class Control(SetattrErrorsMixin):
     """A control of a form."""
     interface.implements(interfaces.IControl)
@@ -370,19 +385,3 @@
                                            include_subcontrols=True)
         control, form = disambiguate(intermediate, msg, index)
         return controlFactory(control, form, self.browser)
-
-
-def controlFactory(control, form, browser):
-    if isinstance(control, ClientForm.Item):
-        # it is a subcontrol
-        return ItemControl(control, form, browser)
-    else:
-        t = control.type
-        if t in ('checkbox', 'select', 'radio'):
-            return ListControl(control, form, browser)
-        elif t in ('submit', 'submitbutton'):
-            return SubmitControl(control, form, browser)
-        elif t=='image':
-            return ImageControl(control, form, browser)
-        else:
-            return Control(control, form, browser)

Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py	2006-08-17 03:47:29 UTC (rev 69580)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.py	2006-08-17 04:33:15 UTC (rev 69581)
@@ -17,21 +17,32 @@
 """
 __docformat__ = "reStructuredText"
 from BeautifulSoup import BeautifulSoup
+from StringIO import StringIO
 from zope.testbrowser import interfaces
 from zope.testbrowser.forms import getControl, getForm, getAllControls, \
     controlFactory
 from zope.testbrowser.real.proxy import ServerManager, PROXY_PORT
 from zope.testbrowser.utilities import disambiguate, zeroOrOne, \
     SetattrErrorsMixin, PystoneTimer
+import ClientForm
 import re
 import urlparse
 
-
 try:
     from zope import interface
 except ImportError:
     from dummymodules import interface
 
+class DummyResponse(object):
+    def __init__(self, contents, url):
+        self.stringIo = StringIO(contents)
+        self.url = url
+    def read(self, size):
+        return self.stringIo.read(size)
+
+    def geturl(self):
+        return self.url
+
 def getTagText(soup):
     text = str(soup)
     text = re.sub('<[^>]*>', '', text)
@@ -46,6 +57,7 @@
     _contents = None
     _counter = 0
     _soup = None
+    _forms = None
 
     def __init__(self, url=None):
         self.serverManager = ServerManager()
@@ -182,23 +194,15 @@
         link, n = disambiguate(links, msg, index)
         return Link(link, n, self)
 
+    def _getForms(self):
+        if self._forms is None:
+            dummy_response = DummyResponse(self.contents, self.url)
+            self._forms = ClientForm.ParseResponse(dummy_response)
+        return self._forms
+
     def getControl(self, label=None, name=None, index=None):
         """See zope.testbrowser.interfaces.IBrowser"""
-        import ClientForm
-        from StringIO import StringIO
-        class DummyResponse(object):
-            def __init__(self, contents, url):
-                self.stringIo = StringIO(contents)
-                self.url = url
-            def read(self, size):
-                return self.stringIo.read(size)
-
-            def geturl(self):
-                return self.url
-
-        dummy_response = DummyResponse(self.contents, self.url)
-        forms = ClientForm.ParseResponse(dummy_response)
-        control, form = getControl(forms, label, name, index)
+        control, form = getControl(self._getForms(), label, name, index)
         return controlFactory(control, form, self)
 
     def getForm(self, id=None, name=None, action=None, index=None):
@@ -209,6 +213,7 @@
         self._counter += 1
         self._contents = None
         self._soup = None
+        self._forms = None
 
 
 class Link(SetattrErrorsMixin):

Modified: Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt
===================================================================
--- Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt	2006-08-17 03:47:29 UTC (rev 69580)
+++ Zope3/branches/benji-testbrowser-with-real-browsers-take-2/src/zope/testbrowser/real/real.txt	2006-08-17 04:33:15 UTC (rev 69581)
@@ -318,15 +318,17 @@
     >>> browser.getControl('Ambiguous Control')
     Traceback (most recent call last):
     ...
-    AmbiguityError: label 'Ambiguous Control'
+    AmbiguityError: "label 'Ambiguous Control'"
 
+XXX Why in the world did AmbiguityErrors start quoting the error message?!?
+
 This is also true if an option in a control is ambiguous in relation to
 the control itself.
 
     >>> browser.getControl('Sub-control Ambiguity')
     Traceback (most recent call last):
     ...
-    AmbiguityError: label 'Sub-control Ambiguity'
+    AmbiguityError: "label 'Sub-control Ambiguity'"
 
 Ambiguous controls may be specified using an index value.  We use the control's
 value attribute to show the two controls; this attribute is properly introduced
@@ -391,7 +393,7 @@
     >>> browser.getControl(name='ambiguous-control-name')
     Traceback (most recent call last):
     ...
-    AmbiguityError: name 'ambiguous-control-name'
+    AmbiguityError: "name 'ambiguous-control-name'"
     >>> browser.getControl(name='does-not-exist')
     Traceback (most recent call last):
     ...
@@ -529,7 +531,7 @@
     >>> browser.getControl('Third') # ambiguous in the browser, so useful
     Traceback (most recent call last):
     ...
-    AmbiguityError: label 'Third'
+    AmbiguityError: "label 'Third'"
 
 Finally, submit controls provide ISubmitControl, and image controls provide
 IImageSubmitControl, which extents ISubmitControl.  These both simply add a
@@ -1041,11 +1043,11 @@
     >>> browser.getControl(name='text-value')
     Traceback (most recent call last):
     ...
-    AmbiguityError: name 'text-value'
+    AmbiguityError: "name 'text-value'"
     >>> browser.getControl('Text Control')
     Traceback (most recent call last):
     ...
-    AmbiguityError: label 'Text Control'
+    AmbiguityError: "label 'Text Control'"
 
 I'll always get an ambiguous form field.  I can use the index argument, or
 with the `getForm` method I can disambiguate by searching only within a given



More information about the Zope3-Checkins mailing list