[Checkins] SVN: zope.schema/branches/tseaver-test_cleanup/src/zope/schema/ Rip out doctest-only 'print_' compatibility shim.
Tres Seaver
cvs-admin at zope.org
Fri Apr 20 19:20:43 UTC 2012
Log message for revision 125214:
Rip out doctest-only 'print_' compatibility shim.
Changed:
U zope.schema/branches/tseaver-test_cleanup/src/zope/schema/_compat.py
U zope.schema/branches/tseaver-test_cleanup/src/zope/schema/sources.txt
U zope.schema/branches/tseaver-test_cleanup/src/zope/schema/validation.txt
-=-
Modified: zope.schema/branches/tseaver-test_cleanup/src/zope/schema/_compat.py
===================================================================
--- zope.schema/branches/tseaver-test_cleanup/src/zope/schema/_compat.py 2012-04-20 15:34:57 UTC (rev 125213)
+++ zope.schema/branches/tseaver-test_cleanup/src/zope/schema/_compat.py 2012-04-20 19:20:39 UTC (rev 125214)
@@ -12,7 +12,6 @@
text_type = str
binary_type = bytes
integer_types = int,
- print_ = getattr(builtins, "print")
else: #pragma NO COVER
def b(s):
return s
@@ -22,48 +21,3 @@
text_type = unicode
binary_type = str
integer_types = (int, long)
-
- def print_(*args, **kwargs):
- """The new-style print function."""
- fp = kwargs.pop("file", sys.stdout)
- if fp is None:
- return
- def write(data):
- if not isinstance(data, basestring):
- data = str(data)
- fp.write(data)
- want_unicode = False
- sep = kwargs.pop("sep", None)
- if sep is not None:
- if isinstance(sep, unicode):
- want_unicode = True
- elif not isinstance(sep, str):
- raise TypeError("sep must be None or a string")
- end = kwargs.pop("end", None)
- if end is not None:
- if isinstance(end, unicode):
- want_unicode = True
- elif not isinstance(end, str):
- raise TypeError("end must be None or a string")
- if kwargs:
- raise TypeError("invalid keyword arguments to print()")
- if not want_unicode:
- for arg in args:
- if isinstance(arg, unicode):
- want_unicode = True
- break
- if want_unicode:
- newline = unicode("\n")
- space = unicode(" ")
- else:
- newline = "\n"
- space = " "
- if sep is None:
- sep = space
- if end is None:
- end = newline
- for i, arg in enumerate(args):
- if i:
- write(sep)
- write(arg)
- write(end)
Modified: zope.schema/branches/tseaver-test_cleanup/src/zope/schema/sources.txt
===================================================================
--- zope.schema/branches/tseaver-test_cleanup/src/zope/schema/sources.txt 2012-04-20 15:34:57 UTC (rev 125213)
+++ zope.schema/branches/tseaver-test_cleanup/src/zope/schema/sources.txt 2012-04-20 19:20:39 UTC (rev 125214)
@@ -60,9 +60,9 @@
`bind` method will be called with the context as its only argument. The
result must implement ISource and will be used as the source.
- >>> from zope.schema._compat import print_
+ >>> _my_binder_called = []
>>> def my_binder(context):
- ... print_("Binder was called.")
+ ... _my_binder_called.append(context)
... source = MySource()
... source.divisor = context.divisor
... return source
@@ -73,7 +73,8 @@
>>> choice = Choice(__name__='number', source=my_binder)
>>> bound = choice.bind(Context())
- Binder was called.
+ >>> len(_my_binder_called)
+ 1
>>> bound.vocabulary
<...MySource...>
>>> bound.vocabulary.divisor
@@ -85,8 +86,10 @@
>>> choice = Choice(__name__='number', source=my_binder, default=2)
+ >>> del _my_binder_called[:]
>>> bound = choice.bind(Context())
- Binder was called.
+ >>> len(_my_binder_called)
+ 1
>>> bound.validate(bound.default)
>>> bound.validate(3)
Modified: zope.schema/branches/tseaver-test_cleanup/src/zope/schema/validation.txt
===================================================================
--- zope.schema/branches/tseaver-test_cleanup/src/zope/schema/validation.txt 2012-04-20 15:34:57 UTC (rev 125213)
+++ zope.schema/branches/tseaver-test_cleanup/src/zope/schema/validation.txt 2012-04-20 19:20:39 UTC (rev 125214)
@@ -16,14 +16,14 @@
>>> import zope.interface
>>> import zope.schema
- >>> from zope.schema._compat import print_
+ >>> _a_greater_b_called = []
>>> class ITwoInts(zope.interface.Interface):
... a = zope.schema.Int(max=10)
... b = zope.schema.Int(min=5)
...
... @zope.interface.invariant
... def a_greater_b(obj):
- ... print_("Checking if a > b")
+ ... _a_greater_b_called.append(obj)
... if obj.a <= obj.b:
... raise zope.interface.Invalid("%s<=%s" % (obj.a, obj.b))
...
@@ -92,7 +92,8 @@
>>> ti.b = 10
>>> errors = zope.schema.getValidationErrors(ITwoInts, ti)
- Checking if a > b
+ >>> len(_a_greater_b_called)
+ 1
>>> errors
[(None, <zope.interface.exceptions.Invalid instance at 0x...>)]
@@ -106,9 +107,11 @@
Set `b=5` so everything is fine:
>>> ti.b = 5
+ >>> del _a_greater_b_called[:]
>>> zope.schema.getValidationErrors(ITwoInts, ti)
- Checking if a > b
[]
+ >>> len(_a_greater_b_called)
+ 1
Compare ValidationError
More information about the checkins
mailing list