stop using RuntimeError in unit tests, for #639
authorBrian Warner <warner@lothar.com>
Mon, 23 Feb 2009 00:27:22 +0000 (17:27 -0700)
committerBrian Warner <warner@lothar.com>
Mon, 23 Feb 2009 00:27:22 +0000 (17:27 -0700)
src/allmydata/test/test_upload.py
src/allmydata/test/test_util.py
src/allmydata/test/test_web.py

index d1c7531c2cb79616c215eb309ca0e72f659df7f1..a0bc7984fbe94f01b4002d9a4e4fd89eb4986860 100644 (file)
@@ -182,6 +182,9 @@ class FakeClient:
     def get_cancel_secret(self):
         return ""
 
+class GotTooFarError(Exception):
+    pass
+
 class GiganticUploadable(upload.FileHandle):
     def __init__(self, size):
         self._size = size
@@ -197,7 +200,7 @@ class GiganticUploadable(upload.FileHandle):
         self._fp += length
         if self._fp > 1000000:
             # terminate the test early.
-            raise RuntimeError("we shouldn't be allowed to get this far")
+            raise GotTooFarError("we shouldn't be allowed to get this far")
         return defer.succeed(["\x00" * length])
     def close(self):
         pass
index 8d9796671c76294271ce26df49a06ab9259ca074..246b2b989e6ee0a91f097490a6af8c9e9901266c 100644 (file)
@@ -51,17 +51,17 @@ class HumanReadable(unittest.TestCase):
         self.failUnlessEqual(hr([1,2]), "[1, 2]")
         self.failUnlessEqual(hr({1:2}), "{1:2}")
         try:
-            raise RuntimeError
+            raise ValueError
         except Exception, e:
             self.failUnless(
-                hr(e) == "<RuntimeError: ()>" # python-2.4
-                or hr(e) == "RuntimeError()") # python-2.5
+                hr(e) == "<ValueError: ()>" # python-2.4
+                or hr(e) == "ValueError()") # python-2.5
         try:
-            raise RuntimeError("oops")
+            raise ValueError("oops")
         except Exception, e:
             self.failUnless(
-                hr(e) == "<RuntimeError: 'oops'>" # python-2.4
-                or hr(e) == "RuntimeError('oops',)") # python-2.5
+                hr(e) == "<ValueError: 'oops'>" # python-2.4
+                or hr(e) == "ValueError('oops',)") # python-2.5
         try:
             raise NoArgumentException
         except Exception, e:
@@ -531,12 +531,12 @@ class DeferredUtilTests(unittest.TestCase):
         d1.addErrback(lambda _ignore: None)
         d2.addErrback(lambda _ignore: None)
         d1.callback(1)
-        d2.errback(RuntimeError())
+        d2.errback(ValueError())
         self.failUnlessEqual(good, [])
         self.failUnlessEqual(len(bad), 1)
         f = bad[0]
         self.failUnless(isinstance(f, failure.Failure))
-        self.failUnless(f.check(RuntimeError))
+        self.failUnless(f.check(ValueError))
 
 class HashUtilTests(unittest.TestCase):
 
@@ -694,7 +694,7 @@ class Limiter(unittest.TestCase):
         return d
 
     def bad_job(self, i, foo):
-        raise RuntimeError("bad_job %d" % i)
+        raise ValueError("bad_job %d" % i)
 
     def test_limiter(self):
         self.calls = []
@@ -740,7 +740,7 @@ class Limiter(unittest.TestCase):
             def _good(res):
                 self.fail("should have failed, not got %s" % (res,))
             def _err(f):
-                f.trap(RuntimeError)
+                f.trap(ValueError)
                 self.failUnless("bad_job 21" in str(f))
             d2.addCallbacks(_good, _err)
             return d2
index 9aa5929cf2b0f27ca80176abc08c6b73c2220242..accaa5aac7429557cdb12095ab53077021319a6d 100644 (file)
@@ -2973,7 +2973,7 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase):
                 sf = ShareFile(fn)
                 num_leases = len(list(sf.iter_leases()))
             else:
-                raise RuntimeError("can't get leases on %s" % u)
+                raise ValueError("can't count leases on %s" % u)
         lease_counts.append( (fn, num_leases) )
         return lease_counts