[Checkins] SVN: zope.schema/trunk/ - Stop using the old set type and silence tests on Python2.4

Christian Theune ct at gocept.com
Fri Jan 30 11:25:10 EST 2009


Log message for revision 95582:
  - Stop using the old set type and silence tests on Python2.4
  

Changed:
  U   zope.schema/trunk/CHANGES.txt
  U   zope.schema/trunk/src/zope/schema/_field.py
  U   zope.schema/trunk/src/zope/schema/interfaces.py
  U   zope.schema/trunk/src/zope/schema/tests/test_setfield.py
  U   zope.schema/trunk/src/zope/schema/validation.txt

-=-
Modified: zope.schema/trunk/CHANGES.txt
===================================================================
--- zope.schema/trunk/CHANGES.txt	2009-01-30 16:19:41 UTC (rev 95581)
+++ zope.schema/trunk/CHANGES.txt	2009-01-30 16:25:09 UTC (rev 95582)
@@ -1,10 +1,14 @@
-=========
- Changes
-=========
+=======
+Changes
+=======
 
 3.5.1dev (unreleased)
 ---------------------
 
+- Stop using the old old set type.
+
+- Make tests compatible and silent with Python 2.4.
+
 - Fix __cmp__ method in ValidationError. Show some side effects based on the
   existing __cmp__ implementation. See validation.txt
 

Modified: zope.schema/trunk/src/zope/schema/_field.py
===================================================================
--- zope.schema/trunk/src/zope/schema/_field.py	2009-01-30 16:19:41 UTC (rev 95581)
+++ zope.schema/trunk/src/zope/schema/_field.py	2009-01-30 16:25:09 UTC (rev 95582)
@@ -22,11 +22,6 @@
 import decimal
 from datetime import datetime, date, timedelta, time
 import sys
-if sys.version_info < (2, 6): # deprecation warnings
-    from sets import Set as SetType
-    SET_TYPES = SetType, set
-else:
-    SET_TYPES = set,
 
 from zope.event import notify
 
@@ -418,7 +413,7 @@
 class Set(AbstractCollection):
     """A field representing a set."""
     implements(ISet)
