[Checkins] SVN: zope.testbrowser/trunk/s - rip out backward compatability code from zope.testbrowser.__init__

Benji York benji at zope.com
Sat Nov 29 14:09:39 EST 2008


Log message for revision 93446:
  - rip out backward compatability code from zope.testbrowser.__init__
  - modernize import style
  - remove unneeded imports
  - add zope-functional-testing extra for proper dependency declarations
    when using zope.testbrowser to write functional tests for Zope 3 apps
  

Changed:
  U   zope.testbrowser/trunk/setup.py
  U   zope.testbrowser/trunk/src/zope/testbrowser/__init__.py
  U   zope.testbrowser/trunk/src/zope/testbrowser/browser.py
  U   zope.testbrowser/trunk/src/zope/testbrowser/interfaces.py
  U   zope.testbrowser/trunk/src/zope/testbrowser/testing.py
  U   zope.testbrowser/trunk/src/zope/testbrowser/tests.py

-=-
Modified: zope.testbrowser/trunk/setup.py
===================================================================
--- zope.testbrowser/trunk/setup.py	2008-11-29 13:40:23 UTC (rev 93445)
+++ zope.testbrowser/trunk/setup.py	2008-11-29 19:09:38 UTC (rev 93446)
@@ -29,7 +29,7 @@
 
 setup(
     name = 'zope.testbrowser',
-    version = '3.5.2dev',
+    version = '3.6.0dev',
     url = 'http://pypi.python.org/pypi/zope.testbrowser',
     license = 'ZPL 2.1',
     description = 'Programmable browser for functional black-box tests',
@@ -56,15 +56,18 @@
         'zope.interface',
         'zope.schema',
         ],
-    extras_require = dict(
-        test = [
+    extras_require = {
+        'test': [
             'zope.app.component',
             'zope.app.folder',
             'zope.app.securitypolicy',
             'zope.app.testing',
             'zope.app.zcmlfiles',
             ],
-        ),
+        'zope-functional-testing': [
+            'zope.app.testing',
+            ],
+        },
     include_package_data = True,
     zip_safe = False,
     )

Modified: zope.testbrowser/trunk/src/zope/testbrowser/__init__.py
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/__init__.py	2008-11-29 13:40:23 UTC (rev 93445)
+++ zope.testbrowser/trunk/src/zope/testbrowser/__init__.py	2008-11-29 19:09:38 UTC (rev 93446)
@@ -15,15 +15,3 @@
 
 $Id$
 """
-
-try:
-    from testing import Browser
-    from zope.deprecation import deprecated
-    deprecated('Browser',
-        'importing Browser from zope.testbrowser has been deprecated and will'
-        ' be removed in 3.5; import Browser from zope.testbrowser.testing'
-        ' instead')
-except ImportError:
-    # This is really ugly, but non-Zope code needs to be able to import this
-    # and the testing module depends on Zope 3
-    pass

Modified: zope.testbrowser/trunk/src/zope/testbrowser/browser.py
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/browser.py	2008-11-29 13:40:23 UTC (rev 93445)
+++ zope.testbrowser/trunk/src/zope/testbrowser/browser.py	2008-11-29 19:09:38 UTC (rev 93446)
@@ -15,19 +15,21 @@
 
 $Id$
 """
+
 __docformat__ = "reStructuredText"
-from zope.testbrowser import interfaces
+
+
 import ClientForm
-from cStringIO import StringIO
+import cStringIO
 import mechanize
 import operator
 import re
 import sys
 import time
 import urllib2
+import zope.interface
+import zope.testbrowser.interfaces
 
-from zope import interface
-
 RegexType = type(re.compile(''))
 _compress_re = re.compile(r"\s+")
 compressText = lambda text: _compress_re.sub(' ', text.strip())
@@ -153,7 +155,7 @@
 
 class Browser(SetattrErrorsMixin):
     """A web user agent."""
-    interface.implements(interfaces.IBrowser)
+    zope.interface.implements(zope.testbrowser.interfaces.IBrowser)
 
     _contents = None
     _counter = 0
@@ -406,7 +408,7 @@
 
 
 class Link(SetattrErrorsMixin):
-    interface.implements(interfaces.ILink)
+    zope.interface.implements(zope.testbrowser.interfaces.ILink)
 
     def __init__(self, link, browser):
         self.mech_link = link
