Skip to content

Commit

Permalink
handle setUp/tearDown in the doctestsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
philikon committed Jun 12, 2005
1 parent f4083fa commit 2d16550
Showing 1 changed file with 3 additions and 67 deletions.
70 changes: 3 additions & 67 deletions tests/test_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ def setAnotherBaz(self, value): self._anotherbaz = value
'getAnotherBaz': True, 'setAnotherBaz': False, 'shazam': False},
{'foo':True, 'bar': False, 'shazam': True})

def setUp():
def setUp(test):
"""Setup for tests."""
placelesssetup.setUp()
ztapi.browserView(IFoo, '', FooWidget, providing=IFooWidget)
ztapi.browserView(IBar, '', BarWidget, providing=IBarWidget)

def tearDown():
def tearDown(test):
placelesssetup.tearDown()

def assertRaises(exceptionType, callable, *args):
Expand All @@ -131,8 +131,6 @@ class TestSetUpWidget(object):
def test_typical(self):
"""Documents and tests the typical uses of setUpWidget.
>>> setUp()
setUpWidget ensures that the appropriate widget exists as an
attribute of a view. There are four required arguments to the
function:
Expand Down Expand Up @@ -189,15 +187,11 @@ def test_typical(self):
so we have to change that back.
>>> IContent['foo'].required = True
>>> tearDown()
"""

def test_validation(self):
"""Documents and tests validation performed by setUpWidget.
>>> setUp()
setUpWidget ensures that the the view has an attribute that implements
IWidget. If setUpWidget cannot configure a widget, it raises a
TypeError.
Expand All @@ -223,15 +217,11 @@ def test_validation(self):
>>> assertRaises(TypeError, setUpWidget,
... view, 'foo', IContent['foo'], IFooWidget)
True
>>> tearDown()
"""

def test_context(self):
"""Documents and tests the role of context in setUpWidget.
>>> setUp()
setUpWidget configures a widget by associating it to a bound field,
which is a copy of a schema field that is bound to an object. The
object the field is bound to can be explicitly specified in the
Expand All @@ -255,15 +245,11 @@ def test_context(self):
False
>>> view.foo_widget.context.context is altContext
True
>>> tearDown()
"""

def test_widgetLookup(self):
"""Documents and tests how widgets are looked up by type.
>>> setUp()
If the view does not already have a widget configured for the
specified field name, setUpWidget will look up a widget using
an interface specified for the widgetType argument.
Expand Down Expand Up @@ -304,15 +290,11 @@ def test_widgetLookup(self):
>>> assertRaises(ComponentLookupError, setUpWidget,
... view, 'foo', IContent['foo'], IUnregisteredWidget)
True
>>> tearDown()
"""

def test_prefix(self):
"""Documents and tests the specification of widget prefixes.
>>> setUp()
Widgets support a prefix that can be used to group related widgets
on a view. To specify the prefix for a widget, specify in the call to
setUpWidget:
Expand All @@ -322,15 +304,11 @@ def test_prefix(self):
... prefix='mygroup')
>>> view.foo_widget.getPrefix()
'mygroup.'
>>> tearDown()
"""

def test_value(self):
"""Documents and tests values and setUpWidget.
>>> setUp()
setUpWidget configures the widget with the value specified in the
'value' argument:
Expand Down Expand Up @@ -374,15 +352,11 @@ def test_value(self):
True
>>> view.foo_widget.getRenderedValue() is None
True
>>> tearDown()
"""

def test_stickyValues(self):
"""Documents and tests setUpWidget's handling of sticky values.
>>> setUp()
setUpWidget supports the concept of 'sticky values'. A sticky value
is a value displayed by a widget that should persist across multiple
across multiple object edit sessions. Sticky values ensure that invalid
Expand Down Expand Up @@ -427,17 +401,13 @@ def test_stickyValues(self):
... value="A New Value", ignoreStickyValues=True)
>>> view.foo_widget.getRenderedValue()
'A New Value'
>>> tearDown()
"""

class TestSetUpWidgets(object):

def test_typical(self):
"""Tests the typical use of setUpWidgets.
>>> setUp()
The simplest use of setUpWidget configures a view with widgets of a
particular type for a schema:
Expand Down Expand Up @@ -470,15 +440,11 @@ def test_typical(self):
'Value of Foo'
>>> view.bar_widget.getRenderedValue()
'Value of Bar'
>>> tearDown()
"""

def test_names(self):
"""Documents and tests the use of names in setUpWidgets.
>>> setUp()
The names argument can be used to configure a specific set of widgets
for a view:
Expand All @@ -490,15 +456,11 @@ def test_names(self):
False
>>> hasattr(view, 'bar_widget')
True
>>> tearDown()
"""

def test_delegation(self):
"""Tests setUpWidgets' use of setUpWidget.
>>> setUp()
setUpWidgets delegates several of its arguments to multiple calls to
setUpWidget - one call for each widget being configured. The arguments
passed directly through to calls to setUpWidget are:
Expand Down Expand Up @@ -555,15 +517,11 @@ def test_delegation(self):
True,
'Alt Context']]
>>> zope.app.form.utility.setUpWidget = setUpWidgetsSave
>>> tearDown()
"""

def test_forbiddenAttributes(self):
"""Tests that forbidden attributes cause an error in widget setup.
>>> setUp()
If an attribute cannot be read from a source object because it's
forbidden, the ForbiddenAttribute error is allowed to pass through
to the caller.
Expand Down Expand Up @@ -593,17 +551,13 @@ def test_forbiddenAttributes(self):
>>> setUpDisplayWidgets(view, IMySchema)
Traceback (most recent call last):
ForbiddenAttribute: ('some context', 'tryme')
>>> tearDown()
"""

class TestFormSetUp(object):

def test_setUpEditWidgets(self):
"""Documents and tests setUpEditWidgets.
>>> setUp()
setUpEditWidgets configures a view to collect field values from a
user. The function looks up widgets of type IInputWidget for the
specified schema.
Expand Down Expand Up @@ -775,15 +729,11 @@ def test_setUpEditWidgets(self):
Traceback (most recent call last):
...
AttributeError: 'BrowserView' object has no attribute 'shazam_widget'
>>> tearDown()
"""

def test_setUpDisplayWidgets(self):
"""Documents and tests setUpDisplayWidgets.
>>> setUp()
setUpDisplayWidgets configures a view for use as a display only form.
The function looks up widgets of type IDisplayWidget for the specified
schema.
Expand Down Expand Up @@ -865,17 +815,13 @@ def test_setUpDisplayWidgets(self):
Traceback (most recent call last):
...
AttributeError: 'BrowserView' object has no attribute 'shazam_widget'
>>> tearDown()
"""

class TestForms(object):

def test_viewHasInput(self):
"""Tests viewHasInput.
>>> setUp()
viewHasInput returns True if any of the widgets for a set of fields
have user input.
Expand Down Expand Up @@ -904,15 +850,11 @@ def test_viewHasInput(self):
>>> view.foo_widget.input = 'Some Value'
>>> viewHasInput(view, IContent)
True
>>> tearDown()
"""

def test_applyWidgetsChanges(self):
"""Documents and tests applyWidgetsChanges.
>>> setUp()
applyWidgetsChanges updates the view context, or an optional alternate
context, with widget values. This is typically called when a form
is submitted.
Expand Down Expand Up @@ -1003,17 +945,13 @@ def test_applyWidgetsChanges(self):
'a'
>>> getattr(context, 'bar', 'not really')
'not really'
>>> tearDown()
"""

class TestGetWidgetsData(object):

def test_typical(self):
"""Documents and tests the typical use of getWidgetsData.
>>> setUp()
getWidgetsData retrieves the current values from widgets on a view.
For this test, we'll create a simple edit widget and register it
for the schema field types:
Expand Down Expand Up @@ -1089,8 +1027,6 @@ def test_typical(self):
>>> result = getWidgetsData(view, IContent, names=('bar',))
>>> result.keys()
['bar']
>>> tearDown()
"""

def test_widgetsErrorException(self):
Expand Down Expand Up @@ -1141,7 +1077,7 @@ def test_widgetsErrorException(self):

def test_suite():
from zope.testing.doctest import DocTestSuite
return DocTestSuite()
return DocTestSuite(setUp=setUp, tearDown=tearDown)

if __name__=='__main__':
import unittest
Expand Down

0 comments on commit 2d16550

Please sign in to comment.