[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Merge revision 26859 from the ZopeX3-3.0 branch.

Fred L. Drake, Jr. fdrake at gmail.com
Fri Jul 30 17:04:10 EDT 2004


Log message for revision 26860:
  Merge revision 26859 from the ZopeX3-3.0 branch.
  
  testing that assert statements are triggered does not work when running with
  Python's -O option, since that throws out the assertions
  
  use statements other than assert, and raise specific exceptions that make
  sense for the errors being detected
  


Changed:
  U   Zope3/trunk/src/zope/app/apidoc/utilities.py
  U   Zope3/trunk/src/zope/schema/tests/test_vocabulary.py
  U   Zope3/trunk/src/zope/schema/vocabulary.py


-=-
Modified: Zope3/trunk/src/zope/app/apidoc/utilities.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/utilities.py	2004-07-30 20:39:29 UTC (rev 26859)
+++ Zope3/trunk/src/zope/app/apidoc/utilities.py	2004-07-30 21:04:10 UTC (rev 26860)
@@ -295,11 +295,12 @@
       
       >>> try:
       ...     getFunctionSignature('func')
-      ... except AssertionError:
+      ... except TypeError:
       ...     print 'Argument not a function or method.'
       Argument not a function or method.
     """
-    assert type(func) in (types.FunctionType, types.MethodType)
+    if not isinstance(func, (types.FunctionType, types.MethodType)):
+        raise TypeError("func must be a function or method")
     
     args, varargs, varkw, default = inspect.getargspec(func)
     placeholder = object()
@@ -390,9 +391,9 @@
     This function is nice, if you have an attribute name which you retrieved
     from a class and want to know which interface requires it to be there.
 
-    Either `interfaces` or `klass` must be specified. If `interfaces` is not
-    specified, the `klass` is used to retrieve a list of
-    interfaces. `interfaces` must be iteratable.
+    Either 'interfaces' or 'klass' must be specified. If 'interfaces' is not
+    specified, the 'klass' is used to retrieve a list of
+    interfaces. 'interfaces' must be iterable.
 
     `asPath` specifies whether the dotted name of the interface or the
     interface object is returned.
@@ -428,14 +429,18 @@
       >>> getInterfaceForAttribute('attr2', klass=Sample) is None
       True
 
-      >>> try:
-      ...     getInterfaceForAttribute('getAttr')
-      ... except AssertionError:
-      ...     print 'need to specify the interfaces or a klass'
-      need to specify the interfaces or a klass
+      >>> getInterfaceForAttribute('getAttr')
+      Traceback (most recent call last):
+      ValueError: need to specify interfaces or klass
+      >>> getInterfaceForAttribute('getAttr', interfaces=(I1,I2), klass=Sample)
+      Traceback (most recent call last):
+      ValueError: must specify only one of interfaces and klass
 
     """
-    assert (interfaces is _marker) != (klass is _marker)
+    if (interfaces is _marker) and (klass is _marker):
+        raise ValueError("need to specify interfaces or klass")
+    if (interfaces is not _marker) and (klass is not _marker):
+        raise ValueError("must specify only one of interfaces and klass")
 
     if interfaces is _marker:
         direct_interfaces = list(implementedBy(klass))

Modified: Zope3/trunk/src/zope/schema/tests/test_vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/schema/tests/test_vocabulary.py	2004-07-30 20:39:29 UTC (rev 26859)
+++ Zope3/trunk/src/zope/schema/tests/test_vocabulary.py	2004-07-30 21:04:10 UTC (rev 26860)
@@ -145,10 +145,10 @@
 
     def test_nonunique_tokens(self):
         self.assertRaises(
-            AssertionError, vocabulary.SimpleVocabulary.fromValues,
+            ValueError, vocabulary.SimpleVocabulary.fromValues,
             [2, '2'])
         self.assertRaises(
-            AssertionError, vocabulary.SimpleVocabulary.fromItems, 
+            ValueError, vocabulary.SimpleVocabulary.fromItems, 
             [(1, 'one'), ('1', 'another one')])
 
     def test_overriding_createTerm(self):

Modified: Zope3/trunk/src/zope/schema/vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/schema/vocabulary.py	2004-07-30 20:39:29 UTC (rev 26859)
+++ Zope3/trunk/src/zope/schema/vocabulary.py	2004-07-30 21:04:10 UTC (rev 26860)
@@ -63,8 +63,9 @@
         for term in self._terms:
             self.by_value[term.value] = term
             self.by_token[term.token] = term
-        assert len(self.by_value) == len(self.by_token) == len(terms), \
-               'Supplied vocabulary values resulted in duplicate term tokens'
+        if not (len(self.by_value) == len(self.by_token) == len(terms)):
+            raise ValueError(
+                'Supplied vocabulary values resulted in duplicate term tokens')
         if interfaces:
             directlyProvides(self, *interfaces)
 



More information about the Zope3-Checkins mailing list