[Checkins] SVN: zope.schema/trunk/ Rework 'repr' of the validation error to make it output more sensible information.
Dan Korostelev
nadako at gmail.com
Fri Jan 16 17:10:24 EST 2009
Log message for revision 94780:
Rework 'repr' of the validation error to make it output more sensible information.
Changed:
U zope.schema/trunk/CHANGES.txt
U zope.schema/trunk/src/zope/schema/_bootstrapinterfaces.py
U zope.schema/trunk/src/zope/schema/_field.py
U zope.schema/trunk/src/zope/schema/validation.txt
-=-
Modified: zope.schema/trunk/CHANGES.txt
===================================================================
--- zope.schema/trunk/CHANGES.txt 2009-01-16 17:25:06 UTC (rev 94779)
+++ zope.schema/trunk/CHANGES.txt 2009-01-16 22:10:24 UTC (rev 94780)
@@ -8,7 +8,11 @@
- Fix __cmp__ method in ValidationError. Show some side effects based on the
existing __cmp__ implementation. See validation.txt
+- Make 'repr' of the ValidationError and its subclasses more sensible. This
+ may require you to adapt your doctests for the new style, but now it makes
+ much more sense for debugging for developers.
+
3.5.0a2 (2008/12/11)
--------------------
Modified: zope.schema/trunk/src/zope/schema/_bootstrapinterfaces.py
===================================================================
--- zope.schema/trunk/src/zope/schema/_bootstrapinterfaces.py 2009-01-16 17:25:06 UTC (rev 94779)
+++ zope.schema/trunk/src/zope/schema/_bootstrapinterfaces.py 2009-01-16 22:10:24 UTC (rev 94780)
@@ -39,7 +39,7 @@
return cmp(self.args, other.args)
def __repr__(self):
- return ' '.join(map(str, self.args))
+ return '%s(%s)' % (self.__class__.__name__, ', '.join(repr(arg) for arg in self.args))
class RequiredMissing(ValidationError):
__doc__ = _("""Required input is missing.""")
Modified: zope.schema/trunk/src/zope/schema/_field.py
===================================================================
--- zope.schema/trunk/src/zope/schema/_field.py 2009-01-16 17:25:06 UTC (rev 94779)
+++ zope.schema/trunk/src/zope/schema/_field.py 2009-01-16 22:10:24 UTC (rev 94780)
@@ -344,7 +344,7 @@
>>> errors = _validate_sequence(field, ('foo', u'bar', 1))
>>> errors
- [foo <type 'unicode'>, 1 <type 'unicode'>]
+ [WrongType('foo', <type 'unicode'>), WrongType(1, <type 'unicode'>)]
The only valid value in the sequence is the second item. The others
generated errors.
@@ -354,7 +354,7 @@
>>> errors = _validate_sequence(field, (2, u'baz'), errors)
>>> errors
- [foo <type 'unicode'>, 1 <type 'unicode'>, 2 <type 'unicode'>]
+ [WrongType('foo', <type 'unicode'>), WrongType(1, <type 'unicode'>), WrongType(2, <type 'unicode'>)]
"""
if errors is None:
Modified: zope.schema/trunk/src/zope/schema/validation.txt
===================================================================
--- zope.schema/trunk/src/zope/schema/validation.txt 2009-01-16 17:25:06 UTC (rev 94779)
+++ zope.schema/trunk/src/zope/schema/validation.txt 2009-01-16 22:10:24 UTC (rev 94780)
@@ -36,15 +36,15 @@
>>> ti = TwoInts()
>>> zope.schema.getValidationErrors(ITwoInts, ti)
- [('a', 'TwoInts' object has no attribute 'a'),
- ('b', 'TwoInts' object has no attribute 'b')]
+ [('a', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'a'",))),
+ ('b', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'b'",)))]
The `getSchemaValidationErrors` function returns the same result:
>>> zope.schema.getSchemaValidationErrors(ITwoInts, ti)
- [('a', 'TwoInts' object has no attribute 'a'),
- ('b', 'TwoInts' object has no attribute 'b')]
-
+ [('a', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'a'",))),
+ ('b', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'b'",)))]
+
Note that see no error from the invariant because the invariants are not
vaildated if there are other schema errors.
@@ -53,8 +53,8 @@
>>> ti.a = 11
>>> errors = zope.schema.getValidationErrors(ITwoInts, ti)
>>> errors
- [('a', 11 10),
- ('b', 'TwoInts' object has no attribute 'b')]
+ [('a', TooBig(11, 10)),
+ ('b', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'b'",)))]
>>> errors[0][1].doc()
u'Value is too big'
@@ -64,7 +64,7 @@
>>> ti.a = 8
>>> zope.schema.getValidationErrors(ITwoInts, ti)
- [('b', 'TwoInts' object has no attribute 'b')]
+ [('b', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'b'",)))]
After setting valid value for `b` the schema is valid so the invariants are
More information about the Checkins
mailing list