[Checkins] SVN: zc.form/trunk/ - Fixed tests to run with ``zope.schema`` >= 3.6.
Michael Howitz
mh at gocept.com
Thu Mar 10 02:56:37 EST 2011
Log message for revision 120835:
- Fixed tests to run with ``zope.schema`` >= 3.6.
- Using Python's ``doctest`` module instead of depreacted
``zope.testing.doctest``.
Changed:
A zc.form/trunk/CHANGES.txt
U zc.form/trunk/setup.py
D zc.form/trunk/src/zc/form/CHANGES.txt
U zc.form/trunk/src/zc/form/browser/combinationwidget.txt
U zc.form/trunk/src/zc/form/browser/ftests.py
U zc.form/trunk/src/zc/form/browser/tests.py
U zc.form/trunk/src/zc/form/field.py
U zc.form/trunk/src/zc/form/tests.py
-=-
Copied: zc.form/trunk/CHANGES.txt (from rev 120834, zc.form/trunk/src/zc/form/CHANGES.txt)
===================================================================
--- zc.form/trunk/CHANGES.txt (rev 0)
+++ zc.form/trunk/CHANGES.txt 2011-03-10 07:56:37 UTC (rev 120835)
@@ -0,0 +1,22 @@
+==================
+CHANGES in zc.form
+==================
+
+0.2 (unreleased)
+----------------
+
+- Fixed tests to run with ``zope.schema`` >= 3.6.
+
+- Using Python's ``doctest`` module instead of depreacted
+ ``zope.testing.doctest``.
+
+
+
+0.1
+---
+
+- Exception views are now unicode aware. They used to break on translated
+ content.
+
+- Added use_default_for_not_selected to Union field to use default
+ value even if sub field is not selected.
Modified: zc.form/trunk/setup.py
===================================================================
--- zc.form/trunk/setup.py 2011-03-10 07:45:52 UTC (rev 120834)
+++ zc.form/trunk/setup.py 2011-03-10 07:56:37 UTC (rev 120835)
@@ -28,7 +28,7 @@
'zope.index',
'zope.interface',
'zope.publisher',
- 'zope.schema',
+ 'zope.schema >= 3.6',
# extras
'zope.app.security',
'zope.app.appsetup',
Deleted: zc.form/trunk/src/zc/form/CHANGES.txt
===================================================================
--- zc.form/trunk/src/zc/form/CHANGES.txt 2011-03-10 07:45:52 UTC (rev 120834)
+++ zc.form/trunk/src/zc/form/CHANGES.txt 2011-03-10 07:56:37 UTC (rev 120835)
@@ -1,12 +0,0 @@
-==================
-CHANGES in zc.form
-==================
-
-0.1
----
-
-- Exception views are now unicode aware. They used to break on translated
- content.
-
-- Added use_default_for_not_selected to Union field to use default
- value even if sub field is not selected.
Modified: zc.form/trunk/src/zc/form/browser/combinationwidget.txt
===================================================================
--- zc.form/trunk/src/zc/form/browser/combinationwidget.txt 2011-03-10 07:45:52 UTC (rev 120834)
+++ zc.form/trunk/src/zc/form/browser/combinationwidget.txt 2011-03-10 07:56:37 UTC (rev 120835)
@@ -114,9 +114,9 @@
>>> widget.setPrefix('field')
>>> widget.getInputValue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Traceback (most recent call last):
- ...
WidgetInputError: ('acceptable_count', u'Acceptable Count',
- <zope.app.form.interfaces.WidgetInputError instance at ...>)
+ WidgetInputError('combination_00', u'Minimum',
+ RequiredMissing('combination_00')))
>>> import zope.app.form.browser.interfaces
>>> import zope.app.form.interfaces
>>> import zope.publisher.interfaces.browser
@@ -153,10 +153,10 @@
>>> request.form['field.acceptable_count.combination_01'] = '10'
>>> widget = CombinationWidget(IDemo['acceptable_count'], request)
>>> widget.setPrefix('field')
- >>> widget.getInputValue() # doctest: +ELLIPSIS
+ >>> widget.getInputValue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Traceback (most recent call last):
- ...
- WidgetInputError: ('acceptable_count', u'Acceptable Count', ${minimum} ...
+ WidgetInputError: ('acceptable_count', u'Acceptable Count',
+ MessageValidationError(u'${minimum} ...
>>> print widget() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<...
...<input class="textType" id="field.acceptable_count.combination_00"
Modified: zc.form/trunk/src/zc/form/browser/ftests.py
===================================================================
--- zc.form/trunk/src/zc/form/browser/ftests.py 2011-03-10 07:45:52 UTC (rev 120834)
+++ zc.form/trunk/src/zc/form/browser/ftests.py 2011-03-10 07:56:37 UTC (rev 120835)
@@ -17,7 +17,7 @@
from zope import interface, component
from zope.app.testing.functional import FunctionalDocFileSuite, ZCMLLayer
-from zope.testing import doctest
+import doctest
import zope.schema.interfaces
colors = ['red', 'green', 'cerulean blue']
@@ -79,13 +79,14 @@
ZCFormLayer = ZCMLLayer(
os.path.join(here, "ftesting.zcml"), __name__, "ZCFormLayer")
+
def setUp(test):
component.provideAdapter(ColorTerms)
component.provideAdapter(SimpleColorSourceQueryView)
-
+
def test_suite():
- suite = FunctionalDocFileSuite("mruwidget.txt",
+ suite = FunctionalDocFileSuite("mruwidget.txt",
globs={'AvailableColors': AvailableColors()},
optionflags=doctest.NORMALIZE_WHITESPACE+doctest.ELLIPSIS,
setUp=setUp,
Modified: zc.form/trunk/src/zc/form/browser/tests.py
===================================================================
--- zc.form/trunk/src/zc/form/browser/tests.py 2011-03-10 07:45:52 UTC (rev 120834)
+++ zc.form/trunk/src/zc/form/browser/tests.py 2011-03-10 07:56:37 UTC (rev 120835)
@@ -11,14 +11,12 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""tests of custom widgets defined in Schema
-
-$Id: tests.py 3629 2005-10-06 21:01:27Z gary $
-"""
-import unittest
+"""tests of custom widgets defined in Schema"""
+import doctest
import re
+import unittest
-from zope.testing import doctest, module
+from zope.testing import module
from zope.app.testing import placelesssetup
import zope.traversing.adapters
@@ -36,9 +34,8 @@
import zope.app.security
import zc.form.browser
from zc.form.field import Union
-import zc.form.field
+import zc.form.field
from zc.form.browser.unionwidget import UnionWidget
-from zope.testing.doctestunit import pprint
from zope import component
import zope.app.form.interfaces
@@ -125,14 +122,14 @@
output = widget()
# remove double whitespaces
normalized_output = " ".join(output.split())
-
+
# the value of the textline field should be the default_getter's
# result
value_attr_of_textline = re.search(
'<input.*id="field.identifier.unioned_00".*(value=".*").*></div>',
normalized_output).groups()[0]
self.failUnless('secret password' in value_attr_of_textline)
-
+
# the radio button of the option field should be selected
radio_option_field = re.search(
'<input.*id="field.identifier-01"(.*)/> </td>',
@@ -155,11 +152,13 @@
output = widget() # to initialize
self.assertEquals(widget.loadValueFromRequest(), u'Foo Bar')
+
def zcml(s, execute=True):
context = xmlconfig.file('meta.zcml',
package=zc.form.browser)
return xmlconfig.string(s, context, execute=execute)
+
def pageSetUp(test):
placelesssetup.setUp(test)
component.provideAdapter(
@@ -167,6 +166,7 @@
[None],
)
+
def test_suite():
suite = unittest.makeSuite(TestUnionWidget)
suite.addTest(doctest.DocFileSuite(
@@ -178,6 +178,3 @@
setUp=pageSetUp,
tearDown=placelesssetup.tearDown),)
return suite
-
-if __name__ == "__main__":
- unittest.main(defaultTest='test_suite')
Modified: zc.form/trunk/src/zc/form/field.py
===================================================================
--- zc.form/trunk/src/zc/form/field.py 2011-03-10 07:45:52 UTC (rev 120834)
+++ zc.form/trunk/src/zc/form/field.py 2011-03-10 07:56:37 UTC (rev 120835)
@@ -62,7 +62,7 @@
... title=u'Suggested Password',
... default_getter=lambda context: u'asdf',
... constraints=(secure_password, ))
- ...
+ ...
>>> f = IDummy['suggested_password'].bind(None) # use None as context
>>> interfaces.IExtendedField.providedBy(f)
True
@@ -83,7 +83,7 @@
constraints = ()
_default = default_getter = None
-
+
def __init__(self, constraints=(), default_getter=None, **kw):
self.constraints = constraints
if default_getter is not None and 'default' in kw:
@@ -114,7 +114,7 @@
interface.implements(interfaces.IOptionField)
- def __init__(self, value=None, value_getter=None,
+ def __init__(self, value=None, value_getter=None,
identity_comparison=False, **kw):
self.value = value
self.value_getter = value_getter
@@ -140,24 +140,24 @@
class Union(BaseField):
"""
- The Union field allows a schema field to hold one of many other field
+ The Union field allows a schema field to hold one of many other field
types. For instance, you might want to make a field that can hold
- a duration *or* a date, if you are working with a PIM app. Or perhaps
+ a duration *or* a date, if you are working with a PIM app. Or perhaps
you want to have a field that can hold a string from a vocabulary *or* a
custom string. Both of these examples can be accomplished in a variety of
ways--the union field is one option.
-
+
The second example is more easily illustrated. Here is a union field that
- is a simple way of allowing "write-ins" in addition to selections from a
+ is a simple way of allowing "write-ins" in addition to selections from a
choice. We'll be very explicit about imports, in part so this can be
trivially moved to a doc file test.
-
+
Notice as you look through the example that field order does matter: the
first field as entered in the field list that validates is chosen as the
- validField; thus, even though the options in the Choice field would also
+ validField; thus, even though the options in the Choice field would also
validate in a TextLine, the Choice field is identified as the "validField"
because it is first.
-
+
>>> class IDummy(interface.Interface):
... cartoon_character = Union((
... schema.Choice(
@@ -170,7 +170,7 @@
... required=True,
... title=u'Cartoon Character',
... description=u'Your favorite cartoon character')
- ...
+ ...
>>> f = IDummy['cartoon_character']
>>> interfaces.IUnionField.providedBy(f)
True
@@ -208,13 +208,13 @@
ValueError: union must combine two or more fields
And, unsurprisingly, they must actually be fields:
-
+
>>> from zope.interface.exceptions import DoesNotImplement
>>> try:
... f = Union(('I am not a number.', 'I am a free man!'), title=u'Bar')
... except DoesNotImplement:
... print "Not a field"
- ...
+ ...
Not a field
Binding a union field also takes care of binding the contained fields:
@@ -228,12 +228,12 @@
>>> bound_f.fields[1].context is context
True
"""
-
+
interface.implements(interfaces.IUnionField)
-
+
fields = ()
use_default_for_not_selected = False
-
+
def __init__(self, fields, use_default_for_not_selected=False, **kw):
if len(fields) < 2:
raise ValueError(_("union must combine two or more fields"))
@@ -264,10 +264,10 @@
pass
else:
return field
-
+
def _validate(self, value):
if self.validField(value) is None:
- raise MessageValidationError(_no_unioned_field_validates,
+ raise MessageValidationError(_no_unioned_field_validates,
{'value': value})
class OrderedCombinationConstraint(object):
@@ -302,16 +302,16 @@
_range_less_error,
{'minimum': last, 'maximum': v})
last = v
-
+
class Combination(BaseField):
"""a combination of two or more fields, all of which may be completed.
-
+
It accepts two or more fields. It also accepts a 'constraints' argument.
Unlike the usual 'constraint' argument (which is also available), the
constraints should be a sequence of callables that take a field and a
value, and they should raise an error if there is a problem.
-
+
>>> from zc.form.field import Combination, OrderedCombinationConstraint
>>> from zope import schema, interface
>>> class IDemo(interface.Interface):
@@ -343,11 +343,11 @@
>>> f.validate((datetime.date(2005, 6, 22), None))
Traceback (most recent call last):
...
- RequiredMissing
+ RequiredMissing: combination_01
>>> f.validate(('foo', datetime.date(2005, 6, 22)))
Traceback (most recent call last):
...
- WrongType: ('foo', <type 'datetime.date'>)
+ WrongType: ('foo', <type 'datetime.date'>, 'combination_00')
>>> f.validate('foo') # doctest: +ELLIPSIS
Traceback (most recent call last):
...
@@ -366,7 +366,7 @@
interface.implements(interfaces.ICombinationField)
fields = constraints = ()
-
+
def __init__(self, fields, **kw):
if len(fields) < 2:
raise ValueError(_("combination must combine two or more fields"))
@@ -448,7 +448,7 @@
>>> field.validate('cow') # non-unicode fails, as usual with TextLine
Traceback (most recent call last):
...
- WrongType: ('cow', <type 'unicode'>)
+ WrongType: ('cow', <type 'unicode'>, 'query')
"""
class HTMLSnippet(BaseField, schema.Text):
Modified: zc.form/trunk/src/zc/form/tests.py
===================================================================
--- zc.form/trunk/src/zc/form/tests.py 2011-03-10 07:45:52 UTC (rev 120834)
+++ zc.form/trunk/src/zc/form/tests.py 2011-03-10 07:56:37 UTC (rev 120835)
@@ -11,18 +11,9 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""tests
+"""tests"""
+import doctest
-$Id: tests.py 621 2005-02-15 19:40:07Z jim $
-"""
-from unittest import TestCase, TestSuite, main, makeSuite
-from zope.testing.doctestunit import DocTestSuite
-
def test_suite():
- return TestSuite((
- DocTestSuite("zc.form.field"),
- ))
-
-if __name__ == '__main__':
- main(defaultTest='test_suite')
+ return doctest.DocTestSuite("zc.form.field")
More information about the checkins
mailing list