[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - support.py:1.1 test_browserwidget.py:1.12 test_checkboxwidget.py:1.8 test_filewidget.py:1.6 test_listwidget.py:1.7 test_multicheckboxwidget.py:1.7 test_multilistwidget.py:1.7 test_passwordwidget.py:1.7 test_radiowidget.py:1.8 test_textareawidget.py:1.7 test_textwidget.py:1.6 test_vocabularywidget.py:1.17
Fred L. Drake, Jr.
fred@zope.com
Thu, 5 Jun 2003 10:23:05 -0400
Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv5246
Modified Files:
test_browserwidget.py test_checkboxwidget.py
test_filewidget.py test_listwidget.py
test_multicheckboxwidget.py test_multilistwidget.py
test_passwordwidget.py test_radiowidget.py
test_textareawidget.py test_textwidget.py
test_vocabularywidget.py
Added Files:
support.py
Log Message:
Move support methods to a mix-in class provided by a utility module.
This can also be used by other packages that provide specialized widgets.
Removed the underscore from the _verifyResult() method name.
=== Added File Zope3/src/zope/app/browser/form/tests/support.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""General test support."""
class VerifyResults:
"""Mix-in for test classes with helpers for checking string data."""
def verifyResult(self, result, check_list, inorder=False):
start = 0
for check in check_list:
pos = result.find(check, start)
self.assert_(pos >= 0,
"%r not found in %r" % (check, result[start:]))
if inorder:
start = pos + len(check)
def verifyResultMissing(self, result, check_list):
for check in check_list:
self.assert_(result.find(check) < 0,
"%r unexpectedly found in %r" % (check, result))
=== Zope3/src/zope/app/browser/form/tests/test_browserwidget.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/browser/form/tests/test_browserwidget.py:1.11 Thu May 22 18:49:04 2003
+++ Zope3/src/zope/app/browser/form/tests/test_browserwidget.py Thu Jun 5 10:23:05 2003
@@ -27,9 +27,12 @@
import os
import unittest
from zope.testing.doctestunit import DocTestSuite
+from zope.app.browser.form.tests import support
import zope.app.browser.form.tests
-class BrowserWidgetTest(PlacelessSetup, unittest.TestCase):
+class BrowserWidgetTest(PlacelessSetup,
+ support.VerifyResults,
+ unittest.TestCase):
_FieldFactory = Text
_WidgetFactory = BrowserWidget
@@ -41,11 +44,6 @@
request.form['field.foo'] = u'Foo Value'
self._widget = self._WidgetFactory(field, request)
- def _verifyResult(self, result, check_list):
- for check in check_list:
- self.assertNotEqual(-1, result.find(check),
- '"'+check+'" not found in "'+result+'"')
-
def test_required(self):
self._widget.context.required = False
self.failIf(self._widget.required)
@@ -68,12 +66,12 @@
check_list = ('type="text"', 'id="field.foo"', 'name="field.foo"',
'value="Foo Value"')
self._widget.setData(value)
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('type="hidden"',) + check_list[1:]
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
check_list = ('type="hidden"', 'style="color: red"') + check_list[1:]
self._widget.extra = 'style="color: red"'
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
def testLabel(self):
label = ' '.join(self._widget.label().strip().split())
=== Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py:1.7 Thu May 22 18:50:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_checkboxwidget.py Thu Jun 5 10:23:05 2003
@@ -39,16 +39,16 @@
self._widget.setData(value)
check_list = ('type="checkbox"', 'id="field.foo"',
'name="field.foo"', 'checked="checked"')
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
value = 0
self._widget.setData(value)
check_list = check_list[:-1]
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('type="hidden"',) + check_list[1:-1]
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
def test_getData(self):
self._widget.request.form['field.foo'] = 'on'
=== Zope3/src/zope/app/browser/form/tests/test_filewidget.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/browser/form/tests/test_filewidget.py:1.5 Thu May 22 18:50:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_filewidget.py Thu Jun 5 10:23:05 2003
@@ -47,12 +47,12 @@
check_list = ('type="file"', 'id="field.foo"', 'name="field.foo"',
'size="20"')
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('type="hidden"',) + check_list[1:-1]
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
=== Zope3/src/zope/app/browser/form/tests/test_listwidget.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/form/tests/test_listwidget.py:1.6 Thu May 22 18:50:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_listwidget.py Thu Jun 5 10:23:05 2003
@@ -36,11 +36,11 @@
def testRenderItem(self):
check_list = ('option', 'value="foo"', 'Foo')
- self._verifyResult(
+ self.verifyResult(
self._widget.renderItem(0, 'Foo', 'foo', 'field.bar', None),
check_list)
check_list += ('selected="selected"',)
- self._verifyResult(
+ self.verifyResult(
self._widget.renderSelectedItem(
0, 'Foo', 'foo', 'field.bar', None),
check_list)
@@ -49,8 +49,8 @@
def testRenderItems(self):
check_list = ('option', 'value="foo"', 'bar',
'value="foo"', 'foo', 'selected="selected"')
- self._verifyResult('\n'.join(self._widget.renderItems('foo')),
- check_list)
+ self.verifyResult('\n'.join(self._widget.renderItems('foo')),
+ check_list)
def testRender(self):
@@ -59,14 +59,14 @@
'size="5"', 'option', 'value="foo"', '>foo<',
'value="foo"', '>bar<', 'selected="selected"')
self._widget.setData(value)
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('type="hidden"', 'id="field.foo"', 'name="field.foo"',
'value="foo"')
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
=== Zope3/src/zope/app/browser/form/tests/test_multicheckboxwidget.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/form/tests/test_multicheckboxwidget.py:1.6 Thu May 22 18:50:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_multicheckboxwidget.py Thu Jun 5 10:23:05 2003
@@ -36,11 +36,11 @@
def testRenderItem(self):
check_list = ('type="checkbox"', 'id="field.bar"',
'name="field.bar"', 'value="foo"', 'Foo')
- self._verifyResult(
+ self.verifyResult(
self._widget.renderItem(0, 'Foo', 'foo', 'field.bar', None),
check_list)
check_list += ('checked="checked"',)
- self._verifyResult(
+ self.verifyResult(
self._widget.renderSelectedItem(
0, 'Foo', 'foo', 'field.bar', None),
check_list)
@@ -50,8 +50,8 @@
check_list = ('type="checkbox"', 'id="field.foo"',
'name="field.foo"', 'value="bar"', 'bar',
'value="foo"', 'foo', 'checked="checked"')
- self._verifyResult('\n'.join(self._widget.renderItems('bar')),
- check_list)
+ self.verifyResult('\n'.join(self._widget.renderItems('bar')),
+ check_list)
def testRender(self):
@@ -60,14 +60,14 @@
check_list = ('type="checkbox"', 'id="field.foo"',
'name="field.foo"', 'value="bar"', 'bar',
'value="foo"', 'foo', 'checked="checked"')
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('type="hidden"', 'id="field.foo"', 'name="field.foo"',
'value="bar"')
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
def test_suite():
=== Zope3/src/zope/app/browser/form/tests/test_multilistwidget.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/form/tests/test_multilistwidget.py:1.6 Thu May 22 18:50:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_multilistwidget.py Thu Jun 5 10:23:05 2003
@@ -35,11 +35,11 @@
def testRenderItem(self):
check_list = ('option', 'value="foo"', 'Foo')
- self._verifyResult(
+ self.verifyResult(
self._widget.renderItem(0, 'Foo', 'foo', 'field.bar', None),
check_list)
check_list += ('selected="selected"',)
- self._verifyResult(
+ self.verifyResult(
self._widget.renderSelectedItem(
0, 'Foo', 'foo', 'field.bar', None),
check_list)
@@ -47,8 +47,8 @@
def testRenderItems(self):
check_list = ('option', 'value="foo"', 'bar',
'value="foo"', 'foo', 'selected="selected"')
- self._verifyResult('\n'.join(self._widget.renderItems('foo')),
- check_list)
+ self.verifyResult('\n'.join(self._widget.renderItems('foo')),
+ check_list)
def testRender(self):
@@ -58,14 +58,14 @@
'size="5"', 'option', 'value="foo"', '>foo<',
'value="foo"', '>bar<', 'selected="selected"',
'multiple="multiple"')
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('type="hidden"', 'id="field.foo"', 'name="field.foo"',
'value="foo"')
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
=== Zope3/src/zope/app/browser/form/tests/test_passwordwidget.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/form/tests/test_passwordwidget.py:1.6 Thu May 22 18:50:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_passwordwidget.py Thu Jun 5 10:23:05 2003
@@ -38,7 +38,7 @@
self._widget.setData(value)
check_list = ('type="password"', 'id="field.foo"',
'name="field.foo"', 'value=""', 'size="20"')
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
def testHidden(self):
self.assertRaises(NotImplementedError, self._widget.hidden)
=== Zope3/src/zope/app/browser/form/tests/test_radiowidget.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/browser/form/tests/test_radiowidget.py:1.7 Thu May 22 18:50:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_radiowidget.py Thu Jun 5 10:23:05 2003
@@ -37,11 +37,11 @@
def testRenderItem(self):
check_list = ('type="radio"', 'id="field.bar.0"',
'name="field.bar"', 'value="foo"', 'Foo')
- self._verifyResult(
+ self.verifyResult(
self._widget.renderItem(0, 'Foo', 'foo', 'field.bar', None),
check_list)
check_list += ('checked="checked"',)
- self._verifyResult(
+ self.verifyResult(
self._widget.renderSelectedItem(
0, 'Foo', 'foo', 'field.bar', None),
check_list)
@@ -51,8 +51,8 @@
check_list = ('type="radio"', 'id="field.foo.0"', 'name="field.foo"',
'value="bar"', 'bar', 'value="foo"', 'foo',
'checked="checked"')
- self._verifyResult('\n'.join(self._widget.renderItems('bar')),
- check_list)
+ self.verifyResult('\n'.join(self._widget.renderItems('bar')),
+ check_list)
def testRender(self):
@@ -61,14 +61,14 @@
check_list = ('type="radio"', 'id="field.foo.0"',
'name="field.foo"', 'value="bar"', 'bar',
'value="foo"', 'foo', 'checked="checked"')
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('type="hidden"', 'id="field.foo"',
'name="field.foo"', 'value="bar"')
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
def testLabel(self):
label = ' '.join(self._widget.label().strip().split())
=== Zope3/src/zope/app/browser/form/tests/test_textareawidget.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/form/tests/test_textareawidget.py:1.6 Thu May 22 18:50:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_textareawidget.py Thu Jun 5 10:23:05 2003
@@ -37,13 +37,13 @@
self._widget.setData(value)
check_list = ('rows="15"', 'cols="60"', 'id="field.foo"',
'name="field.foo"', 'textarea')
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('type="hidden"', 'id="field.foo"', 'name="field.foo"',
'value="Foo Value"')
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
def testRow(self):
self._widget.request.form.clear()
=== Zope3/src/zope/app/browser/form/tests/test_textwidget.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/browser/form/tests/test_textwidget.py:1.5 Thu May 22 18:50:09 2003
+++ Zope3/src/zope/app/browser/form/tests/test_textwidget.py Thu Jun 5 10:23:05 2003
@@ -38,12 +38,12 @@
self._widget.setData(value)
check_list = ('type="text"', 'id="field.foo"', 'name="field.foo"',
'value="Foo Value"', 'size="20"')
- self._verifyResult(self._widget(), check_list)
+ self.verifyResult(self._widget(), check_list)
check_list = ('type="hidden"',) + check_list[1:-1]
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
check_list = ('style="color: red"',) + check_list
self._widget.extra = 'style="color: red"'
- self._verifyResult(self._widget.hidden(), check_list)
+ self.verifyResult(self._widget.hidden(), check_list)
=== Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py:1.16 Tue Jun 3 18:46:16 2003
+++ Zope3/src/zope/app/browser/form/tests/test_vocabularywidget.py Thu Jun 5 10:23:05 2003
@@ -17,6 +17,7 @@
import unittest
from zope.app.browser.form import vocabularywidget
+from zope.app.browser.form.tests import support
from zope.app.interfaces.browser.form import IBrowserWidget
from zope.app.interfaces.browser.form import IVocabularyQueryView
from zope.app.tests.placelesssetup import PlacelessSetup
@@ -159,7 +160,9 @@
return "multi"
-class VocabularyWidgetTestBase(PlacelessSetup, unittest.TestCase):
+class VocabularyWidgetTestBase(PlacelessSetup,
+ support.VerifyResults,
+ unittest.TestCase):
"""Base class for all the vocabulary widget tests.
This class provides version helper methods.
@@ -196,19 +199,6 @@
tr = TestRequest(QUERY_STRING=querystring)
tr.processInputs()
return tr
-
- # modified from test_browserwidget.BrowserWidgetTest:
- def verifyResult(self, result, check_list):
- """Ensure that each element of check_list is present in result."""
- for check in check_list:
- self.assert_(result.find(check) >= 0,
- "%r not found in %r" % (check, result))
-
- def verifyResultMissing(self, result, check_list):
- """Ensure that each element of check_list is omitted from result."""
- for check in check_list:
- self.assert_(result.find(check) < 0,
- "%r unexpectedly found in %r" % (check, result))
class SingleSelectionViews: