[Zope-Checkins] CVS: StandaloneZODB/BTrees/tests - testConflict.py:1.8

Jeremy Hylton jeremy@zope.com
Wed, 26 Sep 2001 18:07:19 -0400


Update of /cvs-repository/StandaloneZODB/BTrees/tests
In directory cvs.zope.org:/tmp/cvs-serv7152

Modified Files:
	testConflict.py 
Log Message:
Be more specific about exception begin caugh in test_merge().

The only exceptions that an _p_resolveConflict() method should raise
are ConflictError and ValueError.  If it raises a different exception,
then it has failed.

In general, a unittest should not use a bare except clause, because
they almost always mask failures.  If the test really means to catch
all exceptions, it's best to make a comment to that effect.




=== StandaloneZODB/BTrees/tests/testConflict.py 1.7 => 1.8 ===
 from unittest import TestCase, TestSuite, TextTestRunner, makeSuite
 
+from ZODB.POSException import ConflictError
+
 class Base:
     """ Tests common to all types: sets, buckets, and BTrees """
     def tearDown(self):
@@ -382,17 +384,18 @@
     if expected is None: expected=((((),),),)
 
     if should_fail:
-        try: merged=o1._p_resolveConflict(s1, s2, s3)
-        except: pass # cool
-        else: assert 0, message
+        try:
+            merged=o1._p_resolveConflict(s1, s2, s3)
+        except (ConflictError, ValueError), err:
+            pass # ConflictError is the only exception that should occur
+        else:
+            assert 0, message
     else:
         merged=o1._p_resolveConflict(s1, s2, s3)
         assert merged==expected, message
         
 class BucketTests(MappingBase):
     """ Tests common to all buckets """
-        
-
     
 
 class BTreeTests(MappingBase):