-    _type = SET_TYPES
+    _type = set
     def __init__(self, **kw):
         if 'unique' in kw: # set members are always unique
             raise TypeError(

Modified: zope.schema/trunk/src/zope/schema/interfaces.py
===================================================================
--- zope.schema/trunk/src/zope/schema/interfaces.py	2009-01-30 16:19:41 UTC (rev 95581)
+++ zope.schema/trunk/src/zope/schema/interfaces.py	2009-01-30 16:25:09 UTC (rev 95582)
@@ -424,8 +424,8 @@
     Python list."""
 
 class ISet(IAbstractSet):
-    u"""Field containing a value that implements the API of a conventional
-    Python standard library sets.Set or a Python 2.4+ set."""
+    u"""Field containing a value that implements the API of a Python2.4+ set.
+    """
 
 class IFrozenSet(IAbstractSet):
     u"""Field containing a value that implements the API of a conventional

Modified: zope.schema/trunk/src/zope/schema/tests/test_setfield.py
===================================================================
--- zope.schema/trunk/src/zope/schema/tests/test_setfield.py	2009-01-30 16:19:41 UTC (rev 95581)
+++ zope.schema/trunk/src/zope/schema/tests/test_setfield.py	2009-01-30 16:25:09 UTC (rev 95582)
@@ -27,13 +27,6 @@
 from zope.schema.interfaces import TooShort, TooLong
 from zope.schema.tests.test_field import CollectionFieldTestBase
 
-def _oldSet(values=()):
-    # Avoid importing 'sets' in Python 2.6, where it generates deprectaions.
-    import sys
-    if sys.version_info < (2, 6): # deprecation warnings
-        from sets import Set as SetType
-        return SetType(values)
-    return set(values)
 
 class SetTest(CollectionFieldTestBase):
     """Test the Tuple Field."""
@@ -44,12 +37,12 @@
         field = Set(title=u'Set field', description=u'',
                     readonly=False, required=False)
         field.validate(None)
-        field.validate(_oldSet())
-        field.validate(_oldSet((1, 2)))
-        field.validate(_oldSet((3,)))
         field.validate(set())
         field.validate(set((1, 2)))
         field.validate(set((3,)))
+        field.validate(set())
+        field.validate(set((1, 2)))
+        field.validate(set((3,)))
 
         self.assertRaises(WrongType, field.validate, [1, 2, 3])
         self.assertRaises(WrongType, field.validate, 'abc')
@@ -61,20 +54,20 @@
     def testValidateRequired(self):
         field = Set(title=u'Set field', description=u'',
                     readonly=False, required=True)
-        field.validate(_oldSet())
-        field.validate(_oldSet((1, 2)))
-        field.validate(_oldSet((3,)))
         field.validate(set())
         field.validate(set((1, 2)))
         field.validate(set((3,)))
+        field.validate(set())
+        field.validate(set((1, 2)))
+        field.validate(set((3,)))
 
         self.assertRaises(RequiredMissing, field.validate, None)
 
     def testValidateRequiredAltMissingValue(self):
         missing = object()
         field = Set(required=True, missing_value=missing)
-        field.validate(_oldSet())
         field.validate(set())
+        field.validate(set())
 
         self.assertRaises(RequiredMissing, field.validate, missing)
 
@@ -91,59 +84,59 @@
         field = Set(title=u'Set field', description=u'',
                     readonly=False, required=False, min_length=2)
         field.validate(None)
-        field.validate(_oldSet((1, 2)))
-        field.validate(_oldSet((1, 2, 3)))
         field.validate(set((1, 2)))
         field.validate(set((1, 2, 3)))
+        field.validate(set((1, 2)))
+        field.validate(set((1, 2, 3)))
 
-        self.assertRaises(TooShort, field.validate, _oldSet(()))
-        self.assertRaises(TooShort, field.validate, _oldSet((3,)))
         self.assertRaises(TooShort, field.validate, set(()))
         self.assertRaises(TooShort, field.validate, set((3,)))
+        self.assertRaises(TooShort, field.validate, set(()))
+        self.assertRaises(TooShort, field.validate, set((3,)))
 
     def testValidateMaxValues(self):
         field = Set(title=u'Set field', description=u'',
                     readonly=False, required=False, max_length=2)
         field.validate(None)
-        field.validate(_oldSet())
-        field.validate(_oldSet((1, 2)))
         field.validate(set())
         field.validate(set((1, 2)))
+        field.validate(set())
+        field.validate(set((1, 2)))
 
-        self.assertRaises(TooLong, field.validate, _oldSet((1, 2, 3, 4)))
-        self.assertRaises(TooLong, field.validate, _oldSet((1, 2, 3)))
         self.assertRaises(TooLong, field.validate, set((1, 2, 3, 4)))
         self.assertRaises(TooLong, field.validate, set((1, 2, 3)))
+        self.assertRaises(TooLong, field.validate, set((1, 2, 3, 4)))
+        self.assertRaises(TooLong, field.validate, set((1, 2, 3)))
 
     def testValidateMinValuesAndMaxValues(self):
         field = Set(title=u'Set field', description=u'',
                     readonly=False, required=False,
                     min_length=1, max_length=2)
         field.validate(None)
-        field.validate(_oldSet((3,)))
-        field.validate(_oldSet((1, 2)))
         field.validate(set((3,)))
         field.validate(set((1, 2)))
+        field.validate(set((3,)))
+        field.validate(set((1, 2)))
 
-        self.assertRaises(TooShort, field.validate, _oldSet())
-        self.assertRaises(TooLong, field.validate, _oldSet((1, 2, 3)))
         self.assertRaises(TooShort, field.validate, set())
         self.assertRaises(TooLong, field.validate, set((1, 2, 3)))
+        self.assertRaises(TooShort, field.validate, set())
+        self.assertRaises(TooLong, field.validate, set((1, 2, 3)))
 
     def testValidateValueTypes(self):
         field = Set(title=u'Set field', description=u'',
                     readonly=False, required=False,
                     value_type=Int())
         field.validate(None)
-        field.validate(_oldSet((5,)))
-        field.validate(_oldSet((2, 3)))
         field.validate(set((5,)))
         field.validate(set((2, 3)))
+        field.validate(set((5,)))
+        field.validate(set((2, 3)))
 
         self.assertRaises(WrongContainedType, field.validate,
-                          _oldSet(('',)))
+                          set(('',)))
         self.assertRaises(WrongContainedType, 
-                          field.validate, _oldSet((3.14159,)))
+                          field.validate, set((3.14159,)))
         self.assertRaises(WrongContainedType, field.validate, set(('',)))
         self.assertRaises(WrongContainedType, 
                           field.validate, set((3.14159,)))