@@ -416,7 +418,7 @@
 
     def click(self):
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
         self.browser._start_timer()
         self.browser.mech_browser.follow_link(self.mech_link)
         self.browser._stop_timer()
@@ -445,7 +447,7 @@
 
 class Control(SetattrErrorsMixin):
     """A control of a form."""
-    interface.implements(interfaces.IControl)
+    zope.interface.implements(zope.testbrowser.interfaces.IControl)
 
     _enable_setattr_errors = False
 
@@ -496,7 +498,7 @@
 
         def fset(self, value):
             if self._browser_counter != self.browser._counter:
-                raise interfaces.ExpiredError
+                raise zope.testbrowser.interfaces.ExpiredError
             if self.mech_control.type == 'file':
                 self.mech_control.add_file(value,
                                            content_type=self.content_type,
@@ -512,12 +514,12 @@
             raise TypeError("Can't call add_file on %s controls"
                             % self.mech_control.type)
         if isinstance(file, str):
-            file = StringIO(file)
+            file = cStringIO.StringIO(file)
         self.mech_control.add_file(file, content_type, filename)
 
     def clear(self):
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
         self.mech_control.clear()
 
     def __repr__(self):
@@ -526,7 +528,7 @@
 
 
 class ListControl(Control):
-    interface.implements(interfaces.IListControl)
+    zope.interface.implements(zope.testbrowser.interfaces.IListControl)
 
     @apply
     def displayValue():
@@ -540,7 +542,7 @@
 
         def fset(self, value):
             if self._browser_counter != self.browser._counter:
-                raise interfaces.ExpiredError
+                raise zope.testbrowser.interfaces.ExpiredError
             self.mech_control.set_value_by_label(value)
 
         return property(fget, fset)
@@ -576,7 +578,7 @@
     @property
     def controls(self):
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
         res = [controlFactory(i, self.mech_form, self.browser) for i in
                 self.mech_control.items]
         for s in res:
@@ -585,7 +587,7 @@
 
     def getControl(self, label=None, value=None, index=None):
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
 
         onlyOne([label, value], '"label" and "value"')
 
@@ -602,27 +604,27 @@
 
 
 class SubmitControl(Control):
-    interface.implements(interfaces.ISubmitControl)
+    zope.interface.implements(zope.testbrowser.interfaces.ISubmitControl)
 
     def click(self):
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
         self.browser._clickSubmit(self.mech_form, self.mech_control, (1,1))
         self.browser._changed()
 
 
 class ImageControl(Control):
-    interface.implements(interfaces.IImageSubmitControl)
+    zope.interface.implements(zope.testbrowser.interfaces.IImageSubmitControl)
 
     def click(self, coord=(1,1)):
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
         self.browser._clickSubmit(self.mech_form, self.mech_control, coord)
         self.browser._changed()
 
 
 class ItemControl(SetattrErrorsMixin):
-    interface.implements(interfaces.IItemControl)
+    zope.interface.implements(zope.testbrowser.interfaces.IItemControl)
 
     def __init__(self, item, form, browser):
         self.mech_item = item
@@ -634,7 +636,7 @@
     @property
     def control(self):
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
         res = controlFactory(
             self.mech_item._control, self.mech_form, self.browser)
         self.__dict__['control'] = res
@@ -653,7 +655,7 @@
 
         def fset(self, value):
             if self._browser_counter != self.browser._counter:
-                raise interfaces.ExpiredError
+                raise zope.testbrowser.interfaces.ExpiredError
             self.mech_item.selected = value
 
         return property(fget, fset)
@@ -664,7 +666,7 @@
 
     def click(self):
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
         self.mech_item.selected = not self.mech_item.selected
 
     def __repr__(self):
@@ -675,7 +677,7 @@
 
 class Form(SetattrErrorsMixin):
     """HTML Form"""
-    interface.implements(interfaces.IForm)
+    zope.interface.implements(zope.testbrowser.interfaces.IForm)
 
     def __init__(self, browser, form):
         """Initialize the Form
@@ -712,7 +714,7 @@
     def submit(self, label=None, name=None, index=None, coord=(1,1)):
         """See zope.testbrowser.interfaces.IForm"""
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
         form = self.mech_form
         if label is not None or name is not None:
             intermediate, msg = self.browser._get_all_controls(
@@ -735,7 +737,7 @@
     def getControl(self, label=None, name=None, index=None):
         """See zope.testbrowser.interfaces.IBrowser"""
         if self._browser_counter != self.browser._counter:
-            raise interfaces.ExpiredError
+            raise zope.testbrowser.interfaces.ExpiredError
         intermediate, msg = self.browser._get_all_controls(
             label, name, (self.mech_form,), include_subcontrols=True)
         control, form = disambiguate(intermediate, msg, index)

Modified: zope.testbrowser/trunk/src/zope/testbrowser/interfaces.py
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/interfaces.py	2008-11-29 13:40:23 UTC (rev 93445)
+++ zope.testbrowser/trunk/src/zope/testbrowser/interfaces.py	2008-11-29 19:09:38 UTC (rev 93446)
@@ -17,39 +17,40 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope import interface, schema
+import zope.interface
+import zope.schema
 
 
-class IBrowser(interface.Interface):
+class IBrowser(zope.interface.Interface):
     """A Programmatic Web Browser."""
 
-    url = schema.URI(
+    url = zope.schema.URI(
         title=u"URL",
         description=u"The URL the browser is currently showing.",
         required=True)
 
-    headers = schema.Field(
+    headers = zope.schema.Field(
         title=u"Headers",
         description=(u"Headers of the HTTP response; a "
                      "``httplib.HTTPMessage``."),
         required=True)
 
-    contents = schema.Text(
+    contents = zope.schema.Text(
         title=u"Contents",
         description=u"The complete response body of the HTTP request.",
         required=True)
 
-    isHtml = schema.Bool(
+    isHtml = zope.schema.Bool(
         title=u"Is HTML",
         description=u"Tells whether the output is HTML or not.",
         required=True)
 
-    title = schema.TextLine(
+    title = zope.schema.TextLine(
         title=u"Title",
         description=u"Title of the displayed page",
         required=False)
 
-    handleErrors = schema.Bool(
+    handleErrors = zope.schema.Bool(
         title=u"Handle Errors",
         description=(u"Describes whether server-side errors will be handled "
                      u"by the publisher. If set to ``False``, the error will "
@@ -109,7 +110,7 @@
 
         """
 
-    lastRequestSeconds = schema.Field(
+    lastRequestSeconds = zope.schema.Field(
         title=u"Seconds to Process Last Request",
         description=(
         u"""Return how many seconds (or fractions) the last request took.
@@ -120,7 +121,7 @@
         required=True,
         readonly=True)
 
-    lastRequestPystones = schema.Field(
+    lastRequestPystones = zope.schema.Field(
         title=
             u"Approximate System-Independent Effort of Last Request (Pystones)",
         description=(
@@ -172,34 +173,34 @@
     """The browser page to which this was attached is no longer active"""
 
 
-class IControl(interface.Interface):
+class IControl(zope.interface.Interface):
     """A control (input field) of a page."""
 
-    name = schema.TextLine(
+    name = zope.schema.TextLine(
         title=u"Name",
         description=u"The name of the control.",
         required=True)
 
-    value = schema.Field(
+    value = zope.schema.Field(
         title=u"Value",
         description=u"The value of the control",
         default=None,
         required=True)
 
-    type = schema.Choice(
+    type = zope.schema.Choice(
         title=u"Type",
         description=u"The type of the control",
         values=['text', 'password', 'hidden', 'submit', 'checkbox', 'select',
                 'radio', 'image', 'file'],
         required=True)
 
-    disabled = schema.Bool(
+    disabled = zope.schema.Bool(
         title=u"Disabled",
         description=u"Describes whether a control is disabled.",
         default=False,
         required=False)
 
-    multiple = schema.Bool(
+    multiple = zope.schema.Bool(
         title=u"Multiple",
         description=u"Describes whether this control can hold multiple values.",
         default=False,
@@ -212,20 +213,20 @@
 class IListControl(IControl):
     """A radio button, checkbox, or select control"""
 
-    options = schema.List(
+    options = zope.schema.List(
         title=u"Options",
         description=u"""\
         A list of possible values for the control.""",
         required=True)
 
-    displayOptions = schema.List(
+    displayOptions = zope.schema.List(
         # TODO: currently only implemented for select by ClientForm
         title=u"Options",
         description=u"""\
         A list of possible display values for the control.""",
         required=True)
 
-    displayValue = schema.Field(
+    displayValue = zope.schema.Field(
         # TODO: currently only implemented for select by ClientForm
         title=u"Value",
         description=u"The value of the control, as rendered by the display",
@@ -239,7 +240,7 @@
         'Add a contact' but not 'Address'.  A word is defined as one or more
         alphanumeric characters or the underline."""
 
-    controls = interface.Attribute(
+    controls = zope.interface.Attribute(
         """a list of subcontrols for the control.  mutating list has no effect
         on control (although subcontrols may be changed as usual).""")
 
@@ -256,86 +257,86 @@
         "click the submit button with optional coordinates"
 
 
-class IItemControl(interface.Interface):
+class IItemControl(zope.interface.Interface):
     """a radio button or checkbox within a larger multiple-choice control"""
 
-    control = schema.Object(
+    control = zope.schema.Object(
         title=u"Control",
         description=(u"The parent control element."),
         schema=IControl,
         required=True)
 
-    disabled = schema.Bool(
+    disabled = zope.schema.Bool(
         title=u"Disabled",
         description=u"Describes whether a subcontrol is disabled.",
         default=False,
         required=False)
 
-    selected = schema.Bool(
+    selected = zope.schema.Bool(
         title=u"Selected",
         description=u"Whether the subcontrol is selected",
         default=None,
         required=True)
 
-    optionValue = schema.TextLine(
+    optionValue = zope.schema.TextLine(
         title=u"Value",
         description=u"The value of the subcontrol",
         default=None,
         required=False)
 
 
-class ILink(interface.Interface):
+class ILink(zope.interface.Interface):
 
     def click():
         """click the link, going to the URL referenced"""
 
-    url = schema.TextLine(
+    url = zope.schema.TextLine(
         title=u"URL",
         description=u"The normalized URL of the link",
         required=False)
 
-    attrs = schema.Dict(
+    attrs = zope.schema.Dict(
         title=u'Attributes',
         description=u'The attributes of the link tag',
         required=False)
 
-    text = schema.TextLine(
+    text = zope.schema.TextLine(
         title=u'Text',
         description=u'The contained text of the link',
         required=False)
 
-    tag = schema.TextLine(
+    tag = zope.schema.TextLine(
         title=u'Tag',
         description=u'The tag name of the link (a or area, typically)',
         required=True)
 
 
-class IForm(interface.Interface):
+class IForm(zope.interface.Interface):
     """An HTML form of the page."""
 
-    action = schema.TextLine(
+    action = zope.schema.TextLine(
         title=u"Action",
         description=u"The action (or URI) that is opened upon submittance.",
         required=True)
 
-    method = schema.Choice(
+    method = zope.schema.Choice(
         title=u"Method",
         description=u"The method used to submit the form.",
         values=['post', 'get', 'put'],
         required=True)
 
-    enctype = schema.TextLine(
+    enctype = zope.schema.TextLine(
         title=u"Encoding Type",
         description=u"The type of encoding used to encode the form data.",
         required=True)
 
-    name = schema.TextLine(
+    name = zope.schema.TextLine(
         title=u"Name",
         description=u"The value of the `name` attribute in the form tag, "
                     u"if specified.",
         required=True)
 
-    id = schema.TextLine(
+    id = zope.schema.TextLine(
         title=u"Id",
         description=u"The value of the `id` attribute in the form tag, "
                     u"if specified.",

Modified: zope.testbrowser/trunk/src/zope/testbrowser/testing.py
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/testing.py	2008-11-29 13:40:23 UTC (rev 93445)
+++ zope.testbrowser/trunk/src/zope/testbrowser/testing.py	2008-11-29 19:09:38 UTC (rev 93446)
@@ -15,29 +15,26 @@
 
 $Id$
 """
+
+
+import cStringIO
+import httplib
+import mechanize
 import re
-import sys
 import socket
+import sys
+import transaction
 import unittest
-import httplib
 import urllib2
-from cStringIO import StringIO
+import zope.app.testing
+import zope.testbrowser.browser
 
-import mechanize
 
-import transaction
-from zope.testbrowser import browser
-from zope.testing import renormalizing, doctest
-
-from zope.app.testing import functional
-from zope.app.folder.folder import Folder
-from zope.app.component.site import LocalSiteManager
-
 class PublisherConnection(object):
     """A ``urllib2`` compatible connection obejct."""
 
     def __init__(self, host, timeout=None):
-        self.caller = functional.HTTPCaller()
+        self.caller = zope.app.testing.functional.HTTPCaller()
         self.host = host
 
     def set_debuglevel(self, level):
@@ -110,8 +107,8 @@
         self.content = content
         self.status = status
         self.reason = reason
-        self.msg = httplib.HTTPMessage(StringIO(headers), 0)
-        self.content_as_file = StringIO(self.content)
+        self.msg = httplib.HTTPMessage(cStringIO.StringIO(headers), 0)
+        self.content_as_file = cStringIO.StringIO(self.content)
 
     def read(self, amt=None):
         return self.content_as_file.read(amt)
@@ -169,7 +166,7 @@
         mechanize.Browser.__init__(self, *args, **kws)
 
 
-class Browser(browser.Browser):
+class Browser(zope.testbrowser.browser.Browser):
     """A Zope `testbrowser` Browser that uses the Zope Publisher."""
 
     def __init__(self, url=None):

Modified: zope.testbrowser/trunk/src/zope/testbrowser/tests.py
===================================================================
--- zope.testbrowser/trunk/src/zope/testbrowser/tests.py	2008-11-29 13:40:23 UTC (rev 93445)
+++ zope.testbrowser/trunk/src/zope/testbrowser/tests.py	2008-11-29 19:09:38 UTC (rev 93446)
@@ -16,21 +16,21 @@
 $Id$
 """
 
-from cStringIO import StringIO
-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 cStringIO
 import httplib
 import mechanize
 import os
 import re
+import socket
 import sys
-import socket
 import unittest
 import unittest
 import urllib2
+import zope.app.testing.functional
+import zope.testbrowser.browser
+import zope.testing.renormalizing
 
 
 def set_next_response(body, headers=None, status='200', reason='OK'):
@@ -109,8 +109,8 @@
         self.content = content
         self.status = status
         self.reason = reason
-        self.msg = httplib.HTTPMessage(StringIO(headers), 0)
-        self.content_as_file = StringIO(self.content)
+        self.msg = httplib.HTTPMessage(cStringIO.StringIO(headers), 0)
+        self.content_as_file = cStringIO.StringIO(self.content)
 
     def read(self, amt=None):
         return self.content_as_file.read(amt)
@@ -160,7 +160,7 @@
     default_features = ["_authen", "_redirect", "_cookies"]
 
 
-class Browser(browser.Browser):
+class Browser(zope.testbrowser.browser.Browser):
 
     def __init__(self, url=None):
         mech_browser = FauxMechanizeBrowser()
@@ -168,7 +168,7 @@
 
     def open(self, body, headers=None, status=200, reason='OK'):
         set_next_response(body, headers, status, reason)
-        browser.Browser.open(self, 'http://localhost/')
+        zope.testbrowser.browser.Browser.open(self, 'http://localhost/')
 
 def test_submit_duplicate_name():
     """
@@ -264,7 +264,7 @@
 Fill in the form value using add_file:
 
     >>> browser.getControl(name='foo').add_file(
-    ...     StringIO('sample_data'), 'text/foo', 'x.foo')
+    ...     cStringIO.StringIO('sample_data'), 'text/foo', 'x.foo')
     >>> browser.getControl('OK').click()
     POST / HTTP/1.1
     Content-length: 173
@@ -369,7 +369,7 @@
     def sub(self, replacement, text):
         return text.replace(r'\r','')
 
-checker = renormalizing.RENormalizing([
+checker = zope.testing.renormalizing.RENormalizing([
     (re.compile(r'^--\S+\.\S+\.\S+', re.M), '-'*30),
     (re.compile(r'boundary=\S+\.\S+\.\S+'), 'boundary='+'-'*30),
     (re.compile(r'^---{10}.*', re.M), '-'*30),
@@ -385,7 +385,7 @@
     (re.compile(r'Content-Type: '), 'Content-type: '),
     ])
 
-TestBrowserLayer = functional.ZCMLLayer(
+TestBrowserLayer = zope.app.testing.functional.ZCMLLayer(
     os.path.join(os.path.split(__file__)[0], 'ftests/ftesting.zcml'),
     __name__, 'TestBrowserLayer', allow_teardown=True)
 



More information about the Checkins mailing list