@@ -193,7 +186,7 @@
         self.assertRaises(WrongType, field.validate, {})
         self.assertRaises(WrongType, field.validate, (1, 2, 3))
         self.assertRaises(WrongType, field.validate, set((1, 2, 3)))
-        self.assertRaises(WrongType, field.validate, _oldSet((1, 2, 3)))
+        self.assertRaises(WrongType, field.validate, set((1, 2, 3)))
 
     def testValidateRequired(self):
         field = FrozenSet(title=u'Set field', description=u'',

Modified: zope.schema/trunk/src/zope/schema/validation.txt
===================================================================
--- zope.schema/trunk/src/zope/schema/validation.txt	2009-01-30 16:19:41 UTC (rev 95581)
+++ zope.schema/trunk/src/zope/schema/validation.txt	2009-01-30 16:25:09 UTC (rev 95582)
@@ -35,26 +35,39 @@
 Create an instance of TwoInts but do not set attributes. We get two errors:
 
   >>> ti = TwoInts()
-  >>> zope.schema.getValidationErrors(ITwoInts, ti)
-  [('a', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'a'",))),
-   ('b', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'b'",)))]
+  >>> r = zope.schema.getValidationErrors(ITwoInts, ti)
+  >>> r
+  [('a', SchemaNotFullyImplemented(<exceptions.AttributeError instance at 0x...>)),
+   ('b', SchemaNotFullyImplemented(<exceptions.AttributeError instance at 0x...>))]
+  >>> r[0][1].args[0].args
+  ("'TwoInts' object has no attribute 'a'",)
+  >>> r[1][1].args[0].args
+  ("'TwoInts' object has no attribute 'b'",)
 
 The `getSchemaValidationErrors` function returns the same result:
 
-  >>> zope.schema.getSchemaValidationErrors(ITwoInts, ti)
-  [('a', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'a'",))),
-   ('b', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'b'",)))]
+  >>> r = zope.schema.getSchemaValidationErrors(ITwoInts, ti)
+  >>> r
+  [('a', SchemaNotFullyImplemented(<exceptions.AttributeError instance at 0x...>)),
+   ('b', SchemaNotFullyImplemented(<exceptions.AttributeError instance at 0x...>))]
+  >>> r[0][1].args[0].args
+  ("'TwoInts' object has no attribute 'a'",)
+  >>> r[1][1].args[0].args
+  ("'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.
 
-When we set an invalid value for `a` we still get the same error for `b`:
+When we set a valid value for `a` we still get the same error for `b`:
 
   >>> ti.a = 11
   >>> errors = zope.schema.getValidationErrors(ITwoInts, ti)
   >>> errors
   [('a', TooBig(11, 10)),
-   ('b', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'b'",)))]
+   ('b', SchemaNotFullyImplemented(<exceptions.AttributeError instance at 0x...>))]
+  >>> errors[1][1].args[0].args
+  ("'TwoInts' object has no attribute 'b'",)
+
   >>> errors[0][1].doc()
   u'Value is too big'
 
@@ -63,8 +76,11 @@
 left:
 
   >>> ti.a = 8
-  >>> zope.schema.getValidationErrors(ITwoInts, ti)
-  [('b', SchemaNotFullyImplemented(AttributeError("'TwoInts' object has no attribute 'b'",)))]
+  >>> r = zope.schema.getValidationErrors(ITwoInts, ti)
+  >>> r
+  [('b', SchemaNotFullyImplemented(<exceptions.AttributeError instance at 0x...>))]
+  >>> r[0][1].args[0].args
+  ("'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